TM値計算用スクリプト

BioRubyの中に見つからなかったので,書きました.
BioPHPのhttp://www.biophp.org/minitools/melting_temperature/を参照,というかコピーしています.(ライセンスはGPL)
コマンドラインから引数に配列を与えます.

% ruby tm.rb TTGCTTTCGAACAGTAGACAACATTTGAGCGTTTACATCATTTAGACACAGAAGAAACAT
{:tm=>67.6759141696788, :enthalpy=>-479.6, :entropy=>-1375.14333912341}
#!/usr/bin/ruby

require 'pp'

def nnmethod(seq, conc_primer, conc_salt, conc_mg)
  array_h = Hash.new
  array_s = Hash.new
  
  # enthalpy values
  array_h = {
    "AA" => -7.9, "AC" => -8.4, "AG" => -7.8, "AT" => -7.2,
    "CA" => -8.5, "CC" => -8.0, "CG" => -10.6, "CT" => -7.8,
    "GA" => -8.2, "GC" => -10.6, "GG" => -8.0, "GT" => -8.4,
    "TA" => -7.2, "TC" => -8.2,  "TG" => -8.5, "TT" => -7.9 }
  
  # entropy values
  array_s = {
    "AA" => -22.2, "AC" => -22.4, "AG" => -21.0, "AT" => -20.4,
    "CA" => -22.7, "CC" => -19.9, "CG" => -27.2, "CT" => -21.0,
    "GA" => -22.2, "GC" => -27.2, "GG" => -19.9, "GT" => -22.4,
    "TA" => -21.3, "TC" => -22.2, "TG" => -22.7, "TT" => -22.2 }

  # effect on entropy by salt correction; von Ahsen et al 1999
  # increase of stability due to presence of Mg
  salt_effect = (conc_salt/1000.0) + ((conc_mg/1000.0)*140)
  # effect on entropy
  h = 0.0
  s = 0.368 * (seq.length-1) * Math.log(salt_effect)

  # terminal corrections. Santalucia 1998
  firstnucleotide = seq[0,1]
  if firstnucleotide == "G" || firstnucleotide == "C"
    h += 0.1
    s += -2.8
  elsif firstnucleotide == "A" || firstnucleotide == "T"
    h += 2.3
    s += 4.1
  end
  lastnucleotide = seq[-1,1]
  if lastnucleotide == "G" || lastnucleotide == "C"
    h += 0.1
    s += -2.8
  elsif lastnucleotide == "A" || lastnucleotide == "T"
    h += 2.3
    s += 4.1
  end
  # compute new H and s based on sequence. Santalucia 1998
  0.upto(seq.size-2) do |n|
    nn = seq[n,2]
    h += array_h[nn]
    s += array_s[nn]
  end
  tm = ((1000.0*h)/(s+(1.987*Math.log(conc_primer/2000000000.0))))-273.15
  return {:tm=>tm, :enthalpy=>h, :entropy=>s}
end

pp nnmethod(ARGV.shift, 200, 50, 0)