Nice blog, its worth a glance. I have never been into Bioinformatics though I may give it a look now because your code struck some interest with me.

I suggest the following replacement for Starter_AA:

from pprint import pprint

mapping  = """
Phe: UUU, UUC;
Leu: UUA, UUG, CUU, CUC, CUA, CUG;
Iso: AUU, AUC, AUA;
Met: AUG;
Val: GUU, GUC, GUA, GUG;
Ser: UCU, UCC, UCA, UCG, AGU, AGC;
Pro: CCU, CCC, CCA, CCG;
Thr: ACU, ACC, ACA, ACG;
Ala: GCU, GCC, GCA, GCG;
Tyr: UAU, UAC;
His: CAU, CAC;
Gln: CAA, CAG;
Asn: AAU, AAC;
Lys: AAA, AAG;
Asp: GAU, GAC;
Glu: GAA, GAG;
Sys: UGU, UGC;
Trp: UGG;
Arg: CGU, CGC, CGA, CGG, AGA, AGG;
Gly: GGU, GGC, GGA, GGG;
STOP: UGA, UAG, UAA;
"""

def parse(mapping):
    """Create a dictionary UUU -> Phe, etc"""
    checklist = []
    L = mapping.strip().split(";")[:-1]
    D = dict()
    for i, line in enumerate(L):
        key, value = line.split(":")
        key = key.strip()
        value = [x.strip() for x in value.split(",")]
        checklist.extend(value)
        for v in value:
            D[v] = key
    assert len(checklist) == len(set(checklist))
    return D

mapping = parse(mapping)
# pprint(mapping)

def Starter_AA():    
    for i in range(len(Codons)):
        if Codons[i]=="AUG":
            for j in range(i,len(Codons)): # don't use the same variable i for the inner loop
                display (Codons[j])
                pro = mapping[Codons[j]]
                display("----------->%s" % pro if pro != "STOP" else "Traduction Stopped")
                Protide.append(pro)
            return

The idea is to avoid repetitions in the code (a winning rule).

Edited 7 Years Ago by Gribouillis: n/a

This article has been dead for over six months. Start a new discussion instead.