Rectangle as NodeStyle shape in ete2

271 Views Asked by At

I would like to create my own layout for dendrogram in ete2. I have very specific needs to customize the tree node by node (i.e every node has different style etc..)

Is it possible to set the shape of node as rectangle (I found circle, square and sphere as options)? I would like to set the length and height manually for every node.

Also, do you have any experience with ete2. Does it have any limitations for customization? It seems like a good tool for visualizing trees, but I want to create somewhat a more 'special' layout.

Thanks in advance,

L.

1

There are 1 best solutions below

0
On

only filledRects are supported via NodeStyle. However, you can get the same effect and more control by adding a RectFace in branch-right position to the nodes. Many other configurations are available. For example:

from ete2 import Tree, RectFace, TreeStyle, AttrFace
tree = Tree()
tree.populate(10)

# Disable auto tip names
ts = TreeStyle()
ts.show_leaf_name = False

for node in tree.traverse():
    # disable default node shapes
    node.img_style["size"] = 0
    # add a custom rect shapes to nodes
    rectF = RectFace(10, 10, "blue", "white")
    rectF.margin_right = 5
    node.add_face(rectF, column=0, position="branch-right")

    # Add tip names in a custom position
    if node.is_leaf():
        nameF = AttrFace("name", fsize=10, fgcolor="slateGrey")
        node.add_face(nameF, column=1, position="branch-right")

tree.show(tree_style=ts)

ETE custom tree