#!/usr/bin/env ruby # Method to calculate Tm, melting temperature (short oligos, very rough est. and assumptions) def meltingTemp(dnaSeq, celcius=true) gcCount = dnaSeq.count("gcGC") atCount = dnaSeq.count("atAT") tm = 4 * gcCount + 2 * atCount if(!celcius) # Note: recall what you noticed in class: the version that said 9/5 was wrong. # 9/5 does integer division and the result will be 1 (fraction dropped), as is common # for many languages. We want to do real number division and get a floating point # number as a result. To do this, just one of the numbers can be a float (Ruby will # cast the other to float as well); if we had variables with [possible] integer data # in them, we should use the '.to_f()' method to convert the data to float before # using it in a division. tm = (9.0/5.0) * tm + 32 end return tm end # Example usage: seq = "aattggcc" puts "#{seq}: #{meltingTemp(seq)}" seq = "aattGGcc" tm2 = meltingTemp(seq, false) puts "#{seq}: #{tm2} in F"