Method: Bio::Tree#path

Defined in:
lib/bio/tree.rb

#path(node1, node2) ⇒ Object

Gets path from node1 to node2. Retruns an array of nodes, including node1 and node2. If node1 and/or node2 do not exist, IndexError is raised. If node1 and node2 are not connected, NoPathError is raised. The result is unspecified for cyclic trees.

Raises:

  • (IndexError)


588
589
590
591
592
593
594
595
596
597
# File 'lib/bio/tree.rb', line 588

def path(node1, node2)
  raise IndexError, 'node1 not found' unless @pathway.graph[node1]
  raise IndexError, 'node2 not found' unless @pathway.graph[node2]
  return [ node1 ] if node1 == node2
  step, path = @pathway.bfs_shortest_path(node1, node2)
  unless path[0] == node1 and path[-1] == node2 then
    raise NoPathError, 'node1 and node2 are not connected'
  end
  path
end