Last active
August 29, 2015 14:02
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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