Last active
January 15, 2016 21:11
-
-
Save werdlerk/04f5bcd0076955c97aea to your computer and use it in GitHub Desktop.
Launch School challenge: Protein Translation
This file contains 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
class Translation | |
AMINO_ACIDS = { | |
'Methionine' => [:AUG], | |
'Phenylalanine' => [:UUU, :UUC], | |
'Leucine' => [:UUA, :UUG], | |
'Serine' => [:UCU, :UCC, :UCA, :UCG], | |
'Tyrosine' => [:UAU, :UAC], | |
'Cysteine' => [:UGU, :UGC], | |
'Tryptophan' => [:UGG], | |
'STOP' => [:UAA, :UAG, :UGA] | |
} | |
def self.of_codon(codon) | |
AMINO_ACIDS.each do |protein, codons| | |
return protein if codons.include?(codon.to_sym) | |
end | |
raise InvalidCodonError | |
end | |
def self.of_rna(strand) | |
polypeptide = [] | |
to_codons(strand).each do |codon| | |
protein = Translation.of_codon(codon) | |
break if protein == 'STOP' | |
polypeptide << protein | |
end | |
polypeptide | |
end | |
private | |
def self.to_codons(strand) | |
strand.scan(/.../) | |
end | |
end | |
class InvalidCodonError < RuntimeError | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original challenge at https://launchschool.com/gists/266be03e