How To Plot An Unrooted Tree With Flexible Changes Of Leaf Node Size?
3
2
Entering edit mode
11.3 years ago
ajingnk ▴ 130

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?

http://www.thesgc.org/sites/default/files/firstHumanTree_0.png

tree graph • 6.6k views
ADD COMMENT
4
Entering edit mode
11.3 years ago
jhc ★ 3.0k

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. http://stackoverflow.com/questions/9364609/converting-ndarray-generated-by-hcluster-into-a-newick-string-for-use-with-ete2/17657426#17657426

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()
    else:
       node.img_style["size"] = 0

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

# For very large trees, avoid t.show 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 COMMENT
3
Entering edit mode
11.3 years ago
Josh Herr 5.8k

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 COMMENT
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 1967 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6