etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
792 stars 214 forks source link

PhyloTree node style not rendering #218

Open ConstantinoSchillebeeckx opened 8 years ago

ConstantinoSchillebeeckx commented 8 years ago

Following the example in the documentation found here, but with a PhyloTree object instead of a Tree:

from ete3 import Tree, NodeStyle, TreeStyle, PhyloTree
t = PhyloTree( "((a,b),c);" ) # <-----

# Basic tree style
ts = TreeStyle()
ts.show_leaf_name = True

# Draws nodes as small red spheres of diameter equal to 10 pixels
nstyle = NodeStyle()
nstyle["shape"] = "sphere"
nstyle["size"] = 10
nstyle["fgcolor"] = "darkred"

# Gray dashed branch lines
nstyle["hz_line_type"] = 1
nstyle["hz_line_color"] = "#cccccc"

t.set_style(nstyle)

# Applies the same static style to all nodes in the tree. Note that,
# if "nstyle" is modified, changes will affect to all nodes
for n in t.traverse():
    n.set_style(nstyle)

t.render('/tmp/moo.svg', tree_style=ts)

Generates the following (notice the nodes are not darkred spheres & leaf names are rendered twice) moo

jhcepas commented 8 years ago

you are right. This is a problem with the automatic layout function assignment in PhyloTree objects. A possible workaround while this is being fixed:

ts.layout_fn = lambda x: None
t.render('/tmp/moo.svg', tree_style=ts)