Search

Search papers and lessons

Multiple Sequence Alignment

Level 3 · 13 min read

A multiple sequence alignment lines up three or more sequences column by column, so letters descended from the same position sit together, and it is usually built step by step from pairwise scores.

On this page

  • Colour = topic mix
  • Calculus
  • Linear algebra
  • Classical mechanics
  • Discrete math
  • Quantum physics
  • Probability
  • ReadReady to readNot yet

TL;DR

A multiple sequence alignment lines up three or more sequences, such as the same protein from several species, so that letters descended from the same position sit in the same column. A gap marks where one sequence has an insertion or deletion relative to the others. Finding the best alignment exactly is too expensive for many sequences, so most programs build it step by step: they align the most similar pair first, then add the remaining sequences one at a time.

Builds on: Sequence Alignment, Substitution Matrix, Phylogenetic Tree · Leads to: tree inference from aligned sequences, and searches that compare a new sequence against a whole family

Where it's used

Naming a gene in a new species. A lab sequences a gene from a newly found animal and wants to know whether it is the same gene as the human version. Aligning the new sequence with the human and mouse versions shows which columns agree. A long run of matching columns across all three is the sign that they share the gene.

Finding the parts of a protein that matter. Researchers align the same amino acid chain from dozens of species. A column where almost every species has the same residue is usually one that selection has kept, because the protein cannot change it without losing function, so the column is flagged as important. This is one of the standard ways to find the positions a protein depends on.

Building an evolutionary tree. Many tree methods take a multiple alignment as their input, so a mistake in the alignment becomes a mistake in the tree. Studies of how a virus has spread between hosts build their trees from aligned viral genomes, and the alignment is the first step of that work.

How it works

We use three short DNA sequences and a simple scoring rule: a match scores +1+1, a mismatch scores −1-1, and a gap scores −1-1. The sequences are x=x = ACGT, y=y = AGT and z=z = ACT. The goal is one alignment of all three with the best total score.

  1. Score every pair. Align each pair with the pairwise method from Sequence Alignment. The results are: xx with yy scores 22, xx with zz scores 22, and yy with zz scores 11. For xx and yy the best line-up is ACGT over A-GT, with three matches and one gap, so 3−1=23 - 1 = 2. Check: the three pair scores are the only numbers this method needs.

  2. Build a guide tree. Join the most similar pair first. xx and zz tie with xx and yy at 22, so we take xx and zz. Then yy joins last. The order ((x,z),y)((x, z), y) is the guide tree, which says the order to build the alignment in. Check: the first join uses a pair with the highest score.

  3. Align the first pair. The best alignment of xx and zz is ACGT over AC-T. Its score is 1+1−1+1=21 + 1 - 1 + 1 = 2. Check: this matches the pairwise score from step 1.

  4. Add the third sequence to the alignment. Now y=y = AGT is aligned against the two-row alignment, which we treat as a profile of four columns: P1P_1 = A/A, P2P_2 = C/C, P3P_3 = G/-, P4P_4 = T/T. A letter of yy against a column scores the sum of its pair scores with each row, so G against G/- scores +1−1=0+1 - 1 = 0. A gap in yy against a column scores −1-1 for each row that holds a letter. A letter of yy in a brand-new column, with gaps in both rows, scores −2-2. Each cell takes the best of three moves: a letter of yy against a profile column, a letter of yy in a new column, or a profile column against a gap in yy. Check: the top-right corner is the answer, and every cell is computed from cells above or to its left.

    yy so farnoneP1P_1P2P_2P3P_3P4P_4
    none0-2-4-5-7
    A-220-1-3
    G-4000-2
    T-6-2-2-22
  5. Trace back. Start at the bottom-right value 22. It came from the diagonal, so T of yy sits in column P4P_4. Next, the G cell in column P3P_3 came from the diagonal, so G sits in P3P_3. The cell for column P2P_2 came from the left, so column P2P_2 faces a gap in yy. The A cell in P1P_1 came from the diagonal. The result is:

    x  A C G T
    z  A C - T
    y  A - G T
    

    Check: the cell F(3,4)=2F(3,4) = 2 is the score the new sequence adds to the profile.

  6. Score the whole alignment. Score each column by its three pairs. Column 1 (A, A, A) gives 33. Column 2 (C, C, -) gives +1−1−1=−1+1 - 1 - 1 = -1. Column 3 (G, -, G) gives −1+1−1=−1-1 + 1 - 1 = -1. Column 4 (T, T, T) gives 33. The total is 3−1−1+3=43 - 1 - 1 + 3 = 4. Check: this is the profile score 22 plus the added score 22, so both routes agree on 44.

flowchart LR
  A["Score every pair of sequences"] --> B["Build a guide tree from the scores"]
  B --> C["Align the most similar pair"]
  C --> D["Add the next sequence to the alignment as a profile"]
  D --> E{"Sequences left?"}
  E -->|yes| D
  E -->|no| F["Final alignment and its score"]

The math

Definition: Sum-of-pairs score

An alignment of kk sequences with LL columns has an entry ar,ca_{r,c} in row rr and column cc, which is either a letter or a gap. Let ss be the pair score, with s(gap,gap)=0s(\text{gap}, \text{gap}) = 0 and s(letter,gap)=gs(\text{letter}, \text{gap}) = g. The sum-of-pairs score is

SP=∑c=1L∑1≤r<q≤ks(ar,c,aq,c).\mathrm{SP} = \sum_{c=1}^{L} \sum_{1 \le r \lt q \le k} s(a_{r,c}, a_{q,c}).

Each column is scored by all its pairs of rows, and each pair of rows is counted once.

Step 2 in symbols: the guide tree

The pairwise scores S(x,y)=2S(x,y) = 2, S(x,z)=2S(x,z) = 2 and S(y,z)=1S(y,z) = 1 come from the pairwise method. The first join is the pair with the largest SS. Here two pairs tie at 22, and we take (x,z)(x, z).

Step 4 in symbols: adding a sequence to a profile

Let the profile have pp rows and columns P1,…,PnP_1, \dots, P_n, and let y1…ymy_1 \dots y_m be the new sequence. Define three scores:

  • m(c,Pj)=∑r=1ps(c,Pj,r)m(c, P_j) = \sum_{r=1}^{p} s(c, P_{j,r}), the score of letter cc against profile column jj;
  • e(Pj)=∑r=1ps(gap,Pj,r)e(P_j) = \sum_{r=1}^{p} s(\text{gap}, P_{j,r}), the score of a gap in yy against column jj;
  • d(c)=p gd(c) = p\,g, the score of letter cc in a new column.

Then the dynamic programming table F(i,j)F(i, j), the best score for the first ii letters of yy and the first jj profile columns, satisfies

F(i,j)=max⁡{ F(i−1,j−1)+m(yi,Pj),  F(i−1,j)+d(yi),  F(i,j−1)+e(Pj) }.F(i,j) = \max\bigl\{\, F(i-1,j-1) + m(y_i, P_j),\; F(i-1,j) + d(y_i),\; F(i,j-1) + e(P_j) \,\bigr\}.

In the walkthrough p=2p = 2 and g=−1g = -1, so d=−2d = -2. The gap scores are e(P1)=e(P2)=e(P4)=−2e(P_1) = e(P_2) = e(P_4) = -2, and e(P3)=−1e(P_3) = -1 because P3P_3 holds only one letter. The edges are F(0,j)=∑k≤je(Pk)F(0, j) = \sum_{k \le j} e(P_k) and F(i,0)=i dF(i, 0) = i\,d. For example F(3,4)=2F(3,4) = 2 is the bottom-right value.

Step 6 in symbols: the total score

The profile already had sum-of-pairs score 22, and the new sequence adds F(3,4)−0=2F(3,4) - 0 = 2. The sum of the two is 44, which is the sum-of-pairs score of the final alignment. This is no accident: the recurrence adds only the new pairs, so the total matches the definition.

Worked examples

Example
Example 1: three single letters (tiny)

Sequences A, A and C, with match +1+1 and mismatch −1-1. No gaps are needed, because every sequence has one letter.

  1. Pair the first and second sequences: A with A scores +1+1.
  2. Pair the first and third: A with C scores −1-1.
  3. Pair the second and third: A with C scores −1-1.
  4. The total is 1−1−1=−11 - 1 - 1 = -1.

Interpretation: there is only one possible alignment, so the score is just the sum over pairs. The mismatch costs one point each time it appears, and it appears twice.

Example
Example 2: scoring a given alignment (standard case)

Score the alignment below with match +1+1, mismatch −1-1 and gap −1-1.

x  A C G - T
y  A C G A T
z  A - G A T
  1. Column 1 (A, A, A): three pairs, each +1+1, so the column scores 33.
  2. Column 2 (C, C, -): the pair xx and yy scores +1+1; the pairs xx and zz and yy and zz each have a letter against a gap, so each scores −1-1. The column scores 1−1−1=−11 - 1 - 1 = -1.
  3. Column 3 (G, G, G): three pairs, each +1+1, so the column scores 33.
  4. Column 4 (-, A, A): the pair yy and zz scores +1+1; the pairs xx with yy and xx with zz each have a gap against a letter, so each scores −1-1. The column scores −1−1+1=−1-1 - 1 + 1 = -1.
  5. Column 5 (T, T, T): three pairs, each +1+1, so the column scores 33.
  6. The total is 3−1+3−1+3=73 - 1 + 3 - 1 + 3 = 7.

Interpretation: each gap-letter pair scores −1-1, where a match would score +1+1, so each one costs two points relative to a match. The two gap columns here hold four such pairs. The score rewards the columns that agree and charges for each gap.

Example
Example 3: a conserved residue across four species (realistic)

Suppose one column of a four-species alignment of a binding site holds the residues K, K, K and R, in the order human, mouse, chicken and frog. These letters are illustrative, not from a real protein. The question is what fraction of the species pairs agree at this column.

  1. Four sequences give (42)=6\binom{4}{2} = 6 pairs of species.
  2. The three K residues agree with each other in (32)=3\binom{3}{2} = 3 pairs.
  3. The R residue differs from each K, so it contributes no agreeing pair.
  4. The fraction of agreeing pairs is 3/6=0.53 / 6 = 0.5.

Try it: a column reads K, K, R, R. How many pairs agree, and what fraction is that? Answer: the two K residues agree in one pair and the two R residues agree in one pair, so 22 of the 66 pairs agree, and the fraction is 2/6=1/32 / 6 = 1/3.

Interpretation: half of the pairs agree in the first column, which suggests the residue has mostly been kept, with the frog as the one change. Real studies weight each change by a substitution matrix rather than just counting identical pairs.

Common mistakes and tradeoffs

It is tempting to think that a multiple alignment is just the best pairwise alignment done for every pair. In fact the pairwise alignments can disagree about where gaps go, and they cannot always be combined into one consistent alignment of all sequences.

It is tempting to think that the order of joining does not matter. In fact an early decision is frozen. A gap placed while two sequences are aligned stays in every later alignment, so a poor first step can spoil the result. Methods that revisit and realign the sequences after the first build reduce this problem.

It is tempting to delete every column that contains a gap before building a tree. In fact such a column can be real: it marks a deletion in some species. Removing it discards information and can change the tree, so trimming is a choice to be checked, not a free clean-up.

Exact multiple alignment is a dynamic programming table with one dimension per sequence. For kk sequences of length LL it has about (L+1)k(L+1)^k cells, so it is practical only for a few short sequences. When to use it. Use an exact or iterative method for a small set of sequences where accuracy matters most. Use a progressive method, which follows a guide tree, for dozens to thousands of sequences. When not to use it. Do not treat the output as a fact about evolution: it depends on the scoring, the guide tree and the gap penalties.

History

Saul Needleman and Christian Wunsch published their pairwise method in 1970, as described in the pairwise lesson. For several sequences, Feng and Doolittle published a progressive method in 1987 that builds the alignment in the order of a guide tree.

In 1988 the CLUSTAL program, by Higgins and Sharp, made progressive alignment a standard tool. CLUSTAL W, published in 1994, added weighting of sequences and gap penalties that depend on position. Later programs such as MAFFT, in 2002, and MUSCLE, in 2004, improved speed and accuracy by refining the alignment after building it.

Progressive alignment caught on because it turned a problem that could not be solved exactly into one that a desktop computer could finish in a reasonable time, and its results were good enough for most uses.

Recap

  • A multiple alignment places letters from many sequences in shared columns, with gaps for insertions and deletions.
  • Its score is the sum over columns of the pair scores, the sum-of-pairs score.
  • The exact table has about (L+1)k(L+1)^k cells, so most programs align progressively.
  • A guide tree, built from the pairwise scores, sets the order; each step adds one sequence to a growing profile.
  • Early gap decisions are kept, so refinement methods that revisit them matter.

Read next: Hidden Markov Model for a model that scores a new sequence against an alignment, and Phylogenetic Tree for what the alignments are used to build.

Check yourself

QuestionRecall: what are the two parts of the sum-of-pairs score, and what is the score of a gap against a gap?Show answer

The score adds the pair scores within each column, and it counts every pair of rows in that column once. The score of a gap against a gap is zero, because two gaps show no evidence either way.

QuestionComputation: with match +1+1, mismatch −1-1 and gap −1-1, what is the sum-of-pairs score of the column A, A, G, -?Show answer

The four rows give six pairs. The pair of the two As scores +1+1. Each of the two As against G scores −1-1, which is −2-2. Each of the two As against the gap scores −1-1, which is −2-2. The G against the gap scores −1-1. The total is 1−2−2−1=−41 - 2 - 2 - 1 = -4.

QuestionWhy: why can the best pairwise alignments not simply be combined into one multiple alignment?Show answer

Each pairwise alignment places its gaps to suit only the two sequences it compares. Two pairs can then disagree about where a gap belongs in a shared sequence, so no single set of columns agrees with every pairwise result. A method must choose one order and one set of gap placements, which costs some optimality.

QuestionApplied scenario: before building a tree, a colleague deletes every column that has a gap. What would you check before agreeing?Show answer

Check how many columns are removed and whether the gaps cluster in one sequence. A block of gaps at one end of a single sequence usually means that sequence is incomplete rather than that the species has a deletion there. Then compare the trees built with and without the trimming. If the tree changes a lot, the trimming is driving the result, and the choice should be stated and justified.

Sources