class Bio::CodonTable
Constants
- AMBIGUITY_CODON_TABLES
- DEFINITIONS
- STARTS
- STOPS
- TABLES
Attributes
Accessor methods for the name of the currently selected table.
Accessor methods for an Array which contains a list of start or stop codons respectively.
Accessor methods for an Array which contains a list of start or stop codons respectively.
Accessor methods for a Hash of the currently selected codon table.
Public Class Methods
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
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
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
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
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
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
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
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
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
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