LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 73 lessons

Lesson 6 of 9

Module 4 · Comparing sequences

Multiple alignment and conserved regions

Multiple alignment and conserved regions

Multiple alignment and conserved regions

Line up many related sequences at once and the positions that matter start to show. Learn the progressive idea behind the main tools, run them on the web, and score conservation in Python.

⏱ 13 min readModule 4 · Comparing sequencesFree
Lesson at a glance4 steps · about 13 min
  1. Why line up many sequences at once
  2. The progressive idea
  3. Running a multiple alignment on the web
  4. Reading an alignment in Python

Why line up many sequences at once

A pairwise alignment (Global and local alignment, without heavy maths) compares two sequences. A multiple sequence alignment, or MSA, lines up three or more, so that each column holds letters thought to descend from the same position in a common ancestor. Gaps are inserted where some sequences have gained or lost letters.

Seeing many relatives together shows what two cannot. A position that has stayed the same in every species, over hundreds of millions of years, has probably been kept for a reason: it may hold the protein's shape together, bind a partner, or sit in the active site. Such a column is conserved. A column where the letters vary freely is probably less important to the protein's job. Multiple alignments are also the starting material for trees (Trees from sequences), for judging whether a patient's variant hits a conserved position (Variants: what a change in sequence does, and how it is annotated), and for many tools that predict structure and function.

Conservation is not all or nothing. A column that holds only isoleucine, leucine and valine has changed, but always to another greasy residue: the position is free to swap letters as long as it stays oily, perhaps because it sits in the buried core of the protein. A column of only aspartate and glutamate suggests that a negative charge is what matters there. Reading these partly conserved columns tells you what kind of residue a position needs, which a pair of sequences, as in Pairwise alignment: dot plots, scores and gaps, could rarely show. A multiple alignment also shows indels in context: a gap shared by all the bird sequences but none of the mammals points to a single event in the bird line.

The progressive idea

For two sequences, the best alignment can be found exactly. For many, the exact method becomes far too slow: the work grows explosively with each sequence added. So every practical tool uses a shortcut, and the classic one is progressive alignment.

  • Measure. Compare every pair of sequences quickly and give each pair a distance: how different they are.
  • Guide tree. Join the sequences into a rough tree, with the most similar pairs closest together. This guide tree only sets the order of work; it is not meant as a careful evolutionary tree.
  • Align in order. Align the closest pair first. Then add the next sequence, or join two small alignments, following the guide tree until everything is in. A small alignment treated as one unit is called a profile: at each column, it records which letters occur and how often.

The weak point is that early decisions are never revisited: once a gap is placed between the first two sequences, it stays there. Modern tools reduce this. Some go back and refine the alignment, taking it apart and realigning pieces to see whether the score improves. Others use smarter ways to compare profiles.

The order matters because the most similar sequences are the easiest to align correctly. By starting with them, the tool makes its early, permanent decisions where the evidence is clearest, and the profiles it builds then carry that information forward. A distant sequence is easier to place against a profile than against any single relative, because the profile shows which columns vary and which do not. For speed, the first step often does not align every pair in full. Many tools estimate the distances from the number of short words two sequences share, the same idea as the seeds in Searching databases fast: similarity search and E-values.

Multiple alignment and conserved regions · LSMA free course On the left, a guide tree joins sequences A and B, and C and D, then joins the two pairs. On the right, three steps: first A and B are aligned; then C and D are aligned; then the two small alignments are aligned to each other as profiles, giving one alignment of four sequences in which a gap placed in step 2 is kept. GUIDE TREE AB CD 1 2 3 closest pairs joined first ALIGN IN THE ORDER OF THE TREE 1 · A WITH B 2 · C WITH D 3 · PROFILE WITH PROFILE A WGKVNVDE B WGKVNSDE C WGKV-EEDE D WAKVGEDE A WGKVNVDE B WGKVNSDE C WGKV-EEDE D WAKVGEDE a gap is placed here … … and kept in the final alignment of all four
Progressive alignment follows a guide tree: the closest pair first, then the next, then the two groups together. The four short sequences are made up for teaching. Schematic.

How to read the figure

Start with the guide tree on the left. A and B are joined at the node marked 1, C and D at node 2, and the two pairs at node 3. The numbers give the order of the alignment steps on the right. In step 3, each small alignment is treated as a profile and the two are aligned with each other, so every row moves as a block. The vermilion gap in sequence C, placed in step 2, survives into the final alignment unchanged: that is the "once a gap, always a gap" rule.

Go deeper: how fast the exact method explodes

For two sequences, the grid of Global and local alignment, without heavy maths has one cell per pair of letters. For more, the exact method needs a grid with one dimension per sequence. Five proteins of 150 residues would need 150 × 150 × 150 × 150 × 150 cells, about 76 billion, and each cell can be reached in 31 ways instead of three. Ten such proteins would need about 6 × 10 to the power 21 cells, more than any computer could ever fill.

The problem was proved in 1994 to be computationally hard in general, so no clever trick is expected to make the exact answer cheap. That is why every practical tool, from Clustal to MAFFT, settles for a good alignment rather than a guaranteed best one, and why different tools can disagree in difficult regions.

Running a multiple alignment on the web

The main tools are free to use through the EMBL-EBI (the European Bioinformatics Institute) web pages, collected under its Job Dispatcher service. Three you will meet often:

Clustal Omega
  • Built for very large sets, up to many thousands of sequences
  • A sound default for proteins
MUSCLE
  • Fast, with rounds of refinement
  • Good for small to medium sets
MAFFT
  • Offers strategies from very fast to very careful
  • Popular for both DNA and protein

On the EMBL-EBI page for any of them, the steps are the same. Choose protein or DNA. Paste your sequences in FASTA format, one header line starting with > before each. Leave the settings at their defaults the first time. Submit, wait for the job to finish, and download the alignment, either in Clustal format (blocks of 60 columns with a symbol line underneath) or as an aligned FASTA file, in which every sequence has the same length because gaps are written as -. In the Clustal symbol line, * marks a fully identical column, : a column of strongly similar amino acids and . a weakly similar one.

Different tools can give slightly different alignments of the same sequences, mostly in regions full of gaps. Where the sequences are close and the alignment is easy, they agree. Treat gappy, poorly matching regions of any alignment with caution.

A few practical habits avoid common problems. Give each sequence a short, unique name with no spaces in the header line, because many tools keep only the text up to the first space, and two sequences that end up with the same name cause errors later. Do not mix DNA and protein in one job. Some tools reorder the sequences in the output to follow the guide tree; an option on the form sets whether the input order is kept. Finally, look at the result before using it. Open it in an alignment viewer that colours the residues, such as the free program Jalview, and scroll through: a sequence that is mostly gaps, or that matches nothing around it, is often a fragment or the wrong gene.

Progressive alignment was introduced by Feng and Doolittle (1987), 'Progressive sequence alignment as a prerequisite to correct phylogenetic trees', Journal of Molecular Evolution 25:351–360. The three tools have their own papers: Clustal Omega, Sievers et al. (2011), Molecular Systems Biology 7:539; MUSCLE, Edgar (2004), Nucleic Acids Research 32:1792–1797; and MAFFT version 7, Katoh and Standley (2013), Molecular Biology and Evolution 30:772–780. Cite the tool you used, with its version and any settings you changed. Newer major versions, such as MUSCLE 5, exist and can align the same input differently, so the version matters.

Reading an alignment in Python

This lesson needs Biopython (!pip install biopython in Colab). The alignment below is real: a 30-residue stretch of haemoglobin beta from five species, taken from their UniProt entries and lined up by position, which pairwise alignments like those in Global and local alignment, without heavy maths confirm. In this region the five proteins align without any gaps, so no gap symbols are needed. Writing it as aligned FASTA inside the code means you can run it anywhere.

If you pass AlignIO.read an ordinary FASTA file of unaligned sequences, it stops with an error saying that the sequences must all be the same length. That message usually means the alignment step was skipped: run the sequences through one of the tools above first, then read the aligned file.

Python
from io import StringIO
from Bio import AlignIO

# Real haemoglobin beta fragments (UniProt), residues 4-33 in human numbering
text = """>human
LTPEEKSAVTALWGKVNVDEVGGEALGRLL
>mouse
LTDAEKAAVSCLWGKVNSDEVGGEALGRLL
>cow
LTAEEKAAVTAFWGKVKVDEVGGEALGRLL
>horse
LSGEEKAAVLALWDKVNEEEVGGEALGRLL
>chicken
WTAEEKQLITGLWGKVNVAECGAEALARLL
"""
aln = AlignIO.read(StringIO(text), "fasta")
print(len(aln), "sequences,", aln.get_alignment_length(), "columns")
for rec in aln:
    print(f"{rec.id:8}", rec.seq)

What this does

  • StringIO(text) makes the text behave like an open file, because AlignIO expects a file. With a real file from EMBL-EBI you would pass its name instead, such as AlignIO.read("my.aln", "clustal").
  • AlignIO.read(..., "fasta") reads exactly one alignment in aligned-FASTA format. It checks that every sequence has the same length.
  • len(aln) is the number of sequences (rows); aln.get_alignment_length() is the number of columns.
  • The loop prints each row. f"{rec.id:8}" pads the name to 8 characters so the sequences line up.
5 sequences, 30 columns human LTPEEKSAVTALWGKVNVDEVGGEALGRLL mouse LTDAEKAAVSCLWGKVNSDEVGGEALGRLL cow LTAEEKAAVTAFWGKVKVDEVGGEALGRLL horse LSGEEKAAVLALWDKVNEEEVGGEALGRLL chicken WTAEEKQLITGLWGKVNVAECGAEALARLL

Reading the output

Five sequences, 30 columns each, as expected. Read down any column to compare one position across species. Some are identical all the way down, such as the W in column 13 and the EAL run near the end; others vary, such as column 3, where every species but cow and chicken has its own letter. Chicken stands out most often, as you would expect for a bird among four mammals.

Now measure conservation. For each column, the code finds the commonest letter and the share of sequences that have it. A column scores 1.0 if all five agree and 0.2 if all five differ.

Python
from collections import Counter

marks, scores = "", []
for i in range(aln.get_alignment_length()):
    column = aln[:, i]                       # one residue from each sequence
    top, n = Counter(column).most_common(1)[0]
    scores.append(n / len(column))           # share with the commonest residue
    marks += "*" if n == len(column) else " "

for rec in aln:
    print(f"{rec.id:8}", rec.seq)
print(f"{'':8}", marks)                      # * = all five identical
print("Fully conserved columns:", marks.count("*"))
print("Mean conservation:", round(sum(scores) / len(scores), 2))
print("Column 13:", aln[:, 12], "| column 3:", aln[:, 2])

What this does

  • aln[:, i] takes column i: one letter from every row, as a short string. Python counts from 0, so aln[:, 12] is column 13.
  • Counter(column).most_common(1)[0] counts the letters and returns the commonest one with its count, for example ('W', 5).
  • n / len(column) is the conservation score of that column. The code also builds a line of marks, with * under fully identical columns, like the Clustal symbol line.
  • The last lines count the starred columns, average the scores, and print two columns to compare.
human LTPEEKSAVTALWGKVNVDEVGGEALGRLL mouse LTDAEKAAVSCLWGKVNSDEVGGEALGRLL cow LTAEEKAAVTAFWGKVKVDEVGGEALGRLL horse LSGEEKAAVLALWDKVNEEEVGGEALGRLL chicken WTAEEKQLITGLWGKVNVAECGAEALARLL ** * ** * * *** *** Fully conserved columns: 13 Mean conservation: 0.84 Column 13: WWWWW | column 3: PDAGA

Reading the output

The stars sit under the 13 columns where all five species agree. They cluster: a pair at columns 5 and 6, a group around the tryptophan in column 13, and most of the last nine columns. The average score of 0.84 means that, in a typical column, more than four of the five sequences share the commonest letter. Column 13 reads WWWWW, fully conserved. Column 3 reads PDAGA: four different letters, with alanine the commonest at 2 of 5.

Worked example · scoring two columns

column 13: W W W W W → commonest W, 5 of 5 → 1.0
column 3: P D A G A → commonest A, 2 of 5 → 0.4
mean over 30 columns = 0.84 · fully conserved = 13 of 30

Step by step. In column 13, count the letters: tryptophan (W) five times. The commonest letter appears 5 times out of 5, so the score is 5 ÷ 5 = 1.0, and the column gets a star. In column 3, the letters are proline, aspartate, alanine, glycine and alanine. Alanine appears twice, every other letter once, so the score is 2 ÷ 5 = 0.4. Do this for all 30 columns and average the scores to get 0.84.

What the answer means. Column 13 is residue 16 of the human protein, a tryptophan that every one of these species has kept. Column 3 is a position where change has been tolerated. With only five sequences, four of them mammals, many columns are identical simply because the species are related, not because each position matters. Conservation becomes good evidence of importance when the alignment includes many, distantly related sequences.

This simple score has two limits worth knowing. It treats all changes alike, so a swap between two similar amino acids, such as leucine and isoleucine, counts the same as a swap between very different ones. Better scores use a matrix like BLOSUM62 from Scoring matrices: PAM and BLOSUM, which is what Clustal's : and . marks do. And it ignores gaps, because this alignment has none; with gaps, you must decide whether a gap counts as a difference.

Gaps bring one more thing to watch: column numbers stop matching residue numbers. In this alignment column 13 is residue 16 of the human protein only because the fragment starts at residue 4 and there are no gaps. Once gaps appear, each sequence has its own numbering, and a column number has to be converted back to a residue number for the protein you care about by counting its letters and skipping its dashes. Getting this wrong is a common way to report the wrong position for a variant, the subject of Variants: what a change in sequence does, and how it is annotated. Published tools also use more refined conservation measures, such as one based on entropy, which takes into account how many different letters a column holds and how evenly they are spread, rather than only the commonest one.

Key point

A multiple alignment puts positions that share an ancestor into the same column. Columns that stay the same across distant relatives point to positions that matter. Progressive tools build the alignment step by step along a guide tree, so check the gappy regions before you trust them.

The quality of the input matters as much as the tool. Include enough sequences, from a range of relatives, and remove fragments and near-duplicates first: a handful of almost identical sequences makes every column look conserved.

Further reading · Module 4Clustal Omega at EMBL-EBI: the web form and its help. · MAFFT at EMBL-EBI. · Biopython tutorial: multiple sequence alignments. · All reading for this course

Check your understanding

1. Why does progressive alignment build a guide tree first?

2. A column is identical in five closely related mammals. Why is that only weak evidence that the position is important?

3. A column reads L L I L V. What is its conservation score, as calculated in this lesson?

Up next

Lesson 7

Trees from sequences

Ask BioTutor

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