BioAlgo

Two ways to align two sequences

Global alignment walks the full length. Local alignment stops at the strongest shared stretch.

Aligning two sequences asks where they correspond. There are two different answers, and a pretty score from the wrong one still answers the wrong question.

Global

Needleman–Wunsch aligns the full length of both sequences. The matrix fills from the origin. Each cell chooses one of three steps: take the current pair of letters, skip a letter in the first sequence, or skip a letter in the second. The cell keeps the best score after a match score and a gap penalty. Traceback runs from the final cell back to the start.

Local

Smith–Waterman finds the strongest shared stretch. It does not force the ends to correspond. A cell score cannot fall below zero. When a poor stretch drags the score down, the cell resets and a new stretch can start. Traceback begins at the highest cell and stops at zero.

Which one

  • Two related sequences of similar length, aligned end to end: use global.
  • A short motif inside a longer sequence, or only a partial correspondence: use local.
  • An affine gap penalty — opening a gap costs more than extending it — does not change this choice. It only changes the price of a long gap.

All notes