Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 49 ยท Sequence Alignment

Scoring matrices and gap penalties

Understand how alignment scores are chosen: identity and similarity, log-odds substitution matrices such as BLOSUM62 and PAM, and linear versus affine gap penalties.

An alignment algorithm is a machine for maximizing a score, and the score comes from you. If you reward matches and punish everything else equally, the algorithm will happily align things that biology would not. A protein that swaps leucine for isoleucine (two similar, oily amino acids) is a minor change; swapping leucine for aspartate (oily for charged) can break the protein. A good scoring scheme knows this. This lesson shows where scores come from, why they are logarithms of odds, and how gaps are priced.

Left: a DNA matrix with purines and pyrimidines; right: bars showing BLOSUM62 scores such as I-V plus 3 and W-W plus 11
Caption: substitution scores reward changes that evolution tolerates and penalize rare ones; the DNA values are illustrative, the protein values are real BLOSUM62 entries.

What you will learn

  • The difference between identity, similarity and homology.
  • How a log-odds substitution score is built, and how to read a BLOSUM or PAM matrix.
  • How linear and affine gap penalties differ, and why affine gaps are the norm.
  • How a dot plot shows similarity before any scoring is chosen.

Key terms

  • Identity: the fraction of aligned positions with exactly the same residue.
  • Similarity: the fraction of aligned positions that are identical or chemically similar (positive score).
  • Homology: common evolutionary ancestry. It is a yes-or-no property; "70% homologous" is not meaningful.
  • Substitution matrix: a table giving a score for every pair of residues.
  • Affine gap penalty: a gap costs a large opening charge plus a small charge per extra position.

Identity, similarity and homology

Aligned residues can be identical, similar or unrelated. Percent identity counts only exact matches and is easy to compute. Percent similarity also counts conservative substitutions and depends on the matrix you use. Neither number is homology. Homology means the sequences share an ancestor, and we infer it from the similarity: sequences more similar than chance would produce are likely homologous. A common rule of thumb is that protein pairs over about 30% identity across a long alignment are very likely homologous, while pairs below roughly 20 to 25% fall in a "twilight zone" where similarity alone becomes ambiguous and statistics must decide. These thresholds are guidelines, not laws: short alignments need much higher identity to be convincing.

Scoring DNA

For DNA the simplest scheme is a fixed reward for a match and a fixed penalty for a mismatch, for example +1 and -1, or the +2 and -3 that BLASTN uses by default. Biology adds a refinement. Purines (A, G) are chemically similar to each other, as are pyrimidines (C, T). A change within a class is a transition, and a change between classes is a transversion. Transitions happen more often than transversions, so some DNA matrices penalize transitions less. Whether that matters depends on how closely related the sequences are.

Scoring proteins: log-odds

For proteins there are 20 amino acids and 190 distinct pairs of different residues, and they are not equally likely to replace each other. The standard way to build the matrix is to measure how often each pair appears aligned in trusted alignments of related proteins, and compare that with how often you would see the pair by chance. The score is the logarithm of that ratio, the log-odds score:

Text
S(a, b) = (1 / lambda) * log( q(a,b) / (p(a) * p(b)) )

Here q(a,b) is the observed frequency of the aligned pair, and p(a) and p(b) are the background frequencies of the residues, so p(a) * p(b) is the pair frequency expected if the sequences were unrelated. If the pair appears more often than chance, the ratio exceeds 1, its logarithm is positive and the pair scores positive. If it appears less often, the score is negative. Taking logarithms has a lovely side effect: the score of a whole alignment is the sum of the scores of its columns, which corresponds to multiplying the probabilities of independent columns.

Two families of matrices dominate. PAM matrices (Margaret Dayhoff and colleagues, 1978) were extrapolated from closely related proteins using a model of evolution in which PAM1 represents one accepted point mutation per 100 residues, and higher PAM numbers extrapolate to greater distances. BLOSUM matrices (Steven and Jorja Henikoff, 1992) were counted directly from conserved blocks of aligned protein families, grouping sequences that were more identical than a threshold. BLOSUM62 uses blocks clustered at 62% identity and is the default of BLAST and many aligners. Lower numbers suit distant relatives (BLOSUM45), higher numbers suit close ones (BLOSUM80). The scores are in half-bit units, which is why the matrix entries are small whole numbers.

A few real BLOSUM62 entries make the pattern clear. Identical residues score positively, but rare, structurally special residues score most: cysteine with cysteine is +9 and tryptophan with tryptophan is +11. Similar residues score positively too: isoleucine with valine is +3, phenylalanine with tyrosine is +3, lysine with arginine is +2, aspartate with glutamate is +2 and isoleucine with leucine is +2. A chemically drastic swap scores negatively, for example cysteine with tryptophan at -2.

Gap penalties

Insertions and deletions are rarer than substitutions, but when they happen, they often involve several residues at once. A linear gap penalty charges the same amount for each gap position, so a gap of length k costs k * g. That treats a single three-residue deletion as three independent events, which overcharges it. The affine gap penalty charges an opening cost plus a smaller extension cost per position. NCBI BLASTP with BLOSUM62 uses 11 for existence and 1 for extension, so a gap of length k costs 11 + k (a gap of one residue costs 12). Affine penalties encourage a few long gaps over many scattered short ones, which fits real indels. They need a slightly more elaborate algorithm (Gotoh's version of dynamic programming uses three matrices), which later lessons mention.

Gap penalties interact with matrix choice. Too low, and alignments fill up with gaps; too high, and the algorithm forces mismatches where a gap would be more honest. When in doubt, use the defaults of a well-established tool, which were tuned on benchmark data.

Seeing similarity first: dot plots

Before any scoring, a dot plot gives a picture of how two sequences relate. Put one sequence on each axis and place a dot wherever the residues match. Similar regions appear as diagonal lines, repeats as parallel diagonals, inversions as anti-diagonals. Real dot plots filter out noise by requiring several matches in a window along the diagonal.

Common misconceptions

  • "Percent homology." Sequences are homologous or they are not. Quote percent identity or percent similarity instead.
  • "The best matrix is BLOSUM62 for everything." It is a good all-purpose default, but closely related sequences suit higher-numbered BLOSUM (or lower-numbered PAM) matrices.
  • "Gaps should cost the same as mismatches." Gaps are costed separately, and affine penalties reflect that real indels are often long.
  • "Identical means conserved function." Identity is a clue, not proof of shared function.

Try it

Python Score one alignment under different gap rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python A dot plot with a window filter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Build a log-odds score

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does a positive log-odds score for a residue pair mean?

    Log-odds are positive when the observed pair frequency exceeds the chance expectation.
  2. 2. BLOSUM62 is built from blocks clustered at what level of identity?

    The number in BLOSUM62 is the identity threshold (in percent) used to cluster the blocks.
  3. 3. With BLASTP defaults (existence 11, extension 1), what does a gap of length 3 cost?

    Cost = 11 + 3 x 1 = 14.
  4. 4. Why use affine gap penalties?

    Affine penalties charge less for extending a gap than opening one, favoring a few long gaps.
  5. 5. Which statement is correct?

    Homology is a statement about ancestry; percent identity or similarity measures resemblance.

Summary

  • Identity and similarity measure resemblance; homology is a yes-or-no statement about ancestry.
  • Log-odds scores compare observed with expected pair frequencies; BLOSUM62 and PAM matrices are the standard.
  • Affine gaps charge an opening cost plus an extension cost and suit real indels.
  • A dot plot shows similarity visually before any scoring decisions.

Next: Global alignment: Needleman-Wunsch