我正在编写一个程序,该程序应该采用DNA链,然后将其转换为RNA链,在此之后,它应该采用RNA链并找到氨基酸。似乎我的代码在第30行有问题,但我无法找到它的解决方案。如果有人可以帮助我,我会非常感激。非常感谢你。
DNA = input("Good day, please write your DNA chain: ")
DNA = list(DNA)
DNA = (letter.upper() for letter in DNA)
def letters_check (DNAchain) :
nitrogenbases = ["C", "A", "T", "G"]
others = [symbol for symbol in DNAchain if symbol not in nitrogenbases]
if others :
print("Sorry, but these", others, "are not the DNA elements needed")
else :
print("Magnific! This is a great DNA chain")
def mRNA (DNAchain) :
replacements = {"C":"G","T":"A","G":"C","A":"U"}
return "".join([replacements[base] for base in DNAchain])
return "".join([replacements[base] for base in dnachain])
print ("mRNA(DNA): " ,mRNA(DNA))
def findStartStop(DNAchain):
for x in range(len(DNAchain)):
if DNAchain[x:x+3] == "AUG" :
tmprna = DNAchain[x:]
print("Found the start! tmprna: ", tmprna)
return tmprna
for x in range(len(tmprna)):
tmprna2 = tmprna[x:x+3]
if tmprna2 == "UAG" or tmprna2 == "UAA" or tmprna2 == "UGA" :
tmprna2 = tmprna[:x+3]
print("Found the stop! tmprna2: ",tmprna2)
break
def finalrna(tmprna2) :
Translation = {"UUU":"Phe", "UUC":"Phe", "UUA":"Leu", "UUG":"Leu", 'UCU':'Ser', 'UAU':'Tyr', 'UGU':'Cys', 'UCC':'Ser', 'UAC':'Tyr', 'UGC':'Cys', 'UCA':'Ser', 'UAA':'Stop', 'UGA':'Stop', 'UCG':'Ser', 'UAG':'Stop', 'UGG':'Trp', 'CUU':'Leu', 'CCU':'Pro', 'CAU':'His', 'CGU':'Arg', 'CUC':'Leu', 'CCC':'Pro', 'CAC':'His', 'CGC':'Arg', 'CUA':'Leu', 'CCA':'Pro', 'CAA':'Gln', 'CGA':'Arg', 'CUG':'Leu', 'CCG':'Pro', 'CAG':'Gln', 'CGG':'Arg', 'AUU':'Ile', 'ACU':'Thr', 'AAU':'Asn', 'AGU':'Ser', 'AUC':'Ile', 'ACC':'Thr', 'AAC':'Asn', 'AGC':'Ser', 'AUA':'Ile', 'ACA':'Thr', 'AAA':'Lys', 'AGA':'Arg', 'AUG':'Met', 'ACG':'Thr', 'AAG':'Lys', 'AGG':'Arg', 'GUU':'Val', 'GCU':'Ala', 'GAU':'Asp', 'GGU':'Gly', 'GUC':'Val', 'GCC':'Ala', 'GAC':'Asp', 'GGC':'Gly', 'GUA':'Val', 'GCA':'Ala', 'GAA':'Glu', 'GGA':'Gly','GUG':'Val','GCG':'Ala','GAG':'Glu','GGG':'Gly'}
for y in range(0,len(tmprna2),3):
print(Translation[tmprna2[x:x+3]])
print("This is your new code! finalrna: ", tmprna2[x:x+3])
print(letters_check(DNA))
print("your RNA is:", mRNA(DNA))
print(findStartStop(mRNA))
print(finalrna(tmprna2))
#Taken from: http://www.hgvs.org/mutnomen/codon.html and http://www.dia.uniroma3.it/~paoluzzi/web/did/bioinf/2010/slides/lezione10.pdf
答案 0 :(得分:4)
这一行:
DNA = (letter.upper() for letter in DNA)
创建generator函数。 ......而且你无法得到函数的len()
。
您可能只想在此处列出一个列表:
DNA = [letter.upper() for letter in DNA]
...你也应该删除这一行:
return "".join([replacements[base] for base in dnachain])
您的DNAchain
变量的大小写错误,无论如何都无法到达该行。