Thirty-four letters of the lock: how antigen-presentation models actually work

Published: 2026-09-01

Thirty-four letters of the lock: how antigen-presentation models actually work

In our previous post we described how an individualized mRNA cancer vaccine is made: from one patient's tumour, up to 34 fragments of mutated proteins are picked, and those are what go into the preparation. The picking is not done by a person — it is done by a program. We gave it five paragraphs there, and that was far too few, because this is the point at which machine learning makes the only real decision in the whole process: what ends up in the vaccine.

This article is about that single step. It is longer and more detailed than the previous one, but it assumes no biology whatsoever — we start from scratch, by explaining what the molecules involved actually are. Along the way we also correct one figure from the earlier piece.

Before we start: what all of this means

This entire field rests on one biological mechanism. It is worth understanding once, properly, because everything that follows refers back to it.

A protein is a long chain built from amino acids. There are twenty kinds of amino acid and each has a letter assigned to it, so a protein can be written out like a word — except a word hundreds of letters long. The set of all proteins a human cell can make is called the proteome.

A cell is constantly destroying some of its own proteins: worn out, damaged, or simply surplus ones. This is the job of the proteasome — a molecular shredder shaped like a barrel, which draws in a protein chain and cuts it into short pieces. Such a piece, usually eight to fourteen letters long, is what we call a peptide.

And here the interesting part begins. Some of these peptides are not sent for disposal but are displayed on the surface of the cell, like a sample hung out of a window. A separate protein handles this; in humans it is called HLA (for human leukocyte antigen; the same family of proteins in other species goes by MHC, and the two abbreviations are often used interchangeably). An HLA molecule has a groove on its upper face — an elongated hollow between two spiral walls — and it holds a single peptide in it, turned outwards.

Why does the cell do this? Because T cells patrol nearby: immune cells whose job is to inspect those samples. A T cell carries a receptor on its surface, matched to one particular shape. If the receptor recognises the displayed peptide as foreign, the T cell kills the cell. This is how the body detects virus-infected and cancerous cells: it does not look inside them directly, it reads samples of what is in there.

And now the heart of the problem. The gene encoding HLA exists in the population in thousands of variants, and such a variant is called an allele. The variants differ almost entirely in the shape of the groove — and if the groove has a different shape, different peptides fit into it. This is why the same cell, the same virus and the same tumour look different to the immune systems of two different people. Each of us has three class I HLA genes, called A, B and C, in two copies each — so at most six different alleles, six different grooves, drawn at conception from a catalogue tens of thousands of entries long.

Two more words we will use constantly. A peptide that actually sits in a given allele's groove is that allele's ligand. And an allele's motif describes its taste: which amino acids it likes to see at which positions of the peptide. A motif is usually drawn so that the more important a letter is at a position, the larger it appears.

From protein to T cell: a peptide's journey How to read this: the double horizontal line is the cell membrane — below it the inside of the cell, above it the outside world. 1: a protein, that is, a chain of amino acids. 2: the proteasome, which cuts it into pieces. 3: the resulting peptides. 4: an HLA molecule embedded in the membrane, holding one peptide in its groove and displaying it outwards. 5: a T cell, checking with its receptor — the green fork — what has been displayed. This whole article is about predicting step 4: whether a given peptide–HLA pair will show up there at all.

For reference, all of it in one place:

term meaning
peptide a short fragment of a protein, 8–14 amino acids
proteome the set of all proteins a cell can produce
proteasome the "shredder" that cuts proteins into peptides
HLA (MHC) the protein that displays a peptide on the cell surface
groove the hollow in the HLA molecule where the peptide lies
allele one of thousands of variants of the HLA gene; they differ in groove shape
ligand a peptide that actually lies in a given allele's groove
motif an allele's preferences: which amino acids it likes at which positions
epitope a peptide that actually provoked a T-cell response

So the task this article is about is: given a peptide and given an allele, predict whether that pair will appear on the cell surface. The rest of the text is about how that is done and how anyone knows it works.

Three questions that are easy to confuse

People say, in shorthand, that "the model predicts neoantigens". In reality three different questions hide behind that, nested one inside another like sets.

Three nested sets: binding, presentation, recognition How to read this: the three nested rectangles are three progressively narrower sets of peptides, and the dots show how quickly candidates thin out as you move inwards. Blue (1) — peptides that will bind HLA in a test tube. Gold (2) — the narrower subset the cell actually displays. Green (3) — narrower still: those a T cell really recognises. The icons on the right of each band show what is examined at that level: fit to the groove, display on the membrane, contact with a receptor.

Question one — affinity. Will the peptide fit into the groove and stay there? A purely chemical question: take purified HLA protein and a peptide, and measure the strength of binding. It can be asked in a test tube, with no living cell involved.

Question two — presentation. Will that peptide actually appear on the surface of a living cell? This is much more than binding, because a whole sequence of events has to succeed along the way. The source protein has to be made in that cell at all. The proteasome has to cut out that exact fragment, not one two letters longer. A protein pump called TAP has to carry the peptide into the endoplasmic reticulum — a compartment inside the cell, something like a workshop where new HLA molecules are assembled. There the peptide has to find a freshly made molecule and bind it tightly enough for the complex to survive the trip to the surface. Binding is therefore necessary, but far from sufficient.

Question three — immunogenicity. Does this particular patient's T-cell repertoire contain a receptor matching this complex — and has the body not previously learned to tolerate that shape? A peptide that manages all of this is what we call an epitope.

The models described in this article answer question two. Older tools answered the first. Nobody answers the third well today. This distinction returns in the section on metrics, because setting tools from different levels of this pyramid against each other produces charts that look like a breakthrough and mean almost nothing.

Thirty thousand locks

If there were only one HLA molecule, the problem would be trivial: collect peptides, teach a program to recognise them, done. The trouble is that HLA is the most variable place in the human genome — nowhere else do people differ from one another so much.

As of June 2026 the IPD-IMGT/HLA database names 30,894 class I alleles: 9,279 for the HLA-A gene, 11,258 for HLA-B and 9,416 for HLA-C. Recall that a single patient has at most six of them. Six out of thirty thousand.

If a full set of measurements existed for every allele, you could build a separate model for each. No such set exists — and that is the real problem of this field.

Three well-studied alleles and the rest of the catalogue How to read this: each "holder" in the picture is one allele, that is, one variant of the HLA molecule. The blue bars stacked above a holder are peptides measured in the laboratory for that variant — the taller the stack, the more is known about it. On the left, the three best-studied alleles, labelled with their real names. On the right, the rest of the catalogue: grey holders with nothing above them, because nobody has ever measured a single peptide for them. The gold bracket covers roughly 135 alleles that have any data at all; the grey bracket covers all 30,894 named ones. The stack heights and the number of grey holders are schematic; both numbers at the brackets are real.

There are two orders of magnitude fewer alleles with any data at all than alleles named. The MHC Motif Atlas holds over a million ligands — but spread across just 135 class I molecules. The reference collection of affinity measurements, BD2013, contains 176,161 measurements for 114 alleles, and that is counting six species, not just humans. Tens of thousands of named variants against roughly a hundred studied ones.

The distribution is also extremely uneven. In the IEDB automated benchmark — the field's standard test set — HLA-A*02:01 alone accounts for 24.38% of datasets, the seven commonest alleles for more than half, and 66.24% of class I molecules have six datasets or fewer. It is no accident that HLA-A*02:01 is particularly common in European populations, on whom most of the research has historically been done.

A model trained separately per allele would therefore not merely be unworkable. It would be useless precisely for those patients who differ most from the training sample — that is, for those whose alleles never made it into the studies at all.

The lock described in numbers: the pseudosequence

The solution is simple in conception and clever in execution: make the description of the lock itself part of the model's input.

Let us spell out the difference. A model trained separately per allele receives only the peptide on its input, and knowledge of the allele sits in its weights — it is a separate program for each variant. A pan-specific model receives two things at once: the peptide sequence and the groove sequence. It then learns the general rule of "which groove shape fits which peptide". An allele it has never seen stops being a new category for it — it simply becomes a new point in the same space, described exactly like all the known ones. That is what the pan- prefix in NetMHCpan means, and it is how one model covers more than 11,000 MHC molecules, including ones for which not a single measurement exists.

That leaves the question of how to describe the groove in numbers. A whole HLA class I molecule is several hundred amino acids, the vast majority of which never touch the peptide — feeding it in whole would add hundreds of uninformative numbers.

The authors of NetMHCpan turned to crystal structures, that is, three-dimensional maps of molecules reconstructed from the way they scatter X-rays. With such a map of a peptide–HLA complex, they picked the positions satisfying two conditions at once: the amino acid must lie closer than 4 ångström to the peptide (an ångström is a ten-billionth of a metre, so 4 Å is roughly the distance of direct contact) and it must be polymorphic, that is, differ between alleles. The second condition matters as much as the first: an amino acid that touches the peptide but is identical in every allele carries no information about which variant we are dealing with. There are 34 positions satisfying both.

The HLA groove from above and the pseudosequence extracted from it How to read this: on the left, the HLA groove seen from above, as if we were looking at it from outside the cell. The two gold rods are the spiral walls of the groove; the blue chain between them is the peptide lying in it. The gold dots are those 34 amino acids of the walls that touch the peptide — which is why there are seventeen on each side. The arrow stands for the operation of lifting those 34 amino acids out of the molecule and lining them up in a row: that is the pseudosequence, the thirty-four-letter "name" of the allele that the model receives alongside the peptide. The letters in the frame are illustrative — this is not any particular allele's sequence.

So an allele stops being a name like "HLA-B*57:01" and becomes a thirty-four-letter word. The core of the network's input is 43 amino acids — nine of peptide and thirty-four of groove.

Each letter still has to be turned into numbers, because a neural network does not operate on letters. This is done with the BLOSUM50 matrix: instead of a single number, an amino acid gets a vector of twenty numbers saying how similar it is to each of the others. That way the model knows from the outset that leucine is chemically close to isoleucine and far from aspartic acid — it does not have to learn this from data. That gives 43 × 20 = 860 numbers; later versions add the auxiliary features described below, so the real input layer is larger.

This thirty-four is worth pausing on, because it is the second one in this series — and purely by coincidence. The previous article was about 34 neoantigens in the vaccine; that number follows from the length of mRNA molecule one can manufacture. Here 34 is the count of amino acids touching the peptide, following from protein geometry. The two numbers have nothing to do with each other — we mention it only because it is easy to mistake for a relationship.

A variable-length peptide in a fixed-size network

The HLA class I groove is closed at both ends, like a bathtub — unlike class II, where the peptide can hang over the edges. That is what limits ligands to 8–14 amino acids, with nine by far the commonest. Two positions usually do most of the work: the second from the start, and the last. We call them anchors — their side branches sink into deep pockets in the floor of the groove, and they largely decide whether the peptide stays put. An allele's motif is therefore usually sharp at those two positions and blurred at the others.

But a neural network needs an input of always the same size, and peptides come in different lengths. The solution: everything is reduced to a core of length nine.

An eight-letter peptide has an artificial amino acid "X" inserted, encoded as all zeros — an empty slot that the network knows is empty. A longer peptide gets the opposite treatment: surplus letters are cut out until nine remain.

The key point is that this is not a rigid rule but a search. For an eleven-letter peptide the model tries every possible way of removing two letters — at the start, at the end and in the middle — scores each variant separately and keeps the one that scored highest. The network therefore works out for itself which part of the peptide lies in the groove and which bulges out. You can see this directly in the program's output: alongside the score it reports the core, that is, the nine amino acids in contact with HLA, its start position, and the length and location of any insertion or excision.

A few explicit pieces of information are added to the input as well: the length of the insertion or excision, the length of any part protruding from the groove, and the peptide's own length — that last one encoded by four neurons for the cases L ≤ 8, L = 9, L = 10 and L ≥ 11.

What sits inside

Here comes a surprise. After years of talk about deep learning one might expect an architectural colossus. NetMHCpan is a network with one hidden layer — that is, with a single "floor" of neurons between input and output.

That layer holds 56 or 66 neurons; both versions are trained. The output does not come from a single network but from an ensemble — in version 4.0 that was a hundred networks: two architectures × five cross-validation splits × ten random initial weight settings. The final score is the average over the whole ensemble, which smooths out the effect of a single unlucky start. The authors did not print version 4.1's exact parameters in the paper itself, referring readers to the supplementary material.

One detail of the procedure deserves separate attention, because it determines the credibility of every number published in this field. Cross-validation means splitting the data into several parts, training the model on all but one, and testing it on the one held back — then repeating with the parts swapping roles. Here the splits are not random. Peptides are first grouped by shared motif, and whole groups go into a single part. With random splitting, near-identical peptides would land on both sides of the boundary and the model would be evaluated on a task it had effectively already seen. This "leakage" through sequence similarity is the main mechanism inflating results in binding prediction, and the main reason cross-validated numbers tend to be systematically better than results on genuinely new data.

Data, part one: the test tube

For the field's first fifteen years, data came from affinity measurements, that is, measurements of binding strength. It is worth knowing exactly how they are produced, because that explains why there are so few of them.

You take a purified HLA molecule — historically isolated from cell lines homozygous for the allele in question, meaning ones carrying two identical copies of the gene, since only those yield uniform protein. Add a reference peptide known to bind tightly, labelled with radioactive iodine-125. Now add the test peptide at rising concentrations and check at what concentration it displaces half of the reference peptide from the grooves. That value is the IC50, quoted in nanomoles: the smaller it is, the stronger the binding, because the less test peptide was needed. The IEDB convention says: below 50 nM is high affinity, below 500 nM intermediate, below 5000 nM low. A newer variant of the method drops the isotope — a recombinant protein folds in the presence of the peptide, and the resulting complex is detected by luminescence, in 384-well plates.

This data has two flaws that need stating plainly.

First, it measures a different question. A tube of purified protein knows nothing about whether the cell produces the source protein at all, whether the proteasome cuts out that particular fragment, or whether TAP lets it through. It measures question one; we care about question two.

Second, it is sparse and skewed. Every measurement is a separate laboratory experiment lasting days, and the alleles studied were chosen by people, guided by population frequency and their own interests. Hence 176 thousand measurements across 114 alleles, and an overwhelming over-representation of HLA-A*02:01.

Data, part two: ask the cell itself

The breakthrough came when, instead of the test tube, people started asking the cell. The method is called immunopeptidomics and it comes down to stripping the peptides off the surface of living cells and simply reading them. The procedure is startlingly physical, and worth following, because almost every one of its limitations later shows up inside the model.

It starts with material, and a lot of it: on the order of a hundred million cells, or about a gram of tissue. The cells are broken open with a mild detergent, releasing their contents. From the resulting suspension you now have to fish out the HLA molecules alone — this is the job of the W6/32 antibody, a protein that recognises all class I HLA molecules, immobilised on beads packing a column. The suspension circulates through the column overnight at 4 °C, and the antibody retains the HLA complexes together with the peptides sitting inside them.

The beads are then washed and flooded with dilute acid — trifluoroacetic or acetic. The acid breaks the complex apart, which releases the peptides. These are separated from the much larger proteins by a filter that passes only molecules below 3 kDa, concentrated, and fed to a mass spectrometer — an instrument that weighs molecules precisely enough for the amino acid composition to be read off the mass. The measured spectra are compared with theoretical spectra of every peptide derivable from the human proteome, and matches are accepted if they pass a false discovery rate control — typically at the 1–5% level, that is, accepting up front that this share of the list will be mistakes. The details of this procedure — which acid, which filter cut-off, which rate — vary between laboratories; the above is one common variant.

What comes out is a list of peptides that genuinely lay in the groove on the surface of a living cell. This is qualitatively different data from IC50: not "this peptide could bind" but "this peptide was there".

There is just one problem, and it is a serious one.

Cells with a single lock

An ordinary cell carries up to six different class I HLA molecules at once, and the W6/32 antibody sweeps them all up without distinction. What we get is a bag of unlabelled peptides: we know each was displayed, but not by which of the six variants. For a model whose entire point is the relationship "this groove — these peptides", such data is nearly useless.

The solution was expensive and effective: grow cells that have only one lock. Take the B721.221 cell line, which because of damaged genes produces no class I HLA of its own at all, and introduce a single chosen allele into it. Everything we then strip off such a cell comes from one and the same molecule. The label is certain by the construction of the experiment.

A cell with six alleles versus a cell with one How to read this: both panels have the same layout — at the top, a fragment of the cell membrane with HLA molecules embedded in it; in the middle, the pool of peptides stripped from that cell; at the bottom, the motif computed from them. In panel A the cell is ordinary: six molecules in three colours (colour corresponds to the HLA-A, -B or -C gene, each in two copies), the peptides are mixed, and the motif at the bottom is blurred because several different tastes are superimposed. In panel B the cell has had one allele introduced: the peptides are uniform and the motif is sharp — the large letters at positions 2 and 9 are the anchors. The larger the letter, the stronger the preference.

The first large study of this kind (Abelin et al., Immunity 2017) covered 16 alleles and over 24,000 distinct peptides — between 900 and 3,550 per allele. Three years later Sarkizova et al. (Nature Biotechnology 2020) extended this to 95 mono-allelic lines: 31 HLA-A alleles, 40 HLA-B, 21 HLA-C and 3 HLA-G, for a total of 186,464 peptides, a median of 1,860 per allele. Fifteen of those alleles had no described motif at all before. The set covers at least one allele in 95% of people worldwide — separately for the A, B and C genes.

That single methodological change did more for the field than any change of network architecture.

Motif deconvolution: a model that labels its own data

Mono-allelic cells solve the problem for alleles somebody took the trouble to engineer into a cell line. But an enormous resource remains that it would be a shame to waste: peptides stripped from real tissues and tumours. The HLA Ligand Atlas alone holds 90,428 class I ligands from 29 kinds of tissue across 21 donors. They are valuable precisely because they come from living biology rather than from a cell rebuilt in a laboratory — and they are irreversibly multi-allelic.

The answer is motif deconvolution, that is, untangling a mixture into its separate components. In NetMHCpan-4.1 it is built directly into the training procedure, under the name NNAlign_MA. The idea is elegant, because rather than working around the missing labels it makes the model produce them itself.

Iterative assignment of peptides to alleles How to read this: on the left, the pool of peptides stripped from a multi-allelic sample — grey, because it is unknown which allele each belongs to; the question mark stands for exactly that gap. The arrow leads to the model, the purple frame containing the network. The model scores each peptide against the alleles present in that sample and sends it to one of the three bins on the right — there the peptides already have colours, that is, assignments. The purple arrow returning along the bottom is the heart of the idea: on that colour-coded data the model trains further and on the next pass assigns more accurately. The circular arrow means the loop repeats throughout training.

It runs like this:

  1. Warm-up. For the first 20 iterations the model trains only on single-allele data, the data with certain labels. Only once it has roughly correct motifs is it allowed to label anything itself.
  2. Assignment. Each peptide from a multi-allelic sample is scored against only those alleles that this particular sample actually has — at most six, not thirty thousand. The peptide goes to the allele with the highest score. The assignment is hard: winner takes all.
  3. Putting the scales on a level. Here is the crux. Scores from different alleles are not directly comparable, so before comparison they are converted to standardised values — measured in deviations from the average that allele gives random peptides. Without this step, an allele that naturally issues higher scores would hoover up every peptide in every sample.
  4. Fading the correction out. Early in training the statistics needed for that conversion are still uncertain, so the correction is introduced gradually: its strength changes with the iteration number and fades out roughly between iterations 55 and 95.
  5. Repeat every epoch. The assignment is redone in every training cycle. The better the model, the better the labels; the better the labels, the better the model.

This is the same logic as the classic EM algorithm: alternately guess the missing value and fit the model. The gain is measurable — for epitopes restricted to alleles entirely absent from the single-allele data, the method does roughly twice as well as its predecessors, though this was shown on a small set covering three alleles. The model learns such an allele by subtraction: if these peptides do not fit the five known variants in that cell line, they must belong to the sixth.

Two heads on one network

That leaves the question of how one model reconciles two kinds of data: affinity measurements from the test tube, and peptides stripped from cells. The answer is surprisingly simple.

The network has one hidden layer but two output neurons — one returning predicted affinity, the other the probability that the peptide is a ligand. The weights between input and hidden layer are shared; the weights between hidden layer and output are separate for each data type. During training an example is drawn from one collection or the other: an affinity measurement improves its own head and the shared layer, a stripped peptide improves its head and that same shared layer.

That shared layer is the entire mechanism by which the two collections teach each other. Affinity measurements contribute breadth of allele coverage, including rare ones; mass spectrometry contributes the real presentation signal, with proteasomal cleavage, transport and protein abundance already baked in. The hidden representation has to serve both at once.

%Rank: why a raw score lies

Suppose the model works and returns a number. An unavoidable question follows: does a score of 0.6 for HLA-A*02:01 mean the same as 0.6 for HLA-B*57:01?

It does not. Alleles differ not only in preference but in breadth of taste: some bind a wide class of peptides, others are highly fastidious. Their score distributions therefore sit in different places and have different shapes, and one shared threshold cuts a sensible handful of candidates from one allele and, from another, either almost nothing or half the proteome.

The same threshold on two distributions versus a percentile threshold How to read this: both halves show the same thing — the distributions of scores the model gives peptides, separately for two alleles (blue and red). The horizontal axis is the score, higher towards the right; the height of the curve says how many peptides got a given score. In panel A a single shared threshold has been placed (the white dashed line) and everything beyond it is shaded: a good share of the red allele passes, almost nothing of the blue — so the same threshold means something completely different for the two. In panel B the threshold has been set separately for each allele so as to cut the same top slice, 2%, from each. The raw cut-off value differs for each; the green areas are equal. That is what %Rank does.

So the output is not a raw score but a %Rank — a ranking position expressed as a percentage. The model first scores a large set of random natural peptides for the allele in question and remembers the distribution of those scores as a background. A candidate then receives, not its raw score, but the answer to the question "what percentage of the random background scored better than you". A result of 0.5% therefore means: better than 99.5% of random peptides for this particular allele. The conventional thresholds are 0.5% for strong binders and 2% for weak ones.

This is exactly the same trick we saw inside deconvolution — applied once during training so that assignments are fair, and once at the output so that scores are comparable. It has a consequence that is easy to miss: %Rank speaks of rank position, not probability. A peptide scoring 0.1% is not ten times more likely to be presented than one scoring 1% — it simply ranks higher.

Three other schools

NetMHCpan describes the mainstream, but not the only approach. What is most interesting is that competing tools solve the same three sub-problems — how to describe the allele, how to cope with variable peptide length, and how to extract anything from multi-allelic data — and do it differently every time.

allele description variable length multi-allelic data
NetMHCpan-4.1 34 contact residues 9-letter core by search NNAlign_MA during training
MHCflurry 2.0 37 residues three alignments concatenated to 45 positions best score across the sample's alleles
MixMHCpred position weight matrix a separate model per length MixMHCp before training
MHCnuggets a separate network per allele LSTM, no alignment transfer between alleles

MHCflurry 2.0 encodes the groove with 37 positions — the same 34 contact residues as NetMHCpan plus three extra, needed to tell apart allele pairs that would otherwise have identical descriptions. It handles variable length with surprising brute force: it writes the same peptide three times — left-aligned, centred and right-aligned — and glues that into one fixed-length sequence of 45 positions. Rather than searching for the right alignment as NetMHCpan does, it hands the network all three at once and lets it decide which matter.

Its most important contribution, though, is elsewhere. MHCflurry adds a separate antigen-processing model whose input is not the peptide alone but the peptide together with fifteen amino acids on each side in the source protein. The reason is biological and the authors state it outright: it is the proteasome that decides where to cut the chain, and the efficiency of the cut depends on what lies on both sides of the cut site. A peptide torn out of context loses that information. The model does find it: one sees a shortage of proline just before the peptide and an excess of it at the second position, matching the known action of the ERAP enzyme, which trims peptides before they are loaded into HLA.

Two honest caveats about this idea. First, the gain is real but modest: a mean 3.3% improvement. Second, the way the two components are combined is disarmingly simple — the final score is a logistic regression with three parameters, that is, a formula weighting two numbers and adding a constant. All the intelligence sits in the two component networks; merging them is one line of statistics.

MixMHCpred goes the other way, towards simplicity. Instead of a network it uses position weight matrices: for each position in the peptide and each of the twenty amino acids it stores one number saying how much this allele likes it there. A peptide's score is the sum of those numbers. The choice is not laziness but a conclusion from biology: class I ligands show no strong dependencies between positions — what sits at position two barely affects what fits at position nine. The independence assumption a weight matrix necessarily makes is therefore close to true here.

Its companion tool MixMHCp solves the multi-allelic problem before training rather than during it: it fits several motifs to the mixture at once, with each peptide receiving a fractional assignment to each of them, and a separate "bin" for a flat motif that catches contaminants. The cleverest part is how motifs get attached to specific alleles: the algorithm exploits allele co-occurrence across donors. If two samples share exactly one allele, then a motif present in both must come from that allele. It then extends those assignments recursively, to samples differing by one allele.

A curiosity: the latest MixMHCpred 3.0 has come full circle. It is a hybrid in which a neural network predicts the weight matrix — and its input is the same 34 groove amino acids we started with.

MHCnuggets solves variable length unlike anyone else: with an LSTM layer of 64 units. This is a kind of network that reads a sequence letter by letter and remembers what it has seen — so it naturally accepts input of any length and needs no alignment or concatenated variants.

At the price of giving up pan-specificity — here there is a separate network per allele, 148 for class I — it gets transfer learning in return. A base network is trained on the allele richest in data, HLA-A*02:01, and its weights serve as the starting point for all the others; instead of learning from scratch, each further allele starts from something that already roughly works. If some other allele turns out to be a better starting point for a given allele, the fine-tuning is repeated from that one. Transfer works along a second axis too: the model first learns on affinity measurements, then carries the weights over and fine-tunes them on mass-spectrometry data. For an allele with no data at all, the network of the nearest allele is used, according to a supertype classification that groups variants with similar groove shapes.

How anyone knows the model is good

This is the section most often skipped in popular accounts, and it decides more than the choice of architecture.

The natural reflex is to measure AUROC. This is a popular quality measure answering the question: if I draw one presented and one non-presented peptide at random, what is the chance the model gives the first a higher score? A value of 1.0 means perfection, 0.5 a coin flip. AUROC's advantage is that it does not depend on the proportion of one to the other. And that same thing is its flaw, because in our task the proportion is exactly what makes it hard.

Let us see this in numbers. The human proteome contains about 10 million possible nine-letter fragments. A single allele presents on the order of ten thousand of them. So roughly one peptide in a thousand is presented.

Now take a genuinely good model: it catches 90% of true ligands and errs only once in a hundred non-presented peptides. Run it on a million candidates, of which a thousand are presented. There will be 900 hits. But there will be 9,990 false alarms, because one percent of 999,000 is nearly ten thousand. On the list the model returns, each hit comes with eleven mistakes; the list is 92% junk. And this model's AUROC would be excellent — because AUROC never looks at that list.

This is not a flaw of the model. It is the arithmetic of rare events — and it is exactly why test sets in this field are built in proportions from 1:99 to 1:999, not half and half.

A metric on a balanced set versus a realistic one How to read this: this is a schematic, not real data. Both panels show the same model on two different test sets. At the top, the composition of the set: on the left half and half, on the right one presented peptide per 99 non-presented — the green bar is then barely visible. In the middle, the ROC curve, identical in both panels, as the equals sign between them indicates, because that measure does not depend on the proportion. At the bottom, what actually changes: the first nine positions of the list the model returns. Green circles are hits, grey ones mistakes. On the left, eight of nine are hits; on the right, one.

The main metric is therefore positive predictive value, PPV for short: what fraction of the peptides at the top of the ranking are true ligands. How strongly it depends on the proportion can be seen in concrete numbers — in one study the very same NetMHCpan-4.1 achieves a PPV of 0.791 at a 1:19 ratio and 0.671 at 1:99. Twelve percentage points of difference with no change to the model at all, purely from changing the composition of the test set.

And here we reach the trap that renders most comparisons in this field worthless. The abbreviation "PPV" denotes at least three different things in this literature. HLAthena and MHCnuggets compute it at 1:999, taking the top 0.1% of the list. MHCflurry computes it at 1:99, drawing decoy peptides from the same proteins the hits come from. NetMHCpan takes a list head equal to 95% of the number of ligands, deliberately leaving a margin for contaminants in the data. The 0.42 reported by MHCnuggets and the 0.83 reported by NetMHCpan are not the same quantity, and putting them in one table makes no sense.

That this is not methodological nit-picking is shown by a remark from the authors of the latest MixMHCpred: against random decoys, "AUC values up to 0.95 could be obtained even with relatively unspecific motifs". A model that has learned almost nothing about a particular allele still looks excellent on a ROC chart.

There is also a problem more serious than the choice of metric. Almost every published comparison of these tools was run by the authors of one of the tools being compared — and, unsurprisingly, in every such comparison the host tool wins. Sometimes one has to be excluded from a benchmark altogether because its training set overlaps the test set; this happened to MHCflurry in one such study. The exception is the IEDB automated benchmark, run on data as it is deposited — and the retrospective after eight years of it running is sobering: the leading methods turned out to be statistically indistinguishable, and a new method must wait about four years before enough data accumulates for it to be ranked reliably.

The most trustworthy test is one where the peptides counted as negative genuinely had a chance to turn out positive. In one such study, 220 vaccinia virus peptides were tested experimentally in mice. The result is both impressive and humbling: the best methods captured more than half of the most important epitopes within 0.04% of all predictions — that is, in roughly the first 280 positions out of 767,788. Capturing 90% meant going down to 1.3–1.5% of the list.

And one more sentence, which the authors of NetMHCpan-4.1 wrote about their own tool and which is the most honest in this literature. Version 4.1 clearly beat 4.0 at predicting peptides detected by mass spectrometry — but at predicting real T-cell epitopes it came out comparable to its predecessor, with a consistent improvement only for HLA-B and HLA-C molecules. Being better at guessing what lies on a cell's surface is not the same as being better at guessing what a T cell will attack. Those are our three questions again, and the boundary between the second and the third.

What these models still cannot see

There are no negatives. Mass spectrometry returns only a list of peptides that were detected. Absence from the result may mean "it was not there" or "it was there but was not measured". All negative training examples are therefore assumed, not observed — random protein fragments taken on faith not to have been presented. The assumption is mostly true and entirely unverified.

And here we come to the figure from the previous article that needs correcting. We wrote that NetMHCpan-4.1 was trained on 13,245,212 data points. The quotation is faithful, but those are not measurements. The number of real peptides measured in a laboratory is more than 850 thousand; all the rest are randomly drawn natural peptides from the UniProt database, assumed to be negatives — five times the count of the most abundant peptide length in a given dataset, separately for each of seven lengths. Assumed negatives therefore make up roughly ninety-four percent of the training set. This is not an indictment of the method, because there is no other way — but the figure "13 million" implies a scale of measurement that does not exist.

The spectrometer has preferences of its own, and they depend on the allele. Peptides containing cysteine are systematically under-detected, because cysteine oxidises easily and sticks to its neighbours. That this is an artefact of method rather than biology was shown by an elegant control: in data from a genetic screen, cysteine occurs at the expected frequency, while in mass-spectrometry data it is depleted five- to tenfold. Handling it properly increases the number of predicted ligands by 9–21%. The hydrophobicity example is stronger still: simply changing the solvent concentration used to wash peptides off the beads doubled the number of peptides detected — and while the count of ligands found for HLA-A*02 more than doubled, for HLA-A*30 it fell by 25%. One chemical parameter thus shifted the apparent size of one allele's repertoire relative to another's. A model trained on such data inherits that distortion and treats it as immunology. The NetMHCpan authors say so plainly: easily measurable peptides are over-represented and cysteine-containing ones neglected.

Expression is not in the input. A classical model gets a peptide and an allele, and nothing else. It does not know how intensively that gene is being read in this tumour, or which protein the fragment came from. And source-protein abundance is known to influence strongly whether its fragments reach the surface at all. Models that take expression into account exist — they were Step 4 of the previous article — but they need a readout of gene activity in a specific patient and therefore do not work as a universal "peptide in, score out" tool.

The tail is still a tail. Pan-specificity makes it possible to score an allele with not a single training example, but such a score is prediction by analogy, not knowledge. The authors themselves report worse results for molecules with sparse data, HLA-C especially, and give two reasons: fewer of those molecules on the cell surface, and the fact that the antibody used itself prefers certain genes. The instrument used to gather the data thus helps decide which alleles the model will never learn properly.

Presentation is not recognition. Even a perfect presentation model does not answer question three. A peptide may be displayed impeccably and provoke no reaction at all, because the patient lacks a matching receptor or their immune system has learned to tolerate that shape.

What follows from this

An antigen presentation model does one thing and does it well: out of a list of thousands of candidates it picks the few dozen worth investigating further. It does not say they will work — it says the rest are not worth testing. Given the cost of testing a single peptide on a patient's own cells, that is the whole of its value.

It is also worth noticing where the progress in this story came from. Not from ever-larger networks — recall that we are talking about a model with one hidden layer and sixty-odd neurons, something today's machine-learning student would call a toy. Three things changed this field most: describing the lock as part of the model's input, growing cells with a single allele, and teaching the model to produce its own missing labels. The first is an idea about representation, the second a biological experiment, the third a training procedure. The network architecture is the least interesting variable in that list — and that, we think, is the most instructive conclusion of this whole step.


Sources

  1. Reynisson B. et al., NetMHCpan-4.1 and NetMHCIIpan-4.0: improved predictions of MHC antigen presentation by concurrent motif deconvolution and integration of MS MHC eluted ligand data, Nucleic Acids Research 2020 — academic.oup.com
  2. Alvarez B. et al., NNAlign_MA; MHC peptidome deconvolution for accurate MHC binding motif characterization and improved T-cell epitope predictions, Molecular & Cellular Proteomics 2019 — pmc.ncbi.nlm.nih.gov
  3. Jurtz V. et al., NetMHCpan-4.0: Improved Peptide–MHC Class I Interaction Predictions Integrating Eluted Ligand and Peptide Binding Affinity Data, Journal of Immunology 2017 — pmc.ncbi.nlm.nih.gov
  4. Nielsen M. et al., NetMHCpan, a method for quantitative predictions of peptide binding to any HLA-A and -B locus protein of known sequence, PLoS ONE 2007 (definition of the pseudosequence) — pmc.ncbi.nlm.nih.gov
  5. Andreatta M., Nielsen M., Gapped sequence alignment using artificial neural networks, Bioinformatics 2016 (the 9-residue core) — academic.oup.com
  6. Abelin J.G. et al., Mass Spectrometry Profiling of HLA-Associated Peptidomes in Mono-allelic Cells Enables More Accurate Epitope Prediction, Immunity 2017 — pmc.ncbi.nlm.nih.gov
  7. Sarkizova S. et al., A large peptidome dataset improves HLA class I epitope prediction across most of the human population, Nature Biotechnology 2020 — pmc.ncbi.nlm.nih.gov
  8. O'Donnell T.J., Rubinsteyn A., Laserson U., MHCflurry 2.0: Improved Pan-Allele Prediction of MHC Class I-Presented Peptides by Incorporating Antigen Processing, Cell Systems 2020 — cell.com
  9. Bassani-Sternberg M. et al., Deciphering HLA-I motifs across HLA peptidomes improves neo-antigen predictions and identifies allostery regulating HLA specificity, PLoS Computational Biology 2017 (MixMHCpred, MixMHCp) — pmc.ncbi.nlm.nih.gov
  10. Tadros D.M., Racle J., Gfeller D., Predicting MHC-I ligands across alleles and species: how far can we go?, Genome Medicine 2025 (MixMHCpred 3.0; the AUC 0.95 remark) — pmc.ncbi.nlm.nih.gov
  11. Shao X.M. et al., High-Throughput Prediction of MHC Class I and II Neoantigens with MHCnuggets, Cancer Immunology Research 2020 — pmc.ncbi.nlm.nih.gov
  12. Marcu A. et al., HLA Ligand Atlas: a benign reference of HLA-presented peptides to improve T-cell-based cancer immunotherapy, Journal for ImmunoTherapy of Cancer 2021 — pmc.ncbi.nlm.nih.gov
  13. Kim Y. et al., Dataset size and composition impact the reliability of performance benchmarks for peptide-MHC binding predictions, BMC Bioinformatics 2014 (the BD2013 set) — pmc.ncbi.nlm.nih.gov
  14. Trevizani R. et al., A comprehensive analysis of the IEDB MHC class-I automated benchmark, Briefings in Bioinformatics 2022 — academic.oup.com
  15. Paul S. et al., Benchmarking predictions of MHC class I restricted T cell epitopes in a comprehensively studied model system, PLoS Computational Biology 2020 (validation in mice) — pmc.ncbi.nlm.nih.gov
  16. Solving an MHC allele-specific bias in the reported immunopeptidome, JCI Insight 2020 (the hydrophobicity bias) — insight.jci.org
  17. Hashemi N. et al., Improved prediction of MHC-peptide binding using protein language models, Frontiers in Bioinformatics 2023 (PPV at 1:19 and 1:99) — pmc.ncbi.nlm.nih.gov
  18. High-throughput, targeted MHC class I immunopeptidomics using a functional genetics screening platform, Nature Biotechnology 2023 (EpiScan; the cysteine control) — nature.com
  19. IPD-IMGT/HLA — statistics of named alleles, as of June 2026 — hla.alleles.org

The tools described here are research software, not medical devices — they narrow candidate lists in scientific work; they do not make clinical decisions.

← All posts

This page is educational — it is not medical advice and does not replace consultation with an oncologist. Diagnostic and treatment decisions are made solely by specialist physicians.