Module: Bio::NucleicAcid::Data

Included in:
Bio::NucleicAcid, Bio::NucleicAcid
Defined in:
lib/bio/data/na.rb

Constant Summary collapse

NAMES =

IUPAC code

{

  'y'	=> '[tc]',
  'r'	=> '[ag]',
  'w'	=> '[at]',
  's'	=> '[gc]',
  'k'	=> '[tg]',
  'm'	=> '[ac]',

  'b'	=> '[tgc]',
  'd'	=> '[atg]',
  'h'	=> '[atc]',
  'v'	=> '[agc]',

  'n'	=> '[atgc]',

  'a'	=> 'a',
  't'	=> 't',
  'g'	=> 'g',
  'c'	=> 'c',
  'u'	=> 'u',

  'A'	=> 'Adenine',
  'T'	=> 'Thymine',
  'G'	=> 'Guanine',
  'C'	=> 'Cytosine',
  'U'	=> 'Uracil',

  'Y'	=> 'pYrimidine',
  'R'	=> 'puRine',
  'W'	=> 'Weak',
  'S'	=> 'Strong',
  'K'	=> 'Keto',
  'M'	=> 'aroMatic',

  'B'	=> 'not A',
  'D'	=> 'not C',
  'H'	=> 'not G',
  'V'	=> 'not T',
}
WEIGHT =
{

  # Calculated by BioPerl's Bio::Tools::SeqStats.pm :-)

  'a'	=> 135.15,
  't'	=> 126.13,
  'g'	=> 151.15,
  'c'	=> 111.12,
  'u'	=> 112.10,

  :adenine	=> 135.15,
  :thymine	=> 126.13,
  :guanine	=> 151.15,
  :cytosine	=> 111.12,
  :uracil	=> 112.10,

  :deoxyribose_phosphate	=> 196.11,
  :ribose_phosphate		=> 212.11,

  :hydrogen	=> 1.00794,
  :water	=> 18.015,

}

Instance Method Summary collapse

Instance Method Details

#[](x) ⇒ Object



146
147
148
# File 'lib/bio/data/na.rb', line 146

def [](x)
  NAMES[x]
end

#name(x) ⇒ Object



156
157
158
# File 'lib/bio/data/na.rb', line 156

def name(x)
  NAMES[x.to_s.upcase]
end

#namesObject Also known as: na

backward compatibility



151
152
153
# File 'lib/bio/data/na.rb', line 151

def names
  NAMES
end

#to_re(seq, rna = false) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/bio/data/na.rb', line 160

def to_re(seq, rna = false)
  replace = {
    'y' => '[tcy]',
    'r' => '[agr]',
    'w' => '[atw]',
    's' => '[gcw]',
    '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) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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