Class: Bioroebe::CalculateMeltingTemperature

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/calculate/calculate_melting_temperature.rb

Overview

Bioroebe::CalculateMeltingTemperature

Constant Summary collapse

DEFAULT_SEQUENCE =
#

DEFAULT_SEQUENCE

#
'CGACGTTGTAAAACGACGGCCAGT'
GAS_CONSTANT_R =
#

GAS_CONSTANT_R

#
1.987
DO_TRUNCATE_IF_INPUT_STRING_IS_TOO_LONG =
#

DO_TRUNCATE_IF_INPUT_STRING_IS_TOO_LONG

#
true

Constants inherited from CommandlineApplication

Bioroebe::CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

Bioroebe::ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandlineApplication

#all_aminoacids?, #append_what_into, #at_home?, #be_silent, #be_verbose?, #cat, #ccliner, #change_directory, #cliner, #codon_table_dataset?, #codon_to_aminoacid, #codons_for?, #colourize_this_dna_sequence, #complement, #cp, #disable_warnings, #download_dir?, #editor?, #enable_warnings, #ensure_that_the_base_directories_exist, #esystem, #extract, #is_this_a_start_codon?, #is_this_a_stop_codon?, #leading_five_prime, #load_bioroebe_yaml_file, #log_directory?, #one_letter_to_long_name, #one_to_three, #only_numbers?, #open_in_browser, #opnerev, #opnn, #pad_with_double_quotes, #pad_with_single_quotes, #partner_nucleotide, #remove_numbers, #remove_trailing_ansii_escape_code, #return_all_possible_start_codons, #return_array_of_one_letter_aminoacids, #return_cheerful_person, #return_chunked_display, #return_ubiquitin_sequence, #runmode?, #set_be_verbose, #set_runmode, #start_codon?, #stop_codons?, #strict_filter_away_invalid_aminoacids, #taxonomy_download_directory?, #three_to_one, #to_rna, #trailing_three_prime, #use_opn?, #verbose_truth, #was_or_were, #without_extname, #write_what_into

Methods included from BaseModule

#absolute_path, #default_file_read, #file_readlines

Methods included from CommandlineArguments

#commandline_arguments?, #commandline_arguments_that_are_files?, #e, #first?, #first_non_hyphen_argument?, #remove_hyphens_from_the_commandline_arguments, #return_commandline_arguments_as_string, #return_commandline_arguments_that_are_not_files, #return_entries_without_two_leading_hyphens, #select_commandline_arguments, #select_entries_starting_with_two_hyphens, #set_commandline_arguments

Methods included from ColoursForBase

#colourize_this_aminoacid_sequence_for_the_commandline, #colourize_this_nucleotide_sequence, #disable_colours, #ecomment, #efancy, #egold, #enable_colours, #eorange, #eparse, #erev, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #rev, #sdir, #set_will_we_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?

Methods inherited from Base

#append_what_into, #can_base_pair?, #convert_global_env, #delete_file, #directory_to_the_codon_tables?, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #no_file_exists_at, #no_newlines, #project_yaml_directory?, #rds, #register_sigint, #return_pwd, #return_the_first_line_of_this_file, #word_wrap, #write_what_into

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(i = nil, run_already = true) ⇒ CalculateMeltingTemperature

#

initialize

#


52
53
54
55
56
57
58
59
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 52

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_sequence(i)
  run if run_already
end

Class Method Details

.show_formulasObject

#

CalculateMeltingTemperature.show_formulas

The Wallace Method:

http://www.sigmaaldrich.com/technical-documents/articles/biology/oligos-melting-temp.html#equations
http://openwetware.org/wiki/Primer_Tm_estimation_methods

This method will simply show the Wallace-Formula.

The shorthand notation is:

Tm = 2°C(A+T) + 4°C(G+C)

Note that this is also known as the “GCx4+ATx2” rule. It works for DNA oligomers not longer than 13 nucleotides. This rule also does not take into account the order of nucleotides in the sequence, so it really is not the ideal solution.

#


362
363
364
365
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 362

def self.show_formulas
  Colours.e
    '  Tm = 2°C(A+T) + 4°C(G+C) # <-- The Wallace-Formula, proposed in 1979'
end

.wallace_method(at, gc) ⇒ Object

#

CalculateMeltingTemperature.wallace_method

The argument “at” means the sum of a and t, and “gc” means the sum of g and c.

So for instance, the string TGCTCA has 3 AT, and 3 GC, so the method will yield to us:

18
#


379
380
381
382
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 379

def self.wallace_method(at, gc)
  result = 4 * (gc) + 2 * (at)
  result
end

Instance Method Details

#calculate_tm(ct = 0.5, na = 50, formamide_concentration = 0) ⇒ Object

#

calculate_tm

Calculate the melting temperature.

Note that there are several different ways how the melting temperature (Tm) of an oligo-nucleotide can be calculated.

All of these methods will yield slightly different results.

All of these calculations are also theoretical calculations based on certain assumptions.

The Optimum Tm values should still be determined empirically.

Now, let’s explain the arguments to this method:

* ct: concentration of oligo nucleotide(mM) (default 0.5)
* na: concentration of Na⁺ (mM) (default 50)
* formamide_concentration: concentration of Formamide (mol/L) (default 0)
* This method will return a Float.
#


154
155
156
157
158
159
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 154

def calculate_tm(
    ct = 0.5,
    na =  50,
    formamide_concentration = 0
  )
  # ======================================================================= #
  # === How much formamide we threw into this
  # ======================================================================= #
  formamide_concentration = formamide_concentration.to_f # concentration of Formamide (mol/L)
  ct = ct / 1000000.0 # concentration of oligo (mol/L)
  na = na /    1000.0 # concentration of Na+ (mol/L)
  len = sequence?.length # .prec_f # base length
  # ======================================================================= #
  # === Thermodynamic parameters
  # 
  #   delta_enthalpy ... delta enthalpy
  #   delta_entropy  ... delta entropy
  #
  # ======================================================================= #

  # ======================================================================= #
  # === Delta Enthalpy
  #
  # Different combinations of nucleotides have a different enthalpy.
  # ======================================================================= #
  delta_enthalpy = {
    '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
  }
  # ======================================================================= #
  # === Delta entropy
  # ======================================================================= #
  delta_entropy = {
    '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
  # ======================================================================= #
  # Count up the total enthalpy and entropy.
  # ======================================================================= #
  (sequence?.size - 2).times {|counter|
    enthalpy = @sequence.slice(counter, 2)
    tot_h += delta_enthalpy[enthalpy]
    entropy = @sequence.slice(counter, 2)
    tot_s += delta_entropy[entropy]
  }
  # ======================================================================= #
  # Obtain the amount of AT and GC.
  # ======================================================================= #
  at = ::Bioroebe.count_AT(@sequence)
  gc = ::Bioroebe.count_GC(@sequence)
  report_total_length # Notify the user of the current total length.
  # ======================================================================= #
  # === Show AT and GC counts next, including percentage.
  # ======================================================================= #
  erev 'AT count is: '+simp(at.to_s)+rev+' nucleotides ('+
       sfancy(at * 100 / @sequence.size).to_s+rev+'%)'
  erev 'GC count is: '+simp(gc.to_s)+rev+' nucleotides ('+
       sfancy(gc * 100 / @sequence.size).to_s+rev+'%)'
  # ======================================================================= #
  # We have to calculate the tm first. We do this by also considering
  # the gas constant. 
  # ======================================================================= #
  tm = (
    (1000 * tot_h) / (-10.8+tot_s+GAS_CONSTANT_R * Math.log(ct/4))
  ) - 273.15 + 16.6 * Math.log10(na)
  # ======================================================================= #
  # === First the traditional GC% method.
  # ======================================================================= #
  if    tm > 80
    # ===================================================================== #
    # The traditional GC% method comes next.
    # ===================================================================== #
    tm = 81.5+16.6 * Math.log10(na) +
         41 * ((gc)/len)-500/len-0.62 * formamide_concentration
  elsif tm < 20
    # ===================================================================== #
    # === Wallace Method
    #
    # The Wallace method, also known as "2+4 rule of thumb".
    #
    # This very simple method assigns 2°C to each A-T pair and 4°C to
    # each G-C pair. The Tm then is the sum of these values for all
    # individual pairs in a DNA double strand.
    #
    # This takes into account that the G-C bond is stronger than the
    # A-T bond. Note that the 2+4 rule is valid only for a small
    # length-range, about 20-40 nt - rather 20, than towards 40,
    # though.
    #
    # The Wallace equation was developed for short DNA oligos of
    # 14-20 base pairs.
    #
    # See documentation at:
    #
    #   https://www.sigmaaldrich.com/technical-documents/articles/biology/oligos-melting-temp.html#equations
    #
    # It is very easy to compute, but is of course also very inaccurate.
    #
    # Whenever possible, it should be avoided.
    # ===================================================================== #
    tm = CalculateMeltingTemperature.wallace_method(at, gc)
  else
    # tm = tm
  end
  @result = tm
  return tm
end

#length?Boolean

#

length?

#

Returns:

  • (Boolean)


100
101
102
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 100

def length?
  @sequence.size
end

#report_molecular_weightObject

#

report_molecular_weight

This method will report the molecular weight of the nucleotides at hand, in Dalton.

#


304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 304

def report_molecular_weight
  molecular_weight = 0
  hash = {}
  if File.exist? FILE_NUCLEOTIDES
    dataset = YAML.load_file(FILE_NUCLEOTIDES)
  end
  unless Object.const_defined? :ChemistryParadise
    begin
      require 'chemistry_paradise/utility_scripts/calculate_atomic_mass.rb'
    rescue LoadError; end
  end
  hash['A'] = ::ChemistryParadise.return_molmasse(dataset['Desoxyadenosin'])
  hash['T'] = ::ChemistryParadise.return_molmasse(dataset['Desoxythymidin'])
  hash['C'] = ::ChemistryParadise.return_molmasse(dataset['Desoxycytidin'])
  hash['G'] = ::ChemistryParadise.return_molmasse(dataset['Desoxyguanosin'])
  internal_PO2_group = 62.972
  index = 0 
  sequence?.split(//).each {|this_nucleotide|
    add_this = hash[this_nucleotide].to_f
    case index
    when 0
    else # Else add an internal PO2 group, its weight that is.
      add_this += internal_PO2_group
    end
    molecular_weight += add_this
    index += 1
  }
  erev "Molecular weight:        "\
       "#{sfancy(molecular_weight.to_s)}"\
       "#{rev}"
end

#report_resultObject Also known as: report

#

report_result

#


285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 285

def report_result
  round_to_n_numbers = 5
  report_molecular_weight
  erev "The melting temperature of `#{simp(return_possibly_truncated_input)}"\
       "#{rev}` is #{sfancy(@result.round(round_to_n_numbers).to_s)}#{rev} °C."
  if @sequence.to_s.empty?
    erev 'Notification: it seems as if you did not pass any nucleotide '\
         'string to this.'
    erev 'You could try to "assign" a string or generate a random one '\
         'via "assign random".'
  end
end

#report_total_lengthObject

#

report_total_length

#


92
93
94
95
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 92

def report_total_length
  e "#{rev}The total length of this nucleotide-sequence "\
    "is #{simp(length?.to_s)}."
end

#resetObject

#

reset (reset tag)

#


64
65
66
67
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 64

def reset
  super()
  infer_the_namespace
end

#result?Boolean Also known as: result

#

result?

#

Returns:

  • (Boolean)


120
121
122
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 120

def result?
  @result
end

#return_possibly_truncated_inputObject

#

return_possibly_truncated_input

This method is needed to truncate too long input.

#


109
110
111
112
113
114
115
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 109

def return_possibly_truncated_input
  _ = @sequence.to_s
  if _.size > 60 # Bit more than 50 to account for the length of the message below.
    _ = _[0..49]+' [TRUNCATED PAST 50 CHARACTERS]'
  end if DO_TRUNCATE_IF_INPUT_STRING_IS_TOO_LONG
  return _
end

#runObject

#

run (run tag)

#


339
340
341
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 339

def run
  calculate_tm
end

#sequence?Boolean Also known as: input?

#

sequence?

#

Returns:

  • (Boolean)


127
128
129
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 127

def sequence?
  @sequence
end

#set_sequence(i = DEFAULT_SEQUENCE) ⇒ Object

#

set_sequence

Set the main sequence, the input, to this method.

#


74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 74

def set_sequence(i = DEFAULT_SEQUENCE)
  i = i.first if i.is_a? Array
  i = DEFAULT_SEQUENCE if i.nil?
  i = i.to_s
  case i.delete('-') # case tag
  # ======================================================================= #
  # === melting_temperature --help
  # ======================================================================= #
  when 'help'
    show_help; exit
  end
  i = i.upcase
  @sequence = i
end

#show_helpObject

#

show_help (help tag)

To show this help section, try:

cmt --help
#


276
277
278
279
280
# File 'lib/bioroebe/calculate/calculate_melting_temperature.rb', line 276

def show_help
  e
  opnn; e 'Simply input the DNA sequence.'
  e
end