Sequence Alignment & BLAST — Advanced

You finished the essentials; now the professional depth. This Level 2 companion covers the parts that separate someone who runs BLAST from someone who understands it: affine gap penalties, the statistics that actually produce an E-value, why BLAST is a heuristic that can miss real homologs, and how to find the distant relatives BLAST cannot, using PSI-BLAST, profile HMMs, and structure search.

🎓 Mini-course · Level 2 ⏱️ ~2 hr 🌐 Web tools + optional install ✅ Graded assessment

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

Module 1 of 4

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 4

The 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.
Module 3 of 4

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.

Module 4 of 4

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:

MethodIdeaWhen to reach for it
PSI-BLASTRun 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 / HMMERModel 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.

Under an affine scheme (gap-open −10, gap-extend −1), which is cheaper: one gap of length 5, or five separate gaps of length 1? And what does this preference model biologically?
Correct. One length-5 gap costs open + 5×extend = −10 + (−5) = −15; five length-1 gaps cost 5 × (−10 + −1) = −55. Affine scoring therefore prefers clustering indels into one event, which matches biology. A flat penalty would score both at −15 and could not distinguish them.
You get a hit at E = 1e-4 searching a small custom database. You repeat the exact search against a database 1,000× larger and the same alignment now shows E ≈ 0.1. What happened, and is it a bug?
Exactly. The E-value scales with database size n. A ~1000× larger database inflates E by ~1000× for the same score, here 1e-4 → ~0.1. Significance is relative to what you searched, which is why reporting the database matters and why the bit score (independent of n) is useful for comparison.
A reviewer insists a gene has "no homolog" because blastp returned nothing significant. As an expert, what is the most accurate caution?
Right. "No BLAST hit" means "no hit found by this heuristic at these settings," not "no homolog exists." Because BLAST needs a word seed, distant relatives in the twilight zone can be invisible to it while profile HMMs or structure-based search still detect them.
Why does searching with a profile (PSI-BLAST or a profile HMM) detect more remote homologs than searching with a single sequence?
Exactly. A single-sequence search treats every position equally. A profile captures position-specific conservation (strict at a catalytic residue, lenient in a loop), so it scores the biologically important matches highly and detects family members that fall in the twilight zone for pairwise comparison.
Two proteins share only ~18% sequence identity but have nearly identical 3D folds and the same active-site geometry. What is the best way to detect this relationship, and why?
Correct. At ~18% identity the pair sits in the twilight zone where sequence signal is weak, but conserved fold and active-site geometry are strong evidence of homology. Structure-comparison tools like Foldseek (fast, thanks to AlphaFold structures) are built exactly for this case.

Sources & further reading

  1. Gotoh O. An improved algorithm for matching biological sequences. J Mol Biol 162(3):705–708, 1982. (Affine gap penalties.)
  2. 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.)
  3. 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
  4. Eddy SR. Accelerated profile HMM searches (HMMER3). PLOS Computational Biology 7(10):e1002195, 2011. doi:10.1371/journal.pcbi.1002195
  5. Rost B. Twilight zone of protein sequence alignments. Protein Engineering 12(2):85–94, 1999.
  6. 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.

You finished Level 2

Back to mini-courses →