MHCflurry
MHCflurry predicts which peptides are likely to be displayed by MHC class I molecules. Given peptides or protein sequences and MHC class I alleles, its pretrained models predict:
- Binding affinity: how strongly a peptide binds an MHC allele, in nM.
- Antigen processing: whether cellular processing favors the peptide.
- Presentation: a combined score using binding and processing predictions.
You can use the released models from the command line or Python, scan proteins for candidate epitopes, or train models on your own data.
In the openvax stack, MHCflurry is the built-in class I predictor: mhcgnomes normalizes its allele names, and mhctools wraps it alongside NetMHCpan and other tools behind one interface.
Install
MHCflurry needs Python 3.11 or later on Linux or macOS. Install the latest stable 2.3 patch release and download the pretrained presentation models:
pip install --upgrade "mhcflurry>=2.3,<2.4"
mhcflurry downloads fetch models_class1_presentation
The presentation bundle includes the affinity and processing components. Conda users should follow using conda. There is also a Docker image, and a Colab notebook that needs no installation at all.
Quick start
from mhcflurry import Class1PresentationPredictor
predictor = Class1PresentationPredictor.load()
df = predictor.predict(
peptides=["SIINFEKL", "NLVPMVATV"],
alleles=["HLA-A*02:01", "HLA-B*07:02"],
verbose=0,
)
print(df[["peptide", "best_allele", "affinity", "presentation_score"]])
peptide best_allele affinity presentation_score
0 SIINFEKL HLA-A*02:01 6249.061165 0.033052
1 NLVPMVATV HLA-A*02:01 34.716625 0.899710
The allele list is one MHC allele set, so each peptide gets one row reporting its strongest-binding allele. Pass a dict of sample name to allele list for several genotypes. See the Python tutorial.
Command line
Predict for peptides you supply:
mhcflurry predict \
--alleles HLA-A0201 HLA-A0301 \
--peptides SIINFEKL SIINFEKD SIINFEKQ \
--out predictions.csv
predictions.csv then holds one row per peptide and allele:
allele,peptide,mhcflurry_affinity,mhcflurry_affinity_percentile,mhcflurry_processing_score,mhcflurry_presentation_score,mhcflurry_presentation_percentile
HLA-A0201,SIINFEKL,6249.065499493528,7.964165930516958,0.40422916412353516,0.033052283100532154,6.944031455219743
HLA-A0201,SIINFEKD,23909.568760090307,37.47775351146445,0.37816470861434937,0.0073666587891107905,37.09948787355323
HLA-A0201,SIINFEKQ,18116.302643992014,24.233721813265326,0.38493812084198,0.010121858361444535,27.123365633634172
HLA-A0301,SIINFEKL,33742.20326754587,33.1477898986373,0.40422916412353516,0.005571558837167078,47.903918632744286
HLA-A0301,SIINFEKD,37091.75804533898,70.70629825509532,0.37816470861434937,0.004612722441857152,55.74056664248984
HLA-A0301,SIINFEKQ,32357.81853037747,25.848763661316145,0.38493812084198,0.00545944147265313,48.749722985590026
Or scan a protein sequence for candidate ligands:
mhcflurry predict-scan \
--sequences MFVFLVLLPLVSSQCVNLTTRTQLPPAYTNSFTRGVYYPDKVFRSSVLHS \
--alleles 'HLA-A*02:01' \
--out scan.csv
mhcflurry --help lists every subcommand, including the training, selection
and calibration workflows. The
introduction
explains how to read the output columns.
To complete subcommands and options with Tab, run
activate-global-python-argcomplete once, or add
eval "$(register-python-argcomplete mhcflurry)" to your shell startup file.
Scripts that use the older mhcflurry-* command names, such as
mhcflurry-predict, keep working; see the
2.3.0 release notes.
Documentation
Full documentation: openvax.github.io/mhcflurry.
- Introduction and installation: start here
- Command-line tutorial and Python tutorial
- Docker: published images, notebooks, and building your own
- Model weights and older releases: browse weights with
mhcflurry downloads infoand select one with--model-release - Evaluation of the 2.3.0 weights and training your own models
- Command reference and API reference
- Predicted binding motifs
Please file an issue if you have questions or encounter problems.
Development
Contributions are welcome. Start with CONTRIBUTING.md:
source develop.sh # create/activate .venv and editable-install
./lint.sh # ruff check mhcflurry/ test/
python -m pytest test/ # tests live in test/, singular
The testing guide describes the fast local checks and the full suite.
Citation
If you use MHCflurry in your research, please cite:
T. O'Donnell, A. Rubinsteyn, U. Laserson. "MHCflurry 2.0: Improved pan-allele prediction of MHC I-presented peptides by incorporating antigen processing," Cell Systems, 2020. https://doi.org/10.1016/j.cels.2020.06.010
T. O'Donnell, A. Rubinsteyn, M. Bonsack, A. B. Riemer, U. Laserson, and J. Hammerbacher, "MHCflurry: Open-Source Class I MHC Binding Affinity Prediction," Cell Systems, 2018. https://doi.org/10.1016/j.cels.2018.05.014
License
MHCflurry is released under the Apache License 2.0.
Metadata
Release files for mhcflurry 2.3.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mhcflurry-2.3.26.tar.gz | 805.1 kB | With provenance | Details for mhcflurry-2.3.26.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mhcflurry-2.3.26-py3-none-any.whl | Python 3 | none | any | Details for mhcflurry-2.3.26-py3-none-any.whl |
Total release size: 1.4 MB
Release files / mhcflurry-2.3.26.tar.gz
| Download URL | mhcflurry-2.3.26.tar.gz |
|---|---|
| Size | 805.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f3e9cb2af8effefceead3407d5b7d601f783516588672ecb06f76960c6e380b
|
|
BLAKE2b-256 checksum How to use checksums |
646a6f4a9274101175222441aec16f83222852d30ae1b244d9639486327eddc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / mhcflurry-2.3.26-py3-none-any.whl
| Download URL | mhcflurry-2.3.26-py3-none-any.whl |
|---|---|
| Size | 582.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f8a4857c9fcdde25d87b705da9f5c5178825a3646d3dc8787adda9ab125b73a
|
|
BLAKE2b-256 checksum How to use checksums |
c0111b06943dbc129a73da96d92bc947fe0323b45dd892d7399eab4b93d2dacf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for mhcflurry 2.3.26
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mhcflurry-2.3.26.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.