class Bio::RestrictionEnzyme::DenseIntArray
a class to store integer numbers, containing many contiguous integral numbers.
Bio::RestrictionEnzyme
internal use only. Please do not create the instance outside Bio::RestrictionEnzyme
.
Constants
- MutableRange
Public Class Methods
[](*args)
click to toggle source
Same usage as Array.[]
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 27 def self.[](*args) 28 a = self.new 29 args.each do |elem| 30 a.push elem 31 end 32 a 33 end
new()
click to toggle source
creates a new object
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 36 def initialize 37 @data = [] 38 end
Public Instance Methods
+(other)
click to toggle source
Same usage as Array#+, but accepts only the same classes instance.
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 88 def +(other) 89 unless other.is_a?(self.class) then 90 raise TypeError, 'unsupported data type' 91 end 92 tmpdata = @data + other.internal_data 93 tmpdata.sort! { |a,b| a.first <=> b.first } 94 result = self.class.new 95 return result if tmpdata.empty? 96 newdata = result.internal_data 97 newdata.push tmpdata[0].dup 98 (1...(tmpdata.size)).each do |i| 99 if (x = newdata[-1].last) >= tmpdata[i].first then 100 newdata[-1].last = tmpdata[i].last if tmpdata[i].last > x 101 else 102 newdata.push tmpdata[i].dup 103 end 104 end 105 result 106 end
<<(elem)
click to toggle source
Same usage as Array#<<
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 139 def <<(elem) 140 if !@data.empty? and 141 @data[-1].last + 1 == elem then 142 @data[-1].last = elem 143 else 144 @data << MutableRange.new(elem, elem) 145 end 146 self 147 end
==(other)
click to toggle source
Same usage as Array#==
Calls superclass method
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 109 def ==(other) 110 if r = super(other) then 111 r 112 elsif other.is_a?(self.class) then 113 other.internal_data == @data 114 else 115 false 116 end 117 end
[](*arg)
click to toggle source
Same usage as Array#[]
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 61 def [](*arg) 62 #$stderr.puts "SortedIntArray#[]" 63 to_a[*arg] 64 end
[]=(*arg)
click to toggle source
Not implemented
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 67 def []=(*arg) 68 raise NotImplementedError, 'DenseIntArray#[]= is not implemented.' 69 end
concat(ary)
click to toggle source
Same usage as Array#concat
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 120 def concat(ary) 121 ary.each { |elem| self.<<(elem) } 122 self 123 end
delete(elem)
click to toggle source
Same usage as Array#delete
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 180 def delete(elem) 181 raise NotImplementedError, 'DenseIntArray#delete is not implemented.' 182 end
each() { |num| ... }
click to toggle source
Same usage as Array#each
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 72 def each 73 @data.each do |elem| 74 elem.first.upto(elem.last) { |num| yield num } 75 end 76 self 77 end
first()
click to toggle source
Same usage as Array#first
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 158 def first 159 elem = @data.first 160 elem ? elem.first : nil 161 end
include?(elem)
click to toggle source
Same usage as Array#include?
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 150 def include?(elem) 151 return false if @data.empty? or elem < self.first or self.last < elem 152 @data.any? do |range| 153 range.first <= elem && elem <= range.last 154 end 155 end
initialize_copy(other)
click to toggle source
initialize copy
Calls superclass method
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 41 def initialize_copy(other) 42 super(other) 43 @data = @data.collect { |elem| elem.dup } 44 end
last()
click to toggle source
Same usage as Array#last
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 164 def last 165 elem = @data.last 166 elem ? elem.last : nil 167 end
push(*args)
click to toggle source
Same usage as Array#push
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 126 def push(*args) 127 args.each do |elem| 128 self.<<(elem) 129 end 130 self 131 end
reverse_each() { |num| ... }
click to toggle source
Same usage as Array#reverse_each
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 80 def reverse_each 81 @data.reverse_each do |elem| 82 elem.last.downto(elem.first) { |num| yield num } 83 end 84 self 85 end
size()
click to toggle source
Same usage as Array#size
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 170 def size 171 sum = 0 172 @data.each do |range| 173 sum += (range.last - range.first + 1) 174 end 175 sum 176 end
Also aliased as: length
sort!(&block)
click to toggle source
Does nothing
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 185 def sort!(&block) 186 # does nothing 187 self 188 end
uniq!()
click to toggle source
Does nothing
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 191 def uniq! 192 # does nothing 193 self 194 end
unshift(*arg)
click to toggle source
Same usage as Array#unshift
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 134 def unshift(*arg) 135 raise NotImplementedError, 'DenseIntArray#unshift is not implemented.' 136 end
Protected Instance Methods
internal_data()
click to toggle source
gets internal data object
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 55 def internal_data 56 @data 57 end
internal_data=(a)
click to toggle source
sets internal data object
# File lib/bio/util/restriction_enzyme/dense_int_array.rb 47 def internal_data=(a) 48 #clear_cache 49 @data = a 50 self 51 end