Class: Bio::RestrictionEnzyme::Range::SequenceRange
- 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
Defined Under Namespace
Classes: Bin, CalculatedCuts, Fragment, Fragments
Instance Attribute Summary collapse
-
#c_left ⇒ Object
readonly
Left-most index of complementary strand.
-
#c_right ⇒ Object
readonly
Right-most index of complementary strand.
-
#cut_ranges ⇒ Object
readonly
CutRanges in this SequenceRange.
-
#left ⇒ Object
readonly
Left-most index of DNA sequence.
-
#p_left ⇒ Object
readonly
Left-most index of primary strand.
-
#p_right ⇒ Object
readonly
Right-most index of primary strand.
-
#right ⇒ Object
readonly
Right-most index of DNA sequence.
-
#size ⇒ Object
readonly
Size of DNA sequence.
Instance Method Summary collapse
-
#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.
-
#add_cut_ranges(*cut_ranges) ⇒ Object
Add a series of CutRange objects (HorizontalCutRange or VerticalCutRange).
-
#add_horizontal_cut_range(left, right = left) ⇒ Object
Builds a HorizontalCutRange object and adds it to the SequenceRange.
-
#fragments ⇒ Object
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.
-
#initialize(p_left = nil, p_right = nil, c_left = nil, c_right = nil) ⇒ SequenceRange
constructor
A new instance of SequenceRange.
Constructor Details
#initialize(p_left = nil, p_right = nil, c_left = nil, c_right = nil) ⇒ SequenceRange
Returns a new instance of SequenceRange.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 56 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_left ⇒ Object (readonly)
Left-most index of complementary strand
39 40 41 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 39 def c_left @c_left end |
#c_right ⇒ Object (readonly)
Right-most index of complementary strand
42 43 44 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 42 def c_right @c_right end |
#cut_ranges ⇒ Object (readonly)
CutRanges in this SequenceRange
54 55 56 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 54 def cut_ranges @cut_ranges end |
#left ⇒ Object (readonly)
Left-most index of DNA sequence
45 46 47 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 45 def left @left end |
#p_left ⇒ Object (readonly)
Left-most index of primary strand
33 34 35 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 33 def p_left @p_left end |
#p_right ⇒ Object (readonly)
Right-most index of primary strand
36 37 38 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 36 def p_right @p_right end |
#right ⇒ Object (readonly)
Right-most index of DNA sequence
48 49 50 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 48 def right @right end |
#size ⇒ Object (readonly)
Size of DNA sequence
51 52 53 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 51 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
86 87 88 89 90 91 92 93 94 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 86 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
102 103 104 105 106 107 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 102 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
116 117 118 119 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 116 def add_horizontal_cut_range( left, right=left ) @__fragments_current = false @cut_ranges << HorizontalCutRange.new( left, right ) end |
#fragments ⇒ Object
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
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/bio/util/restriction_enzyme/range/sequence_range.rb', line 158 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 |