Class: Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation

Inherits:
Array
  • Object
show all
Extended by:
CutSymbol
Includes:
CutSymbol
Defined in:
lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb

Overview

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][-1][2][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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CutSymbol

cut_symbol, escaped_cut_symbol, re_cut_symbol, re_cut_symbol_adjacent, set_cut_symbol

Constructor Details

#initialize(*a) ⇒ CutLocationsInEnzymeNotation

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb', line 58

def initialize(*a)
  a.flatten! # in case an array was passed as an argument

  if a.size == 1 and a[0].kind_of? String and a[0] =~ re_cut_symbol
    # Initialize with a cut symbol pattern such as 'n^ng^arraxt^n'
    s = a[0]
    a = []
    i = -( s.tr(cut_symbol, '') =~ %r{[^n]} )  # First character that's not 'n'
    s.each_byte { |c| (a << i; next) if c.chr == cut_symbol; i += 1 }
    a.collect! { |n| n <= 0 ? n-1 : n } # 0 is not a valid enzyme index, decrement from 0 and all negative
  else
    a.collect! { |n| n.to_i } # Cut locations are always integers
  end

  validate_cut_locations( a )
  super(a)
  self.sort!
  @min = self.first
  @max = self.last
  self.freeze
end

Instance Attribute Details

#maxObject (readonly)

Last cut, in enzyme-index notation



45
46
47
# File 'lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb', line 45

def max
  @max
end

#minObject (readonly)

First cut, in enzyme-index notation



42
43
44
# File 'lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb', line 42

def min
  @min
end

Instance Method Details

#to_array_indexObject

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



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb', line 93

def to_array_index
  return [] if @min == nil
  if @min < 0
    calc = lambda do |n| 
      n -= 1 unless n < 0
      n + @min.abs
    end
  else
    calc = lambda { |n| n - 1 }
  end
  self.collect(&calc)
end