Class: Bio::RestrictionEnzyme::DoubleStranded

Inherits:
Object
  • Object
show all
Extended by:
CutSymbol, StringFormatting
Includes:
CutSymbol, StringFormatting
Defined in:
lib/bio/util/restriction_enzyme/double_stranded.rb,
lib/bio/util/restriction_enzyme/double_stranded/cut_locations.rb,
lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb,
lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb,
lib/bio/util/restriction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb,
lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb

Overview

A pair of SingleStrand and SingleStrandComplement objects with methods to add utility to their relation.

Notes

  • This is created by Bio::RestrictionEnzyme.new for convenience.

  • The two strands accessible are primary and complement.

  • SingleStrand methods may be used on DoubleStranded and they will be passed to primary.

FIXME needs better docs

Defined Under Namespace

Classes: AlignedStrands, CutLocationPair, CutLocationPairInEnzymeNotation, CutLocations, CutLocationsInEnzymeNotation, EnzymeAction

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CutSymbol

cut_symbol, escaped_cut_symbol, re_cut_symbol, re_cut_symbol_adjacent, set_cut_symbol

Methods included from StringFormatting

add_spacing, left_padding, right_padding, strip_cuts_and_padding, strip_padding

Constructor Details

#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


63
64
65
66
67
68
69
70
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
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 63

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

Instance Attribute Details

#complementObject (readonly)

The complement strand



35
36
37
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 35

def complement
  @complement
end

#cut_locationsObject (readonly)

Cut locations in 0-based index format, DoubleStranded::CutLocations object



38
39
40
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 38

def cut_locations
  @cut_locations
end

#cut_locations_in_enzyme_notationObject (readonly)

Cut locations in enzyme index notation, DoubleStranded::CutLocationsInEnzymeNotation object



41
42
43
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 41

def cut_locations_in_enzyme_notation
  @cut_locations_in_enzyme_notation
end

#primaryObject (readonly)

The primary strand



32
33
34
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 32

def primary
  @primary
end

Instance Method Details

#aligned_strandsObject

See AlignedStrands.align



121
122
123
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 121

def aligned_strands
  AlignedStrands.align(@primary.pattern, @complement.pattern)
end

#aligned_strands_with_cutsObject

See AlignedStrands.align_with_cuts



126
127
128
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 126

def aligned_strands_with_cuts
  AlignedStrands.align_with_cuts(@primary.pattern, @complement.pattern, @primary.cut_locations, @complement.cut_locations)
end

#blunt?Boolean

Returns true if the cut pattern creates blunt fragments. (opposite of sticky)

Returns:

  • (Boolean)


132
133
134
135
136
137
138
139
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 132

def blunt?
  as = aligned_strands_with_cuts
  ary = [as.primary, as.complement]
  ary.collect! { |seq| seq.split( cut_symbol ) }
  # convert the cut sections to their lengths
  ary.each { |i| i.collect! { |c| c.length } }
  ary[0] == ary[1]
end

#create_action_at(offset) ⇒ Object

Takes a RestrictionEnzyme object and a numerical offset to the sequence and returns an EnzymeAction

restriction_enzyme

RestrictionEnzyme

offset

Numerical offset of where the enzyme action occurs on the seqeunce



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 152

def create_action_at( offset )
  # x is the size of the fully aligned sequence with maximum padding needed
  # to make a match on the primary and complement strand.
  #
  # For example -
  # Note how EcoRII needs extra padding on the beginning and ending of the
  # sequence 'ccagg' to make the match since the cut must occur between
  # two nucleotides and can not occur on the very end of the sequence.
  #
  #   EcoRII:
  #     :blunt: "0"
  #     :c2: "5"
  #     :c4: "0"
  #     :c1: "-1"
  #     :pattern: CCWGG
  #     :len: "5"
  #     :name: EcoRII
  #     :c3: "0"
  #     :ncuts: "2"
  #
  #        -1 1 2 3 4 5
  #   5' - n^c c w g g n - 3'
  #   3' - n g g w c c^n - 5'
  #
  #   (w == [at])

  x = aligned_strands.primary.size

  enzyme_action = EnzymeAction.new( offset,
                                    offset + x-1,
                                    offset,
                                    offset + x-1)

  @cut_locations.each do |cut_location_pair|
    # cut_pair is a DoubleStranded::CutLocationPair
    p, c = cut_location_pair.primary, cut_location_pair.complement
    if c >= p
      enzyme_action.add_cut_range(offset+p, nil, nil, offset+c)
    else
      enzyme_action.add_cut_range(nil, offset+p, offset+c, nil)
    end
  end

  enzyme_action
end

#sticky?Boolean

Returns true if the cut pattern creates sticky fragments. (opposite of blunt)

Returns:

  • (Boolean)


143
144
145
# File 'lib/bio/util/restriction_enzyme/double_stranded.rb', line 143

def sticky?
  !blunt?
end