Topics 2.1 and 5.1
Sequence alignment
Fill a score table where every cell remembers the best way to align two prefixes, then trace back to read off the alignment.
Where people get stuck
- A cell describes prefixes.H(i,j) is the best score for aligning the first i letters of one sequence with the first j letters of the other. It is not the score of a whole alignment until you reach the corner (global) or the best cell (local).
- Three moves, each from a different neighbor.Diagonal adds a match or mismatch score. Up and left each add a gap score. Compute all three, then keep the largest.
- Global borders count gaps.Aligning a prefix against nothing means all gaps, so the first row and column are 0, −2, −4 and so on (with gap −2). Local borders are all 0.
- Local changes both ends.Local adds 0 to the max, meaning start fresh. Traceback starts at the largest cell anywhere in the table and stops when it reaches 0.
- Ties mean several correct answers.Different tie-breaks during traceback give different alignments with the same score.
The recurrence
s(a,b) is the match score when the letters agree and the mismatch score when they do not. g is the score for one gap base, a negative number.
Watch it run
The default is the lecture's GATACA against GATCA with match +1, mismatch −1 and gap −2. Fill cells one at a time, click any cell to see its three candidates, then trace back. Switch to local to see the 0 floor and the new starting point.
Check yourself
Why does a local table never contain a negative number?
Every cell takes the max with 0, which means starting a new alignment there. A bad stretch resets to 0 instead of dragging the score below zero.
Where does traceback begin and end in each version?
Global begins at the bottom-right corner and ends at the top-left corner. Local begins at the largest cell anywhere and ends at the first cell with value 0.
A cell has the same best value from two neighbors. What happens?
Either move gives an optimal alignment. The score is identical, only the alignment differs. The checker on this page accepts any alignment whose score equals the best.