Question: How To Plot An Unrooted Tree With Flexible Changes Of Leaf Node Size?
gravatar for ajingnk
7.2 years ago by
United States
ajingnk130 wrote:

I have a distance matrix for a set of elements. Each element has an attribute size represents the size of a family of proteins or chemicals.

How to plot an unrooted tree with different leaf size or leaf node size? So, I can represent the size of each element as the size of node.

I have checked scipy (dendrogram), NetworkX/GraphVis (too flexible, I need to write code to generate the tree first and then generate the DOT file).

My purpose is relatively simple: a nice unrooted tree from distance matrix with different size of leaf node. But, I have 5000 nodes, so Photoshop is not feasible. Hope there is a simple way to do it. Any suggestion?

Probably, I can get the structure of tree first, and then somehow convert it into a network format and display the network in Cytoscape.

========================another relevant question===============================

I have another relevant question. How do they plot the tree in the link? Is there any existing tool for this plot?

tree graph • 4.7k views
ADD COMMENTlink modified 7.1 years ago • written 7.2 years ago by ajingnk130
gravatar for jhc
7.2 years ago by
jhc2.9k wrote:

You could use ETE to control how different nodes in a tree are drawn.

Load a tree and create your own layout function to control how different nodes should be shown. That's the general idea (see example) and is up to you how different nodes are branches should be drawn. They problem may come with huge trees. I have tested the example with a random 5000 tips tree, and ETE will be able to generate the SVG in few seconds, however you will need quite a lot memory and CPU to handle a vector-graphics document like the one generated.

The ETE GUI will also open the image, but performance could be very bad depending on your system. PNG on the other hand cannot be used to store such a big image, so you will need to scale it to something smaller.

In summary, ETE will help you to draw your trees in a programmatic way, but consider also the possibility of collapsing nodes, or split your tree into smaller partitions if you plan to spend some time inspecting very large topologies. ETE can also help you with that, since you can generate independent tree pictures for different clusters within the same tree, search and traverse node at your convenience, etc.

Also, here you have a little recipe about how to run a clustering analysis using hcluster and convert the result into an ETE tree.

Hope it helps

leaf size example example:

from ete2 import Tree, TreeStyle, random_color
import random

def my_layout(node):
    if node.is_leaf():
       node.img_style["size"] = random.randint(4, 30)
       node.img_style["shape"] = "sphere" 
       node.img_style["fgcolor"] = random_color()
       node.img_style["size"] = 0

t = Tree()
t.dist = 0
ts = TreeStyle()
ts.mode = "c" # circular
ts.show_leaf_name = True
ts.layout_fn = my_layout

# For very large trees, avoid and use SVG rendering
# t.populate(5000)
# t.render("mytree.svg", tree_style=ts)
# PNG will require fixing image dimensions
# t.render("mytree.svg", tree_style=ts, w=15000, units="px")
ADD COMMENTlink written 7.2 years ago by jhc2.9k
gravatar for Josh Herr
7.2 years ago by
Josh Herr5.7k
University of Nebraska
Josh Herr5.7k wrote:

I guess you mean "leaf" and "leaf node" to represent your terminal branches?

There are numerous programs to help you with this, but if you use python I would suggest ETE for drawing the kind of tree that you want.

ADD COMMENTlink written 7.2 years ago by Josh Herr5.7k

Yes, I use python. ETE looks like a lot what I want. So, for each branch, ETE can generate the size for all children branches?

ADD REPLYlink written 7.2 years ago by ajingnk130
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 777 users visited in the last hour