Seeding, extending, and the price of speed
Smith-Waterman finds the best local alignment: The best match between part of one sequence and part of another.
TTTTACGTCA
||||||
ACGTCAGGGG
“Is some region of this database sequence similar to some region of my sequence?” is a local alignment question.
That is the question you ask every time you run BLAST.
How is that possible?!
The scoring table has \(m \times n\) cells (\(O(mn)\)).
One 150-base read against GenBank:
\[ 150 \times (6 \times 10^{13}) \approx 9 \times 10^{15} \text{ cells} \]
A faster computer does not fix this. We need to avoid doing most of the work.
From our algorithms lecture:
“Approximate answer today” beats “exact answer in nine years.”
Today we unpack that second bullet: BLAST1, the Basic Local Alignment Search Tool.
Two homologous sequences almost always share at least one short, exact match.
TGCTTACCAGTCAGGT
TGCTTACGAGTCATTG
So:
Finding exact matches of length \(k\) fast?
Look up every \(k\)-mer of the query (\(k = 4\) below):
query: TGCTTACCAGTCAGGT
subject: GGATCCATGCTTACGAGTCATTGCAACGT
| Query \(k\)-mer | Query position | Subject position(s) |
|---|---|---|
TGCT |
0 | 7 |
GCTT |
1 | 8 |
CTTA |
2 | 9 |
TTAC |
3 | 10 |
TACC |
4 | — |
| … | ||
AGTC |
8 | 15 |
GTCA |
9 | 16 |
| Seed | Query pos | Subject pos | Subject \(-\) query |
|---|---|---|---|
TGCT |
0 | 7 | 7 |
GCTT |
1 | 8 | 7 |
CTTA |
2 | 9 | 7 |
TTAC |
3 | 10 | 7 |
AGTC |
8 | 15 | 7 |
GTCA |
9 | 16 | 7 |
All six are on the same diagonal of a dotplot: Pieces of the same alignment!
A seed alone on its own diagonal is usually just chance.
Grow the seed one base at a time, keeping a running score (match \(+1\), mismatch \(-1\)):
| seed | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| query | TGCT | T | A | C | C | A | G | T | C | A | G | G | T |
| subject | TGCT | T | A | C | G | A | G | T | C | A | T | T | G |
| score | 4 | 5 | 6 | 7 | 6 | 7 | 8 | 9 | 10 | 11 | 10 | 9 | 8 |
X-drop rule: stop once the score falls more than \(X\) below the best score seen (here \(X = 2\)), then trim back to the best.
The result is a high-scoring segment pair (HSP) with a score of 11.
Alpha: CCATGCTAT------CTCTGGGA
Wuhan: CCATGCTATACATGTCTCTGGGA
Gapped BLAST1: Run a gapped alignment, but only in the short region around a good HSP.
Run the Smith-Waterman aligner on ~200 bases, NOT 60 trillion.
In a database of 60 trillion bases, many matches happen by chance.
BLAST reports an E-value1: The number of hits scoring at least this well that you would expect by chance in a database this big.
\[ E = K\,m\,n\,e^{-\lambda S} \]
BLAST only looks where it finds a seed.
A homolog with no exact match of \(k\) consecutive bases is invisible to BLAST, no matter how good the full alignment would be.
TGCTTACCAGTCAGGT
| || ||| || || |
TCCTAACCTGTAAGCT
11 of 16 bases identical, but never more than 3 in a row
Number of chance seeds for a 150-base query against GenBank (\(\approx m\,n / 4^k\)):
| Word size \(k\) | Chance seeds | Needs an exact run of |
|---|---|---|
| 7 | \(\sim 5 \times 10^{11}\) | 7 bases |
| 11 | \(\sim 2 \times 10^{9}\) | 11 bases |
| 28 | \(\sim 0.1\) | 28 bases |
Small \(k\)
More sensitive, much slower
Large \(k\)
Much faster, misses divergent homologs
| Program (task) | Word size | Designed for |
|---|---|---|
megablast (default) |
28 | Highly similar sequences |
blastn |
11 | Somewhat similar sequences |
blastn-short |
7 | Short queries (e.g., primers) |
| Protein BLAST | 3 | Proteins (20-letter alphabet) |
When you pick an option on the BLAST web page, you are choosing a point along the speed/sensitivity trade-off continuum!
Which BLAST program would you use?
ATATATATAT) that would seed everywhereBut the core is what you will build today: Seed, extend, evaluate
You will build BLAST from pieces you mostly already have:
find_seeds: Find seeds with your \(k\)-mer dictionaryWatch for
Which variant the mystery read came from, and which variant is its runner-up. The sequence alignment exercise holds the clue.
I used Anthropic’s Claude (Opus 5 model) to generate a draft of these slides.