class Bio::CodonTable

Constants

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, line 51
def self.[](i)
  hash = TABLES[i]
  raise "ERROR: Unknown codon table No.#{i}" unless hash
  definition = DEFINITIONS[i]
  start = STARTS[i]
  stop = STOPS[i]
  self.new(hash, definition, start, stop)
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, line 62
def self.copy(i)
  ct = self[i]
  return Marshal.load(Marshal.dump(ct))
end
new(hash, definition = nil, start = [], stop = []) 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, line 73
def initialize(hash, definition = nil, start = [], stop = [])
  @table = hash
  @definition = definition
  @start = start
  @stop = stop.empty? ? generate_stop : stop
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, line 92
def [](codon)
  @table[codon]
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, line 108
def []=(codon, aa)
  @table[codon] = aa
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, line 119
def each(&block)
  @table.each(&block)
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, line 128
def revtrans(aa)
  unless (defined? @reverse) && @reverse
    @reverse = {}
    @table.each do |k, v|
      @reverse[v] ||= []
      @reverse[v] << k
    end
  end
  @reverse[aa.upcase]
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, line 141
def start_codon?(codon)
  @start.include?(codon.downcase)
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, line 147
def stop_codon?(codon)
  @stop.include?(codon.downcase)
end