Class | Bio::RestrictionEnzyme::DoubleStranded::CutLocationPair |
In: |
lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb
|
Parent: | Array |
Stores a single cut location pair in 0-based index notation for use with DoubleStranded enzyme sequences.
complement | [R] | Location of the cut on the complementary strand. Corresponds - or ‘pairs’ - to the primary cut. A value of nil is an explicit representation of ‘no cut’. |
primary | [R] | Location of the cut on the primary strand. Corresponds - or ‘pairs’ - to the complement cut. A value of nil is an explicit representation of ‘no cut’. |
CutLocationPair constructor.
Stores a single cut location pair in 0-based index notation for use with DoubleStranded enzyme sequences.
Example:
clp = CutLocationPair.new(3,2) clp.primary # 3 clp.complement # 2
Arguments
Returns: | nothing |
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 47 47: def initialize( *pair ) 48: a = b = nil 49: 50: if pair[0].kind_of? Array 51: a,b = init_with_array( pair[0] ) 52: 53: # no idea why this barfs without the second half during test/runner.rb 54: # are there two Range objects running around? 55: elsif pair[0].kind_of? Range or (pair[0].class.to_s == 'Range') 56: #elsif pair[0].kind_of? Range 57: a,b = init_with_array( [pair[0].first, pair[0].last] ) 58: 59: elsif pair[0].kind_of? Integer or pair[0].kind_of? NilClass 60: a,b = init_with_array( [pair[0], pair[1]] ) 61: 62: else 63: raise ArgumentError, "#{pair[0].class} is an invalid class type to initalize CutLocationPair." 64: end 65: 66: super( [a,b] ) 67: @primary = a 68: @complement = b 69: return 70: end
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 76 76: def init_with_array( ary ) 77: validate_1(ary) 78: a = ary.shift 79: ary.empty? ? b = nil : b = ary.shift 80: validate_2(a,b) 81: [a,b] 82: end
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 84 84: def validate_1( ary ) 85: unless ary.size == 1 or ary.size == 2 86: raise ArgumentError, "Must be one or two elements." 87: end 88: end
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 90 90: def validate_2( a, b ) 91: if (a != nil and a < 0) or (b != nil and b < 0) 92: raise ArgumentError, "0-based index notation only. Negative values are illegal." 93: end 94: 95: if a == nil and b == nil 96: raise ArgumentError, "Neither strand has a cut. Ambiguous." 97: end 98: end