Global Alignment

This code simulates the Needleman-Wunsch Global Alignment Algorithm to find the optimal alignment of two sequences.

import numpy #prompt the user for the sequences seq1=input("Input your first sequence: ") seq2=input("Input your second sequence: ") #make the variables for the final sequences seq1final='' seq2final='' #make the variable for the final alignment score score=0 #construct the scoring matrix scoreMatrix=numpy.zeros(shape=(len(seq1)+1,len(seq2)+1)) #variables for scoring match=1 mismatch=-1 gap=-2 print('Sequence One: ',seq1) print('Sequence Two: ',seq2) print('Match: ',match) print('Mismatch: ',mismatch) print('Gap: ',gap) #construct origin dictionary origins={} for y in range(0, len(seq1)+1): for x in range(0, len(seq2)+1): #make the blank values if y==0: scoreMatrix[y,x]=gap*x origins[y,x]='left' if x==0: scoreMatrix[y,x]=gap*y origins[y,x]='up' #calculate each cell value and store its origin else: if y!=0: u=scoreMatrix[y-1,x]+gap l=scoreMatrix[y,x-1]+gap if seq1[y-1]==seq2[x-1]: d=scoreMatrix[y-1,x-1]+match else: d=scoreMatrix[y-1,x-1]+mismatch scoreMatrix[y,x]=max(u,l,d) if max(u,l,d)==u: origins[(y,x)]='up' elif max(u,l,d)==l: origins[(y,x)]='left' elif max(u,l,d)==d: origins[(y,x)]='diagnol' print(scoreMatrix) print(origins) traceCell=(len(seq1),len(seq2)) while 1==1: if origins[traceCell]=='diagnol': seq1final=seq1[traceCell[0]-1]+seq1final seq2final=seq2[traceCell[1]-1]+seq2final traceCell=(traceCell[0]-1,traceCell[1]-1) elif origins[traceCell]=='left': seq1final='-'+seq1final seq2final=str(seq2[traceCell[1]-1])+seq2final traceCell=(traceCell[0],traceCell[1]-1) elif origins[traceCell]=='up': seq1final=str(seq1[traceCell[0]-1])+seq1final seq2final='-'+seq2final traceCell=(traceCell[0]-1,traceCell[1]) if traceCell==(0,0): break print('Aligned Sequence One: ',seq1final) print('Aligned Sequence Two: ',seq2final) for one in seq1final: for two in seq2final: if one=='-': score=int(score)-2 elif two=='-': score=int(score)-2 elif one==two: score=int(score)+1 else: scoore=int(score)-1 break print('Your Alignment Score Is: ',score)
1