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 48 48: def initialize( *pair ) 49: a = b = nil 50: 51: if pair[0].kind_of? Array 52: a,b = init_with_array( pair[0] ) 53: 54: # no idea why this barfs without the second half during test/runner.rb 55: # are there two Range objects running around? 56: elsif pair[0].kind_of? Range or (pair[0].class.to_s == 'Range') 57: #elsif pair[0].kind_of? Range 58: a,b = init_with_array( [pair[0].first, pair[0].last] ) 59: 60: elsif pair[0].kind_of? Integer or pair[0].kind_of? NilClass 61: a,b = init_with_array( [pair[0], pair[1]] ) 62: 63: else 64: raise ArgumentError, "#{pair[0].class} is an invalid class type to initalize CutLocationPair." 65: end 66: 67: super( [a,b] ) 68: @primary = a 69: @complement = b 70: return 71: end
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 77 77: def init_with_array( ary ) 78: validate_1(ary) 79: a = ary.shift 80: ary.empty? ? b = nil : b = ary.shift 81: validate_2(a,b) 82: [a,b] 83: end
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 85 85: def validate_1( ary ) 86: unless ary.size == 1 or ary.size == 2 87: raise ArgumentError, "Must be one or two elements." 88: end 89: end
# File lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb, line 91 91: def validate_2( a, b ) 92: if (a != nil and a < 0) or (b != nil and b < 0) 93: raise ArgumentError, "0-based index notation only. Negative values are illegal." 94: end 95: 96: if a == nil and b == nil 97: raise ArgumentError, "Neither strand has a cut. Ambiguous." 98: end 99: end