0
나는 Smith-Waterman algorithm을 사용하여 동적 프로그래밍 행렬을 생성하기 위해 Python을 사용하고 있습니다. 여기 Smith-Waterman 알고리즘을 사용하여 파이썬에서 행렬을 생성합니다.
는 지금까지이 작업은 다음과 같습니다 입력으로def score(base1,base2):
base1=base1.upper()
base2=base2.upper()
if base1 not in 'ACTG' or base2 not in 'ACTG':
print 'Not DNA base!'
sys.exit()
elif base1==base2:
return 3
elif base1+base2=='AG' or base1+base2=='GA':
return -1
elif base1+base2=='CT' or base1+base2=='TC':
return -1
else:
return -2
import sys
seq1 = sys.argv[1]
seq2 = sys.argv[2]
mRows = len(seq1)
nCols = len(seq2)
gap = int(sys.argv[3])
matrix = []
# generate empty matrix
for x in range(mRows + 1):
matrix.append([])
for y in range(nCols + 1):
matrix[x].append(0)
for i in range(1, mRows + 1):
for j in range(1, nCols + 1):
dscore = matrix[i-1][j-1] + score(seq1[i-1], seq2[j-1])
vscore = matrix[i-1][j] + gap
hscore = matrix[i][j-1] + gap
matrix[i][j]=max(0, vscore, hscore, dscore)
: sw.py ATGCAT의 ACCT -1 내가 매트릭스 출력을 얻을
: 몇 가지 문제 해결 I와
0 0 0 0 0
0 0 0 0 0
0 0 0 0 3
0 0 0 0 2
0 0 0 0 1
0 0 0 0 0
0 0 0 0 3
을 중첩 된 for 루프에서 j의 최종 값 (이 특정 입력에 대해 4)을 사용하는 점수 만이 행렬, 즉 마지막 열에 저장된다는 것을 알 수있었습니다.
제 질문은 왜 이런 일이 일어나고 어떻게 해결할 수 있습니까? for 루프가 왜 돌아가서 변수 점수를 계속하지 않습니까?
내 문제 해결의 일부 :
for i in range(1, mRows + 1):
for j in range(1, nCols + 1):
print 'this is i', i
print 'this is j', j
print 'seq1', seq1[i-1], 'seq2', seq2[j-1]
dscore = matrix[i-1][j-1] + score(seq1[i-1], seq2[j-1])
vscore = matrix[i-1][j] + gap
hscore = matrix[i][j-1] + gap
matrix[i][j]=max(0, vscore, hscore, dscore)
print 'Vscore = ', vscore
print 'Hscore = ', hscore
print 'Dscore = ', dscore
print '\n'
을 제공합니다
this is i 1
this is j 1
seq1 A seq2 A
this is i 1
this is j 2
seq1 A seq2 C
this is i 1
this is j 3
seq1 A seq2 C
this is i 1
this is j 4
seq1 A seq2 T
Vscore = -1
Hscore = -1
Dscore = -2
this is i 2
this is j 1
seq1 T seq2 A
this is i 2
this is j 2
seq1 T seq2 C
this is i 2
this is j 3
seq1 T seq2 C
this is i 2
this is j 4
seq1 T seq2 T
Vscore = -1
Hscore = -1
Dscore = 3
this is i 3
this is j 1
seq1 G seq2 A
this is i 3
this is j 2
seq1 G seq2 C
this is i 3
this is j 3
seq1 G seq2 C
this is i 3
this is j 4
seq1 G seq2 T
Vscore = 2
Hscore = -1
Dscore = -2
this is i 4
this is j 1
seq1 C seq2 A
this is i 4
this is j 2
seq1 C seq2 C
this is i 4
this is j 3
seq1 C seq2 C
this is i 4
this is j 4
seq1 C seq2 T
Vscore = 1
Hscore = -1
Dscore = -1
this is i 5
this is j 1
seq1 A seq2 A
this is i 5
this is j 2
seq1 A seq2 C
this is i 5
this is j 3
seq1 A seq2 C
this is i 5
this is j 4
seq1 A seq2 T
Vscore = 0
Hscore = -1
Dscore = -2
this is i 6
this is j 1
seq1 T seq2 A
this is i 6
this is j 2
seq1 T seq2 C
this is i 6
this is j 3
seq1 T seq2 C
this is i 6
this is j 4
seq1 T seq2 T
Vscore = -1
Hscore = -1
Dscore = 3
감사합니다!
고마워요! 나는 그 문제가 무엇이든 무작위로 고치려고했다. 귀하의 솔루션은 내 것보다 확실히 우아합니다 : https://github.com/mjmiguel/sequence-alignment – miguel