简体   繁体   中英

Function converting mRNA to peptide sequence depending on the reading frame does not work correctly

I am trying to write a fuction that translates an mRNA sequence to a peptide sequence depending on the nucleotide from which we start counting codons (either the first nucleotide, the second or the third). I have a code for it, but when I print the three results (of the three peptides) I only get a sequence for the first peptide. The last two are blank. Any idea what the problem might be? And how could I return all three peptides by default?

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)

It always return after first if check. It should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM