所以我想寫一個程序,檢查DNA是否發生了變異,我不太清楚如何解釋這個,所以這就是它說的:
編寫一個程序來確定一個病人是否有它們的DNA序列中的突變導致氨基酸序列的改變。你的程序應該像這樣工作:如何分割一個字符串(輸入)和每個部分用作字典值?
Enter original DNA: AAT
Enter patient DNA: AAC
The patient's amino acid sequence is not mutated.
Enter original DNA: AATTGTTCTTCT
Enter patient DNA: AACTGCAGCTCA
The patient's amino acid sequence is not mutated.
Enter original DNA: TGTCATGCCTTATTAGAAAACGGTGAG
Enter patient DNA: TGTCATGTCTTATTAGAAAAAGGTGAG
The patient's amino acid sequence is mutated.
這是我使用的文本文件的一部分:
The mappings from codon to amino acid are available in a file, called codon_amino.txt, an excerpt of which is shown here:
AAC N
AAG K
AAT N
GCG A
GCT A
GGA G
GGC G
GGG G
GGT G
所以這是我到目前爲止的代碼:
n = {}
for line in open('codons.txt'):
codon, codons = line.split()
n[codon] = codons
org = input('Enter original DNA: ')
pat = input('Enter patient DNA: ')
if n[org] == n[pat]:
print("The patient's amino acid sequence is not mutated.")
else:
print("The patient's amino acid sequence is mutated.")
所以我的代碼在第一個例子中工作正常,在那裏只有3個字母被使用,但接下來的兩個有3個以上,我想知道如何操作我的代碼來處理也是?我希望有人能夠理解這個問題。先謝謝你!
這是一樣的這項任務? http://stackoverflow.com/questions/18541215/how-do-you-access-a-list-in-group-of-3-in-python - 看起來像你有你的答案... –
你必須拆分將輸入字符串轉換爲三位,並檢查所有位。 –
基本上你需要的是[你如何將一個列表分割成大小均勻的Python塊?](http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-蟒蛇大小) –