Skip to content

Instantly share code, notes, and snippets.

@werdlerk
Last active January 15, 2016 21:11
Show Gist options
  • Save werdlerk/04f5bcd0076955c97aea to your computer and use it in GitHub Desktop.
Save werdlerk/04f5bcd0076955c97aea to your computer and use it in GitHub Desktop.
Launch School challenge: Protein Translation
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
@werdlerk
Copy link
Author

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