I\'m trying to implement the Smith-Waterman algorithm for local sequence alignment using the affine gap penalty function. I think I understand how to initiate and compute the ma
The important thing to remember about traceback in Smith-Waterman is that the matrix a value is in determines the direction that you move. So, if you are in F
you're moving diagonally, if you're in Ix
, you're moving horizontally, and if you're in Iy
, you're moving vertically. This means that all you need to store in the pointer matrix is the matrix that you arrived at a square from. The matrix that you are coming from, not the one that you are going to, determines the dirction which to go.
For example:
Say you are at F[5][5]
:
Ix
, go to Ix[4][4]
Iy
, go to Iy[4][4]
F
, go to F[4][4]
Whereas if you are at Ix[5][5]
:
Ix
, go to Ix[4][5]
F
, go to F[4][5]
Or if you are at Iy[5][5]
:
Iy
, go to Iy[5][4]
F
, go to F[5][4]
Assuming that the first index is the x coordinate and the second is the y coordinate.
Continue tracing back until you reach a cell with a maximum value of 0.
Building the pointer matrix:
You need one pointer matrix each for F
, Ix
, and Iy
. These matrices only need to indicate which matrix a value came from, because that tells you which direction you were moving in. So, as you're running through the dynamic programming phase of the algorithm, you should also be building up the pointer matrices. Every time you store a new maximum value in a cell in F
, Ix
, or Iy
, you should update the corresponding matrix to indicate where it came from. If, for instance, the highest value you can have in F[5][5]
comes by aligning the two next bases when you're in F[4][4]
, the Fpointer[5][5] should be set to F
, because you got there from the F
matrix.