LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 73 lessons

Lesson 4 of 9

Module 4 · Comparing sequences

Scoring matrices: PAM and BLOSUM

Scoring matrices: PAM and BLOSUM

Scoring matrices: PAM and BLOSUM

Not all amino acid swaps are equal, and a substitution matrix says how much each one counts. Learn how BLOSUM62 was built from real alignments, how to read it, and how to score an alignment with it by hand and in Biopython.

⏱ 13 min readModule 4 · Comparing sequencesFree
Lesson at a glance6 steps · about 13 min
  1. Why one mismatch score is not enough
  2. Scores learned from real alignments
  3. How BLOSUM62 was built
  4. PAM: the earlier family
  5. Reading BLOSUM62
  6. Scoring an alignment by hand and with the aligner

Why one mismatch score is not enough

In Pairwise alignment: dot plots, scores and gaps and Global and local alignment, without heavy maths every mismatch cost the same. For DNA that is a fair simplification. For proteins it throws away most of what we know. The 20 amino acids differ in size, charge and how much they like water. Swapping leucine for isoleucine, two greasy residues of almost the same shape, usually leaves a protein working. Swapping leucine for aspartate, which carries a negative charge, often breaks it, so evolution rarely keeps such a change. An alignment that pairs L with I is better evidence of shared ancestry than one that pairs L with D.

Amino acids fall into rough families that tend to replace one another. The greasy ones, isoleucine (I), leucine (L), valine (V) and methionine (M), swap often. So do the ring-shaped aromatic ones, phenylalanine (F), tyrosine (Y) and tryptophan (W); the negatively charged pair, aspartate (D) and glutamate (E); and the positively charged lysine (K) and arginine (R). You saw this already in Why compare sequences: homology, similarity and identity, where several of the differences between human and mouse beta globin were F for Y or E for D. A good scoring scheme should give those columns credit rather than treat them like any other mismatch.

A substitution matrix captures this. It is a table with one row and one column per amino acid, 20 by 20, and each cell holds the score for aligning that pair. Same-letter pairs sit on the diagonal. The aligner looks up each column of an alignment in the table instead of using a single match or mismatch value. This lesson needs only Biopython, which ships with the common matrices built in.

Scores learned from real alignments

The values are not chosen by hand from chemistry. They are counted from real alignments of related proteins, using the log-odds idea from Pairwise alignment: dot plots, scores and gaps. For each pair of amino acids, two numbers are compared:

  • Observed: how often the pair appears in the same column of trusted alignments of related proteins.
  • Expected: how often it would appear by chance, worked out from how common each amino acid is on its own.

If a pair is seen more often than chance, the score is positive; if less often, negative; if about as often, close to zero. The score is the logarithm of observed divided by expected. A logarithm turns "times as likely" into a number you can add: scores for each column add up along the alignment, just as probabilities multiply.

Learning the scores from data has a consequence worth keeping in mind: a matrix reflects the proteins it was counted from. Those were mostly ordinary, water-soluble proteins of typical composition. Proteins that are unusual, such as those that sit in cell membranes and are rich in greasy residues, or stretches made of only a few amino acids, follow somewhat different patterns of change. Standard matrices still work for them, but less well, and a weak score for such a protein is not by itself proof that there is no relative.

How BLOSUM62 was built

The matrix you will use most is BLOSUM62, published in 1992. BLOSUM stands for BLOcks SUbstitution Matrix. The figure shows the idea in four steps.

The key choice was to count only from regions that line up without gaps. If gapped alignments had been used, the counts would depend on where some earlier program had placed the gaps, and that program would itself have needed a scoring matrix. Blocks avoid this circle: in a gap-free stretch of a family, the columns can be trusted as they stand.

Scoring matrices: PAM and BLOSUM · LSMA free course Four steps from left to right. One: collect blocks, short gap-free aligned segments from many protein families. Two: group sequences that are at least 62% identical so they count as one. Three: count how often each pair of amino acids appears in the same column. Four: compare each count with what chance predicts and turn the ratio into a log-odds score, rounded to a whole number. Example scores: L with I is plus 2, L with D is minus 4, W with W is plus 11. FROM REAL ALIGNMENTS TO A TABLE OF SCORES 1 · Blocks 2 · Group 3 · Count pairs 4 · Log-odds GLKVE GLRVE GIKVD GLKIE gap-free segments Sequences at least 62% identical are grouped and count as one, so close relatives do not dominate In each column, tally every pair: L–L, L–I, ... L–I: often L–D: rarely observed ÷ expected then log, rounded L–I +2 L–D −4 W–W +11 The column boxed in step 1 holds L, L, I and L: three L–L pairs and three L–I pairs. Block sequences made up for teaching; the three scores are real BLOSUM62 values.
The 62 in BLOSUM62 is the grouping threshold in step 2. The scores in step 4 are the real values from the matrix, which the code below prints. Schematic.

How to read this figure

  • Step 1. A block is a short stretch of a protein family that lines up without gaps across many members, usually a conserved, important region. Because there are no gaps, every column is a clean set of residues that sit at the same ancestral position.
  • Step 2. Some families have many near-identical members, which would swamp the counts with easy, uninformative pairs. Sequences at least 62% identical are therefore grouped and counted as a single sequence. Other members of the family were built with other thresholds: BLOSUM80 from groups at 80%, BLOSUM45 at 45%.
  • Step 3. In every column, each pair of residues is tallied. In the boxed column, three sequences have L and one has I. Pairing them up gives three L–L pairs and three L–I pairs.
  • Step 4. Each tally becomes a frequency, is divided by its chance expectation, and the logarithm is taken. BLOSUM62 scores are in half-bits: the log is taken to base 2 and doubled, then rounded to a whole number.

Worked example · from counts to a score

pair seen in 0.8% of aligned pairs · chance predicts 0.2%
ratio = 0.8 ÷ 0.2 = 4 · log2(4) = 2 bits · × 2 = +4
pair seen in 0.05% · chance predicts 0.2%
ratio = 0.25 · log2(0.25) = −2 bits · × 2 = −4

Example numbers for two imaginary pairs, chosen to keep the arithmetic easy; they are not taken from the real counts.

Step by step. For the first pair, divide what was seen by what chance predicts: 0.8 ÷ 0.2 = 4, so the pair turns up four times as often as chance. The base-2 logarithm asks "2 to what power gives 4?", and the answer is 2. Doubling for half-bit units gives +4. For the second pair, 0.05 ÷ 0.2 = 0.25, a quarter of what chance predicts; 2 to the power −2 is 0.25, so the log is −2, and doubled it is −4. A pair seen exactly as often as chance has a ratio of 1, a log of 0, and a score of 0.

What the answer means. A positive score says "related proteins make this pairing more often than chance", a negative one says "evolution tends to avoid this swap". Because the scores are logs, adding them along an alignment is the same as multiplying the ratios, so the total measures how much more likely the whole alignment is under shared ancestry than under chance.

Go deeper: the standard BLOSUM62 was miscalculated

In 2008, Styczynski and colleagues repeated the original BLOSUM calculation and found an error in the 1992 program. The BLOSUM62 built into BLAST and almost every other tool is therefore not quite the matrix the method describes. Recomputed correctly, it becomes a matrix they called RBLOSUM62, with a number of scores changed.

The surprise was that the miscalculated version did slightly better at finding distant relatives in their tests. It has remained the standard, partly because so many results and default settings depend on it. The general point: a matrix is a tool, judged by how well it finds real relationships, not a fact of nature. Note also that the 62 refers to the grouping step, not to the proteins you compare; BLOSUM62 works well for pairs far less than 62% identical.

PAM: the earlier family

Before BLOSUM, the standard was the PAM matrices, from the 1970s. PAM stands for Point Accepted Mutation: a change in the DNA that altered the protein and was "accepted" by natural selection, so it is still seen today. PAM was built differently. It counted changes in alignments of very closely related proteins, defined PAM1 as the amount of change that alters 1% of amino acids, and then extrapolated mathematically to longer distances. PAM250 is meant for proteins that have changed a great deal.

PAM250 does not mean that every amino acid has changed two and a half times. Some positions change several times, some change and change back, and many are held fixed by selection, so two proteins 250 PAM apart are still roughly 20% identical. The weakness of PAM lies in the extrapolation: small errors in the counts from close relatives are multiplied many times on the way to PAM250. BLOSUM avoided this by counting directly from more distant alignments, which is one reason it replaced PAM as the default for most searches.

PAMBLOSUM
Built fromClose relatives, extrapolated to distant onesBlocks of real alignments at each distance
For distant proteinsHigher number: PAM250Lower number: BLOSUM45
For close proteinsLower number: PAM30Higher number: BLOSUM80
Common defaultPAM30 for very short queriesBLOSUM62 for most protein searches, including BLAST

How to read this table

Read down each column to compare the two families. The trap is that the numbers run in opposite directions. A PAM number is an evolutionary distance, so bigger means more distant. A BLOSUM number is the grouping threshold, so bigger means the matrix was built from closer relatives. BLOSUM62 sits in the middle and works well across a wide range, which is why it is the default in the BLAST protein search and in Biopython's "blastp" setting used in Why compare sequences: homology, similarity and identity and Global and local alignment, without heavy maths. Change it only with a reason, such as very short or very distant sequences; the BLAST web page lets you choose another matrix under its algorithm parameters.

PAM matrices come from Dayhoff, Schwartz and Orcutt (1978), 'A model of evolutionary change in proteins', in Atlas of Protein Sequence and Structure, volume 5, supplement 3 (National Biomedical Research Foundation), pages 345–352. BLOSUM comes from Henikoff and Henikoff (1992), 'Amino acid substitution matrices from protein blocks', PNAS 89:10915–10919. Both were built from the protein data of their day, a small fraction of what is known now, yet both remain standards. When you report a protein alignment or search, name the matrix and the gap costs, because scores and E-values depend on both. Scores from different matrices are on different scales and should not be compared directly.

Reading BLOSUM62

Because the table is symmetrical, its 20 rows and 20 columns hold only 210 separate scores: 20 on the diagonal and 190 for the pairs of different amino acids. The version in Biopython and BLAST has a few extra rows and columns for codes you may meet in real files: B and Z for residues that could not be told apart (D or N, E or Q), X for an unknown residue and * for a stop. They let an aligner cope with imperfect sequences without crashing.

The first block loads BLOSUM62 and prints a corner of it.

Python
from Bio.Align import substitution_matrices

blosum62 = substitution_matrices.load("BLOSUM62")
print(blosum62.select("ACDGILW"))      # a corner of the full 20 x 20 table
print(blosum62["L", "I"], blosum62["L", "D"], blosum62["W", "W"])

What this does

  • substitution_matrices.load("BLOSUM62") loads the matrix that comes with Biopython. Calling load() with nothing in the brackets lists every matrix available, PAM250 and BLOSUM45 among them.
  • .select("ACDGILW") keeps only the rows and columns for those seven amino acids, so the table fits on screen.
  • blosum62["L", "I"] looks up a single score: row L, column I.
A C D G I L W A 4.0 0.0 -2.0 0.0 -1.0 -1.0 -3.0 C 0.0 9.0 -3.0 -3.0 -1.0 -1.0 -2.0 D -2.0 -3.0 6.0 -1.0 -3.0 -4.0 -4.0 G 0.0 -3.0 -1.0 6.0 -4.0 -4.0 -2.0 I -1.0 -1.0 -3.0 -4.0 4.0 2.0 -3.0 L -1.0 -1.0 -4.0 -4.0 2.0 4.0 -2.0 W -3.0 -2.0 -4.0 -2.0 -3.0 -2.0 11.0 2.0 -4.0 11.0

Reading the output

  • The diagonal is always positive, but not equal. Tryptophan (W) scores 11 with itself and cysteine (C) 9, while alanine (A) and leucine (L) score only 4. W and C are rare, so finding them in the same column is unlikely by chance and strong evidence; A and L are common, so a match is less surprising.
  • Alike pairs are positive. I with L scores +2. Elsewhere in the full table, F with Y scores +3 and E with D +2.
  • Unlike pairs are negative. L with D scores −4: a greasy residue for a charged one is a swap evolution rarely keeps.
  • The table is symmetrical: L with I is the same as I with L. The .0 on each number only means Biopython stores the scores as decimals.

Scoring an alignment by hand and with the aligner

The second block returns to the human and mouse haemoglobin beta fragments from Why compare sequences: homology, similarity and identity. They align without gaps, so the score is just the sum of one matrix value per column. The code adds them up by hand, then asks the aligner.

Python
from Bio import Align

# First 50 amino acids of haemoglobin beta (UniProt P68871 human, P02088 mouse)
human = "MVHLTPEEKSAVTALWGKVNVDEVGGEALGRLLVVYPWTQRFFESFGDLS"
mouse = "MVHLTDAEKAAVSCLWGKVNSDEVGGEALGRLLVVYPWTQRYFDSFGDLS"

total = 0
for pos, (h, m) in enumerate(zip(human, mouse), start=1):
    total += blosum62[h, m]
    if h != m:
        print(f"position {pos}: {h}/{m} scores {blosum62[h, m]:+.0f}")
print("score by hand:", total)

aligner = Align.PairwiseAligner()
aligner.substitution_matrix = blosum62
aligner.open_gap_score = -12      # the same gap costs BLAST uses by default
aligner.extend_gap_score = -1
print("score from the aligner:", aligner.score(human, mouse))

What this does

  • enumerate(..., start=1) numbers the pairs from 1, so positions match everyday counting.
  • Each pair's BLOSUM62 score is added to total. For the mismatched pairs only, a line is printed; :+.0f shows the score with its sign and no decimals.
  • The aligner is given BLOSUM62 and affine gap penalties of −12 to open and −1 to extend. In BLAST's own terms these are its defaults of 11 and 1, counted the other way, as Pairwise alignment: dot plots, scores and gaps explained.
  • aligner.score(...) returns only the best score, without building the alignment, which is quicker.
position 6: P/D scores -1 position 7: E/A scores -1 position 10: S/A scores +1 position 13: T/S scores +1 position 14: A/C scores +0 position 21: V/S scores -2 position 42: F/Y scores +3 position 44: E/D scores +2 score by hand: 226.0 score from the aligner: 226.0

Reading the output

There are the same 8 mismatches that Why compare sequences: homology, similarity and identity found, but now they are not all equal. F/Y (+3), E/D (+2), S/A and T/S (+1 each) are swaps between alike residues and earn points; P/D, E/A and V/S cost a little. Taken together the mismatches add 3 points, and the 42 matches supply the other 223. The aligner reaches the same 226, which confirms that its best alignment has no gaps and is scored exactly as we did by hand. Under a plain identity count these 8 positions all looked like differences; BLOSUM62 shows that half of them are conservative swaps, which is why the two proteins are more similar than their 84% identity suggests.

Key point

A substitution matrix gives each pair of amino acids a log-odds score learned from real alignments: positive for swaps evolution keeps, negative for swaps it avoids. BLOSUM62 is the standard default. Remember that BLOSUM and PAM numbers run in opposite directions.

A second example: aligning two distantly related bacterial enzymes with BLOSUM80 gives a weak, patchy alignment. BLOSUM80 was built from close relatives and punishes many swaps that are common over long times. Trying BLOSUM45, built for more distant proteins, is a reasonable next step, and the scores are then only comparable with other BLOSUM45 scores.

Further reading · Module 4Biopython tutorial: pairwise sequence alignment, including substitution matrices. · NCBI BLAST help, including scoring parameters. · All reading for this course

Check your understanding

1. In BLOSUM62, W with W scores +11 but A with A scores only +4. Why?

2. You are comparing two proteins you expect to be only distantly related. Which matrix change makes sense?

3. Two fragments differ at 8 of 50 positions, yet their BLOSUM62 mismatch scores add up to a positive number. What does that tell you?

Up next

Lesson 5

Searching databases fast: similarity search and E-values

Ask BioTutor

Create a free website with Framer, the website builder loved by startups, designers and agencies.