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 52 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
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 63 def self.copy(i) ct = self[i] return Marshal.load(Marshal.dump(ct)) end
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 74 def initialize(hash, definition = nil, start = [], stop = []) @table = hash @definition = definition @start = start @stop = stop.empty? ? generate_stop : stop end
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 93 def [](codon) @table[codon] end
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 109 def []=(codon, aa) @table[codon] = aa end
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 120 def each(&block) @table.each(&block) end
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 129 def revtrans(aa) unless @reverse @reverse = {} @table.each do |k, v| @reverse[v] ||= [] @reverse[v] << k end end @reverse[aa.upcase] end
Generated with the Darkfish Rdoc Generator 2.