昨日のBioRubyネタの続き

twitterBioRubyの中の人( @さん)の助言を受ける。そもそも、methodの追加程度であれば、継承したclassは作らんでも良いらしい。オレってちっともrubyを理解できてないな。

方針

以下のcode( http://gist.github.com/641871 )をna.rbとして保存して、実行した時に、tmを計算した結果が表示されれば、OKということで、昨日書いたヤツを書き換えることにする。

require 'bio'

class Bio::Sequence::NA
  def self.compute_melting_temperature(nastr)
    10 # code here ...
  end

  def melting_temperature
    if @melting_temperature
      @melting_temperature
    else
      @melting_temperature = self.class.compute_melting_temperature(self)
    end
  end
end


if __FILE__ == $0
  # as a class method (static method ?)
  p Bio::Sequence::NA.compute_melting_temperature("ACGT")
  
  # as an instance method
  na = Bio::Sequence::NA.new("ACGT")
  p na.melting_temperature
end

書き換え版

まあ、「BioRubyのお作法に則ってるか」という観点は怪しいとして、とりあえず。まだ、20度以下のとき、80度以上の時の計算を入れてない(塩基数を数える処理を加えるのが面倒だけれど、それさえやれば、すぐできるから)。

require 'bio'

class Bio::Sequence::NA
  def self.compute_melting_temperature(nastr, _ct=0.5, _na=50, _fa=0)
    len = nastr.split(//).size
    ct = _ct.prec_f / 1000000
    na = _na.prec_f / 1000
    fa = _fa.prec_f
    @@r = 1.987
    nastr.upcase!
   # thermodynamic parameter 
   #  _h ...delta enthalpy
   #  _s ...delta entropy
    _h = {"AA" => -9.1, "TT" => -9.1, "AT" => -8.6, "TA" => -6.0,
             "CA" => -5.8, "TG" => -5.8, "GT" => -6.5, "AC" => -6.5,
             "CT" => -7.8, "AG" => -7.8, "GA" => -5.6, "TC" => -5.6,
             "CG" => -11.9,"GC" => -11.1,"GG" => -11.0,"CC" => -11.0 }
    _s={"AA" => -24.0, "TT" => -24.0, "AT" => -23.9, "TA" => -16.9,
           "CA" => -12.9, "TG" => -12.9, "GT" => -17.3, "AC" => -17.3,
           "CT" => -20.8, "AG" => -20.8, "GA" => -13.5, "TC" => -13.5,
           "CG" => -27.8, "GC" => -26.7, "GG" => -26.6, "CC" => -26.6}
    tot_h=0.0
    tot_s=0.0
    for i in 0..(len-2)
      tot_h += _h[ nastr.slice(i,2) ]
      tot_s += _s[ nastr.slice(i,2) ]
    end
    ((1000*tot_h)/(-10.8+tot_s+@@r*Math::log(ct/4)))-273.15+16.6*Math::log10(na)
  end

  def melting_temperature
    if @melting_temperature
      @melting_temperature
    else
      @melting_temperature = self.class.compute_melting_temperature(self)
    end
  end
end

とりあえず、http://www.sigmaaldrich.com/japan/lifescience/custom-products/custom-dna/oligo-learning-center.html#o04 のページにあるように、5'-CGACGTTGTAAAACGACGGCCAGT-3'という配列のtmを計算すると、73.15度となる。