"NoneType" error when draw Phyloxmltree

162 views
Skip to first unread message

zeng...@gmail.com

unread,
May 22, 2015, 4:17:08 AM5/22/15
to eteto...@googlegroups.com
Hi,

I am trying to use ete2 on a toy PhyloXml file, but failed to plot the phylogeny tree. Here is the PhyloXml file (https://github.com/homopolymer/PyroTools/blob/master/wiki/61_otus.phyloxml).

I use the following code to display the tree along with the internal branch labels.
#---begin--
from ete2 import Phyloxml
from ete2 import Tree, TreeStyle, NodeStyle, faces, AttrFace

# load xml file
project = Phyloxml()
project.build_from_file('61_otus.phyloxml')

# get the phylogeny tree
tree=project.get_phylogeny()[0]

# define layout function
def layout(node):
N = AttrFace("name", fsize=14, fgcolor="black")
faces.add_face_to_node(N, node, 0)

# set tree style
ts=TreeStyle()
ts.layout_fn=layout
tree.show(tree_style=ts)
#---finish---

Here are the error messages when running the above script. I don't know what's wrong here. Sincerely appreciate if someone could give a hint or help.

#------------see below--------------------------------
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/coretype/tree.py", line 1335, in show
tree_style=tree_style, win_name=name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/treeview/drawer.py", line 76, in show_tree
tree_item, n2i, n2f = render(t, img)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/treeview/qt4_render.py", line 268, in render
update_node_faces(n, n2f, img)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/treeview/qt4_face_render.py", line 389, in update_node_faces
faceblock[position] = _FaceGroupItem(all_faces, node, as_grid=as_grid)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/treeview/qt4_face_render.py", line 101, in __init__
self.update_columns_size()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/treeview/qt4_face_render.py", line 143, in update_columns_size
width = f._width() + f.margin_right + f.margin_left
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ete2-2.3.1-py2.7.egg/ete2/treeview/faces.py", line 310, in _width
return self.get_bounding_rect().width()
AttributeError: 'NoneType' object has no attribute 'width'

Jaime Huerta Cepas

unread,
May 22, 2015, 4:27:31 AM5/22/15
to eteto...@googlegroups.com
It seems some nodes lack the name property, so it produces the error. I will look into it to provide a better error handling. In the meantime, try adding the AttrFace only to nodes with a non-empty 'name' attribute: 

def layout(node):
         if node.name:
                 N = AttrFace('name', fsize=14, fgcolor="black")
                 faces.add_face_to_node(N, node, 0) 

or use TextFace(node.name, fsize=14, fgcolor='black') instead

hope it helps
-jaime



--
You received this message because you are subscribed to the Google Groups "The ETE toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etetoolkit+...@googlegroups.com.
To post to this group, send email to eteto...@googlegroups.com.
Visit this group at http://groups.google.com/group/etetoolkit.
For more options, visit https://groups.google.com/d/optout.

Feng Zeng

unread,
May 23, 2015, 5:31:32 AM5/23/15
to eteto...@googlegroups.com
Hi Jaime,

Thanks for the help.  It is caused by the empty node label indeed.
Reply all
Reply to author
Forward
0 new messages