Class: Bio::Velvet::Graph::NodeArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bio-velvet/graph.rb

Overview

A container class for a list of Node objects. Can index with 1-offset IDs, so that they line up with the identifiers in velvet Graph files, yet respond sensibly to NodeArray#length, etc.

Instance Method Summary collapse

Constructor Details

#initializeNodeArray

Returns a new instance of NodeArray.



283
284
285
286
# File 'lib/bio-velvet/graph.rb', line 283

def initialize
  # Internal index is required because when things get deleted stuff changes.
  @internal_structure = {}
end

Instance Method Details

#[](node_id) ⇒ Object



292
293
294
# File 'lib/bio-velvet/graph.rb', line 292

def [](node_id)
  @internal_structure[node_id]
end

#[]=(node_id, value) ⇒ Object



288
289
290
# File 'lib/bio-velvet/graph.rb', line 288

def []=(node_id, value)
  @internal_structure[node_id] = value
end

#delete(node) ⇒ Object



296
297
298
# File 'lib/bio-velvet/graph.rb', line 296

def delete(node)
  @internal_structure.delete node.node_id
end

#each(&block) ⇒ Object



304
305
306
307
308
# File 'lib/bio-velvet/graph.rb', line 304

def each(&block)
  @internal_structure.each do |internal_id, node|
    block.yield node
  end
end

#lengthObject



300
301
302
# File 'lib/bio-velvet/graph.rb', line 300

def length
  @internal_structure.length
end