Skip to content

Instantly share code, notes, and snippets.

@olveirap
Created February 15, 2017 01:30
Show Gist options
  • Select an option

  • Save olveirap/55f622f5bc723e4e9b2b7c763a094965 to your computer and use it in GitHub Desktop.

Select an option

Save olveirap/55f622f5bc723e4e9b2b7c763a094965 to your computer and use it in GitHub Desktop.
A implementation of a RNA to Protein translator
function RNAtoProtein(str){
var protein = [];
var codons = str.match(/.{3}/g); //http://stackoverflow.com/questions/6259515/javascript-elegant-way-to-split-string-into-segments-n-characters-long
var codonDict = {"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"};
for(var i = 0; i<codons.length; i++){
var codon = codons[i];
var aminoacid = codonDict[codon];
if(aminoacid != "Stop"){
protein.push(aminoacid)
}
}
return protein.join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment