I have a big phylogeny and would like to color the branches to easily detect clusters in my data. Something like what is depicted in phylogeny1.png. Notice that the branches are colored until the most recent common ancestor shared by individuals in the same cluster. The rest of the tree is plotted in black and I would like to keep that characteristic.
I was working upon an old example published in this same forum (https://groups.google.com/forum/#!topic/etetoolkit/6Ceb4Mlmj5w), in which the tips of the tree are coloured, but didn't went to far. Is it possible to do such thing with ETE? To go from Tree1 (code included below) to Tree2?
#!/bin/python3
from ete3 import Tree, TreeStyle, NodeStyle, AttrFace
# init colors, note capitals: http://etetoolkit.org/docs/latest/reference/reference_treeview.html#color-names
colors = {'a':'Red', 'b':'Green', 'c':'Green', 'd':'Green', 'e':'Orange', 'f':'LightGreen'}
# init a newick string
newick = "(a:0.2,(b:0.1,((c:0.8,d:0.4),(e:0.5,f:0.1))));"
# init a tree
t = Tree(newick)
# iterate over tree leaves only
for l in t.iter_leaves():
# create a new label with a color attribute
N = AttrFace("name", fgcolor=colors[l.name])
# label margins
N.margin_top = N.margin_bottom = N.margin_left = 4.0
# labels aligned to the same level
l.add_face(N, 1, position='aligned')
# optionally colorize nodes too
ns = NodeStyle()
ns["fgcolor"] = colors[l.name]
l.img_style = ns
# init tree style
ts = TreeStyle()
# remove default labels
ts.show_leaf_name = False
# render image on notebook
t.render("plot1.png", tree_style=ts)
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to eteto...@googlegroups.com.
Visit this group at https://groups.google.com/group/etetoolkit.
For more options, visit https://groups.google.com/d/optout.