i wrote a code to align two sequences with the needleman-wunsch algorithm. it is going well for two sequences same length. When i use two sequences of different length i get an error : string index out of range. Could anyone help me ?
Thats is my code:
Thats is my code:
M=len(s1) N=len(s2) match=+2 gap=-1 mismatch=-2 matrix=np.zeros((N+1,M+1)) #builduing the score matrix # 1. putting horizontal and vertical gaps in columns and rows for i in range(1,N+1): matrix[i,0]=matrix[i-1,0]+gap for j in range(1,M+1): matrix[0,j]=matrix[j-1,0]+gap # 2. putting in the score/values in the score matrix for i in range(1,N+1): for j in range(1,M+1): if s1[i-1] == s2[j-1]: score1 = matrix[i-1,j-1] + match else: score1 = matrix[i-1,j-1] + mismatch score2 = matrix[i,j-1] + gap score3 = matrix[i-1,j] + gap matrix[i,j] = max(score1,score2,score3) #create a traceback matrix with D=diagonal, V=vertikal, H=horizontal trace_mat=np.zeros((N+1,M+1),dtype=str) for i in range(1,N+1): trace_mat[i,0]= 'V' for j in range(1,M+1): trace_mat[0,j]='H'I would appreciate your help !!!