class Bio::CodonTable

Constants

AMBIGUITY_CODON_TABLES
DEFINITIONS
STARTS
STOPS
TABLES

Attributes

definition[RW]

Accessor methods for the name of the currently selected table.

start[RW]

Accessor methods for an Array which contains a list of start or stop codons respectively.

stop[RW]

Accessor methods for an Array which contains a list of start or stop codons respectively.

table[RW]

Accessor methods for a Hash of the currently selected codon table.

Public Class Methods

[](i) click to toggle source

Select a codon table by number. This method will return one of the hard coded codon tables in this class as a Bio::CodonTable object.

   # File lib/bio/data/codontable.rb
51 def self.[](i)
52   hash = TABLES[i]
53   raise "ERROR: Unknown codon table No.#{i}" unless hash
54   if AMBIGUITY_CODON_TABLES != nil
55     atable = AMBIGUITY_CODON_TABLES[i]
56   else
57     atable = nil
58   end
59   definition = DEFINITIONS[i]
60   start = STARTS[i]
61   stop = STOPS[i]
62   self.new(hash, definition, start, stop, atable)
63 end
copy(i) click to toggle source

Similar to Bio::CodonTable but returns a copied codon table. You can modify the codon table without influencing hard coded tables.

   # File lib/bio/data/codontable.rb
67 def self.copy(i)
68   ct = self[i]
69   return Marshal.load(Marshal.dump(ct))
70 end
new(hash, definition = nil, start = [], stop = [], atable = nil) click to toggle source

Create your own codon table by giving a Hash table of codons and relevant amino acids. You can also able to define the table’s name as a second argument.

Two Arrays ‘start’ and ‘stop’ can be specified which contains a list of start and stop codons used by ‘start_codon?’ and ‘stop_codon?’ methods.

   # File lib/bio/data/codontable.rb
78 def initialize(hash, definition = nil, start = [], stop = [], atable = nil)
79   @table = hash
80   if atable == nil
81     @atable = gen_ambiguity_map(hash)
82   else
83     @atable = atable
84   end
85   @definition = definition
86   @start = start
87   @stop = stop.empty? ? generate_stop : stop
88 end

Public Instance Methods

[](codon) click to toggle source

Translate a codon into a relevant amino acid. This method is used for translating a DNA sequence into amino acid sequence.

    # File lib/bio/data/codontable.rb
146 def [](codon)
147   @atable=gen_ambiguity_map(@table) if @atable == nil
148   @atable[codon]
149 end
[]=(codon, aa) click to toggle source

Modify the codon table. Use with caution as it may break hard coded tables. If you want to modify existing table, you should use copy method instead of [] method to generate CodonTable object to be modified.

# This is OK.
table = Bio::CodonTable.copy(1)
table['tga'] = 'U'

# Not recommended as it overrides the hard coded table
table = Bio::CodonTable[1]
table['tga'] = 'U'
    # File lib/bio/data/codontable.rb
163 def []=(codon, aa)
164   @table[codon] = aa
165   @atable = nil
166 end
each(&block) click to toggle source

Iterates on codon table hash.

table = Bio::CodonTable[1]
table.each do |codon, aa|
  puts "#{codon} -- #{aa}"
 end
    # File lib/bio/data/codontable.rb
175 def each(&block)
176   @table.each(&block)
177 end
gen_ambiguity_map(hash) click to toggle source

Compute possible ambiguity nucleotide code to amino acid conversion the codon is defined when all decomposed codon translates to the same amino acid / stop codon

    # File lib/bio/data/codontable.rb
103 def gen_ambiguity_map(hash)
104   nucleotide_sets={
105     'a'       => ['a'],
106     't'       => ['t'],
107     'g'       => ['g'],
108     'c'       => ['c'],
109 
110     'y'       => ['t','c'],
111     'r'       => ['a','g'],
112     'w'       => ['a','t'],
113     's'       => ['g','c'],
114     'k'       => ['t','g'],
115     'm'       => ['a','c'],
116 
117     'b'       => ['t','g','c'],
118     'd'       => ['a','t','g'],
119     'h'       => ['a','t','c'],
120     'v'       => ['a','g','c'],
121 
122     'n'       => ['a','t','g','c'],
123   }
124   atable=Hash.new
125   nucleotide_sets.keys.each{|n1|
126     nucleotide_sets.keys.each{|n2|
127       nucleotide_sets.keys.each{|n3|
128         a = Array.new
129         nucleotide_sets[n1].each{|c1|
130           nucleotide_sets[n2].each{|c2|
131             nucleotide_sets[n3].each{|c3|
132               a << hash["#{c1}#{c2}#{c3}"]
133             }
134           }
135         }
136         a.uniq!
137         atable["#{n1}#{n2}#{n3}"] = a.to_a[0] if a.size== 1
138       }
139     }
140   }
141   atable
142 end
revtrans(aa) click to toggle source

Reverse translation of a amino acid into a list of relevant codons.

table = Bio::CodonTable[1]
table.revtrans("A")       # => ["gcg", "gct", "gca", "gcc"]
    # File lib/bio/data/codontable.rb
184 def revtrans(aa)
185   unless (defined? @reverse) && @reverse
186     @reverse = {}
187     @table.each do |k, v|
188       @reverse[v] ||= []
189       @reverse[v] << k
190     end
191   end
192   @reverse[aa.upcase]
193 end
start_codon?(codon) click to toggle source

Returns true if the codon is a start codon in the currently selected codon table, otherwise false.

    # File lib/bio/data/codontable.rb
197 def start_codon?(codon)
198   @start.include?(codon.downcase)
199 end
stop_codon?(codon) click to toggle source

Returns true if the codon is a stop codon in the currently selected codon table, otherwise false.

    # File lib/bio/data/codontable.rb
203 def stop_codon?(codon)
204   @stop.include?(codon.downcase)
205 end