class Qu::Pcr::Primer3Parser

Public Class Methods

new(p3_out) click to toggle source
# File lib/qu/pcr/primer3.rb, line 102
def initialize(p3_out)
  if p3_out.class != String
    $stderr.puts "\tNeed primer3 output file content (not file name) for parsing."
  end
  @p3_out = p3_out
end

Public Instance Methods

records() click to toggle source
# File lib/qu/pcr/primer3.rb, line 129
def records
  p3_hash = {}
  p3_record = parse
  p3_record.each do |record|
    seq_id = record['SEQUENCE_ID']
    if record.has_key?('PRIMER_ERROR')
      $stderr.puts "\t#{record['PRIMER_ERROR']}"
      return p3_hash
    end
    pp_num = record['PRIMER_PAIR_NUM_RETURNED'].to_i
    if pp_num < 1
      $stderr.puts "\tFailed design for %s" % [seq_id]
      $stderr.puts "\tLeft: #{record['PRIMER_LEFT_EXPLAIN']}"
      $stderr.puts "\tRight: #{record['PRIMER_RIGHT_EXPLAIN']}"
      $stderr.puts "\INTERNAL: #{record['PRIMER_INTERNAL_EXPLAIN']}" if record.has_key?("PRIMER_INTERNAL_EXPLAIN")
      $stderr.puts "\tPair: #{record['PRIMER_PAIR_EXPLAIN']}"
    end
    p3_hash[seq_id] = []
    (0...pp_num).each do |i|
      p3_hash[seq_id] << Amplicon.new(record, i, type='primer3')
    end
  end

  return p3_hash
end

Private Instance Methods

parse() click to toggle source
# File lib/qu/pcr/primer3.rb, line 110
def parse
  result = []
  if @p3_out.empty?
    return result
  end
  @p3_out.split(/\n=\n/).each do |record|
    record_result = {}
    record.each_line do |line|
      line.strip!
      items = line.split('=')
      record_result[items[0]] = items[1]
    end
    result << record_result
  end

  return result
end