Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.Pathway.Rep.MultiGraph.MultiGraph Class Reference

List of all members.

Public Member Functions

def __init__
def __eq__
def __ne__
def __repr__
def __str__
def add_node
def add_edge
def child_edges
def children
def edges
def labels
def nodes
def parent_edges
def parents
def remove_node
def remove_edge

Private Attributes

 _adjacency_list
 _label_map

Detailed Description

A directed multigraph abstraction with labeled edges.

Definition at line 9 of file MultiGraph.py.


Constructor & Destructor Documentation

def Bio.Pathway.Rep.MultiGraph.MultiGraph.__init__ (   self,
  nodes = [] 
)
Initializes a new MultiGraph object.

Definition at line 12 of file MultiGraph.py.

00012 
00013     def __init__(self, nodes = []):
00014         """Initializes a new MultiGraph object."""
00015         self._adjacency_list = {}    # maps parent -> set of (child, label) pairs
00016         for n in nodes:
00017             self._adjacency_list[n] = set()
00018         self._label_map = {}         # maps label -> set of (parent, child) pairs


Member Function Documentation

Returns true if g is equal to this graph.

Definition at line 19 of file MultiGraph.py.

00019 
00020     def __eq__(self, g):
00021         """Returns true if g is equal to this graph."""
00022         return isinstance(g, MultiGraph) and \
00023                (self._adjacency_list == g._adjacency_list) and \
00024                (self._label_map == g._label_map)

Here is the caller graph for this function:

Returns true if g is not equal to this graph.

Definition at line 25 of file MultiGraph.py.

00025 
00026     def __ne__(self, g):
00027         """Returns true if g is not equal to this graph."""
00028         return not self.__eq__(g)

Here is the call graph for this function:

Returns an unique string representation of this graph.

Definition at line 29 of file MultiGraph.py.

00029 
00030     def __repr__(self):
00031         """Returns an unique string representation of this graph."""
00032         s = "<MultiGraph: "
00033         keys = sorted(self._adjacency_list.keys())
00034         for key in keys:
00035             values = sorted(self._adjacency_list[key])
00036             s += "(" + repr(key) + ": " + ",".join(map(repr, values)) + ")" 
00037         return s + ">"

Returns a concise string description of this graph.

Definition at line 38 of file MultiGraph.py.

00038 
00039     def __str__(self):
00040         """Returns a concise string description of this graph."""
00041         nodenum = len(self._adjacency_list)
00042         edgenum = reduce(lambda x,y: x+y,
00043                          map(len, self._adjacency_list.values()))
00044         labelnum = len(self._label_map)
00045         return "<MultiGraph: " + \
00046                str(nodenum) + " node(s), " + \
00047                str(edgenum) + " edge(s), " + \
00048                str(labelnum) + " unique label(s)>"

def Bio.Pathway.Rep.MultiGraph.MultiGraph.add_edge (   self,
  source,
  to,
  label = None 
)
Adds an edge to this graph.

Definition at line 54 of file MultiGraph.py.

00054 
00055     def add_edge(self, source, to, label = None):
00056         """Adds an edge to this graph."""
00057         if source not in self._adjacency_list:
00058             raise ValueError("Unknown <from> node: " + str(source))
00059         if to not in self._adjacency_list:
00060             raise ValueError("Unknown <to> node: " + str(to))
00061         edge = (to, label)
00062         self._adjacency_list[source].add(edge)
00063         if label not in self._label_map:
00064             self._label_map[label] = set()
00065         self._label_map[label].add((source,to))

Adds a node to this graph.

Definition at line 49 of file MultiGraph.py.

00049 
00050     def add_node(self, node):
00051         """Adds a node to this graph."""
00052         if node not in self._adjacency_list:
00053             self._adjacency_list[node] = set()

Returns a list of (child, label) pairs for parent.

Definition at line 66 of file MultiGraph.py.

00066 
00067     def child_edges(self, parent):
00068         """Returns a list of (child, label) pairs for parent."""
00069         if parent not in self._adjacency_list:
00070             raise ValueError("Unknown <parent> node: " + str(parent))
00071         return sorted(self._adjacency_list[parent])

Here is the caller graph for this function:

def Bio.Pathway.Rep.MultiGraph.MultiGraph.children (   self,
  parent 
)
Returns a list of unique children for parent.

Definition at line 72 of file MultiGraph.py.

00072 
00073     def children(self, parent):
00074         """Returns a list of unique children for parent."""
00075         return sorted(set([x[0] for x in self.child_edges(parent)]))

Here is the call graph for this function:

def Bio.Pathway.Rep.MultiGraph.MultiGraph.edges (   self,
  label 
)
Returns a list of all the edges with this label.

Definition at line 76 of file MultiGraph.py.

00076 
00077     def edges(self, label):
00078         """Returns a list of all the edges with this label."""
00079         if label not in self._label_map:
00080             raise ValueError("Unknown label: " + str(label))
00081         return sorted(self._label_map[label])

Returns a list of all the edge labels in this graph.

Definition at line 82 of file MultiGraph.py.

00082 
00083     def labels(self):
00084         """Returns a list of all the edge labels in this graph."""
00085         return self._label_map.keys()

Returns a list of the nodes in this graph.

Definition at line 86 of file MultiGraph.py.

00086 
00087     def nodes(self):
00088         """Returns a list of the nodes in this graph."""
00089         return self._adjacency_list.keys()

Returns a list of (parent, label) pairs for child.

Definition at line 90 of file MultiGraph.py.

00090 
00091     def parent_edges(self, child):
00092         """Returns a list of (parent, label) pairs for child."""
00093         if child not in self._adjacency_list:
00094             raise ValueError("Unknown <child> node: " + str(child))
00095         parents = []
00096         for parent, children in self._adjacency_list.iteritems():
00097             for x in children:
00098                 if x[0] is child:
00099                     parents.append((parent, x[1]))
00100         return sorted(parents)

Here is the caller graph for this function:

def Bio.Pathway.Rep.MultiGraph.MultiGraph.parents (   self,
  child 
)
Returns a list of unique parents for child.

Definition at line 101 of file MultiGraph.py.

00101 
00102     def parents(self, child):
00103         """Returns a list of unique parents for child."""
00104         return sorted(set([x[0] for x in self.parent_edges(child)]))

Here is the call graph for this function:

def Bio.Pathway.Rep.MultiGraph.MultiGraph.remove_edge (   self,
  parent,
  child,
  label 
)
Removes edge. -- NOT IMPLEMENTED

Definition at line 125 of file MultiGraph.py.

00125 
00126     def remove_edge(self, parent, child, label):
00127         """Removes edge. -- NOT IMPLEMENTED"""
00128         # hm , this is a multigraph - how should this be implemented?
00129         raise NotImplementedError("remove_edge is not yet implemented")
00130 
00131 # auxilliary graph functions

Removes node and all edges connected to it.

Definition at line 105 of file MultiGraph.py.

00105 
00106     def remove_node(self, node):
00107         """Removes node and all edges connected to it."""
00108         if node not in self._adjacency_list:
00109             raise ValueError("Unknown node: " + str(node))
00110         # remove node (and all out-edges) from adjacency list
00111         del self._adjacency_list[node]
00112         # remove all in-edges from adjacency list
00113         for n in self._adjacency_list:
00114             self._adjacency_list[n] = set(x for x in self._adjacency_list[n] \
00115                                           if x[0] is not node)
00116         # remove all refering pairs in label map
00117         for label in self._label_map.keys():
00118             lm = set(x for x in self._label_map[label] \
00119                      if (x[0] is not node) and (x[1] is not node))
00120             # remove the entry completely if the label is now unused
00121             if lm:
00122                 self._label_map[label] = lm
00123             else:
00124                 del self._label_map[label]


Member Data Documentation

Definition at line 14 of file MultiGraph.py.

Definition at line 17 of file MultiGraph.py.


The documentation for this class was generated from the following file: