首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据阅读框架将mRNA转换为肽序列的功能不能正常工作

根据阅读框架将mRNA转换为肽序列的功能不能正常工作
EN

Stack Overflow用户
提问于 2021-05-09 00:51:20
回答 1查看 26关注 0票数 1

我正在尝试写一个函数,它根据我们开始计算密码子的核苷酸(第一个核苷酸,第二个或第三个核苷酸),将mRNA序列转换为肽序列。我有一个代码,但当我打印(三个肽中的)三个结果时,我只得到第一个肽的序列。最后两个是空白的。你知道问题出在哪里吗?另外,如何在默认情况下返回所有三个肽?

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-09 01:05:55

它总是在第一次检查后返回。它应该是:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67450015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档