Class | Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts
In: | lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb
Parent: | Object

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

### Methods

add_cuts_from_cut_ranges clean_all new remove_incomplete_cuts strands_for_display

### Included Modules

CutSymbol StringFormatting

### Attributes

circular | [RW] | Set to `true` if the fragment CalculatedCuts is working on is circular
hc_between_strands | [R] | `Array` of horizontal cuts between strands in 0-based index notation
size | [R] | Size of the sequence being digested.
strands_for_display_current | [R] | 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.
vc_complement | [R] | `Array` of vertical cuts on the complementary strand in 0-based index notation
vc_primary | [R] | `Array` of vertical cuts on the primary strand in 0-based index notation

### Public Class methods

new(size=nil, circular=false)

[Source]

        # File lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb, line 60
    60:   def initialize(size=nil, circular=false)
    61:     @size = size
    62:     @circular = circular
    63:     @vc_primary = []
    64:     @vc_complement = []
    65:     @hc_between_strands = []
    66:   end

### Public Instance methods

add_cuts_from_cut_ranges(cut_ranges)

Accepts an `Array` of CutRange type objects and applies them to @vc_complement, @vc_primary, and @hc_between_strands.

Arguments

- `cut_ranges`: An `Array` of HorizontalCutRange or VerticalCutRange objects

Returns: | nothing

[Source]

        # File lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb, line 75
    75:   def add_cuts_from_cut_ranges(cut_ranges)
    76:     @strands_for_display_current = false
    77:
    78:     cut_ranges.each do |cut_range|
    79:       @vc_primary += [cut_range.p_cut_left, cut_range.p_cut_right]
    80:       @vc_complement += [cut_range.c_cut_left, cut_range.c_cut_right]
    81:
    82:       # Add horizontal cut ranges.  This may happen from cuts made inbetween a
    83:       # VerticalCutRange or may be specifically defined by a HorizontalCutRange.
    84:       if cut_range.class == VerticalCutRange
    85:         ( cut_range.min + 1 ).upto( cut_range.max ){|i| @hc_between_strands << i} if cut_range.min < cut_range.max
    86:       elsif cut_range.class == HorizontalCutRange
    87:         ( cut_range.hcuts.first ).upto( cut_range.hcuts.last ){|i| @hc_between_strands << i}
    88:       end
    89:     end
    90:     clean_all
    91:     #return
    92:   end

remove_incomplete_cuts(size=nil)

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

[Source]

         # File lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb, line 122
    122:   def remove_incomplete_cuts(size=nil)
    123:     @strands_for_display_current = false
    124:     @size = size if size
    125:     raise IndexError, "Size of the strand must be provided here or during initalization." if !@size.kind_of?(Fixnum) and not @circular
    126:
    127:     vcuts = (@vc_primary + @vc_complement).uniq.sort
    128:     hcuts = @hc_between_strands
    129:     last_index = @size - 1
    130:     good_hcuts = []
    131:     potential_hcuts = []
    132:
    133:     if @circular
    134:     # NOTE
    135:     # if it's circular we should start at the beginning of a cut for orientation,
    136:     # scan for it, hack off the first set of hcuts and move them to the back
    137:     else
    138:       vcuts.unshift(-1) unless vcuts.include?(-1)
    139:       vcuts.push(last_index) unless vcuts.include?(last_index)
    140:     end
    141:
    142:     hcuts.each do |hcut|
    143:       raise IndexError if hcut < -1 or hcut > last_index
    144:       # skipped a nucleotide
    145:       potential_hcuts.clear if !potential_hcuts.empty? and (hcut - potential_hcuts.last).abs > 1
    146:
    147:       if potential_hcuts.empty?
    148:         if vcuts.include?( hcut ) and vcuts.include?( hcut - 1 )
    149:           good_hcuts += [hcut]
    150:         elsif vcuts.include?( hcut - 1 )
    151:           potential_hcuts << hcut
    152:         end
    153:       else
    154:         if vcuts.include?( hcut )
    155:           good_hcuts += potential_hcuts + [hcut]
    156:           potential_hcuts.clear
    157:         else
    158:           potential_hcuts << hcut
    159:         end
    160:       end
    161:     end
    162:
    163:     check_vc = lambda do |vertical_cuts, opposing_vcuts|
    164:       # opposing_vcuts is here only to check for blunt cuts, so there shouldn't
    165:       # be any out-of-order problems with this
    166:       good_vc = []
    167:       vertical_cuts.each { |vc| good_vc << vc if good_hcuts.include?( vc ) or good_hcuts.include?( vc + 1 ) or opposing_vcuts.include?( vc ) }
    168:       good_vc
    169:     end
    170:
    171:     @vc_primary = check_vc.call(@vc_primary, @vc_complement)
    172:     @vc_complement = check_vc.call(@vc_complement, @vc_primary)
    173:     @hc_between_strands = good_hcuts
    174:
    175:     clean_all
    176:   end

strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil)

Sets @strands_for_display_current to `true` and populates @strands_for_display.

Arguments

- +str1+: (optional) For displaying a primary strand. If `nil` a numbered sequence will be used in place.
- +str2+: (optional) For displaying a complementary strand. If `nil` a numbered sequence will be used in place.
- `vcp`: (optional) An array of vertical cut locations on the primary strand. If `nil` the contents of @vc_primary is used.
- `vcc`: (optional) An array of vertical cut locations on the complementary strand. If `nil` the contents of @vc_complementary is used.
- `hc`: (optional) An array of horizontal cut locations between strands. If `nil` 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.

[Source]

         # File lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb, line 189
    189:   def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil)
    190:     return @strands_for_display if @strands_for_display_current
    191:     vcs = '|'   # Vertical cut symbol
    192:     hcs = '-'   # Horizontal cut symbol
    193:     vhcs = '+'  # Intersection of vertical and horizontal cut symbol
    194:
    195:     num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0..@size-1] }
    196:     (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup
    197:     (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup
    198:
    199:     vcp = @vc_primary if vcp==nil
    200:     vcc = @vc_complement if vcc==nil
    201:     hc = @hc_between_strands if hc==nil
    202:
    203:     vcuts = (vcp + vcc).uniq.sort
    204:
    205:     vcp.reverse.each { |c| a.insert(c+1, vcs) }
    206:     vcc.reverse.each { |c| b.insert(c+1, vcs) }
    207:
    208:     between = ' ' * @size
    209:     hc.each {|hcut| between[hcut,1] = hcs }
    210:
    211:     s_a = add_spacing(a, vcs)
    212:     s_b = add_spacing(b, vcs)
    213:     s_bet = add_spacing(between)
    214:
    215:     # NOTE watch this for circular
    216:     i = 0
    217:     0.upto( s_a.size-1 ) do
    218:       if (s_a[i,1] == vcs) or (s_b[i,1] == vcs)
    219:         s_bet[i] = vhcs
    220:       elsif i != 0 and s_bet[i-1,1] == hcs and s_bet[i+1,1] == hcs
    221:         s_bet[i] = hcs
    222:       end
    223:       i+=1
    224:     end
    225:
    226:     @strands_for_display_current = true
    227:     @strands_for_display = [s_a, s_bet, s_b]
    228:   end

### Protected Instance methods

clean_all()

remove nil values, remove duplicate values, and sort @vc_primary, @vc_complement, and @hc_between_strands

[Source]

         # File lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb, line 236
    236:   def clean_all
    237:     [@vc_primary, @vc_complement, @hc_between_strands].collect { |a| a.delete(nil); a.uniq!; a.sort! }
    238:   end

[Validate]