[Biopython] Phylo.draw_graphviz(tree) not showing node names
Eric Talevich
eric.talevich at gmail.com
Mon Jan 26 21:06:38 UTC 2015
Thanks, Jan, that was helpful for debugging. I pushed a fix to GitHub, so
if you can install the development version of Biopython, it should work for
you now.
The problem was a bug in networkx release 1.9.1 (and maybe others) that
existed between August 2013 and September 2014. The networkx "draw"
function would pass all keywords to "draw_networkx", except that while
"draw_networkx" has a keywords argument "with_labels" that defaults to
True, "draw" would override this to "False" unless it had been specified
explicitly. It has since been fixed in networkx and should be included in
the next release:
https://github.com/networkx/networkx/blame/master/networkx/drawing/nx_pylab.py
On Mon, Jan 26, 2015 at 2:41 AM, Jan Zaucha <Jan.Zaucha at bristol.ac.uk>
wrote:
> Thanks Eric,
>
> I'm using biopython 1.65 and networkx 1.9.1.
>
> When I ran the commands you've proposed I still see the node names
> assigned:
> [Clade(branch_length=2.0, name='foo'), Clade(branch_length=4.0,
> name='bar), Clade(...), ... ]
>
> I'm not sure what the source file format is, I created the tree myself
> from a distance matrix, the examples I was looking at were importing trees
> from PhyloXML. Here's the code I'm running, maybe this will help:
>
> ###################### testing graphviz
> from Bio import Phylo
> from Bio.Phylo.TreeConstruction import _DistanceMatrix
> from Bio.Phylo.TreeConstruction import DistanceTreeConstructor
> import pylab
>
> names = ['foo', 'bar', 'cat', 'dog']
> matrix = [[0], [1, 0], [2, 3, 0], [4, 5, 6, 0]]
> m = _DistanceMatrix(names, matrix)
> constructor = DistanceTreeConstructor()
> tree = constructor.nj(m)
> graph = Phylo.to_networkx(tree)
> print graph.nodes()
> Phylo.draw_graphviz(tree, prog="neato", node_size=50)
> pylab.show()
> ##########################
>
>
> I still don't understand where I'm going wrong.
>
> Best wishes,
> Jan
>
>
> On 23 January 2015 at 16:33, Eric Talevich <eric.talevich at gmail.com>
> wrote:
>
>> Hi Jan,
>>
>> Could you show us some more information about your tree, like the first
>> few lines you see with "print tree"? Also try converting the tree to a
>> NetworkX graph, which is the intermediate form used by draw_graphviz, and
>> inspecting the nodes to see if names were lost or retained:
>>
>> graph = Phylo.to_networkx(tree)
>> graph.nodes()
>>
>> Also:
>>
>> - What was the source file format (e.g. Newick, Nexus, PhyloXML, NeXML)
>> - Which versions of Biopython and NetworkX are you using?
>>
>> It's possible the node names are assigned to a different attribute than
>> the node name, in which case you can use the "label_func" argument in
>> draw_graphviz to retrieve the name from the graph node.
>>
>> Hope that helps,
>> Eric
>>
>>
>>
>> On Thu, Jan 22, 2015 at 8:02 AM, Jan Zaucha <Jan.Zaucha at bristol.ac.uk>
>> wrote:
>>
>>> Hi everyone,
>>>
>>> I'm trying to visualize the trees I generate, but for some reason the
>>> plots do not display the node names. When I print the tree each node has an
>>> associated name (string format). Phylo.draw(tree) also works fine and plots
>>> a tree with the node names.
>>>
>>> I simply use:
>>> Phylo.draw_graphviz(tree)
>>> pylab.show()
>>>
>>> There is no error, I can't work out how to force the node names to be
>>> printed.
>>>
>>> Any ideas?
>>>
>>> Thanks,
>>> Jan Zaucha
>>>
>>> --
>>> Jan Zaucha
>>> Bristol Centre for Complexity Sciences
>>> Computational Genomics Group
>>> University of Bristol
>>>
>>> _______________________________________________
>>> Biopython mailing list - Biopython at mailman.open-bio.org
>>> http://mailman.open-bio.org/mailman/listinfo/biopython
>>>
>>
>>
>
>
> --
> Jan Zaucha
> Bristol Centre for Complexity Sciences
> Computational Genomics Group
> University of Bristol
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20150126/e0854667/attachment-0001.html>
More information about the Biopython
mailing list