What you'll be able to do
- Explain affine gap penalties and why they model real indels better than a flat penalty.
- Describe what an E-value is built from (Karlin-Altschul) and how query length and database size move it.
- Explain why BLAST, as a heuristic, can miss true remote homologs, and what low-complexity masking does.
- Choose the right tool to detect distant homology: PSI-BLAST, profile HMMs (HMMER), or structure search (Foldseek).
Before you start
- Finish Level 1: Sequence Alignment & BLAST first. This builds directly on it.
- Any term new? The Glossary has it.
Affine gap penalties: not all gaps are equal
In Level 1 the demo charged a flat penalty per gap position. That is biologically wrong. A single insertion or deletion of five bases is one mutational event; five separate one-base gaps are five events, and far less likely. A flat (linear) penalty scores them the same. The fix is an affine gap penalty: a larger one-time cost to open a gap, plus a small cost to extend it. This makes one long gap much cheaper than many short ones, which matches how indels actually happen. Gotoh (1982) showed how to compute this efficiently.
Decode the jargonGap-open vs gap-extend
Two separate penalties. Gap-open is paid once when a gap starts (e.g., −10); gap-extend is paid for each additional position in that same gap (e.g., −1). Total cost of a gap of length L is: open + (L × extend). This is why aligners cluster indels into single runs rather than scattering them.
See the difference (in your browser)
The cell compares the same five gap positions arranged two ways: one 5-base indel versus five scattered single gaps. Watch how affine scoring strongly prefers the single event while a flat penalty is indifferent. Press Run (first run loads Python).
Module 2 of 4The statistics behind the E-value
In Level 1 you learned to trust the E-value. Here is what it is made of. The Karlin-Altschul theory (1990) says that the number of chance high-scoring alignments follows a known distribution, giving the famous form:
# Expected number of chance hits scoring at least S
E = K · m · n · e^(-λS)
where m is your query length, n is the total database length, S is the alignment score, and K and λ are constants set by the scoring system. Three consequences a professional internalizes:
- Bigger database, worse E-value. The same alignment becomes less surprising in a larger database (n goes up, E goes up). Your hit's significance is not absolute; it depends on what you searched against.
- Longer query, worse E-value for the same score (m goes up). This is why the bit score exists: it is the score rescaled by K and λ so it is comparable across searches.
- Score must clear the noise. Because E falls exponentially in S, a small increase in alignment score sharply drops the E-value.
🔗 Connection: a BLAST search is a multiple-testing problem
When you BLAST one query against millions of database sequences, you are making millions of comparisons, exactly the situation from the statistics track. The E-value already builds the database size (n) into the calculation, so it is the multiple-testing correction for a single search: it answers "how many hits this good would I expect by chance across this whole database?" See The multiple-testing problem for the general principle.
BLAST is a heuristic, and heuristics miss things
Smith-Waterman is guaranteed to find the optimal local alignment, but it is too slow for huge databases. BLAST trades that guarantee for speed: it first finds short exact (or near-exact) word matches, called seeds, and only extends alignments around those seeds. That is the whole trick, and it has a consequence professionals must respect.
- No seed, no hit. If a true but distant homolog shares no high-scoring word with your query, BLAST never starts an alignment there and the homolog is missed entirely. BLAST is sensitive for close relatives and progressively blind to distant ones.
- Word size is a sensitivity knob. A smaller word size (seed) finds more distant hits but runs slower and returns more noise; a larger word size is faster but less sensitive. The defaults are a compromise, not a law.
⚠️ Low-complexity regions produce false hits, and BLAST masks them
Stretches like AAAAAAAA or proline-rich runs are "low-complexity": they match many unrelated sequences by chance and generate spurious high-scoring hits. BLAST masks these by default (DUST for nucleotides, SEG for proteins), replacing them so they cannot seed alignments. Usually correct, but if your real signal lives in a low-complexity region, masking can hide it, so know the masking is happening.
Finding the homologs BLAST cannot: remote homology
The hardest and most valuable case is the twilight zone: roughly 20 to 35% identity for proteins (with the sharpest drop in reliability around 25%), where true homologs become statistically hard to distinguish from random matches by pairwise methods (Rost, 1999). Plain BLAST struggles here. The professional toolkit climbs in sensitivity by using a profile, a position-specific model of a whole family, instead of a single sequence:
| Method | Idea | When to reach for it |
|---|---|---|
| PSI-BLAST | Run BLAST, build a position-specific scoring matrix (profile) from the hits, search again, and iterate. Each round pulls in more distant relatives. | More sensitive than blastp for distant homologs, still in the BLAST family (Altschul 1997). |
| Profile HMMs / HMMER | Model a family as a hidden Markov model with per-position match, insert, and delete probabilities. The gold standard for sensitive sequence search (Pfam is built on this). | When you need maximum sequence-based sensitivity, or to search domain databases (Eddy 2011). |
| Structure search (Foldseek) | Structure is conserved far longer than sequence. Foldseek encodes 3D shape as a "structural alphabet" and searches it at BLAST-like speed, now practical thanks to AlphaFold's structures. | When sequence similarity is gone but you have (or can predict) a structure (van Kempen 2024). |
Decode the jargonProfile (position-specific scoring)
Instead of one query sequence, a profile records, for every column of an alignment, how conserved each residue is. A position that is always tryptophan scores a strong reward for tryptophan and heavy penalties otherwise; a variable loop position is lenient. This per-position weighting is why profile methods detect relatives that a single-sequence search misses.
🛠️ Hands-on (guided): see the sensitivity climb
Take a protein with well-known distant relatives, for example human lysozyme C (UniProt P61626). Run a normal blastp against nr and note how far down the hit list the identity drops toward the twilight zone. Then run the same query with PSI-BLAST for two or three iterations. What you should see: each iteration recovers additional, more distant homologs that the first pass ranked poorly or missed, because the profile now encodes the whole family, not one sequence. That is remote-homology detection in action.
✅ Final assessment (Level 2)
Five questions covering the advanced material. Aim for at least 4 out of 5 correct. These test reasoning, not recall.
Sources & further reading
- Gotoh O. An improved algorithm for matching biological sequences. J Mol Biol 162(3):705–708, 1982. (Affine gap penalties.)
- Karlin S, Altschul SF. Methods for assessing the statistical significance of molecular sequence features using general scoring schemes. PNAS 87:2264–2268, 1990. (The E-value theory.)
- Altschul SF, et al. Gapped BLAST and PSI-BLAST: a new generation of protein database search programs. Nucleic Acids Research 25(17):3389–3402, 1997. doi:10.1093/nar/25.17.3389
- Eddy SR. Accelerated profile HMM searches (HMMER3). PLOS Computational Biology 7(10):e1002195, 2011. doi:10.1371/journal.pcbi.1002195
- Rost B. Twilight zone of protein sequence alignments. Protein Engineering 12(2):85–94, 1999.
- van Kempen M, et al. Fast and accurate protein structure search with Foldseek. Nature Biotechnology 42:243–246, 2024. doi:10.1038/s41587-023-01773-0
Last reviewed: June 2026.