根据阅读框将 mRNA 转换为肽序列的功能无法正常工作
Function converting mRNA to peptide sequence depending on the reading frame does not work correctly
我正在尝试编写一个函数,根据我们开始计算密码子的核苷酸(第一个核苷酸、第二个或第三个核苷酸)将 mRNA 序列翻译成肽序列。
我有它的代码,但是当我打印(三个肽的)三个结果时,我只得到第一个肽的序列。最后两个是空的。知道问题可能是什么吗?
我怎么能默认 return 所有三个肽?
def translate(mrna, reading_frame=1):
"""
Converts a given mRNA sequence to a protein sequence
starting counting codons from either 1st, 2nd or 3rd nucleotide
:param: an mRNA sequence
: type: str
: reading_frame - default is 1. Accepts 2 and 3, too.
: return: peptide sequence
:rtype: str
"""
codon2aa = {
"UUU": "F", "UUC": "F", "UUA": "L", "UUG": "L", "CUU": "L",
"CUC": "L", "CUA": "L", "CUG": "L", "AUU": "I", "AUC": "I",
"AUA": "I", "GUU": "V", "GUC": "V", "GUA": "V", "GUG": "V",
"UCU": "S", "UCC": "S", "UCA": "S", "UCG": "S", "AGU": "S",
"AGC": "S", "CCU": "P", "CCC": "P", "CCA": "P", "CCG": "P",
"ACU": "T", "ACC": "T", "ACA": "T", "ACG": "T", "GCU": "A",
"GCC": "A", "GCA": "A", "GCG": "A", "UAU": "Y", "UAC": "Y",
"CAU": "H", "CAC": "H", "CAA": "Q", "CAG": "Q", "AAU": "N",
"AAC": "N", "AAA": "K", "AAG": "K", "GAU": "D", "GAC": "D",
"GAA": "E", "GAG": "E", "UGU": "C", "UGC": "C", "UGG": "W",
"CGU": "R", "CGC": "R", "CGA": "R", "CGG": "R", "AGA": "R",
"AGG": "R", "GGU": "G", "GGC": "G", "GGA": "G", "GGG": "G",
"AUG": "<Met>", "UAA": "<STOP>", "UAG": "<STOP>", "UGA": "<STOP>"
}
peptide = str()
length = len(mrna)
if reading_frame == 1:
for item in range(0, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
if reading_frame == 2:
for item in range(1, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
if reading_frame == 3:
for item in range(2, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
peptide_sequence1 = translate(gpcr_mrna, reading_frame=1)
peptide_sequence2 = translate(gpcr_mrna, reading_frame=2)
peptide_sequence3 = translate(gpcr_mrna, reading_frame=3)
print('peptide1:', peptide_sequence1)
print('peptide2:', peptide_sequence2)
print('peptide3:', peptide_sequence3)
它总是 return 在第一次 if 检查之后。应该是:
if reading_frame == 1:
for item in range(0, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
if reading_frame == 2:
for item in range(1, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
if reading_frame == 3:
for item in range(2, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
我正在尝试编写一个函数,根据我们开始计算密码子的核苷酸(第一个核苷酸、第二个或第三个核苷酸)将 mRNA 序列翻译成肽序列。 我有它的代码,但是当我打印(三个肽的)三个结果时,我只得到第一个肽的序列。最后两个是空的。知道问题可能是什么吗? 我怎么能默认 return 所有三个肽?
def translate(mrna, reading_frame=1):
"""
Converts a given mRNA sequence to a protein sequence
starting counting codons from either 1st, 2nd or 3rd nucleotide
:param: an mRNA sequence
: type: str
: reading_frame - default is 1. Accepts 2 and 3, too.
: return: peptide sequence
:rtype: str
"""
codon2aa = {
"UUU": "F", "UUC": "F", "UUA": "L", "UUG": "L", "CUU": "L",
"CUC": "L", "CUA": "L", "CUG": "L", "AUU": "I", "AUC": "I",
"AUA": "I", "GUU": "V", "GUC": "V", "GUA": "V", "GUG": "V",
"UCU": "S", "UCC": "S", "UCA": "S", "UCG": "S", "AGU": "S",
"AGC": "S", "CCU": "P", "CCC": "P", "CCA": "P", "CCG": "P",
"ACU": "T", "ACC": "T", "ACA": "T", "ACG": "T", "GCU": "A",
"GCC": "A", "GCA": "A", "GCG": "A", "UAU": "Y", "UAC": "Y",
"CAU": "H", "CAC": "H", "CAA": "Q", "CAG": "Q", "AAU": "N",
"AAC": "N", "AAA": "K", "AAG": "K", "GAU": "D", "GAC": "D",
"GAA": "E", "GAG": "E", "UGU": "C", "UGC": "C", "UGG": "W",
"CGU": "R", "CGC": "R", "CGA": "R", "CGG": "R", "AGA": "R",
"AGG": "R", "GGU": "G", "GGC": "G", "GGA": "G", "GGG": "G",
"AUG": "<Met>", "UAA": "<STOP>", "UAG": "<STOP>", "UGA": "<STOP>"
}
peptide = str()
length = len(mrna)
if reading_frame == 1:
for item in range(0, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
if reading_frame == 2:
for item in range(1, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
if reading_frame == 3:
for item in range(2, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide
peptide_sequence1 = translate(gpcr_mrna, reading_frame=1)
peptide_sequence2 = translate(gpcr_mrna, reading_frame=2)
peptide_sequence3 = translate(gpcr_mrna, reading_frame=3)
print('peptide1:', peptide_sequence1)
print('peptide2:', peptide_sequence2)
print('peptide3:', peptide_sequence3)
它总是 return 在第一次 if 检查之后。应该是:
if reading_frame == 1:
for item in range(0, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
if reading_frame == 2:
for item in range(1, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
if reading_frame == 3:
for item in range(2, length - (length % 3), 3):
codon = mrna[item:item+3]
peptide+= codon2aa[codon]
return peptide