根據以下評分方案編寫一個比較兩個DNA序列的函數:匹配+1,每個連續匹配+3,每個不匹配-1。python條件並計算總和?
我的代碼:
def pairwiseScore(seqA, seqB):
'''1+1+3-1-1+1+3+1-1-1+1-1-1-1'''
print
signed = ''
score = 0
for i in range(len(seqA)):
if(seqA[i] == seqB[i]):
signed += '|'
score += 1
if signed=='||':
score=0
score += 3
else:
score += 1
else:
signed += ' '
score -=1
return seqA+"\n"+signed+"\n"+seqB+"\n"+'score:'+ str(score)
print pairwiseScore("ATTCGT", "ATCTAT")
print pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA")
print pairwiseScore('ATCG', 'ATCG')
print pairwiseScore('CATTCATCATGCAA', 'GATAAATCTGGTCT')
OUPUT:
ATTCGT
|| |
ATCTAT
score:2
GATAAATCTGGTCT
|| ||| |
CATTCATCATGCAA
score:4
ATCG
||||
ATCG
score:7 // this should be 10 because +3 for each consecutive match` 1 + 3 +3 +3 =10
CATTCATCATGCAA
|| ||| |
GATAAATCTGGTCT
score:4
誰能給我提示嗎?
感謝
提示:使用一致的縮進。除此之外,你有什麼特別的問題? – geoffspear
看看分數:7我應該得分:10因爲每個連續比賽都會得到+3的分數' – kn3l
看起來像功課。請關注你的問題。如問題所述,目前還不清楚要問什麼,它將被關閉。 –