Skip to content

Instantly share code, notes, and snippets.

@Vini2
Last active September 1, 2021 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vini2/cbcf4d379952dc64c7742265510aa5d3 to your computer and use it in GitHub Desktop.
Save Vini2/cbcf4d379952dc64c7742265510aa5d3 to your computer and use it in GitHub Desktop.
# 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