rosalind



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]:
{'AAA': 'K',
 'AAC': 'N',
 'AAG': 'K',
 'AAU': 'N',
 'ACA': 'T',
 'ACC': 'T',
 'ACG': 'T',
 'ACU': 'T',
 'AGA': 'R',
 'AGC': 'S',
 'AGG': 'R',
 'AGU': 'S',
 'AUA': 'I',
 'AUC': 'I',
 'AUG': 'M',
 'AUU': 'I',
 'CAA': 'Q',
 'CAC': 'H',
 'CAG': 'Q',
 'CAU': 'H',
 'CCA': 'P',
 'CCC': 'P',
 'CCG': 'P',
 'CCU': 'P',
 'CGA': 'R',
 'CGC': 'R',
 'CGG': 'R',
 'CGU': 'R',
 'CUA': 'L',
 'CUC': 'L',
 'CUG': 'L',
 'CUU': 'L',
 'GAA': 'E',
 'GAC': 'D',
 'GAG': 'E',
 'GAU': 'D',
 'GCA': 'A',
 'GCC': 'A',
 'GCG': 'A',
 'GCU': 'A',
 'GGA': 'G',
 'GGC': 'G',
 'GGG': 'G',
 'GGU': 'G',
 'GUA': 'V',
 'GUC': 'V',
 'GUG': 'V',
 'GUU': 'V',
 'UAA': '',
 'UAC': 'Y',
 'UAG': '',
 'UAU': 'Y',
 'UCA': 'S',
 'UCC': 'S',
 'UCG': 'S',
 'UCU': 'S',
 'UGA': '',
 'UGC': 'C',
 'UGG': 'W',
 'UGU': 'C',
 'UUA': 'L',
 'UUC': 'F',
 'UUG': 'L',
 'UUU': 'F'}

In [42]:
def translate(seq):
    pass

In [43]:
def test_translate():
    seq = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA'
    assert translate(seq) == 'MAMAPRTEINSTRING'
    print('ok')
    
test_translate()


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-43-d13b73b295e4> in <module>()
      4     print('ok')
      5 
----> 6 test_translate()

<ipython-input-43-d13b73b295e4> in test_translate()
      1 def test_translate():
      2     seq = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA'
----> 3     assert translate(seq) == 'MAMAPRTEINSTRING'
      4     print('ok')
      5 

AssertionError: 

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]:
'MA'

In [45]:
test_translate()


ok