Here is my solution to the problem of rosalind project.
def prot(rna):
for i in xrange(3, (5*len(rna))//4+1, 4):
rna=rna[:i]+','+rna[i:]
rnaList=rna.split(',')
bases=['U','C','A','G']
codons = [a+b+c for a in bases for b in bases for c in bases]
amino_acids = 'FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG'
codon_table = dict(zip(codons, amino_acids))
peptide=[]
for i in range (len (rnaList)):
if codon_table[rnaList[i]]=='*':
break
peptide+=[codon_table[rnaList[i]]]
output=''
for i in peptide:
output+=str(i)
return output
If I run prot('AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA')
, I get the correct output 'MAMAPRTEINSTRING'
. However if the sequence of rna (the input string) is hundreds of nucleotides (characters) long I got an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 11, in prot
KeyError: 'CUGGAAACGCAGCCGACAUUCGCUGAAGUGUAG'
Can you point me where I went wrong?