Class: Bio::RestrictionEnzyme::Range::SequenceRange

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/util/restriction_enzyme/range/sequence_range.rb,
lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb,
lib/bio/util/restriction_enzyme/range/sequence_range/fragments.rb,
lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb

Overview

A defined range over a nucleotide sequence.

This class accomadates having cuts defined on a sequence and returning the fragments made by those cuts.

Direct Known Subclasses

DoubleStranded::EnzymeAction

Defined Under Namespace

Classes: Bin, CalculatedCuts, Fragment, Fragments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p_left = nil, p_right = nil, c_left = nil, c_right = nil) ⇒ SequenceRange

Returns a new instance of SequenceRange.

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 48

def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil )
  raise ArgumentError if p_left == nil and c_left == nil
  raise ArgumentError if p_right == nil and c_right == nil
  (raise ArgumentError unless p_left <= p_right) unless p_left == nil or p_right == nil
  (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil

  @p_left, @p_right, @c_left, @c_right = p_left, p_right, c_left, c_right
  @left = [p_left, c_left].compact.sort.first
  @right = [p_right, c_right].compact.sort.last
  @size = (@right - @left) + 1 unless @left == nil or @right == nil
  @cut_ranges = CutRanges.new
  @__fragments_current = false
end

Instance Attribute Details

#c_leftObject (readonly)

Left-most index of complementary strand



31
32
33
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 31

def c_left
  @c_left
end

#c_rightObject (readonly)

Right-most index of complementary strand



34
35
36
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 34

def c_right
  @c_right
end

#cut_rangesObject (readonly)

CutRanges in this SequenceRange



46
47
48
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 46

def cut_ranges
  @cut_ranges
end

#leftObject (readonly)

Left-most index of DNA sequence



37
38
39
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 37

def left
  @left
end

#p_leftObject (readonly)

Left-most index of primary strand



25
26
27
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 25

def p_left
  @p_left
end

#p_rightObject (readonly)

Right-most index of primary strand



28
29
30
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 28

def p_right
  @p_right
end

#rightObject (readonly)

Right-most index of DNA sequence



40
41
42
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 40

def right
  @right
end

#sizeObject (readonly)

Size of DNA sequence



43
44
45
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 43

def size
  @size
end

Instance Method Details

#add_cut_range(p_cut_left = nil, p_cut_right = nil, c_cut_left = nil, c_cut_right = nil) ⇒ Object

If the first object is HorizontalCutRange or VerticalCutRange, that is added to the SequenceRange. Otherwise this method builds a VerticalCutRange object and adds it to the SequenceRange.

Note: Cut occurs immediately after the index supplied. For example, a cut at ‘0’ would mean a cut occurs between bases 0 and 1.


Arguments

  • p_cut_left: (optional) Left-most cut on the primary strand or a CutRange object. nil to skip

  • p_cut_right: (optional) Right-most cut on the primary strand. nil to skip

  • c_cut_left: (optional) Left-most cut on the complementary strand. nil to skip

  • c_cut_right: (optional) Right-most cut on the complementary strand. nil to skip

Returns

nothing



78
79
80
81
82
83
84
85
86
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 78

def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil )
  @__fragments_current = false
  if p_cut_left.kind_of? CutRange # shortcut
    @cut_ranges << p_cut_left
  else
    [p_cut_left, p_cut_right, c_cut_left, c_cut_right].each { |n| (raise IndexError unless n >= @left and n <= @right) unless n == nil }
    @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right )
  end
end

#add_cut_ranges(*cut_ranges) ⇒ Object

Add a series of CutRange objects (HorizontalCutRange or VerticalCutRange).


Arguments

  • cut_ranges: A series of CutRange objects

Returns

nothing



94
95
96
97
98
99
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 94

def add_cut_ranges(*cut_ranges)
  cut_ranges.flatten.each do |cut_range|
    raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange
    self.add_cut_range( cut_range )
  end
end

#add_horizontal_cut_range(left, right = left) ⇒ Object

Builds a HorizontalCutRange object and adds it to the SequenceRange.


Arguments

  • left: Left-most cut

  • right: (optional) Right side - by default this equals the left side, default is recommended.

Returns

nothing



108
109
110
111
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 108

def add_horizontal_cut_range( left, right=left )
  @__fragments_current = false
  @cut_ranges << HorizontalCutRange.new( left, right )
end

#fragmentsObject

Calculates the fragments over this sequence range as defined after using the methods add_cut_range, add_cut_ranges, and/or add_horizontal_cut_range

Example return value:

[#<Bio::RestrictionEnzyme::Range::SequenceRange::Fragment:0x277bdc
  @complement_bin=[0, 1],
  @primary_bin=[0]>,
 #<Bio::RestrictionEnzyme::Range::SequenceRange::Fragment:0x277bc8
  @complement_bin=[],
  @primary_bin=[1, 2]>,
 #<Bio::RestrictionEnzyme::Range::SequenceRange::Fragment:0x277bb4
  @complement_bin=[2, 3],
  @primary_bin=[]>,
 #<Bio::RestrictionEnzyme::Range::SequenceRange::Fragment:0x277ba0
  @complement_bin=[4, 5],
  @primary_bin=[3, 4, 5]>]

Arguments

  • none

Returns

Bio::RestrictionEnzyme::Range::SequenceRange::Fragments



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 150

def fragments
  return @__fragments if @__fragments_current == true
  @__fragments_current = true

  num_txt = '0123456789'
  num_txt_repeat = (num_txt * ( @size / num_txt.size.to_f ).ceil)[0..@size-1]
  fragments = Fragments.new(num_txt_repeat, num_txt_repeat)

  cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size)
  cc.add_cuts_from_cut_ranges(@cut_ranges)
  cc.remove_incomplete_cuts

  create_bins(cc).sort.each { |k, bin| fragments << Fragment.new( bin.p, bin.c ) }
  @__fragments = fragments
  return fragments
end