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:



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
743
744
745
# File 'lib/bio/db/primer3.rb', line 705

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())


747
748
749
750
751
# File 'lib/bio/db/primer3.rb', line 747

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.



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

def left
  @left
end

#recordObject (readonly)

Returns the value of attribute record.



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

def record
  @record
end

#rightObject (readonly)

Returns the value of attribute right.



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

def right
  @right
end

Instance Method Details

#<=>(anOther) ⇒ Object



701
702
703
# File 'lib/bio/db/primer3.rb', line 701

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

#parse_coordinates(str) ⇒ Object



690
691
692
693
694
695
# File 'lib/bio/db/primer3.rb', line 690

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

#sizeObject



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

def size
  return product_size.to_i
end