Overview
Curated: · Written: · Reviewed:
Sequence Alignment (Needleman-Wunsch, Smith-Waterman, BLAST)
In one line
An alignment is a model-based claim about which residues correspond, under a scoring model, a gap model and a search space. Use Needleman-Wunsch for end-to-end global comparison, Smith-Waterman for the best local segment, and BLAST when you must search a large database and need E-values.
Key definitions
- Global alignment: every residue of both sequences is aligned, end gaps included.
- Local alignment: the best-scoring pair of subsequences, with each DP cell floored at zero.
- Substitution matrix: log-odds score per residue pair. BLOSUM62 is the blastp default.
- Affine gap: one opening cost plus an extension cost per further residue. Needs three DP states (Gotoh).
- Bit score: raw score normalized by the scoring system. Comparable across searches that use the same matrix and gap costs.
- E-value: expected number of chance alignments at or above that score in the effective search space.
Formulas and complexity
Full DP: O(nm) time and space. Hirschberg: O(nm) time, O(min(n,m)) space, roughly double the work. Banded: roughly O(n w) for band width w.
How it works
- Needleman-Wunsch fills each cell with the maximum of diagonal, up and left moves. Boundaries carry cumulative gap penalties, and the answer is the bottom-right cell.
- Smith-Waterman floors each cell at zero. Traceback starts at the highest cell and stops at a zero.
- The matrix stores scores, not alignments. Traceback needs stored pointers or recomputation, and ties need a fixed order.
- BLAST indexes query words (blastp uses word size 3), finds seed hits, requires two nearby seeds on one diagonal, extends ungapped with an X-drop, then refines with a gapped alignment.
When to use and when not to
| Situation | Use | Avoid |
|---|---|---|
| Similar-length proteins, homologous end to end | Needleman-Wunsch | Smith-Waterman, which returns a fragment |
| One shared domain in otherwise unrelated proteins | Smith-Waterman or BLAST local HSP | Needleman-Wunsch, which forces poor end alignment |
| Search over millions of residues | BLAST with E-values | Full Smith-Waterman, exact but slow |
| Chromosome-scale pair | Banded or Hirschberg | Full matrix, 9 x 10^12 cells for 3 Mb by 3 Mb |
| Protein query, unannotated nucleotide genome | tblastn | blastp, which finds no protein database to search |
| Very close homologs | BLOSUM80 or BLOSUM90 | BLOSUM45 |
| Distant homologs | BLOSUM45 or PAM250 | BLOSUM80 |
Traps interviewers probe
- Treating percent identity as significance. Fix: report the E-value, the threshold and the database together, and read identity with alignment length and coverage.
- Reading an E-value as the probability that a hit is correct, or as proof of homology or function. Fix: it is an expected count of chance alignments. Homology is common ancestry. Function needs domain architecture and catalytic residues.
- Assuming a bigger database changes the bit score. Fix: the bit score is fixed. E scales with the search space, so doubling the database doubles E for the same hit.
- Using Needleman-Wunsch when only a domain is shared. Fix: use local alignment, since global alignment forces gaps across the ends.
- Reading a missing hit as absence. Fix: BLAST is a heuristic. Word size, masking, matrix and gap costs all change what it finds.
Interview tips
Open with the question type and the model: global or local, matrix, gap model, search space and threshold.
Expected follow-ups: what happens when the database doubles (E doubles, bit score unchanged); why BLOSUM62 versus BLOSUM80 or BLOSUM45; why Needleman-Wunsch cannot run on genomes; why two correct aligners show different alignments (tied optima); why a reciprocal best hit is not enough for orthology.
30-second outline: state the question and the model. Name the algorithm and why it fits. Give the statistic and the threshold, and say what a missing hit would not mean. Name the evidence still needed before claiming orthology or function.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.