module Bio::DB::Primer3

Public Class Methods

prepare_input_file(file, opts2={}) click to toggle source
# File lib/bio/db/primer3.rb, line 19
def self.prepare_input_file(file, opts2={})
 opts = {
  :primer_product_size_range => "50-150" ,
  :primer_max_size => 25 , 
  :primer_lib_ambiguity_codes_consensus => 1,
  :primer_liberal_base => 1, 
  :primer_num_return => 5,
  :primer_explain_flag => 1,
  :primer_thermodynamic_parameters_path => File.expand_path(File.dirname(__FILE__) + '../../../../conf/primer3_config/') + '/'
  }.merge(opts2)
  
  opts.each do |key,value|
    file.puts "#{key.to_s.upcase}=#{value}\n"
  end
end
read_primer_preferences(file, defaults) click to toggle source
# File lib/bio/db/primer3.rb, line 6
def self.read_primer_preferences(file, defaults)

  File.open(file) do |f|
    f.each_line do | line | 
      line.chomp!
      arr = line.split("=")
      defaults[arr[0].downcase.to_sym] = arr[1];
    end
  end

  return defaults
end
run(opts={}) click to toggle source
# File lib/bio/db/primer3.rb, line 35
def self.run(opts={})
  puts "Primer3.run running..."
  timeout = 600
  f_in=opts[:in]
  f_out=opts[:out]
  timeout = opts[:timeout] if opts[:timeout]
  opts.delete(:in)
  opts.delete(:out)
  primer_3_in = File.read(f_in)
  status = systemu "primer3_core", 0=>primer_3_in, 1=>stdout='', 2=>stderr='' do |cid|
    sleep timeout
    Process.kill 9, cid
  end
  # $stderr.puts cmdline
  if status.exitstatus == 0
    File.open(f_out, 'w') { |f| f.write(stdout) }
  else
    raise Primer3Exception.new(), "Error running primer3. Command line was 'primer3_core'\nPrimer3 STDERR was:\n#{stderr}"
  end
end