| Class | Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation |
| In: |
lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb
|
| Parent: | Array |
Stores the cut location in thier enzyme index notation
May be initialized with a series of cuts or an enzyme pattern marked with cut symbols.
| Enzyme index notation: | 1..n, value before 1 is -1 |
| example: | [-3][-2][-1][1][2][3][4][5] |
Negative values are used to indicate when a cut may occur at a specified distance before the sequence begins. This would be padded with ‘n’ nucleotides to represent wildcards.
Notes:
| max | [R] | Last cut, in enzyme-index notation |
| min | [R] | First cut, in enzyme-index notation |
Constructor for CutLocationsInEnzymeNotation
Arguments
Examples:
| Returns: | nothing |
# File lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb, line 59
59: def initialize(*a)
60: a.flatten! # in case an array was passed as an argument
61:
62: if a.size == 1 and a[0].kind_of? String and a[0] =~ re_cut_symbol
63: # Initialize with a cut symbol pattern such as 'n^ng^arraxt^n'
64: s = a[0]
65: a = []
66: i = -( s.tr(cut_symbol, '') =~ %r{[^n]} ) # First character that's not 'n'
67: s.each_byte { |c| (a << i; next) if c.chr == cut_symbol; i += 1 }
68: a.collect! { |n| n <= 0 ? n-1 : n } # 0 is not a valid enzyme index, decrement from 0 and all negative
69: else
70: a.collect! { |n| n.to_i } # Cut locations are always integers
71: end
72:
73: validate_cut_locations( a )
74: super(a)
75: self.sort!
76: @min = self.first
77: @max = self.last
78: self.freeze
79: end
Transform the cut locations from enzyme index notation to 0-based index notation.
input -> output [ 1, 2, 3 ] -> [ 0, 1, 2 ] [ 1, 3, 5 ] -> [ 0, 2, 4 ] [ -1, 1, 2 ] -> [ 0, 1, 2 ] [ -2, 1, 3 ] -> [ 0, 2, 4 ]
Arguments
| Returns: | Array of cuts in 0-based index notation |
# File lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb, line 94
94: def to_array_index
95: return [] if @min == nil
96: if @min < 0
97: calc = lambda do |n|
98: n -= 1 unless n < 0
99: n + @min.abs
100: end
101: else
102: calc = lambda { |n| n - 1 }
103: end
104: self.collect(&calc)
105: end
# File lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb, line 111
111: def validate_cut_locations( input_cut_locations )
112: unless input_cut_locations == input_cut_locations.uniq
113: err = "The cut locations supplied contain duplicate values. Redundant / undefined meaning.\n"
114: err += "cuts: #{input_cut_locations.inspect}\n"
115: err += "unique: #{input_cut_locations.uniq.inspect}"
116: raise ArgumentError, err
117: end
118:
119: if input_cut_locations.include?(nil)
120: err = "The cut locations supplied contained a nil. nil has no index for enzyme notation, alternative meaning is 'no cut'.\n"
121: err += "cuts: #{input_cut_locations.inspect}"
122: raise ArgumentError, err
123: end
124:
125: if input_cut_locations.include?(0)
126: err = "The cut locations supplied contained a '0'. '0' has no index for enzyme notation, alternative meaning is 'no cut'.\n"
127: err += "cuts: #{input_cut_locations.inspect}"
128: raise ArgumentError, err
129: end
130:
131: end