Created
January 14, 2016 21:46
-
-
Save gavinmcgimpsey/b18db122c091e80ca017 to your computer and use it in GitHub Desktop.
Revisions
-
gavinmcgimpsey created this gist
Jan 14, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ class InvalidCodonError < ArgumentError; end module Translation def self.of_rna(string) result = [] tris = string.chars .each_slice(3) .to_a .map(&:join) tris.each do |tri| next_codon = of_codon(tri) break if next_codon == 'STOP' result << next_codon end result end def self.of_codon(tri) case tri when 'AUG' 'Methionine' when 'UUU', 'UUC' 'Phenylalanine' when 'UUA', 'UUG' 'Leucine' when 'UCU', 'UCC', 'UCA', 'UCG' 'Serine' when 'UAU', 'UAC' 'Tyrosine' when 'UGU', 'UGC' 'Cysteine' when 'UGG' 'Tryptophan' when 'UAA', 'UAG', 'UGA' 'STOP' else fail InvalidCodonError end end end