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 matrices required for calculating alignment scores, but am clueless as to how to then traceback to find the alignment. To generate the 3 matrices required I have the following code
for j in range(1, len2):
for i in range(1, len1):
fxOpen = F[i][j-1] + gap
xExtend = Ix[i][j-1] + extend
Ix[i][j] = max(fxOpen, xExtend)
fyOpen = F[i-1][j] + gap
yExtend = Iy[i-1][j] + extend
Iy[i][j] = max(fyOpen, yExtend)
matchScore = (F[i-1][j-1] + simMatrixDict[seq1[i-1]+seq2[j-1]])
xScore = Ix[i-1][j-1] + simMatrixDict[seq1[i-1]+seq2[j-1]]
yScore = Iy[i-1][j-1] + simMatrixDict[seq1[i-1]+seq2[j-1]]
F[i][j] = max(0, matchScore, xScore, yScore)
I am unsure if I need a single matrix for traceback, or just 1? Any clarification on how to go about tracing back from the max score in F would be much appreciated.