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:

- `0` is invalid as it does not refer to any index
- `nil` is not allowed here as it has no meaning
- `nil` values are kept track of in DoubleStranded::CutLocations as they need a reference point on the correlating strand. In DoubleStranded::CutLocations `nil` represents no cut or a partial digestion.

### Methods

new to_array_index validate_cut_locations

### Included Modules

CutSymbol

### Attributes

max | [R] | Last cut, in enzyme-index notation
min | [R] | First cut, in enzyme-index notation

### Public Class methods

new(*a)

Constructor for CutLocationsInEnzymeNotation

Arguments

- `a`: Locations of cuts represented as a string with cuts or an array of values

Examples:

- n^ng^arraxt^n
- 2
- -1, 5
- [-1, 5]

Returns: | nothing

[Source]

        # File lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb, line 58
    58:   def initialize(*a)
    59:     a.flatten! # in case an array was passed as an argument
    60:
    61:     if a.size == 1 and a[0].kind_of? String and a[0] =~ re_cut_symbol
    62:       # Initialize with a cut symbol pattern such as 'n^ng^arraxt^n'
    63:       s = a[0]
    64:       a = []
    65:       i = -( s.tr(cut_symbol, '') =~ %r{[^n]} )  # First character that's not 'n'
    66:       s.each_byte { |c| (a << i; next) if c.chr == cut_symbol; i += 1 }
    67:       a.collect! { |n| n <= 0 ? n-1 : n } # 0 is not a valid enzyme index, decrement from 0 and all negative
    68:     else
    69:       a.collect! { |n| n.to_i } # Cut locations are always integers
    70:     end
    71:
    72:     validate_cut_locations( a )
    73:     super(a)
    74:     self.sort!
    75:     @min = self.first
    76:     @max = self.last
    77:     self.freeze
    78:   end

### Public Instance methods

to_array_index()

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

- none

Returns: | `Array` of cuts in 0-based index notation

[Source]

         # File lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb, line 93
     93:   def to_array_index
     94:     return [] if @min == nil
     95:     if @min < 0
     96:       calc = lambda do |n|
     97:         n -= 1 unless n < 0
     98:         n + @min.abs
     99:       end
    100:     else
    101:       calc = lambda { |n| n - 1 }
    102:     end
    103:     self.collect(&calc)
    104:   end

### Protected Instance methods

validate_cut_locations( input_cut_locations )

[Source]

         # File lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb, line 110
    110:   def validate_cut_locations( input_cut_locations )
    111:     unless input_cut_locations == input_cut_locations.uniq
    112:       err = "The cut locations supplied contain duplicate values.  Redundant / undefined meaning.\n"
    113:       err += "cuts: #{input_cut_locations.inspect}\n"
    114:       err += "unique: #{input_cut_locations.uniq.inspect}"
    115:       raise ArgumentError, err
    116:     end
    117:
    118:     if input_cut_locations.include?(nil)
    119:       err = "The cut locations supplied contained a nil.  nil has no index for enzyme notation, alternative meaning is 'no cut'.\n"
    120:       err += "cuts: #{input_cut_locations.inspect}"
    121:       raise ArgumentError, err
    122:     end
    123:
    124:     if input_cut_locations.include?(0)
    125:       err = "The cut locations supplied contained a '0'.  '0' has no index for enzyme notation, alternative meaning is 'no cut'.\n"
    126:       err += "cuts: #{input_cut_locations.inspect}"
    127:       raise ArgumentError, err
    128:     end
    129:
    130:   end

[Validate]