In [13]:
codon_table = """
UUU F CUU L AUU I GUU V
UUC F CUC L AUC I GUC V
UUA L CUA L AUA I GUA V
UUG L CUG L AUG M GUG V
UCU S CCU P ACU T GCU A
UCC S CCC P ACC T GCC A
UCA S CCA P ACA T GCA A
UCG S CCG P ACG T GCG A
UAU Y CAU H AAU N GAU D
UAC Y CAC H AAC N GAC D
UAA Stop CAA Q AAA K GAA E
UAG Stop CAG Q AAG K GAG E
UGU C CGU R AGU S GGU G
UGC C CGC R AGC S GGC G
UGA Stop CGA R AGA R GGA G
UGG W CGG R AGG R GGG G
""".strip().split()
codon_table = dict((seq, prot.replace('Stop', ''))
for (seq, prot) in zip(codon_table[0::2],
codon_table[1::2]))
codon_table
Out[13]:
In [42]:
def translate(seq):
pass
In [43]:
def test_translate():
seq = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA'
assert translate(seq) == 'MAMAPRTEINSTRING'
print('ok')
test_translate()
In [44]:
def translate(seq):
"""use codon table to translate DNA sequence to protein"""
prot = [codon_table[seq[i*3:i*3+3]]
for i in range(len(seq)//3)]
return ''.join(prot)
translate('AUGGCC')
Out[44]:
In [45]:
test_translate()