Machine learning

What makes a splice site?

Last time

  • HMMs found CpG islands, but finding genes needs splice sites
  • HBB (β-globin): 87 GTs and 81 AGs, but only 2 real donors and 2 real acceptors
  • What makes a real splice site? Today, we let the computer learn the answer from examples

What is machine learning?

Learning from examples

  • Programming: We write the rules
    • “If GT at +1, +2 → donor”
  • Machine learning: We give the computer examples, and it learns the rules
    • “Here are 2,990 windows of DNA; this one is a donor, this one isn’t”
  • The learned rules are a model, and learning them is training the model
  • You’ve already done this: We trained HMMs by counting!

Supervised vs. unsupervised

  • Supervised: learn to predict labels (classification) or numbers (regression) from labeled examples (today)
  • Unsupervised: find structure without labels, e.g., clustering cells by gene expression (e.g., k-means)

The “hello world” of machine learning

  • MNIST: 70,000 images of handwritten digits (28 × 28 pixels), each labeled 0–9 (LeCun et al. 1998)
  • One-hot encoding turns DNA into a tiny black-and-white image: 4 rows (A, C, G, T) × 60 positions = 240 numbers

Splice sites

Splicing

  • Donor: exon → intron (“EI”); almost always GT at the start of the intron
  • Acceptor: intron → exon (“IE”); almost always AG at the end of the intron
  • But GT and AG are everywhere; the spliceosome must use more clues

The data

  • 3,190 windows of 60 bases of primate DNA from GenBank, collected by Noordewier et al. (1990) to train some of the first neural networks for DNA (UCI Machine Learning Repository 1991)
  • The junction is in the middle: positions -30 to -1, then +1 to +30
  • Three labels: EI (donor), IE (acceptor), and N (neither, from random places in DNA without splice sites)
  • Cleaning: Drop 15 windows with ambiguity codes (N, R, …) and 185 exact duplicates → 2,990 windows
  • Duplicates can end up in both the training and test sets: a model gets them right by memorizing them (data leakage)

What do splice sites look like?

  • Donors: (C/A)AG | GT(A/G)AGT
  • Acceptors: a C/T-rich polypyrimidine tract, then (C/T)AG |

Neurons and networks

A neuron

  1. Multiply each input by its weight, add them up, and add a bias: \(z = w_1 x_1 + \cdots + w_n x_n + b\)
  2. Squash \(z\) into a number between 0 and 1: a probability

A position weight matrix is a neuron

  • Set each weight by counting: red = more common in donors, blue = less common
  • Biologists call this a position weight matrix (PWM), and have used it for decades to find binding sites and splice sites
  • Stormo et al. (1982) learned weights like these with the perceptron algorithm (a single neuron), to find where translation starts in E. coli genes

Neural networks

  • Each hidden neuron combines all the inputs; hidden layers can learn combinations, like “GT at +1, +2 and G at +5”
  • With no hidden layer, each output neuron is a PWM

Training: gradient descent

  • Start with random weights → predict → measure the loss → nudge every weight a little bit downhill → repeat
  • Backpropagation calculates the slope for every weight at once (Rumelhart et al. 1986); scikit-learn does it for us (Pedregosa et al. 2011)

Testing models

Training data, test data, and baselines

  • Split the data before building any models: a training set (75%) to learn from, and a test set (25%) locked away to check them
  • Accuracy means little on its own; compare to baselines:
    • Predict the most common label (N) for every window
    • A simple rule: GT at +1, +2 → EI; else AG at -2, -1 → IE; else N
  • Does a neural network beat the rule? Does a bigger network do better?

Overfitting and regularization

  • A model with many weights can overfit: memorize the training data, noise and all, and do worse on new data
  • Regularization penalizes large weights (alpha in scikit-learn)
  • Similar to choosing substitution models with AIC: extra parameters must earn their keep

Opening the black box

Window (positions -14 to +8) Mutation P(donor)
AGGCCAGCGAGCAG|GTCTGTTC No mutation 0.81
AGGCCAGCGAGCAG|CTCTGTTC G → C at +1 0.35
AGGCCAGCGAGCAG|GTCTCTTC G → C at +5 0.38
CGGCCAGCGAGCAG|GTCTGTTC A → C at -14 0.78
  • In silico mutagenesis: mutate each position of each test window, and see how much the prediction drops
  • Works for any model, however complicated; a big drop means the network relies on that position

Limits

Harder problems

Human chromosome 19: 10,362 real donors vs. 104,049 GTs that are not donors, from the same 1,387 genes (train on one half of the chromosome, test on the other)

Hidden layers Accuracy Real donors found Calls that are real
(Never a donor) 0.910 0%
None 0.955–0.959 56–61% 90–91%
100, 100 0.967–0.968 73–76% 88–90%
  • Accuracy can mislead: “never a donor” is right 91% of the time! Ask what fraction of the real sites a model finds
  • With hard examples and lots of data, hidden layers start to help

Where deep learning shines

  • SpliceAI (Jaganathan et al. 2019): a deep network (dozens of layers) that uses 10,000 bases around each position to predict donors and acceptors
  • Trained on genes from some human chromosomes, and tested on the others
  • Finds mutations outside the GT and AG that create or break splice sites, and estimated that 9–11% of disease-causing mutations in rare genetic disorders act this way
  • More data + more complex patterns (spread over long distances) → bigger networks help

A short history

Resources

3Blue1Brown

A beautiful series of short videos about neural networks

Summary

  • Supervised learning: learn to predict labels from labeled examples
  • A neuron is a weighted sum + bias, squashed; a PWM is a neuron; a neural network stacks neurons in layers
  • Training nudges the weights downhill on the loss
  • Clean the data, watch for leakage, test on held-out data, and beat baselines
  • Bigger isn’t always better: overfitting and regularization
  • We can open the black box (weights, in silico mutagenesis)
  • A great test accuracy doesn’t guarantee good predictions on real data

In the exercise

  1. clean_windows: Drop ambiguous and duplicate windows
  2. rule_classifier: A GT/AG baseline
  3. one_hot and neuron: DNA → numbers → a neuron
  4. train_network: Train networks with scikit-learn
  5. plot_accuracies: Is bigger better?
  6. scan_gene: Find the splice sites of HBB

Watch for

How many of the 87 GTs in HBB does your network think are donors?

Exercise

  1. Log into molab
  2. Open the exercise in molab
  3. Click “Fork” button

References

Burge, Chris, and Samuel Karlin. 1997. “Prediction of Complete Gene Structures in Human Genomic DNA.” Journal of Molecular Biology 268 (1): 78–94. https://doi.org/10.1006/jmbi.1997.0951.
Jaganathan, Kishore, Sofia Kyriazopoulou Panagiotopoulou, Jeremy F. McRae, et al. 2019. “Predicting Splicing from Primary Sequence with Deep Learning.” Cell 176 (3): 535–548.e24. https://doi.org/10.1016/j.cell.2018.12.015.
LeCun, Yann, Léon Bottou, Yoshua Bengio, and Patrick Haffner. 1998. “Gradient-Based Learning Applied to Document Recognition.” Proceedings of the IEEE 86 (11): 2278–324. https://doi.org/10.1109/5.726791.
Noordewier, Michiel O., Geoffrey G. Towell, and Jude W. Shavlik. 1990. “Training Knowledge-Based Neural Networks to Recognize Genes in DNA Sequences.” In Advances in Neural Information Processing Systems 3, edited by Richard P. Lippmann, John E. Moody, and David S. Touretzky. Morgan Kaufmann.
Pedregosa, Fabian, Gaël Varoquaux, Alexandre Gramfort, et al. 2011. “Scikit-Learn: Machine Learning in Python.” Journal of Machine Learning Research 12 (85): 2825–30. http://jmlr.org/papers/v12/pedregosa11a.html.
Rumelhart, David E., Geoffrey E. Hinton, and Ronald J. Williams. 1986. “Learning Representations by Back-Propagating Errors.” Nature 323 (6088): 533–36. https://doi.org/10.1038/323533a0.
Stormo, Gary D., Thomas D. Schneider, Larry Gold, and Andrzej Ehrenfeucht. 1982. “Use of the ‘Perceptron’ Algorithm to Distinguish Translational Initiation Sites in e. Coli.” Nucleic Acids Research 10 (9): 2997–3011. https://doi.org/10.1093/nar/10.9.2997.
UCI Machine Learning Repository. 1991. Molecular Biology (Splice-Junction Gene Sequences) [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C5M888.

Acknowledgements

I drafted and iterated on these slides in collaboration with Anthropic’s Claude (Opus 5.5 model).