Back to index

python-biopython  1.60
Classes | Functions
Bio.Pathway.Rep.MultiGraph Namespace Reference

Classes

class  MultiGraph

Functions

def df_search
def bf_search

Function Documentation

def Bio.Pathway.Rep.MultiGraph.bf_search (   graph,
  root = None 
)
Breadth first search of g.

Returns a list of all nodes that can be reached from the root node
in breadth-first order.

If root is not given, the search will be rooted at an arbitrary node.

Definition at line 158 of file MultiGraph.py.

00158 
00159 def bf_search(graph, root = None):
00160     """Breadth first search of g.
00161 
00162     Returns a list of all nodes that can be reached from the root node
00163     in breadth-first order.
00164 
00165     If root is not given, the search will be rooted at an arbitrary node.
00166     """
00167     seen = {}
00168     search = []
00169     if len(graph.nodes()) < 1:
00170         return search
00171     if root is None:
00172         root = (graph.nodes())[0]
00173     seen[root] = 1
00174     search.append(root)
00175     current = graph.children(root)
00176     while len(current) > 0:
00177         node = current[0]
00178         current = current[1:]
00179         if node not in seen:
00180             search.append(node)
00181             seen[node] = 1
00182             current.extend(graph.children(node))
00183     return search
00184 
def Bio.Pathway.Rep.MultiGraph.df_search (   graph,
  root = None 
)
Depth first search of g.

Returns a list of all nodes that can be reached from the root node
in depth-first order.

If root is not given, the search will be rooted at an arbitrary node.

Definition at line 132 of file MultiGraph.py.

00132 
00133 def df_search(graph, root = None):
00134     """Depth first search of g.
00135 
00136     Returns a list of all nodes that can be reached from the root node
00137     in depth-first order.
00138 
00139     If root is not given, the search will be rooted at an arbitrary node.
00140     """
00141     seen = {}
00142     search = []
00143     if len(graph.nodes()) < 1:
00144         return search
00145     if root is None:
00146         root = (graph.nodes())[0]
00147     seen[root] = 1
00148     search.append(root)
00149     current = graph.children(root)
00150     while len(current) > 0:
00151         node = current[0]
00152         current = current[1:]
00153         if node not in seen:
00154             search.append(node)
00155             seen[node] = 1
00156             current = graph.children(node) + current
00157     return search