How MHC/HLA Binding Prediction Works: NetMHCpan and MHCflurry Explained
How MHC/HLA binding prediction works: the peptide groove, anchor residues, and running NetMHCpan-4.2 and MHCflurry 2.2 to interpret %rank and IC50.
Every neoantigen pipeline, vaccine design study, and T-cell epitope screen eventually asks the same deceptively simple question: out of the thousands of peptides a protein can be chopped into, which ones will actually be presented on the cell surface for a T cell to see? You cannot test all of them in the lab, so the field leans on prediction. Tools like NetMHCpan-4.2 and MHCflurry 2.2 answer that question in seconds, but their outputs — a %rank, an IC50, an eluted-ligand score — are easy to misread if you do not understand the biology and the machine learning underneath. This post builds that understanding from the groove up.
The Peptide-MHC Binding Groove
Major histocompatibility complex (MHC) molecules, called human leukocyte antigens (HLA) in humans, are cell-surface proteins whose entire job is to display short peptide fragments to T cells. The business end is the binding groove: a shallow cleft formed by two alpha-helices sitting on a beta-sheet floor. Peptides nestle into this groove, and specific pockets along it (conventionally labeled A through F) grip particular side chains of the peptide.
The residues at defined peptide positions that plug into these pockets are called anchor residues. For many HLA class I alleles, positions 2 and the C-terminus are the dominant anchors — which is why a peptide's binding motif is often written as something like "leucine at P2, valine at the C-terminus." Because every HLA allele has a slightly different groove chemistry, each allele prefers a different motif. With over 43,000 HLA alleles catalogued in the IPD-IMGT/HLA database, memorizing motifs is hopeless; this is exactly the gap prediction tools fill.
Class I vs Class II: Why Length Matters
The single most important practical distinction is class. It changes which peptides you predict, which tool settings you use, and how you interpret results.
| Feature | MHC Class I | MHC Class II |
|---|---|---|
| Presents to | CD8+ cytotoxic T cells | CD4+ helper T cells |
| Peptide source | Cytosolic/endogenous proteins | Endosomal/exogenous proteins |
| Typical length | 8-11 mers (mostly 9) | 13-25 mers, open-ended |
| Groove ends | Closed | Open |
| Genes | HLA-A, HLA-B, HLA-C | HLA-DR, HLA-DQ, HLA-DP |
| Core binding | Whole peptide | 9-mer binding core + flanks |
Class I grooves are closed at both ends, so they clamp short peptides of a defined length. Class II grooves are open, letting longer peptides hang out both sides while a 9-residue core sits in the groove. That open geometry makes class II prediction genuinely harder — the model must find the register (where the core sits) inside a longer sequence. If you are predicting class I, tools default to -l 9 and related lengths; class II uses separate models entirely (NetMHCIIpan).
From Binding Affinity to Eluted Ligands
Early predictors were trained purely on binding affinity (BA) data: peptides synthesized and measured for how tightly they stick to a purified HLA molecule, reported as an IC50 in nanomolar. A lower IC50 means tighter binding. A common rule of thumb calls IC50 < 500 nM a binder and IC50 < 50 nM a strong binder.
But affinity alone is an incomplete picture. Real antigen presentation involves proteasomal cleavage, TAP transport, and MHC loading — a whole pathway that pure BA assays skip. The breakthrough of the last decade was mass-spectrometry eluted-ligand (EL) data: peptides actually stripped off HLA molecules from real cells and sequenced. EL data captures the full presentation pipeline, not just the last binding step.
NetMHCpan-4.0 onward trains on both BA and EL data jointly, and MHCflurry 2.2 adds a dedicated antigen-processing predictor on top of its affinity model. This is why modern tools report an eluted-ligand score or "presentation score" that often predicts real immunogenicity better than raw affinity.
IC50 and eluted-ligand scores as interchangeable. An IC50 answers "how tightly does this peptide bind in isolation?" while the EL/presentation score answers "how likely is this peptide to actually be displayed on a cell?" For neoantigen and vaccine work, the presentation-oriented score is usually the one you rank on.The Neural Network Under the Hood
Both tools are, at heart, neural networks that map a peptide sequence plus an HLA sequence to a binding or presentation score. The "pan" in NetMHCpan is the key trick: instead of training one model per allele (impossible for rare alleles with little data), it encodes the HLA molecule itself using a pseudosequence — roughly 34 groove-lining residues that contact the peptide. By feeding both the peptide and this allele pseudosequence into one shared network, the model generalizes to alleles it barely saw in training, even ones with zero experimental peptides.
The peptides are encoded (historically via BLOSUM matrices, now often learned embeddings), passed through hidden layers, and the network outputs a score. Training on tens of millions of BA and EL measurements, with EL data framed as a positive-versus-random classification, lets the network learn motifs implicitly. MHCflurry 2.2 uses an ensemble of such networks for robustness and, crucially, separates the "cleavage/processing" signal from the "affinity" signal so you can inspect each. If the idea of learning patterns from labeled biological data feels familiar, it is the same paradigm covered in machine learning in drug discovery, applied to immunology instead of chemistry.
Reading %rank, IC50, and EL Scores
The output most people should anchor on is %rank, not the raw score. Here is why it matters: raw scores are not comparable across alleles because some HLA molecules are inherently "stickier" and bind many peptides. The %rank normalizes against a large background of random peptides scored on that same allele. A %rank of 0.5 means the peptide scores in the top 0.5% of random peptides for that allele — an allele-independent, apples-to-apples metric.
Default thresholds you will see in NetMHCpan class I output:
| Metric | Strong binder | Weak binder |
|---|---|---|
%rank (EL) | < 0.5 | < 2.0 |
IC50 (BA) | < 50 nM | < 500 nM |
Rank the candidates by %rank, then sanity-check the IC50 and the raw EL score. A peptide with %rank 0.1 and IC50 20 nM that shows a clean anchor motif is a confident hit. Watch the columns carefully: NetMHCpan reports both a BA %rank and an EL %rank, and mixing them up is a classic beginner error.
Running NetMHCpan-4.2 and MHCflurry 2.2
NetMHCpan-4.2 is distributed as a downloadable package from DTU Health Tech (free for academic use, license required). A typical class I run on a FASTA of protein sequences looks like this:
# Predict 9-mers for two HLA alleles, sort by rank, show binders
netMHCpan -a HLA-A02:01,HLA-B07:02 \
-l 9 \
-f antigen.fasta \
-BA \
-s -xls -xlsfile predictions.xlsThe -BA flag adds binding-affinity IC50 output alongside the default eluted-ligand scores, -l 9 sets peptide length, and -s sorts by score. Allele names must match the tool's nomenclature exactly (HLA-A02:01, no asterisk).
MHCflurry 2.2 is a pip-installable Python package, which makes it trivial to script and to embed in a pipeline. It works well inside a dedicated conda environment — see conda environments and Bioconda channels for keeping it isolated.
# One-time model download, then predict from a CSV of peptides + alleles
pip install mhcflurry
mhcflurry-downloads fetch models_class1_presentation
mhcflurry-predict peptides.csv --out mhcflurry_out.csvThe output CSV includes mhcflurry_affinity (in nM), mhcflurry_presentation_score, and a mhcflurry_presentation_percentile. For screening, rank on the presentation percentile.
HLA-A02:01, MHCflurry wants HLA-A*02:01, and IEDB has its own dropdown. Always confirm your allele string is one the tool recognizes — an unrecognized allele can be dropped without an obvious error, leaving you with a suspiciously short results table.The IEDB Resource, MixMHCpred, and Choosing a Tool
If you do not want to install anything, the IEDB Analysis Resource (tools.iedb.org) wraps NetMHCpan, MHCflurry, and several consensus methods behind a web form and a REST API. It is the fastest way to get started and the standard reference many papers cite. For programmatic batch work, the IEDB API and the standalone tools scale far better than the web form.
MixMHCpred is a complementary predictor built primarily from mass-spec eluted-ligand data using an explicit motif-deconvolution approach rather than a large pan-allele network. It is fast, strong on presentation, and a good orthogonal check: peptides flagged by both NetMHCpan and MixMHCpred are higher-confidence calls than either alone. A pragmatic workflow is to screen broadly with NetMHCpan-4.2 or MHCflurry 2.2, then intersect top candidates with MixMHCpred before committing to synthesis.
Whichever tool you pick, remember the output is a ranked hypothesis list, not ground truth. Predicted binders still need functional validation — much like a predicted protein structure needs experimental confirmation, a theme running through the AlphaFold revolution.
Practical Takeaways
- Anchor your interpretation on
%rank, not raw scores:%rank < 0.5is a strong binder,< 2.0a weak binder, and it is comparable across alleles. - Know your class — class I predicts 8-11mers (
-l 9default) for CD8 T cells; class II needsNetMHCIIpanand handles 13-25mers with an internal binding core. - Prefer eluted-ligand / presentation scores over raw
IC50for immunogenicity screening, because EL data captures the whole antigen-processing pathway, not just affinity. - Get allele nomenclature right:
HLA-A02:01for NetMHCpan versusHLA-A*02:01for MHCflurry — a wrong string can be dropped silently. - Use
NetMHCpan-4.2orMHCflurry 2.2for the broad screen, then confirm top hits withMixMHCpredand treat overlap as higher confidence. - Start on the IEDB Analysis Resource if you want zero installation, then move to the standalone tools or API for batch pipelines.
Epitope prediction sits at the intersection of structural immunology and applied machine learning, and the tools have matured to the point where a careful reader can trust their rankings for prioritization. If you are assembling a reproducible neoantigen or vaccine-design pipeline around these predictors, wrapping the NetMHCpan and MHCflurry steps in a workflow manager — the same approach covered in reproducible pipelines with Snakemake — will save you from the dependency conflicts and manual bookkeeping that plague immunoinformatics stacks.