Access Noteson Genomic Information Sources
Home/Guides/How sequence alignment works

Guide

How sequence alignment works

Alignment lines up two or more sequences so that matching positions sit together, giving a measured way to judge how similar the sequences are.

4 min readGuide

To compare two sequences, you need to decide which position in one corresponds to which position in the other. Alignment does this by writing the sequences one above the other and shifting them until the best possible correspondence is found. It is the basis of most sequence comparison, from checking two short pieces of DNA to searching a large collection.

Matches, mismatches and gaps

Once two sequences are lined up, each column falls into one of three kinds.

  • A match is a column where both sequences have the same letter.
  • A mismatch is a column where the letters differ.
  • A gap is a column where one sequence has a letter and the other has a dash, meaning a base was inserted or lost in one of them.

Scoring a tiny example

Programs choose between possible alignments by giving each one a score. A simple scheme rewards each match, penalises each mismatch and penalises each gap. Real programs use more refined schemes, but the idea is the same.

Take two made-up strings, ACGTA and ACTA. One way to line them up is to place a gap in the second string.

  • ACGTA
  • AC-TA

Here four columns match and one column holds a gap. With a reward of one for each match, a penalty of one for each mismatch and a penalty of two for each gap, the score is four minus two, which is two. Without that gap, the strings would line up as ACGTA over ACTA with mismatches at the third and fourth positions and a missing end. That is two matches, two mismatches and one gap, so the score would be two minus two minus two, which is minus two. The alignment with the highest score is taken as the best one under those rules.

Changing the penalties changes the answer. A heavy gap penalty favours alignments with few gaps, while a light one allows more.

Global and local alignment

A global alignment stretches across the whole length of both sequences. It suits sequences that are similar from end to end, such as two versions of the same gene.

A local alignment looks for the best matching stretch only, and ignores the rest. It suits cases where two sequences share one region, such as a common domain, but differ elsewhere.

Pairwise and multiple alignment

A pairwise alignment compares two sequences. A multiple alignment places three or more in the same set of columns. Multiple alignments are useful for seeing which positions stay the same across a whole family of sequences, and those conserved positions often matter for function.

Similarity, homology and function

When two sequences are more alike than chance would explain, the likely reason is shared ancestry. Such sequences are called homologous. Homology is a statement about ancestry, so a sequence pair is either homologous or it is not, even though the similarity itself comes in degrees.

Similarity is a useful clue to function, but it is not proof. Related sequences can come to do different jobs, and unrelated sequences can sometimes look alike by accident. Treat a predicted function as a lead to check against experimental evidence.

Searching databases quickly

Comparing a query against every entry in a large collection with full alignment would take a long time. Search programs such as BLAST therefore use fast heuristics. They first look for short exact or near matches, then extend promising ones into full alignments. This is quick and usually reliable, though it can occasionally miss a weak match that a slower method would find.

Where to go next

For the programs that carry out these comparisons, see the overview of sequence-analysis tools. To see where query sequences are usually searched, read a first look at public databases, and check unfamiliar words in the glossary.