Class: Codon
- Inherits:
-
Object
- Object
- Codon
- Defined in:
- lib/genetic_code.rb
Instance Attribute Summary collapse
-
#aa ⇒ Object
readonly
Returns the value of attribute aa.
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
Class Method Summary collapse
Instance Method Summary collapse
- #compute_degeneracy ⇒ Object
- #degeneracy ⇒ Object
- #distance_to(codon) ⇒ Object
-
#initialize(seq) ⇒ Codon
constructor
A new instance of Codon.
Constructor Details
#initialize(seq) ⇒ Codon
Returns a new instance of Codon.
101 102 103 104 105 |
# File 'lib/genetic_code.rb', line 101 def initialize seq @seq = seq @aa = GeneticCode.aa_for seq @aliases = @aa.codons end |
Instance Attribute Details
#aa ⇒ Object (readonly)
Returns the value of attribute aa.
100 101 102 |
# File 'lib/genetic_code.rb', line 100 def aa @aa end |
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
100 101 102 |
# File 'lib/genetic_code.rb', line 100 def aliases @aliases end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
100 101 102 |
# File 'lib/genetic_code.rb', line 100 def seq @seq end |
Class Method Details
.[](seq) ⇒ Object
89 90 91 92 |
# File 'lib/genetic_code.rb', line 89 def [] seq @codons ||= {} @codons[seq] ||= build_codon seq end |
.build_codon(seq) ⇒ Object
94 95 96 97 |
# File 'lib/genetic_code.rb', line 94 def build_codon seq return nil unless seq.is_a?(Symbol) && seq.to_s =~ /^[ATGC]{3}$/ new seq end |
Instance Method Details
#compute_degeneracy ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/genetic_code.rb', line 119 def compute_degeneracy 3.times.map do |i| [ "A", "T", "G", "C" ].count do |n| mut = seq.to_s mut[i] = n @aliases.include? mut.to_sym end end end |
#degeneracy ⇒ Object
107 108 109 |
# File 'lib/genetic_code.rb', line 107 def degeneracy @degeneracy ||= compute_degeneracy end |
#distance_to(codon) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/genetic_code.rb', line 111 def distance_to codon s1 = seq.to_s s2 = codon.seq.to_s 3.times.count do |i| s1[i] != s2[i] end end |