[Biopython] Phylo.draw_graphviz(tree) not showing node names

Jan Zaucha Jan.Zaucha at bristol.ac.uk
Tue Jan 27 15:48:29 UTC 2015


Hi Eric,

This is brilliant, the problem is solved on the linux, and I'm totally
happy with that (as can get on with my work :) ), but please be advised
that this seems to have created some issue the matplotlib mac OSX backend
doesn't like:

on mac OSX pylab.show() yields:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/artist.pyc
in draw_wrapper(artist, renderer, *args, **kwargs)
     57     def draw_wrapper(artist, renderer, *args, **kwargs):
     58         before(artist, renderer)
---> 59         draw(artist, renderer, *args, **kwargs)
     60         after(artist, renderer)
     61

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/figure.pyc
in draw(self, renderer)
   1077         dsu.sort(key=itemgetter(0))
   1078         for zorder, a, func, args in dsu:
-> 1079             func(*args)
   1080
   1081         renderer.close_group('figure')

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/artist.pyc
in draw_wrapper(artist, renderer, *args, **kwargs)
     57     def draw_wrapper(artist, renderer, *args, **kwargs):
     58         before(artist, renderer)
---> 59         draw(artist, renderer, *args, **kwargs)
     60         after(artist, renderer)
     61

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc
in draw(self, renderer, inframe)
   2090
   2091         for zorder, a in dsu:
-> 2092             a.draw(renderer)
   2093
   2094         renderer.close_group('axes')

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/artist.pyc
in draw_wrapper(artist, renderer, *args, **kwargs)
     57     def draw_wrapper(artist, renderer, *args, **kwargs):
     58         before(artist, renderer)
---> 59         draw(artist, renderer, *args, **kwargs)
     60         after(artist, renderer)
     61

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/text.pyc
in draw(self, renderer)
    536         renderer.open_group('text', self.get_gid())
    537
--> 538         bbox, info, descent = self._get_layout(renderer)
    539         trans = self.get_transform()
    540

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/text.pyc
in _get_layout(self, renderer)
    309         tmp, lp_h, lp_bl =
renderer.get_text_width_height_descent('lp',
    310
 self._fontproperties,
--> 311
 ismath=False)
    312         offsety = (lp_h - lp_bl) * self._linespacing
    313

/Users/janzaucha/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.pyc
in get_text_width_height_descent(self, s, prop, ismath)
    164         size = self.points_to_pixels(points)
    165         width, height, descent =
self.gc.get_text_width_height_descent(
--> 166             six.text_type(s), family, size, weight, style)
    167         return  width, height, 0.0*descent
    168

Best wishes,
Jan Zaucha

On 26 January 2015 at 21:06, Eric Talevich <eric.talevich at gmail.com> wrote:

> 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
>>
>
>


-- 
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/20150127/f334f2c9/attachment.html>


More information about the Biopython mailing list