diff --git a/global.py b/global.py new file mode 100644 index 0000000..eb918ce --- /dev/null +++ b/global.py @@ -0,0 +1,139 @@ +from blosum62 import * +import numpy as np +from numpy import argmin +from fasta import readFASTA + +# this is an implementation of the needleman-wunsch algorithm +# and it should handle the affine gap situation + + +def mismatch_penalty(A,B): + if A!=B: + return -blosum62[A+B] + else: + return -blosum62[A+B] + +s=readFASTA("rosalind_gcon.txt") +A=s.values()[0] +B=s.values()[1] + +#A='MMM' +#B='YYYYYYY' + +nA=len(A)+1 +nB=len(B)+1 + +def gap(x,start=0,step=1): + return start + step*x + +dpV=np.zeros((nB,nA),dtype=float) +dpG=np.zeros((nB,nA),dtype=float) +dpE=np.zeros((nB,nA),dtype=float) +dpF=np.zeros((nB,nA),dtype=float) +print nA, nB +print '*' +for i in xrange(1,nA): + for j in xrange(1,nB): + if dpV[j,i]=1 and j>=1: + + if s==2: + R.append(A[i-1]) + S.append(B[j-1]) + #print '**',i,j,s,dpE[j,i],dpF[j,i],dpG[j,i],''.join(reversed(R)),''.join(reversed(S)) + i=i-1 + j=j-1 + + elif s==0: + R.append('-') + S.append(B[j-1]) + #print '**',i,j,s,dpE[j,i],dpF[j,i],dpG[j,i],''.join(reversed(R)),''.join(reversed(S)) + j=j-1 + while j>=1 and dpE[j,i]+gap(j)-gap(j-1)=1 and dpF[j,i]+gap(i)-gap(i-1)0: + R.append('-') + S.append(B[j-1]) + j=j-1 + +elif j==0: + while i>0: + S.append('-') + R.append(A[i-1]) + i=i-1 + + +Rx= ''.join(reversed(R)) +Sx=''.join(reversed(S)) + +print -dpV[nB-1][nA-1] +print Rx +print Sx + + + \ No newline at end of file