module Bio::NucleicAcid::Data
Constants
- NAMES
IUPAC code
-
Faisst and Meyer (Nucleic Acids Res. 20:3-26, 1992)
-
- WEIGHT
Public Instance Methods
[](x)
click to toggle source
# File lib/bio/data/na.rb, line 146 def [](x) NAMES[x] end
name(x)
click to toggle source
# File lib/bio/data/na.rb, line 156 def name(x) NAMES[x.to_s.upcase] end
names()
click to toggle source
backward compatibility
# File lib/bio/data/na.rb, line 151 def names NAMES end
Also aliased as: na
to_re(seq, rna = false)
click to toggle source
# File lib/bio/data/na.rb, line 160 def to_re(seq, rna = false) replace = { 'y' => '[tcy]', 'r' => '[agr]', 'w' => '[atw]', 's' => '[gcs]', 'k' => '[tgk]', 'm' => '[acm]', 'b' => '[tgcyskb]', 'd' => '[atgrwkd]', 'h' => '[atcwmyh]', 'v' => '[agcmrsv]', 'n' => '[atgcyrwskmbdhvn]' } replace.default = '.' str = seq.to_s.downcase str.gsub!(/[^atgcu]/) { |na| replace[na] } if rna str.tr!("t", "u") end Regexp.new(str) end
weight(x = nil, rna = nil)
click to toggle source
# File lib/bio/data/na.rb, line 117 def weight(x = nil, rna = nil) if x if x.length > 1 if rna phosphate = WEIGHT[:ribose_phosphate] else phosphate = WEIGHT[:deoxyribose_phosphate] end hydrogen = WEIGHT[:hydrogen] water = WEIGHT[:water] total = 0.0 x.each_byte do |byte| base = byte.chr.downcase if WEIGHT[base] total += WEIGHT[base] + phosphate - hydrogen * 2 else raise "Error: invalid nucleic acid '#{base}'" end end total -= water * (x.length - 1) else WEIGHT[x.to_s.downcase] end else WEIGHT end end