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

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

Instance Method Summary collapse

Constructor Details

#initialize(graph) ⇒ NodeArray

Returns a new instance of NodeArray.



53
54
55
56
# File 'lib/bio-velvet_underground/graph.rb', line 53

def initialize(graph)
  @graph = graph
  @node_cache = []
end

Instance Method Details

#[](node_id) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/bio-velvet_underground/graph.rb', line 68

def [](node_id)
  cache = @node_cache[node_id]
  return cache unless cache.nil?

  return nil if node_id < 1 or node_id > @graph.internal_graph_struct[:nodeCount]
  pointer = Bio::Velvet::Underground.getNodeInGraph @graph.internal_graph_struct, node_id
  node_struct = Bio::Velvet::Underground::NodeStruct.new pointer
  @node_cache[node_id] = Node.new(@graph, node_struct)
end

#eachObject



58
59
60
61
62
# File 'lib/bio-velvet_underground/graph.rb', line 58

def each
  (1..length).each do |node_id|
    yield self[node_id]
  end
end

#lengthObject



64
65
66
# File 'lib/bio-velvet_underground/graph.rb', line 64

def length
  Bio::Velvet::Underground.nodeCount @graph.internal_graph_struct
end