Main

Balancing selection maintains much of the biological diversity on our planet1. Pathogen-mediated balancing selection (PMBS), in particular, shapes the exceptionally high polymorphism commonly observed in genomic regions encoding innate2,3 and adaptive4,5 immune responses. In vertebrates, the major histocompatibility complex (MHC) is the most polymorphic and best-understood genetic basis of pathogen resistance6,7. MHC molecules are an essential cell surface component of the immunological cascade that recognizes and presents pathogen-derived peptides to T cells8. A central tenet of PMBS in maintaining MHC polymorphism is the rare-allele advantage, which emerges from pathogens evolving to evade common MHC variants. Thus, rare variants, if advantageous, increase in frequency until pathogens counter-adapt6,9,10. This sets up a cyclic arms race between hosts and pathogens that theoretically maintains high levels of MHC polymorphism11. Yet, such negative frequency-dependent selection on the MHC has been documented only in experiments on short-lived model organisms, such as mice and fish12,13,14, or inferred from snapshots in time15,16,17. Robust evidence from natural populations documenting the entire cycle in which a common MHC allele becomes rare following pathogen evasion and then regains resistance is lacking.

One explanation for the lack of evidence for the rare-allele advantage, especially from natural systems, is that findings are often also compatible with other mechanisms of PMBS, such as heterozygote advantage9,18 and fluctuating selection19,20. The heterozygote advantage hypothesis is conceptually related to the rare-allele advantage in that both stem from the idea that single alleles can bind peptides from a limited range of pathogens. Hosts with a greater number or a more divergent repertoire of alleles are therefore expected to mount efficient responses against a wider range of pathogens4,21,22,23. Fluctuating selection arises from spatio-temporal variation in PMBS, resulting in the enormous allelic diversity seen at the species level, while maintaining a more limited subset in local populations24,25. Owing to their conceptual similarities, host–pathogen associations may resemble any of these mechanisms, making a clear differentiation difficult6,9,26,27. However, depending on the underlying mechanisms, the MHC is expected to evolve differently compared with neutral markers9,25,27,28,29. Hence, delineating between mechanisms requires a comparison of MHC and neutral genetic evolution, and a contrast of MHC–pathogen associations over space and time, ideally across multiple populations6,9.

Although bacteria of the Mycobacterium tuberculosis complex cause debilitating, often lethal, tuberculosis (TB) infections in humans30 and wildlife31, evidence for long-term selection is lacking32,33,34,35. Here we leverage two decades of Mycobacterium suricattae surveillance, individual disease records and new MHC class II data from over 1,500 wild meerkats (Suricata suricatta) living in tight social groups at the Kuruman River Reserve in the Kalahari Desert, South Africa. In the cooperative breeding system of meerkats, a dominant breeding pair largely monopolizes reproduction and employs group members to help in pup care36. The pair asserts their dominance through aggression within their social group37, and aggressive feuds over territories between neighbouring groups are common38. Aggression is also presumed to be among the main behavioural mechanisms by which the meerkat-specific M. suricattae, first reported in the 1990s, spread through the population39,40,41. After a long latent period, the infection causes swelling of the submandibular, inguinal and cervical lymph nodes, progressing to lesions, physical deterioration (Fig. 1a) and death within an average of 6.6 months after clinical signs appear39,42,43. While TB curbs survival, disease progression varies widely, with some individuals surviving up to 7 years after the onset of clinical signs39. This variability provides a unique opportunity to investigate the links between TB, immunogenetics and fitness in a longitudinally monitored wildlife population (Supplementary Fig. 1 and Supplementary Table 1). First, we describe MHC class II diversity in meerkats and then test whether the evolution at the MHC outpaces evolution at neutral genetic markers, indicating that PMBS affects host immunogenetics rather than microsatellite markers. Second, we hypothesize that the MHC composition and functional diversity explains interindividual differences in meerkat TB susceptibility, survival and lifetime reproductive success better than neutral genetic diversity and compare them with other biological, socio-ecological and environmental covariates. Finally, we attempt to distinguish between three mechanisms of PMBS, that is, rare-allele advantage, heterozygote advantage and fluctuating selection (Fig. 1b). Indeed, we document that a single allele correlated with TB susceptibility, survival and lifetime reproductive success, and we draw from several lines of evidence to suggest that the dominant mechanisms are likely to be rare-allele advantage or fluctuating selection.

Fig. 1: Indicators for meerkat TB infection and alternative mechanisms of PMBS.
figure 1

a, Contrast between meerkats without clinical signs of Mycobacterium suricattae infection and those displaying swelling of head lymph nodes (for example, white arrow in central picture), open lesions (for example, white arrow in right picture) and physical deterioration. b, A comparison between allele frequency distribution, population structure and MHC–pathogen association allows to differentiate evolution at the MHC from evolution at neutral markers and to inferentially distinguish between possible non-mutually exclusive mechanisms of PMBS (visually adapted from ref. 9). Meerkat photo credit: Simone Sommer and Shaylee Alderton. This figure was created with BioRender.com.

Results

Meerkat MHC class II DRB polymorphism and neutral genetic evolution

High-throughput sequencing identified 37 functional MHC-DRB exon 2 alleles in 1,567 meerkats (Fig. 2a,b). Meerkats carried between one and seven MHC alleles (median: 2, mean: 2.5 ± 1.1 standard deviation (s.d.)), suggesting the presence of at least four distinct DRB loci. This was confirmed by manual annotation of the MHC class II genes, where we identified two complete DRB loci and an additional two exon 2 fragments as well as two potential pseudogenes (Supplementary Tables 4 and 5). All functional alleles map to exon 2 of the functional DRB loci (for more details, see Supplementary Results).

Fig. 2: Meerkat MHC class II diversity and neutral genetic evolution over time.
figure 2

a, The relative abundance of MHC-DRB alleles among 1,567 sampled meerkats. The dashed line indicates the 5% threshold. Coloured boxes represent alleles with data available for all study years. b, The total number of uninfected (dark grey), TB-exposed (blue) and TB-positive (orange) individuals with MHC genotype information compared with the rest of uncharacterized meerkats in the population (light grey). c, Change in relative abundance (termed frequency; mean ± s.d.) of the six Susu-DRB alleles present in at least 5% of the population in each year since 1999. The dashed line and shaded area represent neutral genetic diversity (measured as Hexp; mean ± sd). d, Estimated annual evenness of MHC (black) and microsatellite (grey) allele frequencies. e, Fitted regression (±95% CIs) of genetic differentiation (that is, pairwise Fst) of the meerkat population over time estimated from microsatellite (grey) and MHC data (black).

Source data

MHC alleles varied in their relative abundance (referred to as frequency henceforth) over time (Fig. 2c), with average individual expected microsatellite heterozygosity (Hexp) remaining stable over time. We found that MHC allele frequencies were more evenly distributed compared with those of neutral genetic markers (mean difference: 0.08; paired t-test −8.10, P < 0.001; Fig. 2d), possibly arguing for recycling of MHC alleles in line with a frequency-dependent rare-allele advantage. Besides, MHC and microsatellite fixation index (Fst) diverged over time (Mantel test on microsatellites: P = 0.001; slope 1.1 × 10−3, confidence interval (CI) 1.0 × 10−3 to 1.2 × 10−3; on MHC markers: P = 0.001; slope 1.9 × 10−3, CI 1.7 × 10−3 to 2.0 × 10−3). The molecular divergence was higher at the MHC-DRB alleles than estimated for the microsatellites (interaction: P < 0.001; estimate −7.8 × 10−4; CI 8.9 × 10−4 to 6.6 × 10−4; Fig. 2e and Supplementary Table 6), suggesting stronger selection acting on MHC alleles.

The 37 functional alleles clustered into 12 functionally distinct MHC supertypes (Supplementary Table 7 and Supplementary Fig. 2a) and combinations of these alleles were probabilistically sorted into 16 functional haplotypes (Supplementary Table 8 and Supplementary Fig. 2b). Individuals carried between one and six supertypes (median: 2, mean 2.3 ± 0.9 s.d.). Most individuals carry two haplotypes, with only 14.6% classified as homozygotes. Any further analyses were performed on functional MHC alleles, supertypes and haplotypes occurring in more than 5% of the study population and in all years.

MHC associations with TB and fitness

First, we identified four MHC alleles (Susu-DRB*01, Susu-DRB*03, Susu-DRB*07 and Susu-DRB*13; Fig. 3a), six supertypes (ST01, ST02, ST03, ST04, ST05 and ST09; Supplementary Fig. 3a) and one haplotype (F; Supplementary Fig. 4a) to be repeatedly associated with clinical signs of TB over the 20 years studied since 1999. For each candidate MHC allele, supertype and haplotype, we ran separate models to estimate the likelihood to ever develop clinical TB signs (TB susceptibility), the likelihood to progress from exposure to clinical signs (TB progression), persist with a clinical TB infection (TB resilience), survive and reproduce (lifetime reproductive success). All models controlled for MHC and neutral genetic diversity, as well as biological, socio-ecological, and environmental covariates, and presented P values are false discovery rate corrected. Because we were interested in whether pathogen–MHC associations vary over time, we included interactions between the linear and quadratic terms of year and MHC measures (see Methods for more detail).

Fig. 3: MHC-DRB allele association with TB susceptibility.
figure 3

a, A heat map displaying higher (that is, positive association) and lower (that is, negative association) likelihood of observing TB signs in meerkats with different MHC-DRB alleles based on co-occurrence analysis (*P < 0.05, **P < 0.01). b,c, Effect sizes (±95% CIs; n = 1,497) for all explanatory variables included in the generalized linear mixed-effects model including the MHC allele Susu-DRB*13 (b) and visualization of nonlinear effects of Susu-DRB*13 (green) on TB susceptibility over time (c). Significant effects are in blue (lower likelihood of developing TB signs) and red (higher likelihood of developing TB signs).

Source data

Carrying Susu-DRB*13 influenced TB susceptibility over time (estimate −1.16, CI −2.02 to −0.31; P < 0.01; Fig. 3b and Supplementary Table 9). Meerkats with Susu-DRB*13 experienced a heightened risk of developing TB signs between 1999 and 2010. This pattern reversed by 2013, when individuals carrying the Susu-DRB*13 allele had a lower likelihood of developing clinical signs compared with those with other alleles (Fig. 3b). Susu-DRB*13 is the only common allele (occurrence >5%) to feature an arginine at the positively selected site (PSS) 56 and a serine at 57 (Supplementary Data 1). Similarly, individuals with haplotype F, which included Susu-DRB*13, faced higher risk until the early 2010s before the risk of developing signs declined (estimate −5.04, CI −8.57 to −1.51, P < 0.05, Supplementary Fig. 4b,c and Supplementary Table 9c), although this analysis relied on a smaller sample size. By contrast, TB susceptibility was generally increased in meerkats carrying Susu-DRB*07 (estimate 0.68, CI 0.25 to 1.21, P < 0.01; Supplementary Table 9), whereas individuals carrying alleles clustering into the supertype ST04 showed low susceptibility initially until approximately 2010 when individuals with ST04 became more likely to develop TB signs (estimate 2.38, CI 1.25 to 3.52, P < 0.001; Supplementary Fig. 3b,c and Supplementary Table 9b).

TB-exposed individuals carrying Susu-DRB*13 (and its corresponding ST09 and haplotype F) were less likely to progress to clinical signs of TB over the course of the study (estimate −1.23, CI −1.95 to −0.51, P < 0.01; Supplementary Table 10). A weaker influence on TB progression over time was also detected for Susu-DRB*07 (and its corresponding ST03, estimate −0.77, CI −1.26 to −0.28, P < 0.01; Supplementary Tables 10), ST01 (estimate 0.71, CI 0.19 to 1.24, P < 0.05; Supplementary Table 10) and ST04 (estimate 0.74, CI 0.13 to 1.36, P < 0.05; Supplementary Table 10). In addition, meerkats carrying Susu-DRB*13 lived for longer after showing first clinical signs than TB-positive individuals with other alleles (estimate 0.29, CI 0.13 to 0.44, P < 0.001; corresponding ST09: estimate 0.24, CI 0.08 to 0.40, P < 0.05; haplotype F: estimate 0.35, CI 0.10 to 0.61, P < 0.05; Fig. 4a and Supplementary Table 11). However, this effect on resilience was independent of year. The results of the survival models argue a similar point (Supplementary Table 12): while individuals with clinical TB signs showed a roughly fivefold mortality risk (estimate 1.50; CI 1.14 to 1.87, P < 0.001), TB-positive individuals carrying Susu-DRB*13 survived for longer (estimate −0.95; CI −1.17 to −0.17, P < 0.05; Fig. 4b). The same was true for individuals with haplotype F in the smaller sample population (estimate −2.33; CI −3.91 to −0.74, P < 0.01; Supplementary Table 12). Finally, individual lifetime reproductive success, as the ultimate Darwinian fitness measure, was generally higher in individuals that carried Susu-DRB*13 (estimate 0.99, CI 0.23 to 1.75, P < 0.05) and peaked between 2005 and 2013 (estimate −2.58, CI −4.59 to −0.58, P < 0.05; Fig. 4c and Supplementary Table 13). By contrast, for individuals with the most common MHC allele Susu-DRB*01 or its corresponding supertype, lifetime reproductive success declined linearly over the years (Susu-DRB*01: estimate −0.85, CI −1.45 to −0.25, P < 0.05; ST01: estimate −0.89, CI −1.54 to −0.24, P < 0.05; Supplementary Fig. 5).

Fig. 4: MHC-DRB allele association with fitness.
figure 4

ac, Carrying MHC allele Susu-DRB*13 (green) when infected with TB improved TB resilience (*P < 0.05; n = 1,497) (a), life expectancy (n = 1,535) (b) and lifetime reproductive success (LRS; n = 1,497) (c). A summary of the generalized linear mixed-effects model output is given (left), and visualizations—including a box plot (median and interquartile range), a violin plot (density, median, and interquartile range) and the nonlinear effect of Susu-DRB*13 (green) over time—are presented (right). P-adjusted significant positive effects (±95% CIs; for example, longer survival with TB signs) are given in blue and negative effects (for example, shorter survival with TB signs) in red.

Source data

In addition, socio-ecological and environmental factors correlated with TB risk and fitness in meerkats: For example, dominant meerkats were more susceptible but subordinates with TB have a sevenfold lower survival chance. Higher mean temperature increased the likelihood to progress to clinical signs of TB, while reduced rainfall increased mortality risk (see Supplementary Results for detailed information; Supplementary Tables 913).

Delineating between mechanisms of PMBS

Comparing between the evolution of MHC and neutral genetic markers, and looking at MHC–pathogen associations, can help differentiate among rare-allele advantage, fluctuating selection and heterozygote advantage (Fig. 1b). Yet, without replicated meerkat populations, we are left with inference and deduction. The higher evenness of MHC allele frequencies compared with those of neutral markers supports the rare-allele and heterozygote advantages, whereas the greater temporal divergence at the MHC is characteristic of rare-allele advantage or fluctuating selection. Among these mechanisms, we think heterozygote advantage is least likely because, even though in the TB susceptibility null model (that is, without specific MHC alleles) allelic diversity had a significant effect (estimate −1.56, CI −2.63 to −0.50, P < 0.05; Fig. 5a and Supplementary Table 9), when Susu-DRB*13 was included, this effect was not recovered (estimate −0.46, CI −1.70 to 0.78, P = 0.466; Supplementary Table 9). We hypothesized, therefore, that the effect of MHC diversity was driven by the effect of this single allele. If this were the case, we would expect MHC diversity to have no effect when meerkats carrying Susu-DRB*13 were excluded from the model. As predicted, MHC diversity was not retained in the model (Fig. 5b and Supplementary Table 14). To underscore this, we assessed whether hosts with more alleles were also more likely to carry Susu-DRB*13. We found that a higher number of MHC alleles increased the chance of carrying Susu-DRB*13 (G = 295.25, chi-squared d.f. 6, P < 0.001; Fig. 5c) and homozygous individuals never carried haplotype F, whereas 10.7% of heterozygous individuals did. Although there are exceptions (for example, TB progression models), this pattern holds true across TB and fitness measures, as well as for supertypes and haplotypes.

Fig. 5: Effect of MHC allelic diversity on TB susceptibility.
figure 5

a,b, MHC allelic diversity impacts TB susceptibility (effect size ± 95% CIs) in the null model (not including MHC allele Susu-DRB*13 as an explanatory variable but including individuals with Susu-DRB*13 as part of their MHC profile) (a) but not after excluding individuals carrying Susu-DRB*13 (effect size ± 95% CIs) (b). c, The likelihood of carrying MHC allele Susu-DRB*13 increases in individuals with more MHC alleles.

Source data

Finally, we found that, when TB prevalence was high, implying a stronger selection by TB, the change in frequency of the allele Susu-DRB*13 from one year to the next tended to be positive (correlation: R2 = 0.51, P = 0.035, Fig. 6), which implies individuals with this allele either survive better and/or produce more offspring. By contrast, Susu-DRB*03 was negatively correlated with TB prevalence (R2 = 0.52, P = 0.034). Yet, even this time-lagged approach of selection-driven frequency changes cannot clearly distinguish between rare-allele advantage and fluctuating selection as the dominant mechanism driving evolution at the MHC without a comparison to other populations.

Fig. 6: MHC-DRB allele frequency changes with TB prevalence.
figure 6

a, Visualization of the change in Susu-DRB allele frequency and TB prevalence (black line) over time. The dashed grey line represents zero change from one year to the next, with declines in the relative abundance of the MHC allele shown as negative changes (indicated by a downward-pointing arrow) and increases as positive changes (indicated by an upward-pointing arrow). b, Correlation (±95% CIs) between MHC-DRB allele frequency changes and TB prevalence. Dashed lines are non-significant, whereas solid lines indicate significant correlations.

Source data

Discussion

Tracking PMBS on host immunogenetics over time is a rare feat, with few studies able to show dynamics beyond one decade28,29,44,45. Particularly in the wild where other ecological and evolutionary processes co-occur, delineating between mechanisms driving PMBS proved difficult6,9. We collated data on two decades of selection by the TB-causing bacterium Mycobacterium suricattae in wild meerkats with molecular data from neutral and MHC genetic markers as well as socio-ecological and environmental information. We find that TB signs and TB-associated deaths drove stronger selection on MHC than on neutral genetic diversity. An initially susceptible MHC allele (and corresponding haplotype) emerged as advantageous variant in the later years, with benefits for host survival and reproduction. Our study offers rare evidence for multidecadal host immune gene evolution arising from selection by a devastating wildlife pathogen.

To understand pathogen-mediated selection on the MHC, one ideally compares MHC evolution with that of neutral genetic markers, examines MHC–pathogen associations in space and time across multiple populations, and aims to distinguish between the non-mutually exclusive mechanisms of PMBS, that is, rare-allele advantage, fluctuating selection and heterozygote advantage9. While our study meets some of these criteria, it falls short in others. For instance, the distribution of MHC allele frequencies was more even than for neutral markers, aligning with result from house finches46 and montane voles47. This pattern is indicative of PMBS and could arise from the advantage of having multiple co-dominant alleles, recycling of (rare) alleles in the population or fluctuating selection9,19,27. In addition, comparing population structure estimated from MHC and neutral genetic markers over time48, we found a greater differentiation at the MHC. This was also found in one out of three hefts in the St. Kilda Soay sheep29 and suggests either rare-allele advantage or fluctuating selection. Yet, our incomplete MHC and pedigree information for the 3,420 meerkats alive during our study, and our reliance on microsatellites over single-nucleotide polymorphisms, prevented a more sophisticated analytical approach to detect deviations in allele frequencies beyond neutral expectation (for example, gene-drop analysis)45. All in all, we find evidence that PMBS drives immune gene evolution in meerkats, albeit this conclusion is based on microsatellites.

We also found that clinical TB infection probability was associated with certain MHC alleles. For example, the risk of developing clinical signs was higher in meerkats carrying Susu-DRB*07 throughout the 20-year study. By contrast, meerkats with Susu-DRB*13 were initially more likely to develop signs than those with other MHC alleles, until around 2013, when the individuals with this allele became less likely to develop clinical TB. We found the same results for individuals carrying the haplotype F, to which Susu-DRB*13 was assigned to, although the analysis was carried out on a subsample. In humans as well, where TB has been a leading cause of death for centuries, individual single sequence variants between HLA-DQA1 and HLA-DRB1 have been strongly and repeatedly associated with M. tuberculosis infections and pulmonary TB disease in Icelandic, Russian and Croatian populations34. We lack this cross-populations comparison, which is necessary to differentiate between the mechanisms of PMBS9. This was attempted in an 11-year-long study in which three subpopulations of bank voles were sampled every 3–4 years44. The authors found that distinct MHC supertypes explained differences in helminth abundance between years and populations44, invoking either locally (or regionally) fluctuating selection or rare-allele advantage as key mechanisms in this system. Yet, in line with predictions from the rare-allele advantage, voles carrying MHC supertypes common in the recent past were more intensely infected with helminths44. Applying this time-lagged approach, we showed that DRB*13 increased in frequency between years when TB prevalence was high in the year before, possibly suggesting a rare-allele advantage in our continuously sampled wildlife population.

A unique feature of our work is the switch from high to low susceptibility in the MHC allele Susu-DRB*13. When exposed to TB, meerkats with Susu-DRB*13 are also less likely to develop clinical TB. The fitness advantage was evident even among TB-positive meerkats, with those carrying Susu-DRB*13 surviving longer than individuals with other alleles in 90% of cases. Single MHC genotypes also determined survival in Seychelles warblers49, red jungle fowls50, Chiricahua leopard frogs51 and root voles52. In rhesus macaques infected with simian immunodeficiency virus—which has a TB-like disease progression characterized by a long latency period followed by rapid deterioration once AIDS-like symptoms appear—a distinct MHC haplotype explained 48% of the observed variation in survival time53. Compared with this experimental study, the effects of MHC on meerkat survival in nature were subtle. This subtlety may reflect the complexity of innate and adaptive immune responses to TB: in humans, TB can evade or even exploit MHC-II-mediated responses, suppressing antigen presentation or co-opting CD4+ T cells to access host tissues54,55,56,57. As a result, strong immune activation may benefit the host only if the infection is rapidly cleared, which may be uncommon in natural settings54,58. Additionally, meerkats with Susu-DRB*13 benefitted from increased lifetime reproductive success. Associations between MHC genetics and reproductive output has been observed in stickleback59, pied flycatchers60, great tits61 and Soay sheep45. As in these systems (but see ref. 61), greater reproductive success probably arises from prolonged survival because living for longer is the strongest predictor of lifetime reproductive success. Greater resilience, prolonged survival and, as a consequence, increased reproduction may explain the steady increase in Susu-DRB*13 frequency when TB selection was high. Taken together, our findings support a role of host genetics in TB susceptibility and host fitness.

Neither the comparison with neutral markers, nor the patterns of MHC–pathogen association, nor the correlation between frequency changes and TB prevalence allowed us to fully discriminate between the mechanisms of PMBS. However, a few arguments support fluctuating selection and rare-allele advantage as key mechanisms at play in meerkats of the Kuruman River Reserve in South Africa. The greater divergence of MHC compared with neutral markers, the comparisons of models with and without Susu-DRB*13 and an increased chance to carry Susu-DRB*13 the more alleles an individual carried can be interpreted as exclusion criteria for the heterozygote advantage. Similar criteria ruled out heterozygote advantage in helminth-infected Soay sheep29,45,62, in root voles infected with bacterial and protozoan blood parasites52 and in humans infected with human immunodeficiency virus63. Still, we lack infection data for other pathogens affecting meerkats, which could reveal that different MHC alleles confer resistance to distinct pathogens, ultimately contributing to a heterozygote advantage4,23,64. Associating MHC measures and pathogen diversity would further help to delineate between PMBS mechanisms9. Moreover, we lack information on the co-evolution of M. suricattae over the course of our study. Because M. suricattae, like other members of the Mycobacterium complex, is likely to be under purifying selection, we expect a slow evolutionary rate65. This may allow ample time for hosts to adapt to a dominant variant and for beneficial genotypes to increase in frequency (as in some multigenerational studies12,23,28,48 but not in others16,17,62,66,67,68,69). Although this suggests a rare-allele advantage, without a cross-population comparison, both rare-allele advantage and fluctuating selection are plausible.

However, socio-ecological factors cannot be ignored in a disease disseminated via direct contact. For instance, in the banded mongooses, which, like meerkats, deposit scent marking from their anal glands, the bacterial load of M. mungi in the anal gland and nasal planum was strongly linked to the level of tuberculous tissue in the lungs and lymph nodes70. Social communication may thus act as transmission route in meerkats too41. Equally important might be intragroup aggression, with the higher infection risk observed in the breeding pair potentially explained by their aggressive assertion of dominance in this cooperatively breeding species37,41,71. Intergroup aggression, female evictions or male dispersal may be other pathways by which TB spreads beyond one social group41,72,73. Yet, owing to the disease’s long latency period, the individual circumstances leading to TB transmission are elusive even in this well-studied wildlife population. In parallel, higher temperatures and lower rainfall also increased the chance of TB outbreaks and mortality from TB in meerkats (our data and refs. 71,74; possibly mediated via a reduction in body condition75 and a decline in gut symbionts76), mirroring observations from other study systems where drier environments are linked with increased TB susceptibility and prevalence77,78. Our data suggests that the allele Susu-DRB*13 was probably most beneficial when TB selection was strongest. For instance, shortly after a historic population collapse between 2012 and 2013 caused by a severe drought79, TB signs had emerged in ~20% of the population39. In one scenario, the social groups that persisted may have been those containing more resilient and longer-lived individuals—possibly carriers of Susu-DRB*13—who were better able to support pup care and had more opportunities to reproduce80,81. Alternatively, in collapsing social groups, survivors may have disseminated both TB, especially as immigrants are more regularly harassed82, and, thus, effectively spread TB during aggressive interactions. If they carried Susu-DRB*13, however, they may have profitted from greater resilience, survival and, consequently, chances to reproduce and contribute their immunogenetic make-up to the new group. Future monitoring may answer whether Susu-DRB*13 has risen in frequency even further. In summary, our work illustrates the intricacies of contemporary evolution at the MHC driven by TB-driven selection in a longitudinally sampled wildlife population.

Methods

Study site and population

The meerkat population inhabiting the Kuruman River Reserve and surrounding farms (26° 580′ S, 21° 490′ E) in the Kalahari, South Africa, has been monitored since 199336. The population includes several habituated social groups, where individual behaviour, life history events and health were recorded on a regular basis83. Tail tips were collected from all individuals born into the population at first emergence from the burrow84,85. We gathered first and final dates, social group membership, genealogy, lifetime reproductive success and records of clinical TB signs for 3,420 individuals born before 2020 from the Kalahari Meerkat Project Database (Supplementary Tables 1 and 2). We then focused on individuals observed at least 20 times, belonging to groups persisting for longer than 720 days with on average 6 or more individuals and a known TB history. Meerkats were classified as unexposed if no member of the group showed clinical signs of TB, as exposed if group members developed clinical signs of TB and as having clinical signs when lymph node swelling, lesions and physical deterioration were reported39 (Fig. 1).

Characterization of neutral genetic and MHC diversity

DNA was extracted from meerkat tail tips following the standardized Kalahari Meerkat Project protocol and used to genotype individuals at up to 18 microsatellite loci84,85, with microsatellite data available for most individuals within the Kalahari Meerkat Project Database. Microsatellite data were used to estimate individual expected microsatellite heterozygosity (Hexp) with the R package ‘GENHET’86 and assign parentage with the R package ‘relatedness’84. From parentage, we estimated lifetime reproductive success as the number offspring surviving to 1 year of age, at which juveniles reach sexual maturity.

To characterize the MHC class II, we developed and validated primers (CS1_Crcr_MHC2F: 3′-CCTGTSYCCACAGCACATTTCYT-5′; CS2_Crcr_MHC2R: 5′-GCTCAMCTCGCCGSTGCAC-3′) and successfully amplified MHC-DRB-exon 2 for 1,567 individuals following standard in-house procedures for high-throughput sequencing on an Illumina MiSeq platform (for details, see Supplementary Infomation). We used the ACACIA pipeline for quality filtering and allele calling87, resulting in sequences of 247 bp. Three sequences identified included a 9-bp insertion, resulting in sequences of 256 bp. Our analysis included 360 technical replicates of 170 individuals, showing repeatability at individual level of 79.4% and repeatability at allele level of 96.1%.

MHC class II gene annotation

We used reference-guided transcriptome assembly of 14 publicly available meerkat tissues (for details, see Supplementary Table 3) and using hisat288 aligned them to the current best meerkat reference genome (GCF_006229205)89,90. The MHC class II annotation was performed using blastn91 with human class II query sequences against the meerkat reference genome89,90. All BLAST hits were manually inspected along with aligned transcripts to determine correct splice sites and open reading frames. To determine which locus each allele belonged to, we compared identified DRB exon 2 alleles to reference sequence of each annotated DRB gene using blastn92,93.

MHC supertyping and allelic divergence

We clustered MHC alleles into supertypes based on shared physicochemical properties at PSSs presumed to be involved in antigen binding94,95,96. PSSs were identified by comparing model 7 and model 8 in CodeML encoded in the program PAML497, which yielded 14 PSSs across the 37 alleles. After transcribing the amino acids at those 14 PSS into a matrix of z values describing their physicochemical properties98, we applied the find.cluster() and dapc() functions (that is, discriminant analysis of principal components) of the package ‘adegenet’99, and, based on goodness-of-fit assessment via a scores and x values, arrived at 12 clusters as most reliable supertype grouping. In addition to MHC supertypes, the divergence of MHC alleles (that is, mean and sum p-distance for amino acid alleles) was calculated using the DistCalc() function included in the ‘MHCtools’ package100.

MHC haplotyping

In contrast to supertyping, which is often performed to gain functional information and increase statistical power in MHC studies101, haplotyping provides information on alleles inherited together, forming evolutionary units. MHC haplotypes were probabilistically inferred using the HapltFind() function in the ‘MHCtools’ package100, designed to infer haplotypes by analysing the segregation of individual alleles from parents–offspring triads (POTs). Therefore, parentage was first assigned on the basis of the microsatellite data. This was done only for a total of 843 individuals with unambiguous parent–offspring information. These individuals grouped into 153 POTs consisting of both parents and their shared offspring across all litters. The output of the HpltFind() was then manually curated to exclude rare alleles (<8%) and two alleles (that is, Susu-DRB*07 and Susu-DRB*14) that were not inherited by offspring reliably and therefore could not reliably be assigned to haplotypes. Manual curating is necessary as the algorithm considers single POTs rather than including related POTs across multiple generations. If alleles occur in both parents, comparing inheritance patterns across different POTs and multiple generations can be necessary to disentangle haplotypes100. After reiterating Hapltfind(), we excluded POTs with unclear haplotype assignment, successfully inferring haplotypes for 741 meerkats.

Statistics

Statistical analyses were performed using R (ref. 102) versions 4.2.3. and 4.3.2 in RStudio103, with plots generated using the ggplot2104 and sjplot105 packages. For all analyses, given the high number of control variables throughout, we chose an information criterion based approach, using the function dregde() of the ‘MuMin’ package106 to identify the best models (delta AIC <2; code and data can be accessed publically107). We reported the full model average of all best models and report false discovery rate-corrected P values to account for multiple testing108 because we calculated models separately for each candidate MHC allele, supertype and haplotype associated with TB.

Evolution at the MHC versus neutral markers

Aside from calculating individual Hexp as an explanatory variable in later analyses, we contrasted the evenness of MHC and microsatellite allele distributions and divergence over time to ascertain whether the MHC is indeed under selection. To contrast allele frequency distribution, we calculated the Simpson Evenness Index for both microsatellite and MHC data and compared the output using a paired t-test. A more even distribution (Simpson Index closer to 0) at the MHC than at neutral markers suggests overdominance and rare-allele advantage, whereas a lower evenness (Simpson Index closer to 1) indicates directional and fluctuating selection9. To estimate molecular divergence, we estimated θ^ of Fst calculated from each allele or locus for each pair of years and tested whether temporal and genetic distances were independent using a Mantel test29. The Fst values were then regressed against the number of years under the assumption that the temporal genetic divergence of MHC alleles should be higher than that found at neutral genetic markers, if selection varied over time29. The model included an interaction term between temporal distance and whether the value came from the MHC or microsatellite data. A significant interaction implies a difference in slope—and thus in selection—between the MHC and neutral markers.

Co-occurrence analysis of MHC association with developing clinical signs of TB

We used a probabilistic model of co-occurrence included in the ‘cooccur’ package109 for each year to assess which MHC allele, supertype and haplotype was more or less frequently associated with TB than expected by chance. This and further analyses were computed on alleles, supertypes and haplotypes present in at least 5% of the study population (Supplementary Fig. 1b–d). Although filtering is necessary to maintain statistical power101, this approach may lower chances to uncover links to recombinant or novel alleles arising within the study period. Furthermore, we restricted our analysis to years with more than ten TB-positive individuals (1999–2020), to MHC alleles and supertypes present in at least ten individuals, and to haplotypes present in at least five individuals. MHC alleles, supertypes and haplotypes with co-occurrence data for all years and multiple significant associations were considered as candidates for all follow-up analyses.

Generalized linear model of MHC association with TB susceptibility, resilience and lifetime reproductive success

To assess the impact of specific MHC alleles, supertypes and haplotypes and diversity on TB susceptibility (that is, ever developing clinical signs of TB), we ran a generalized linear model with binomial error structure, controlling for the biological factors sex, age and individual’s neutral genetic diversity (Hexp)60 as well as socio-ecological factors, namely dominance status (that is, whether an individual had ever attained dominance). MHC diversity metrics included the number of alleles and supertypes, mean and sum amino acid p-distance between alleles, and haplotype heterozygosity. To account for changes in TB prevalence throughout the study period and allow for a nonlinear effect of time in relation to MHC measures, we included individual death year as linear and quadratic term, and interactions between the year variables and MHC measures. Lifetime reproductive success was assessed considering a negative binomial error distribution while otherwise keeping the same model structure. The model assessing the factors influencing TB resilience (that is, number of years surviving with TB signs; log-transformed) excluded final age as explanatory variable and used a Gaussian distribution instead. To improve convergence, age, number of MHC alleles and supertypes, and year were rescaled. We excluded individuals with missing sex and microsatellite information and the only two individuals that carried seven MHC alleles. Analyses of alleles and supertypes were conducted on data from 1,497 individuals, while haplotype analyses used data from 714 individuals.

Survival analyses of MHC association with TB progression and survival

The temporal dynamics of TB progression and survival was modelled on 3-month periods (January to March, April to June, July to September and October to December) using the mixed-effects Cox model from the package ‘coxme’110. For TB progression, models used the transition to clinical signs of TB before the start of the next period as endpoints. One model was run for each MHC allele, supertype and haplotype and MHC diversity measure, including only individuals observed at least five times during the respective period. We controlled for biological and socio-ecological factors as described earlier and added population density (meerkats per squared kilometre), social group size, known environmental correlates of survival (that is, mean maximum temperature and mean rainfall; rescaled)74,76 and season (January to March, April to June, July to September and October to December). Year was included as a linear and quadratic term, including the interactions between year and MHC measures. Meerkat ID was coded as a random factor. For modelling meerkat survival, we used the same model structure while including individual TB status (unexposed, exposed and signs) and the interactions between TB status and MHC measures with and without time to account for MHC effects on survival conditional on TB status and temporal shifts. After excluding individuals with missing metadata, the modelled datasets comprised 1,535 individuals and 12,936 meerkat periods for the TB progression analysis, and 13,804 meerkat periods for the survival analysis. From haplotyped individuals, we modelled with 722 individuals in 6,970 meerkat periods for the progression and 725 individuals in 7,492 meerkat periods for the survival analysis.

Delineating between mechanisms of PMBS

We are aware that irrefutable evidence for the distinct mechanisms of PMBS is achievable only in connection with a comparison across populations9. While we cannot provide this comparison, we have temporally dense, long-term data. A critical evaluation of MHC–pathogen associations over time, combined with comparisons to neutral evolution, can at minimum suggest the key PMBS mechanisms at play. First, we compared the fit of null models with models including specific MHC alleles, supertypes and haplotypes. This was done to test whether effects of MHC diversity (that is, number of MHC alleles and supertypes or haplotype heterozygosity) in null models are possibly driven by individual alleles. In cases where single alleles, supertypes and haplotypes appear linked to TB infection status, we additionally compared null models with and without individuals with the specific MHC allele, supertype and haplotype. Next, although a crude measure, we used a G test to determine whether specific alleles, supertypes and haplotypes were more likely to be found in meerkats with a higher number of alleles52,63.

Finally, we calculated the change in MHC allele, supertype and haplotype frequency from one year to the next. Values below 0 imply the allele became less frequent, whereas values above 0 imply the allele become more frequent from one year to the next. We then correlated frequency change of candidate alleles with TB prevalence, as a measure of selection strength. The same time-lag approach was previously used in a short-lived vole population to account for selection in the previous year44.

Inclusion and ethics statement

Research for this study was conducted with permission of the ethical committee of 383 Pretoria University and the Northern Cape Conservation Service, South Africa (Permit 384 number: EC031-13, FAUNA 1020-2016). The field portion of our study was conducted at the Kalahari Meerkat Project, located at a remote site in the Kalahari Desert of South Africa. Fieldwork was discussed with and approved by the local stakeholders of the Kuruman River Reserve. As is the norm at the Kalahari Meerkat Project, fieldwork was conducted by an international and diverse team, including South Africa-born volunteers, to whom we are indebted.

Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.