Class: Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts
- Includes:
- CutSymbol, StringFormatting
- Defined in:
- lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb
Overview
cc = CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts
1 2 3 4 5 6 7
G A|T T A C A
+-----+
C T A A T|G T
1 2 3 4 5 6 7
Primary cut = 2 Complement cut = 5 Horizontal cuts = 3, 4, 5
Instance Attribute Summary collapse
-
#circular ⇒ Object
Set to
true
if the fragment CalculatedCuts is working on is circular. -
#hc_between_strands ⇒ Object
readonly
Array
of horizontal cuts between strands in 0-based index notation. -
#size ⇒ Object
readonly
Size of the sequence being digested.
-
#strands_for_display(str1 = nil, str2 = nil, vcp = nil, vcc = nil, hc = nil) ⇒ Object
readonly
Sets @strands_for_display_current to
true
and populates @strands_for_display. -
#strands_for_display_current ⇒ Object
readonly
If
false
the strands_for_display method needs to be called to update the contents of @strands_for_display. -
#vc_complement ⇒ Object
readonly
Array
of vertical cuts on the complementary strand in 0-based index notation. -
#vc_primary ⇒ Object
readonly
Array
of vertical cuts on the primary strand in 0-based index notation.
Instance Method Summary collapse
-
#add_cuts_from_cut_ranges(cut_ranges) ⇒ Object
Accepts an
Array
of CutRange type objects and applies them to @vc_complement, @vc_primary, and @hc_between_strands. -
#initialize(size = nil, circular = false) ⇒ CalculatedCuts
constructor
A new instance of CalculatedCuts.
-
#remove_incomplete_cuts(size = nil) ⇒ Object
There may be incomplete cuts made, this method removes the cuts that don’t create sub-sequences for easier processing.
Methods included from StringFormatting
#add_spacing, #left_padding, #right_padding, #strip_cuts_and_padding, #strip_padding
Methods included from CutSymbol
#cut_symbol, #escaped_cut_symbol, #re_cut_symbol, #re_cut_symbol_adjacent, #set_cut_symbol
Constructor Details
#initialize(size = nil, circular = false) ⇒ CalculatedCuts
Returns a new instance of CalculatedCuts.
58 59 60 61 62 63 64 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 58 def initialize(size=nil, circular=false) @size = size @circular = circular @vc_primary = [] @vc_complement = [] @hc_between_strands = [] end |
Instance Attribute Details
#circular ⇒ Object
Set to true
if the fragment CalculatedCuts is working on is circular
46 47 48 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 46 def circular @circular end |
#hc_between_strands ⇒ Object (readonly)
Array
of horizontal cuts between strands in 0-based index notation
43 44 45 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 43 def hc_between_strands @hc_between_strands end |
#size ⇒ Object (readonly)
Size of the sequence being digested.
56 57 58 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 56 def size @size end |
#strands_for_display(str1 = nil, str2 = nil, vcp = nil, vcc = nil, hc = nil) ⇒ Object (readonly)
Sets @strands_for_display_current to true
and populates @strands_for_display.
Arguments
-
str1
: (optional) For displaying a primary strand. Ifnil
a numbered sequence will be used in place. -
str2
: (optional) For displaying a complementary strand. Ifnil
a numbered sequence will be used in place. -
vcp
: (optional) An array of vertical cut locations on the primary strand. Ifnil
the contents of @vc_primary is used. -
vcc
: (optional) An array of vertical cut locations on the complementary strand. Ifnil
the contents of @vc_complementary is used. -
hc
: (optional) An array of horizontal cut locations between strands. Ifnil
the contents of @hc_between_strands is used.
- Returns
-
Array
An array with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts.
49 50 51 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 49 def strands_for_display @strands_for_display end |
#strands_for_display_current ⇒ Object (readonly)
If false
the strands_for_display method needs to be called to update the contents of @strands_for_display. Becomes out of date whenever add_cuts_from_cut_ranges is called.
53 54 55 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 53 def strands_for_display_current @strands_for_display_current end |
#vc_complement ⇒ Object (readonly)
Array
of vertical cuts on the complementary strand in 0-based index notation
40 41 42 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 40 def vc_complement @vc_complement end |
#vc_primary ⇒ Object (readonly)
Array
of vertical cuts on the primary strand in 0-based index notation
37 38 39 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 37 def vc_primary @vc_primary end |
Instance Method Details
#add_cuts_from_cut_ranges(cut_ranges) ⇒ Object
Accepts an Array
of CutRange type objects and applies them to @vc_complement, @vc_primary, and @hc_between_strands.
Arguments
-
cut_ranges
: AnArray
of HorizontalCutRange or VerticalCutRange objects
- Returns
-
nothing
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 73 def add_cuts_from_cut_ranges(cut_ranges) @strands_for_display_current = false cut_ranges.each do |cut_range| @vc_primary += [cut_range.p_cut_left, cut_range.p_cut_right] @vc_complement += [cut_range.c_cut_left, cut_range.c_cut_right] # Add horizontal cut ranges. This may happen from cuts made inbetween a # VerticalCutRange or may be specifically defined by a HorizontalCutRange. if cut_range.class == VerticalCutRange ( cut_range.min + 1 ).upto( cut_range.max ){|i| @hc_between_strands << i} if cut_range.min < cut_range.max elsif cut_range.class == HorizontalCutRange ( cut_range.hcuts.first ).upto( cut_range.hcuts.last ){|i| @hc_between_strands << i} end end clean_all #return end |
#remove_incomplete_cuts(size = nil) ⇒ Object
There may be incomplete cuts made, this method removes the cuts that don’t create sub-sequences for easier processing.
For example, stray horizontal cuts that do not end with a left and right separation:
G A T T A C A
+-- ---
C T|A A T G T
Or stray vertical cuts:
G A T T A C A
+-- +
C T|A A T|G T
However note that for non-circular sequences this would be a successful cut which would result in a floating ‘GT’ sub-sequence:
G A T T A C A
+---
C T A A T|G T
Blunt cuts are also complete cuts.
Arguments
-
size
: (optional) Size of the sequence being digested. Defined here or during initalization of CalculatedCuts.
- Returns
-
nothing
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb', line 120 def remove_incomplete_cuts(size=nil) @strands_for_display_current = false @size = size if size raise IndexError, "Size of the strand must be provided here or during initalization." if !@size.kind_of?(Fixnum) and not @circular vcuts = (@vc_primary + @vc_complement).uniq.sort hcuts = @hc_between_strands last_index = @size - 1 good_hcuts = [] potential_hcuts = [] if @circular # NOTE # if it's circular we should start at the beginning of a cut for orientation, # scan for it, hack off the first set of hcuts and move them to the back else vcuts.unshift(-1) unless vcuts.include?(-1) vcuts.push(last_index) unless vcuts.include?(last_index) end hcuts.each do |hcut| raise IndexError if hcut < -1 or hcut > last_index # skipped a nucleotide potential_hcuts.clear if !potential_hcuts.empty? and (hcut - potential_hcuts.last).abs > 1 if potential_hcuts.empty? if vcuts.include?( hcut ) and vcuts.include?( hcut - 1 ) good_hcuts += [hcut] elsif vcuts.include?( hcut - 1 ) potential_hcuts << hcut end else if vcuts.include?( hcut ) good_hcuts += potential_hcuts + [hcut] potential_hcuts.clear else potential_hcuts << hcut end end end check_vc = lambda do |vertical_cuts, opposing_vcuts| # opposing_vcuts is here only to check for blunt cuts, so there shouldn't # be any out-of-order problems with this good_vc = [] vertical_cuts.each { |vc| good_vc << vc if good_hcuts.include?( vc ) or good_hcuts.include?( vc + 1 ) or opposing_vcuts.include?( vc ) } good_vc end @vc_primary = check_vc.call(@vc_primary, @vc_complement) @vc_complement = check_vc.call(@vc_complement, @vc_primary) @hc_between_strands = good_hcuts clean_all end |