这是我正在使用的内容。我在循环中添加了几个打印函数,以确保一切正常工作,直到它调用定义的函数。一旦达到该点,它就会像第一个if语句一样返回,无论如何,即使我将语句更改为!=,它也会给出相同的结果。它似乎完全忽略了if语句。我错过了什么?我正在使用python 2.7。
#Genome Analysis tool
#Importing Stuffs
#Creating Usefull functions
#.#Asseses codon in an RNA sequence (Uses U instead of T)
def codon_RNA(text):
if text == "UUU" or "UUC":
return "Phe"
elif text == "UUA" or "UUG" or "CUU" or "CUC" or "CUA" or "CUG":
return "Leu"
elif text == "AUU" or "AUC" or "AUA":
return "Ile"
elif text == "AUG":
return "Met"
elif text == "GUU" or "GUC" or "GUA" or "GUG":
return "Val"
elif text == "UCU" or "UCC" or "UCA" or "UCG" or "AGU" or "AGC":
return "Ser"
elif text == "CCU" or "CCC" or "CCA" or "CCA" or "CCG":
return "Pro"
elif text == "ACU" or "ACC" or "ACA" or "ACG":
return "Thr"
elif text == "GCU" or "GCC" or "GCA" or "GCG":
return "Ala"
elif text == "UAU" or "UAC":
return "Tyr"
elif text == "UAA" or "UAG" or "UGA":
return "|STOP| "
elif text == "CAU" or "CAC":
return "His"
elif text == "CAA" or "CAG":
return "Gln"
elif text == "AAU" or "AAC":
return "Asn"
elif text == "AAA" or "AAG":
return "Lys"
elif text == "GAU" or "GAC":
return "Asp"
elif text == "GAA" or "GAG":
return "Glu"
elif text == "UGU" or "UGC":
return "Cys"
elif text == "UGG":
return "Trp"
elif text == "CGU" or "CGC" or "CGA" or "CGG" or "AGA" or "AGG":
return "Arg"
elif text == "GGU" or "GGC" or "GGA" or "GGG":
return "Gly"
else:
return null
#Setting up the variables
genome = "ACUCGAUCAGCUAGCUAGCAUGCACUCGAUACGCGCUAUAUAGCUAGCUAGCAUAGCUACGAUCGAUGCUAGUGUGUGUUACCUAAUAAUAAUUAAUUAAUUAAUUAA"
#Breaking down into codons
""" Loop as long as 1/3 of the sequence breaks each chunk into an amino acid """
count = len(genome)/3
print count
for i in range(0,count):
temp = genome[3*i:3*i+3]
print temp
print i
print codon_RNA(temp)
答案 0 :(得分:1)
text == "UUU" or "UUC"
这实际上意味着
(text == "UUU") or ("UUC")
在Python中,非空字符串被视为“真实”,因此这相当于(something) or True
,它总是True
。
正确的方法是写:
text == "UUU" or text == "UUC"
和Pythonic方式是
text in {"UUU", "UUC"}
或者你应该建立一个字典来将每个密码子映射到氨基酸而不是巨大的if / elif链
CODON_TABLE = {
"UUU": "Phe",
"UUC": "Phe",
...
"GGG": "Gly",
}
def codon_RNA(text):
return CODON_TABLE.get(text)
答案 1 :(得分:0)
if语句中有错误。它应该是:
if text == "UUU" or text == "UUC":
同样适用于其他陈述。你现在正在做的基本上是:
if (text == "UUU") or ("UUC"):
由于任何非空字符串的计算结果为True
,因此您实际编写了if True: