Class: Bio::Velvet::Graph::ArcArray
- Inherits:
-
Object
- Object
- Bio::Velvet::Graph::ArcArray
- Includes:
- Enumerable
- Defined in:
- lib/bio-velvet/graph.rb
Instance Method Summary collapse
- #delete(arc) ⇒ Object
- #each(&block) ⇒ Object
-
#get_arcs_by_node_id(node_id1, node_id2 = nil) ⇒ Object
Return all arcs into or out of the given node_id, or.
-
#initialize ⇒ ArcArray
constructor
A new instance of ArcArray.
- #length ⇒ Object
- #push(arc) ⇒ Object
Constructor Details
#initialize ⇒ ArcArray
Returns a new instance of ArcArray.
311 312 313 314 315 |
# File 'lib/bio-velvet/graph.rb', line 311 def initialize # Internal structure is hash of [node_id1, node_id2] => Array of arcs @internal_structure = {} @node_to_keys = {} end |
Instance Method Details
#delete(arc) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/bio-velvet/graph.rb', line 347 def delete(arc) key = [arc.begin_node_id, arc.end_node_id].sort @internal_structure[key].delete arc # If there is no other arcs with this same key, clean up more if @internal_structure[key].empty? @internal_structure.delete key @node_to_keys[key[0]].delete key @node_to_keys[key[1]].delete key @node_to_keys[key[0]] = nil if @node_to_keys[key[0]].nil? or @node_to_keys[key[0]].empty? @node_to_keys[key[1]] = nil if @node_to_keys[key[1]].nil? or @node_to_keys[key[1]].empty? end end |
#each(&block) ⇒ Object
364 365 366 367 368 369 370 |
# File 'lib/bio-velvet/graph.rb', line 364 def each(&block) @internal_structure.each do |internal_id, arcs| arcs.each do |arc| block.yield arc end end end |
#get_arcs_by_node_id(node_id1, node_id2 = nil) ⇒ Object
Return all arcs into or out of the given node_id, or
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/bio-velvet/graph.rb', line 330 def get_arcs_by_node_id(node_id1, node_id2=nil) if node_id2.nil? next_keys = @node_to_keys[node_id1] return [] if next_keys.nil? next_keys.uniq.collect do |key| @internal_structure[key] end.flatten else to_return = @internal_structure[[node_id1, node_id2].sort] if to_return.nil? return [] else return to_return end end end |
#length ⇒ Object
360 361 362 |
# File 'lib/bio-velvet/graph.rb', line 360 def length @internal_structure.values.flatten.length end |
#push(arc) ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/bio-velvet/graph.rb', line 317 def push(arc) key = [arc.begin_node_id, arc.end_node_id].sort @internal_structure[key] ||= [] @internal_structure[key].push arc @node_to_keys[arc.begin_node_id] ||= [] @node_to_keys[arc.begin_node_id].push key unless arc.begin_node_id == arc.end_node_id @node_to_keys[arc.end_node_id] ||= [] @node_to_keys[arc.end_node_id].push key end end |