Skip to content

Instantly share code, notes, and snippets.

@stepjue
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save stepjue/d9c1cca9f97bfef185ed to your computer and use it in GitHub Desktop.

Select an option

Save stepjue/d9c1cca9f97bfef185ed to your computer and use it in GitHub Desktop.
Solution for Rosalind "prot" problem. Translates an RNA string into a protein string.
from rna_codons import codons
def chunks(l, n):
for i in xrange(0, len(l), n):
yield l[i:i+n]
def translate(dna):
protein = ""
for codon in chunks(dna, 3):
amino = codons[codon]
if amino is "Stop":
break
else:
protein += amino
return protein
if __name__ == "__main__":
protein = ""
for dna in open("rosalind_prot.txt"):
protein = translate(dna)
f = open("output_prot.txt", "w")
f.write(protein)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment