Skip to content
Snippets Groups Projects

Build Status Coverage Status

mhcflurry

Peptide-MHC binding affinity prediction

The presentation of protein fragments by MHC molecules is central to adaptive immunity. Machine learning models of the strength of the peptide/MHC interaction are routinely used in studies of infectious diseases, autoimmune diseases, vaccine development, and cancer immunotherapy. MHCflurry is an open source implementation of neural network models for this task.

MHCflurry currently supports peptide / MHC class I affinity prediction using one model per MHC allele. The predictors may be trained on data that has been augmented with data imputed based on other alleles (see Rubinsteyn 2016). We anticipate developing a number of additional models in the future, including pan-allele and class II predictors.

You can fit MHCflurry models to your own data or download trained models that we provide. Our models are trained on data from IEDB and Kim 2014. See here for details on the training data preparation. The steps we use to train predictors on this data, including hyperparameter selection using cross validation, are here.

The MHCflurry predictors are implemented in Python using keras.

Setup

From a checkout run:

pip install .

then download the trained models (as well as some datasets used in the unit tests):

mhcflurry-downloads fetch

You can now run the unit tests if you like:

nosetests .

Making predictions

from mhcflurry import predict
predict(alleles=['A0201'], peptides=['SIINFEKL'])
  Allele   Peptide  Prediction
0  A0201  SIINFEKL  586.730529

Details on the downloaded class I allele-specific models

Besides the actual model weights, the data downloaded with mhcflurry-downloads fetch also includes a CSV file giving the hyperparameters used for each predictor. Another CSV gives the cross validation results used to select these hyperparameters.

To see the hyperparameters for the production models, run:

open "$(mhcflurry-downloads path models_class1_allele_specific_single)/production.csv"

To see the cross validation results:

open "$(mhcflurry-downloads path models_class1_allele_specific_single)/cv.csv"

Environment variables

The path where MHCflurry looks for model weights and data can be set with the MHCFLURRY_DOWNLOADS_DIR environment variable. This directory should contain subdirectories like "models_class1_allele_specific_single". Setting this variable overrides the other environment variables described below.

If you only want to change the version of the released data used, you can set MHCFLURRY_DOWNLOADS_CURRENT_RELEASE. If you want to change the base directory used for all releases, set MHCFLURRY_DATA_DIR.

By default,MHCFLURRY_DOWNLOADS_DIR is a platform specific application storage directory, MHCFLURRY_DOWNLOADS_CURRENT_RELEASE is the latest release, and MHCFLURRY_DOWNLOADS_DIR is set to $MHCFLURRY_DATA_DIR/$MHCFLURRY_DOWNLOADS_CURRENT_RELEASE.

See downloads.py for details.