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.



280
281
282
283
# File 'lib/bio-velvet/graph.rb', line 280

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

Instance Method Details

#[](node_id) ⇒ Object



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

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

#[]=(node_id, value) ⇒ Object



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

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

#delete(node) ⇒ Object



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

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

#each(&block) ⇒ Object



301
302
303
304
305
# File 'lib/bio-velvet/graph.rb', line 301

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

#lengthObject



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

def length
  @internal_structure.length
end