module Bio::NucleicAcid::Data

Constants

NAMES

IUPAC code

WEIGHT

Public Instance Methods

[](x) click to toggle source
    # File lib/bio/data/na.rb
146 def [](x)
147   NAMES[x]
148 end
na()
Alias for: names
name(x) click to toggle source
    # File lib/bio/data/na.rb
156 def name(x)
157   NAMES[x.to_s.upcase]
158 end
names() click to toggle source

backward compatibility

    # File lib/bio/data/na.rb
151 def names
152   NAMES
153 end
Also aliased as: na
to_re(seq, rna = false) click to toggle source
    # File lib/bio/data/na.rb
160 def to_re(seq, rna = false)
161   replace = {
162     'y' => '[tcy]',
163     'r' => '[agr]',
164     'w' => '[atw]',
165     's' => '[gcs]',
166     'k' => '[tgk]',
167     'm' => '[acm]',
168     'b' => '[tgcyskb]',
169     'd' => '[atgrwkd]',
170     'h' => '[atcwmyh]',
171     'v' => '[agcmrsv]',
172     'n' => '[atgcyrwskmbdhvn]'
173   }
174   replace.default = '.'
175 
176   str = seq.to_s.downcase
177   str.gsub!(/[^atgcu]/) { |na|
178     replace[na]
179   }
180   if rna
181     str.tr!("t", "u")
182   end
183   Regexp.new(str)
184 end
weight(x = nil, rna = nil) click to toggle source
    # File lib/bio/data/na.rb
117 def weight(x = nil, rna = nil)
118   if x
119     if x.length > 1
120       if rna
121         phosphate = WEIGHT[:ribose_phosphate]
122       else
123         phosphate = WEIGHT[:deoxyribose_phosphate]
124       end
125       hydrogen    = WEIGHT[:hydrogen]
126       water       = WEIGHT[:water]
127 
128       total = 0.0
129       x.each_byte do |byte|
130         base = byte.chr.downcase
131         if WEIGHT[base]
132           total += WEIGHT[base] + phosphate - hydrogen * 2
133         else
134           raise "Error: invalid nucleic acid '#{base}'"
135         end
136       end
137       total -= water * (x.length - 1)
138     else
139       WEIGHT[x.to_s.downcase]
140     end
141   else
142     WEIGHT
143   end
144 end