Skip to main content

Build Status Docs Open In Colab

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 mhcflurry-predict, mhcflurry-predict-scan or mhcflurry-downloads keep working. The other older mhcflurry-* names are deprecated in favour of mhcflurry <subcommand>; see the 2.3.0 release notes.

Documentation

Full documentation: openvax.github.io/mhcflurry.

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/
./test.sh                  # 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.38

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mhcflurry 2.3.38
File Size Uploaded Provenance Actions
mhcflurry-2.3.38.tar.gz 793.3 kB With provenance Details for mhcflurry-2.3.38.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mhcflurry 2.3.38
File Interpreter ABI Platform Actions
mhcflurry-2.3.38-py3-none-any.whl Python 3 none any Details for mhcflurry-2.3.38-py3-none-any.whl

Total release size: 1.4 MB

Release files / mhcflurry-2.3.38.tar.gz

Download URL mhcflurry-2.3.38.tar.gz
Size 793.3 kB
Tags Source
SHA-256 checksum
How to use checksums
813196edb30ec8b4ecc834c216f1eda8d053aeed2d9b05f4ce0b6ad920f76e6c
BLAKE2b-256 checksum
How to use checksums
331d68f9df4e1024da2dc837e791a1eba5c5a55904fe127d3210f659f9f2f00c
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 24, 2026.

Transparency log

Release files / mhcflurry-2.3.38-py3-none-any.whl

Download URL mhcflurry-2.3.38-py3-none-any.whl
Size 568.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
066ba755cd09e3709730bbf0fc99c3b835a2bd0dbe3d46f54d8b96d7eb382603
BLAKE2b-256 checksum
How to use checksums
5d5373f02c364c9616700df6a25e9abb49c30ace9044464764c0c9abf31cea9c
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 24, 2026.

Transparency log

Security for mhcflurry 2.3.38

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.

Select from 2 files

Attestation for mhcflurry-2.3.38.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 24, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

2.3.38 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page