Posts Tagged ‘codons’

Return a list of codons from a sequence

Thursday, January 10th, 2008

There are no built-in functions (that I know of) for returning a list of codons from a sequence, but making your own is quite simple. This function is from Solution A.5 from the Python Course in Bioinformatics


def codons(s, frame=0):
    """Return a list of codons from a string, s, giving an optional frameshift."""

    codons=[]

    end=len(s[frame:]) - (len(s[frame:]) % 3) - 1

    for i in range(frame,end,3):
        codons.append(s[i:i+3])

    return codons

A quick codon table

Wednesday, December 5th, 2007

Sometimes it’s nice to be able to have a codon table handy. Rather than typing out one by hand, theTranslate module contains the codon table of your choice in dictionary form: (more…)