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