Class: Bio::DB::Primer3::PrimerPair

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/bio/db/primer3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, index) ⇒ PrimerPair

Returns a new instance of PrimerPair.

Raises:



702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/bio/db/primer3.rb', line 702

def initialize(record, index)
  raise Primer3Exception.new(), "Index #{index} is greater than the number of records" unless index < record.size
  @record = record
  @left = Primer.new
  @right = Primer.new
  @values = Hash.new
  

  @left.set_value("added", false)
  @right.set_value("added", false)
  @left.pair = self
  @right.pair = self
  index_s = index.to_s
  record.properties.each do |key, value|
    tokens = key.to_s.split("_")
    if tokens.size > 2 and tokens[2] == index_s
      primer = nil
      primer = @right if tokens[1] == "right"
      primer = @left if tokens[1] == "left"
      if primer != nil
        primer.set_value("added", true)
        if tokens.size == 3
          primer.set_value("coordinates", parse_coordinates(value) )
        else

          to_add = value
          to_add = value.to_f unless tokens[3]=="sequence"
          n_key = tokens[3..6].join("_")
          primer.set_value(n_key, to_add)
        end
      else
        n_key = tokens[3..6].join("_")
        @values[n_key] = value  
      end

    end
  end

  raise Primer3Exception.new(), "The pair is not complete (l:#{left.added}, r:#{right.added})" if @left.added == false or @right.added == false

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Raises:

  • (NoMethodError.new())


744
745
746
747
748
# File 'lib/bio/db/primer3.rb', line 744

def method_missing(m, *args, &block)  

  return @values[m.to_s] if @values[m.to_s]
  raise NoMethodError.new(), "There's no method called #{m}. Available methods: #{@values.keys.to_s}"
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



685
686
687
# File 'lib/bio/db/primer3.rb', line 685

def left
  @left
end

#recordObject (readonly)

Returns the value of attribute record.



684
685
686
# File 'lib/bio/db/primer3.rb', line 684

def record
  @record
end

#rightObject (readonly)

Returns the value of attribute right.



685
686
687
# File 'lib/bio/db/primer3.rb', line 685

def right
  @right
end

Instance Method Details

#<=>(anOther) ⇒ Object



698
699
700
# File 'lib/bio/db/primer3.rb', line 698

def <=>(anOther)
  penalty.to_f <=> anOther.penalty.to_f
end

#parse_coordinates(str) ⇒ Object



687
688
689
690
691
692
# File 'lib/bio/db/primer3.rb', line 687

def parse_coordinates(str)
  coords = str.split(',')
  coords[0] = coords[0].to_i
  coords[1] = coords[1].to_i
  coords
end

#sizeObject



694
695
696
# File 'lib/bio/db/primer3.rb', line 694

def size
  return product_size.to_i
end