Return a list of codons from a sequence
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
Tags: codons