Predicting antibiotic-resistance mutation trajectories

Sequence models for predicting mutations during adaptive evolution. Tests compare gradient boosting, transformers, and reranking, and measure the contribution of ordered mutation history.

At a glance

Question
Does the order of previous mutations help predict the next step in antibiotic resistance?
My contribution
Compared gradient boosting, sequence models, and reranking against controls for mutation history.
Result & scope
Recorded held-out transition predictions can be inspected alongside the observed next mutations. The explorer uses saved predictions.

This project asks whether the next mutation in an adaptive-evolution trajectory can be predicted from the ordered mutations that precede it. Most antibiotic resistance machine learning predicts phenotype from genome. Given this bacterium’s whole genome, will it be resistant to ciprofloxacin? I wanted to do something different. Given an ordered history of mutations that have already accumulated under selection, what’s the next one going to be? That’s a sequential-decision problem on the evolution side rather than a classification problem on the diagnostic side, and at the start of Day 1 I had not realized how much that framing matters.

Day 1 was the foundation. 28,768 lab-evidence genomes pulled from BV-BRC, annotated with AMRFinderPlus at 98.81% coverage. 17,991 unique resistance protein sequences embedded with ESM2-650M at half precision on an 8GB RTX 4060 Ti. Trajectory data from ALEdb (28,028 transitions across 860 trajectories) plus deep mutational scanning measurements from Pal 2015, Marcusson 2009, and Gullberg 2014 for fluoroquinolone-target proteins. A LightGBM LambdaRank model over candidate mutations hit top-3 = 0.708 overall, which sounded fine. Then I sliced by canonical-AMR mutations specifically — the ones that show up in the CARD database of clinically-relevant resistance — and canonical-AMR top-3 dropped to 0.13–0.21.

The Day-1 test split was a more specific problem. About 86% of the ALE trajectories came from one hypermutator-strain experiment selecting for fluoroquinolone resistance, so the data has wild proportions of passenger mutations riding along with the canonical ones. The held-out e1230 trajectory had n=7 canonical-AMR transitions in it. Anything I did to the canonical-AMR metric on that split was within ±14 percentage points of meaningless.

Day 2 I built an autoregressive transformer over the trajectory token sequence. Four-layer causal decoder, d_model=128, taking concatenated learned-mutation-embedding + ESM2-residue-projection + DMS-fitness-scalar inputs, conditioned on drug class and organism. Cross-entropy loss with a 5× weight on canonical-AMR mutations. The headline finding from the day was an ablation. Removing the autoregressive context (predict next mutation from a <START> token only, no history) drops top-3 from 0.527 to 0.156. A +0.37 lift from giving the model ordered mutation history.

That was a clean architectural finding and it survived every form of scrutiny I put it through. The trouble was that the transformer alone at top-3 = 0.527 still underperformed the LightGBM LambdaRank baseline of 0.708 on the same test split. So the transformer wasn’t replacing the LGBM. It was learning something the LGBM wasn’t, and also losing to it on the overall metric.

Day 3 was the realization that the right structure isn’t a single end-to-end model. It’s a reranker.

LightGBM and the transformer fail in opposite ways on full-vocabulary scoring. LGBM gets canonical-AMR top-3 = 0.054 because it ranks all 14,006 mutation tokens additively without considering trajectory context, so it’s dominated by per-class frequency priors. Transformer gets 0.000 because the per-position softmax over 14,006 candidates loses to frequency priors when there’s no candidate filtering at all. So: let the LGBM filter down to the top-10 candidates per transition, score those 10 with the transformer’s autoregressive log-probabilities, and combine them in a second LightGBM that takes both signals plus frequency priors and 14 drug-class one-hots as features.

I rebuilt the test split (n=571 canonical-AMR transitions across all 14 drug classes, because the Day-2 n=7 split was unusable). The reranker scored canonical-AMR top-3 = 0.403, but that number needs two qualifications, and together they undo it. First, it is measured only on the 72 of 571 transitions (12.6%) where the true mutation was already in LightGBM’s top-10; on all 571 the equivalent is about 0.051, slightly below LightGBM alone at 0.054. Second, on those same 72 transitions, plain LightGBM ranking scores 0.431 and the transformer alone 0.403. The reranker beats neither of its own components.

Within that 72-transition subset the per-class picture is uneven and the counts are tiny: carbapenem 0.67 (n=9), diaminopyrimidine 0.67 (n=3), rifamycin 0.40 (n=10), glycopeptide and nitrofuran 0.375 (n=8 each), fosfomycin and sulfonamide 0.30 (n=10 each), macrolide 0.18 (n=11). The other six classes (aminoglycoside, cephalosporin, fluoroquinolone, penicillin, phenicol, tetracycline) have n=0 because LightGBM’s top-10 never contained the true mutation for any of their test transitions, so they never reached the reranker.

Transformer ablations: removing autoregressive context drops top-3 from 0.527 to 0.156. Removing ESM2/DMS features or canonical loss weighting barely changes anything.

Several limitations remain. The MIC supervision is on a linear-ramp proxy, because ALEdb provides endpoint MIC measurements but not per-flask values. The apparent Pearson 0.92 between predicted step number and MIC is largely tautological, since the proxy was constructed to be a linear function of step number to begin with. The macrolide canonical-AMR top-1 = 0 on n=11 transitions is biologically suspicious and probably means the mutation tokenization breaks for ribosomal-RNA loci, where most macrolide resistance actually lives. No held-out-organism or held-out-drug-class evaluation either, so every number here is on chromosomally-similar data to the training set.

What survives is the Day-2 ablation: ordered mutation history carries real signal (top-3 0.156 without context, 0.527 with it). The reranker, which I originally thought was the contribution, is not supported by its own numbers. The data is almost entirely chromosomal point-mutation evolution (1 of 28,028 transitions is plasmid-borne, consistent with ALEdb’s serial-passage origin), so the model is learning chromosomal evolution patterns specifically. That’s a useful narrow regime, not a general-purpose AMR predictor.

Repo: github.com/rohit-ravi2/amr-mutation-trajectory