Robust self-nonself discrimination requires negative T cell selection on non-random peptides

Self-foreign discrimination by the immune system was long thought to arise because negative selection in the thymus silences self-reactive T cells. Yet recent data show that this silencing is remarkably incomplete. Here we ask how a repertoire containing many self-reactive cells can nevertheless discriminate self from foreign. We address this question using realistic-scale computational models of the T cell repertoire. Our models show that when foreign peptides dif-fer systematically from self, moderate T cell cross-reactivity skews the post-selection repertoire towards foreign recognition. When no such systematic differences exist, self-foreign discrim-ination is only possible if peptide presentation in the thymus minimizes the co-occurrence of similar, redundant self peptides. These results imply that negative selection needs to be based on non-random self peptides to allow robust self-foreign discrimination for both self-similar and -dissimilar pathogens.


and -dissimilar pathogens.
To eliminate pathogens without damaging healthy cells, the immune system must discriminate between self and foreign (nonself). The innate arm of the immune system is able to do so with a limited number of germline-encoded receptors that recognize pathogenassociated molecular patterns. By contrast, the adaptive arm of the immune system, which is found in all jawed vertebrates and is mediated by T and B lymphocytes, uses a vastly diverse repertoire of receptors to generate specific protective responses against any pathogen it encounters [1,2]. For example, humans have a repertoire of at least 10 7 different T cells [3], each expressing one or two of the >10 15 unique receptor sequences that can arise from the stochastic recombination of V(D)J gene segments and addition of non-templated nucleotides [4,5]. These T cell receptors (TCRs) recognize short foreign peptides presented on major histocompatibility complex (MHC) molecules on the surface of infected or cancerous cells.
However, the random TCR generation process inevitably also produces TCRs that recognize self peptides presented by healthy cells. It was long thought that the majority of these self-reactive receptors are effectively eliminated during T cell development in the thymus through a process termed negative selection [6], but recent studies have shown that this process is nowhere near as complete as it was thought to be [7,8,9]. In fact, given that T cells may only encounter an estimated 10 3 -10 5 different peptides during negative selection -a small fraction of all MHC-binding self peptides -it is not trivial how negative selection can achieve self-foreign discrimination at all [10,11,12]. English Xhosa reacting TCRs/million (a) Our model of string recognition represents TCRs by a binding motif -the string they bind to most strongly (top). Their affinity for any given string equals the maximum number of adjacent positions where the binding motif matches the string (bottom). (b) Simulating negative selection in silico: (1) TCRs in the unbiased pre-selection repertoire (with all possible 27 6 ≈400 million TCR motifs of 6 characters [a-z and ]) are deleted if their affinity for any of the training strings exceeds the functional response threshold t. (2) Unseen English and Xhosa strings are exposed to the post-selection repertoire to find the number of remaining TCRs reacting to them (that is, TCRs with affinity ≥t). (c) Reacting TCRs per million of unseen English and Xhosa strings, before and after negative selection on 500 English strings. Horizontal lines indicate medians. (d) Median and interquartile range of English-and Xhosa-reactivity after negative selection on English strings. (e) Percentage of Xhosa strings among the 10% of strings with the most reacting TCRs after negative selection on English strings (mean±standard deviation, SD, of 30 simulations). No discrimination should result in equal amounts (50%) of English and Xhosa strings in this top 10%. Throughout this figure, we tested 50 English and 50 Xhosa strings using an affinity threshold t = 3 for negative selection.

An artificial immune system discriminates self from foreign after negative selection
To investigate how incomplete negative selection can still foster effective self-foreign discrimination, we devised an "artificial immune system" (AIS) [13]. Our AIS is an algorithmic model of a T cell repertoire [14], similar to how an artificial neural network (ANN) is an algorithmic model of the central nervous system.
Because it was important to consider T cell repertoires of realistic scale and complexity, we exploited data compression techniques that allow building AISs containing billions of TCRs [15].
Like ANNs, AISs are not only used for in silico modelling of the biological system, but also as generalpurpose classification algorithms. We took advantage of this property by first using a well-interpretable classi-fication problem outside of immunology to investigate how a TCR repertoire could discriminate a foreign peptide from a self peptide it has not encountered during selection. Specifically, we built an AIS that distinguishes English from other languages based on short strings (letter sequences) of text. This artificial problem mimics the task of self-foreign discrimination because in both cases, classes (languages or proteomes) are to be distinguished based on a limited amount of information (short strings or peptides). A useful property of the language problem is that it can take on a range of difficulties, as very dissimilar languages such as English and the South-African language Xhosa are much easier to distinguish than related languages such as modern and medieval English.
Our model is based on an existing AIS [14,15,16] that represents each TCR as a binding motif, and defines a TCR's affinity for a string as the maximum number of adjacent positions where this motif matches the string ( Fig. 1A) [17]. A TCR is defined to react to all strings for which it has an affinity of at least some threshold t, which represents a functional response threshold rather than a mere binding threshold. Crucially, reaction does not require a perfect match between the string and TCR motif. Thus, our TCRs are cross-reactive and react to multiple, related peptides.
To test how well TCR repertoires could discriminate between two very dissimilar languages (English and Xhosa) after incomplete negative selection, we started with an unbiased pre-selection repertoire with equal numbers of TCRs reacting to English and Xhosa, and Given that peptides to which many TCRs react tend to elicit stronger immune responses [18], it is important that these most frequently recognized peptides are predominantly foreign. The 10% most frequently recognized strings in our simulation were indeed predominantly Xhosa strings (Fig. 1E). The affinity distribution of these TCR interactions was shifted towards higher affinities for Xhosa, but only very slightly ( Fig   S1A). For sake of simplicity, we therefore focus only on the number of reacting TCRs throughout this paper, rather than considering different affinities separately.

Discrimination success relies on moderate cross-reactivity and sequence dissimilarity
These results confirm that our AIS can easily distinguish English from Xhosa even after incomplete negative selection. To investigate in more detail under which conditions this discrimination arises, we analyzed which TCRs were deleted during negative selection on English strings (Fig. 2). TCRs reacting to "unseen" English strings (those absent from the training set TCRs were exposed to during negative selection) had a reduced survival compared to TCRs reacting to Xhosa strings ( Fig. 2A). Because TCRs are only deleted when they react to at least one string in the training set, this implies that strings eliciting reactions from the same TCRs tend to represent the same language. To visualize this, we created graphs in which each node represents a string, and two nodes become connected neighbors when at least 5 TCRs per million pre-selection TCRs react to both of them (Fig. 2B). Indeed, neighbor strings are largely from the same language (Fig. 2B, left), which is quantified by the concordance, the average proportion of neighbors from the same language. To show that the high concordance (0.81) of English and Xhosa strings represents intrinsic differences between English and Xhosa strings, we randomly divided English strings into two groups and constructed a similar graph, which as expected has a concordance of only 0.5 (Fig. 2B, right). This confirms that our TCRs can only discriminate between two sets of strings that are intrinsically different.
Our results indicate two key requirements for achieving self-foreign discrimination through negative selection on an incomplete subset of self: an appropriate level of TCR cross-reactivity towards multiple, related strings, and sufficient dissimilarity between self-and foreign.
To illustrate the importance of cross-reactivity, we set the affinity threshold in our model to t = 6, so that each TCR was maximally specific and only reacted to the one string matching its binding motif perfectly (i.e., no cross-reactivity). The corresponding graph contains no neighbors at all (Fig. 2C, left) and has a concordance of 0.5 (Fig. 2D,E). Consequently, maximal TCR specificity abolishes self-foreign discrimination in our model (Fig. 2E) because without cross-reactivity, negative selection cannot delete TCRs for strings that are not part of the training set -it therefore deletes very few TCRs (Fig. S1B). However, very low specificity (t = 1) is equally problematic as it results in a graph where any two strings are neighbors irrespective of language (Fig. 2C, right), which leads to low concordance even between dissimilar languages (Fig. 2D,E), poor self-foreign discrimination (Fig. 2E), and often even deletion of the entire repertoire (Fig. S1B). Only intermediate specificities allow TCRs to preferentially react to either English or Xhosa strings (Fig. 2C, middle).
This results in both a high concordance (Fig. 2D,E) and a preference for Xhosa-reactivity in the post-selection repertoire (Fig. 2E).
As shown in Fig. 2B, even an optimal level of cross-reactivity will not result in a high concordance unless the languages are intrinsically different. The accomplished level of self-foreign discrimination therefore depends directly on the similarity between self- The control "English" compares two sets of English strings from the same book that was used for training (Moby Dick), whereas "English (different book)" compares unseen English strings from the training book to those from the Bible. and foreign sequences. Indeed, when we repeated our analysis for a number of other languages with varying similarity to English, we found a linear correlation between concordance and the acquired level of discrimination (Fig. 2F). This was a property of the tested languages rather than the specific texts chosen, as our model could not discriminate between English strings from different books (Fig. 2F).

Sequence similarity hampers discrimination between self-and foreign peptides
These results on natural languages suggest that TCR cross-reactivity and sequence dissimilarity should also be important for self-foreign discrimination in the im-mune system. We therefore applied our AIS model to self-foreign discrimination by CD8 + T cells, which recognize peptides bound to the MHC class I (MHC-I) complex with a typical length of nine amino acids (AAs). The six residues at positions 3-8 are thought to be most relevant for TCR binding [19]. Accordingly, we modified our TCR model to accommodate 6-mer peptide sequences rather than six-letter strings ( repertoires (Fig. S2B), in line with experimental data [21,22,23,24]. These results suggest that the crossreactivity level of TCRs roughly matches that of our model at t = 4, well within the "moderate" range allowing discrimination between dissimilar strings (Fig.   2D,E).
To examine whether self-and foreign peptides are dissimilar enough to allow self-foreign discrimination, we first predicted MHC-I-binding peptides from the human proteome [25] and used the residues 3-8 as MHC-bound self peptides in our model. To obtain foreign sequences, we predicted MHC binders for a variety of pathogens associated with T cell immunity: the malaria parasite, the bacterium Listeria monocytogenes, and the viruses ebola, hepatitis B, hepatitis C, human cytomegalovirus (HCMV), human immunodeficiency virus (HIV), and vaccinia (Table S1).
Graphs of self versus foreign peptides had strikingly low concordances (Fig. 3B) [17], barely exceeding the control concordance observed between two random, different sets of self peptides ("Self", negative control), and lower than the concordance we had observed between modern and medieval English. This was a property of the sequences themselves rather than the chosen threshold t (Fig. S3A). In a graph of all HIV peptides and their neighbors, the majority of HIV peptides had many self neighbors whereas none of them had HIV neighbors (Fig. 3C) -indicating that most HIV peptides are more similar to peptides from the human proteome than to other HIV peptides.
This high similarity between self-and foreign peptides suggests that achieving self-foreign discrimination via negative selection is difficult. Indeed, although the realistic cross-reactivity at t = 4 allowed some discrimination between self-and HIV peptides as shown by a small enrichment of HIV among most frequently recognized peptides (Fig. 3D, left), this effect came nowhere close to that observed for languages (Fig. 1E), even with very large numbers of training self peptides.
Consistent with this observation, the survival of selfreactive TCRs was only slightly lower than that of HIV-reactive TCRs (Fig. 3E, left). These results were not specific for HIV peptides, as we obtained similarly low levels of self-foreign discrimination for all other (a) Self peptides from large clusters delete the same TCRs as their neighbors and are thus exchangeable during negative selection, whereas peptides from small clusters are not. (b) Mean percentage of self-reactive TCRs deleted by optimal versus random training sets of self peptides during negative selection. (c) Peptide exchangeability distribution in the full set of all self peptides compared to that in random and optimal subsets of 100,000 peptides. Exchangeability is defined as the number of self neighbors + 1. (d) Self-HIV discrimination after selection on random or optimal training sets. (e) Percentage of self peptides with HIV neighbor(s) plotted against exchangeability (self peptides were divided into 10 equal-number deciles from low to high exchangeability). (f) AA enrichment in optimal training set. Enrichment is the log of the observed frequency divided by the frequency among all self peptides. Negative values indicate depletion. (g) Exchangeability versus peptide AA frequency score in a random sample of 1000 self peptides (frequency score is low for peptides with many rare AAs, [17]). Pearson's correlation coefficient r = 0.716, with 95% confidence interval [0.684, 0.745]. (h) Discrimination after negative selection on self peptides chosen with a (weak/strong) bias for rare AAs. Plots show self-HIV discrimination (left), and self-other self discrimination (right, where a random sample of self was assigned the label "foreign" before selection on training sets from the remaining "self" peptides). (e) Self-foreign discrimination for different pathogens after negative selection on 150,000 self peptides chosen randomly or with AA bias. Negative selection in panels b, d, h, and i was performed with t = 4, and results were plotted as mean±SD of 30 simulations.
pathogens tested (Fig. S3B). Self-HIV discrimination was even worse for t = 3 and rapidly disappeared completely as TCR survival diminished for large training sets (Fig. 3D,E, right), confirming that self-foreign discrimination becomes more difficult when TCRs are too cross-reactive.

Selection on non-random peptides greatly improves self-foreign discrimination
Thus, although incomplete negative selection can achieve self-foreign discrimination in principle, achieving sufficient discrimination is very difficult in practice because self-and foreign peptides can be extremely similar and therefore can be recognized by the same TCRs. Clearly, the immune system must overcome this problem in order to balance the removal of self-reactivity with the preservation of foreign recognition. It has previously been suggested that thymic selection should occur on a non-random set of self peptides to achieve self-foreign discrimination [12]. We therefore used our model to investigate what an "optimal" set of self peptides would look like, and how much this might improve self-foreign discrimination.
As a starting point, we based the optimization of the training set on the peptide cluster structure as observed in Fig 3C. The large clusters in this graph contain many similar self peptides, which can delete the same TCRs during negative selection (Fig 4A). Exchanging one such peptide for one of its neighbors during selection thus has little effect on the post-selection repertoireand presenting both has little added value. By contrast, self peptides in smaller clusters are far less exchangeable ( Fig 4A): their TCRs cannot be removed as easily by other peptides. Thus, negative selection on randomly chosen training sets is inefficient: these sets often contain several exchangeable peptides that delete the same TCRs, while simultaneously missing many non-exchangeable peptides and allowing the corresponding self-reactive TCRs to escape. We therefore used combinatorial optimization techniques [17] to compute peptide combinations that deleted as many different self-reactive TCRs as possible ("optimal" training sets, Fig 4B). As expected, these optimal training sets contained fewer exchangeable peptides (Fig 4C, where exchangeability equals the number of self neighbors plus one).
We then tested whether these training sets optimized for inducing tolerance could also establish selfforeign discrimination. This is not guaranteed, as the latter requires not only the removal of self-reactive TCRs, but also the preservation of foreign-reactivity.
Nevertheless, our optimal training sets substantially improved self-foreign discrimination (Fig 4D). This seems to be a consequence of the enrichment for low exchangeability peptides (Fig 4C), which are less likely to delete HIV-reactive TCRs (Fig 4E). Importantly, this discrimination still required appropriate TCR crossreactivity and was absent at t = 3 (Fig. S4B). From these results, we conclude that negative selection on a representative set of self peptides can alleviate the problem of self-foreign similarity, but only when TCRs are sufficiently specific.
Obviously, our optimal training sets are artificial, and biological negative selection cannot calculate which self peptides should be present in the thymus. We therefore investigated how a representative set of self peptides might reasonably be obtained during real negative selection. Analysis of our optimal training sets revealed an enrichment for rare AAs compared to the total set of self peptides (Fig. 4F). Interestingly, peptides with many rare AAs were typically less exchangeable ( Fig 4G). This finding suggests that training sets enriched for rare AAs -similar to our optimal sets -contain fewer exchangeable peptides, and might thus result in better self-foreign discrimination.
To test this hypothesis, we again generated training sets of different sizes, but this time picked our training peptides with a probability that depended on the AA composition of each peptide [17]. These probabilities introduced either a weak or a strong bias for self peptides with rare AAs, mimicking the AA enrichment pattern observed in our optimal training sets. This AA bias substantially improved self-foreign discrimination after negative selection, for HIV (Fig. 4H, left) and all other pathogens tested (Fig. 4I, S4A). Interestingly, this strategy also worked when we first set aside a random sample of other self peptides as "foreign" before selecting training sets from the remaining "self" peptides. In this scenario, biased training sets still yielded substantial self-"foreign" discrimination, whereas random sets did not (Fig 4H, right). This result demonstrates that negative selection on non-random training peptides facilitates self-foreign discrimination -even in the extreme case where no inherent difference between self and foreign peptides exists.

Discussion
Our AIS model explains how negative selection on an incomplete set of self peptides can nonetheless bias a T cell repertoire towards foreign recognition. We demonstrate that a non-random subset of self peptides enriched for rare AAs can balance the removal of selfreactive TCRs with the preservation of foreign-reactive receptors. Importantly, this strategy works even when self and foreign peptides are not inherently different.
In fact, for the pathogens we considered, the similarity to self was so high that it is hard to conceive how any self-foreign discrimination could be achieved through negative selection on random peptides. By contrast, a "smart" peptide presentation strategy could still ensure that the peptides best recognized by the immune system are predominantly foreign -even in this difficult scenario. This notion reconciles textbook negative selection theory with recent observations that T cells see only a fraction of all self peptides during thymic selection, and that even healthy individuals have many self-reactive T cells [7].
Our finding that non-random peptide presentation is a prerequisite for efficient self-foreign discrimination raises the question how the thymus might obtain a preference for presenting low-exchangeability peptides.
Although it remains unclear exactly which and how many peptides a T cell sees during selection, the importance of the thymic peptidome in shaping the TCR repertoire is evident from the existence of specialized antigen presenting cells, transcription factors such as AIRE, and even special proteasomes controlling thymic peptide presentation [26]. We suggest that the biased presentation of low-exchangeability peptides required for self-foreign discrimination might arise from special binding preferences of thymic antigen presentation proteins. As has already been shown for the thymoproteasome during thymic positive selection [27,28], such binding preferences can enrich for specific subsets of self peptides and thereby impact the ability of a TCR repertoire to recognize self and foreign. While a bias for specific AAs such as described in this paper would be one way to enrich for low-exchangeability peptides, we do not exclude that other binding preferences could have a similar impact on self-foreign discrimination.
Importantly, our imperfect selection accomplishes self-foreign discrimination by also reducing the recognition of peptides the T cell repertoire has not seen during selection. This capability of the T cell repertoire to generalize beyond given examples is a fundamental property of learning systems [29], and allows the repertoire to perform a cognitive task: learning to distinguish self from foreign. Even though this learning process mechanistically differs from learning by the central nervous system, its high-level outcome is remarkably similar, and shares many properties with "slow learning" systems as described in psychology and neuroscience [30].