[Biopython-dev] [Bug 3134] to_networkx returns weird stuff

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Mon Aug 30 18:01:52 UTC 2010


http://bugzilla.open-bio.org/show_bug.cgi?id=3134





------- Comment #1 from eric.talevich at gmail.com  2010-08-30 14:01 EST -------
(In reply to comment #0)
> Hi,
> 
> I tried to read 
> http://www.phylosoft.org/archaeopteryx/examples/data/multiple_supports.xml 
> and convert it using to_networkx(). Strangely, all nodes in the resulting graph
> are named Clade, and when using networkx.write_dot() I get a file with a single
> clade node, although the number of nodes in the graph object is correct.

Hello,

Yes, that's how it works. The exported graph uses Clade objects as nodes, and
the string representation of unnamed nodes is just the name of the class,
Clade. This should still work OK for most NetworkX operations, but not the
Graphviz-based ones.

The Graphviz-based operations in NetworkX convert the nodes to strings, and
then assumes all identical strings refer to the same node, so you'll get a star
graph whenever the internal nodes are unnamed. For drawing, try Biopython's
Phylo.draw_graphviz instead -- it handles this naming issue safely:

>>> Phylo.draw_graphviz(my_tree, prog='neato')

You can fix the naming issue yourself by assigning unique names to all the
internal clades:

>>> for i, clade in enumerate(my_tree.find_clades()):
...     if not clade.name:
...         clade.name = "Clade_%d" % i

Then networkx.write_dot should work better. Or, if you want to do something
else involving Graphviz layout, you can look at the source for
Phylo.draw_graphviz in the file Bio/Phylo/_utils.py.

Is there anything else you'd like to see built into Bio.Phylo to make these
operations easier?

Thanks,
-Eric


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list