Skip to content

Instantly share code, notes, and snippets.

@Vini2
Last active September 1, 2021 13:24
Embed
What would you like to do?
# Read the file and get the RNA string
file = open('sample_rna.txt', 'r')
rna = file.read()
print "RNA String: ", rna
# RNA codon table
rna_codon = {"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"
}
protein_string = ""
# Generate protein string
for i in range(0, len(rna)-(3+len(rna)%3), 3):
if rna_codon[rna[i:i+3]] == "STOP" :
break
protein_string += rna_codon[rna[i:i+3]]
# Print the protein string
print "Protein String: ", protein_string
# End of program
@Vini2
Copy link
Author

Vini2 commented Aug 12, 2017

Translating RNA into Protein
Solution for problem at ROSALIND.info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment