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, line 27
def self.[](*args)
  a = self.new
  args.each do |elem|
    a.push elem
  end
  a
end
new() click to toggle source

creates a new object

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 36
def initialize
  @data = []
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, 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) click to toggle source

Same usage as Array#<<

# 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) click to toggle source

Same usage as Array#==

Calls superclass method
# 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) click to toggle source

Same usage as Array#[]

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 61
def [](*arg)
  #$stderr.puts "SortedIntArray#[]"
  to_a[*arg]
end
[]=(*arg) click to toggle source

Not implemented

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 67
def []=(*arg)
  raise NotImplementedError, 'DenseIntArray#[]= is not implemented.'
end
concat(ary) click to toggle source

Same usage as Array#concat

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 120
def concat(ary)
  ary.each { |elem| self.<<(elem) }
  self
end
delete(elem) click to toggle source

Same usage as Array#delete

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 180
def delete(elem)
  raise NotImplementedError, 'DenseIntArray#delete is not implemented.'
end
each() { |num| ... } click to toggle source

Same usage as Array#each

# 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() click to toggle source

Same usage as Array#first

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 158
def first
  elem = @data.first
  elem ? elem.first : nil
end
include?(elem) click to toggle source

Same usage as Array#include?

# 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) click to toggle source

initialize copy

Calls superclass method
# 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() click to toggle source

Same usage as Array#last

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 164
def last
  elem = @data.last
  elem ? elem.last : nil
end
length()
Alias for: size
push(*args) click to toggle source

Same usage as Array#push

# 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() { |num| ... } click to toggle source

Same usage as Array#reverse_each

# 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() click to toggle source

Same usage as Array#size

# 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
Also aliased as: length
sort!(&block) click to toggle source

Does nothing

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 185
def sort!(&block)
  # does nothing
  self
end
uniq!() click to toggle source

Does nothing

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 191
def uniq!
  # does nothing
  self
end
unshift(*arg) click to toggle source

Same usage as Array#unshift

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 134
def unshift(*arg)
  raise NotImplementedError, 'DenseIntArray#unshift is not implemented.'
end

Protected Instance Methods

internal_data() click to toggle source

gets internal data object

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 55
def internal_data
  @data
end
internal_data=(a) click to toggle source

sets internal data object

# File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 47
def internal_data=(a)
  #clear_cache
  @data = a
  self
end