test/data/vclamp_jpk/README: Document sample versions
[hooke.git] / hooke / util / graph.py
index 248858572131490fe8de655625fddeb48246c1ce..cecb04509f1ed58701257c4b057f04a67f819928 100644 (file)
@@ -1,20 +1,19 @@
-# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """Define :class:`Graph`, a directed, acyclic graph structure.
 :class:`Graph`\s are composed of :class:`Node`\s, also defined by this
@@ -44,20 +43,20 @@ class Node (list):
 
     We can list all of a node's ancestors.
 
-    >>> print [node for node in d.ancestors()]
+    >>> print([node for node in d.ancestors()])
     [b, c, a]
-    >>> print [node for node in d.ancestors(depth_first=True)]
+    >>> print([node for node in d.ancestors(depth_first=True)])
     [b, a, c]
 
     Ancestors works with cycles.
 
     >>> a.append(d)
-    >>> print [node for node in d.ancestors()]
+    >>> print([node for node in d.ancestors()])
     [b, c, a, d]
 
     We can find the cycle path.
 
-    >>> print d.parent_path(d)
+    >>> print(d.parent_path(d))
     [b, a, d]
 
     After a run through :meth:`Graph.set_children`, we can also
@@ -65,12 +64,12 @@ class Node (list):
 
     >>> g = Graph([a, b, c, d])
     >>> g.set_children()
-    >>> print a.children
+    >>> print(a.children)
     [b, c]
 
     And descendents.
 
-    >>> print [node for node in a.descendents(depth_first=True)]
+    >>> print([node for node in a.descendents(depth_first=True)])
     [b, d, a, c]
     """
     def __init__(self, parents=[], data=None):
@@ -328,7 +327,7 @@ class GraphRowGenerator (list):
         p = GraphRowPrinter(tip_to_root=tip_to_root)
         for node in nodes:
             g.insert(node)
-            print p(g[-1])
+            print(p(g[-1]))
 
     For the split/join branch columns, "born" and "dead" are defined
     from the point of view of `GraphRow`.  For root-to-tip ordering
@@ -404,9 +403,9 @@ class Graph (list):
     >>> n.i.extend([n.f, n.g, n.h])
     >>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
     >>> g.topological_sort(tip_to_root=True)
-    >>> print [node for node in g]
+    >>> print([node for node in g])
     [i, h, g, f, e, d, c, b, a]
-    >>> print g.ascii_graph()
+    >>> print(g.ascii_graph())
     r-\-\ a
     | | * b
     | * | c
@@ -416,7 +415,7 @@ class Graph (list):
     | * | g
     * | | h
     t-/-/ i
-    >>> print g.ascii_graph(tip_to_root=True)
+    >>> print(g.ascii_graph(tip_to_root=True))
     t-\-\ i
     | | * h
     | * | g
@@ -437,7 +436,7 @@ class Graph (list):
     >>> n.g.extend([n.e, n.f])
     >>> n.h.extend([n.c, n.g])
     >>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h])
-    >>> print g.ascii_graph(tip_to_root=True)
+    >>> print(g.ascii_graph(tip_to_root=True))
     t-\ h
     | *-\ g
     | | *-\ f
@@ -453,7 +452,7 @@ class Graph (list):
     ...     nx = getattr(n, char)
     ...     n.i.append(nx)
     >>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
-    >>> print g.ascii_graph(tip_to_root=True)
+    >>> print(g.ascii_graph(tip_to_root=True))
     t-\-\-\-\-\-\-\ i
     | | | | | | | r h
     | | | | | | r g
@@ -470,7 +469,7 @@ class Graph (list):
     ...     nx = getattr(n, char)
     ...     nx.append(n.a)
     >>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
-    >>> print g.ascii_graph(tip_to_root=True)
+    >>> print(g.ascii_graph(tip_to_root=True))
     t i
     | t h
     | | t g
@@ -490,7 +489,7 @@ class Graph (list):
     >>> n.h.extend([n.a, n.c, n.d, n.g])
     >>> n.i.extend([n.a, n.b, n.c, n.g])
     >>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
-    >>> print g.ascii_graph(tip_to_root=True)
+    >>> print(g.ascii_graph(tip_to_root=True))
     t-\-\-\ i
     | | | | t-\-\-\ h
     | | | *-|-|-|-<-\ g