Method: Bio::RestrictionEnzyme::DoubleStranded#initialize

Defined in:
lib/bio/util/restriction_enzyme/double_stranded.rb

#initialize(erp, *raw_cut_pairs) ⇒ DoubleStranded

erp

One of three possible parameters: The name of an enzyme, a REBASE::EnzymeEntry object, or a nucleotide pattern with a cut mark.

raw_cut_pairs

The cut locations in enzyme index notation.

Enzyme index notation

1..n, value before 1 is -1

Examples of the allowable cut locations for raw_cut_pairs follows. ‘p’ and ‘c’ refer to a cut location on the ‘p’rimary and ‘c’omplement strands.

1, [3,2], [20,22], 57
p, [p,c], [p, c],  p

Which is the same as:

1, (3..2), (20..22), 57
p, (p..c), (p..c),   p

Examples of partial cuts:

1, [nil,2], [20,nil], 57
p, [p,  c], [p, c],   p


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 71

def initialize(erp, *raw_cut_pairs)
  # 'erp' : 'E'nzyme / 'R'ebase / 'P'attern
  k = erp.class

  if k == Bio::REBASE::EnzymeEntry
    # Passed a Bio::REBASE::EnzymeEntry object

    unless raw_cut_pairs.empty?
      err = "A Bio::REBASE::EnzymeEntry object was passed, however the cut locations contained values.  Ambiguous or redundant.\n"
      err += "inspect = #{raw_cut_pairs.inspect}"
      raise ArgumentError, err
    end
    initialize_with_rebase( erp )

  elsif erp.kind_of? String
    # Passed something that could be an enzyme pattern or an anzyme name

    # Decide if this String is an enzyme name or a pattern
    if Bio::RestrictionEnzyme.enzyme_name?( erp )
      # FIXME we added this to rebase...
      # Check if it's a known name
      known_enzyme = false
      known_enzyme = true if Bio::RestrictionEnzyme.rebase[ erp ]

      # Try harder to find the enzyme
      unless known_enzyme
        re = %r"^#{erp}$"i
        Bio::RestrictionEnzyme.rebase.each { |name, v| (known_enzyme = true; erp = name; break) if name =~ re }
      end

      if known_enzyme
        initialize_with_rebase( Bio::RestrictionEnzyme.rebase[erp] )
      else
        raise IndexError, "No entry found for enzyme named '#{erp}'"
      end

    else
      # Not an enzyme name, so a pattern is assumed
      if erp =~ re_cut_symbol
        initialize_with_pattern_and_cut_symbols( erp )
      else
        initialize_with_pattern_and_cut_locations( erp, raw_cut_pairs )
      end
    end

  elsif k == NilClass
    err = "Passed a nil value.  Perhaps you tried to pass a Bio::REBASE::EnzymeEntry that does not exist?\n"
    err += "inspect = #{erp.inspect}"
    raise ArgumentError, err
  else
    err = "I don't know what to do with class #{k} for erp.\n"
    err += "inspect = #{erp.inspect}"
    raise ArgumentError, err
  end

end