Sha256: 1c83dad6d18919ff3efacb0d02b2adf77679a95843cc6bf3b7d3d60c67ab00ca
Contents?: true
Size: 834 Bytes
Versions: 396
Compression:
Stored size: 834 Bytes
Contents
class InvalidCodonError < StandardError; end class Translation def self.of_codon(codon) found_key = lookups.keys.find { |sequences| sequences.include?(codon) } fail InvalidCodonError if lookups[found_key].nil? lookups[found_key] end def self.of_rna(sequence) sequence.chars.each_slice(3).with_object([]) do |codon, output| return output if of_codon(codon.join) == 'STOP' output << of_codon(codon.join) end end private def self.lookups { ['AUG'] => 'Methionine', %w(UUU UUC) => 'Phenylalanine', %w(UUA UUG) => 'Leucine', %w(UCU UCC UCA UCG) => 'Serine', %w(UAU UAC) => 'Tyrosine', %w(UGU UGC) => 'Cysteine', ['UGG'] => 'Tryptophan', %w(UAA UAG UGA) => 'STOP' } end end
Version data entries
396 entries across 396 versions & 1 rubygems