Hello!
I really like the idea of programming the trees. However, in the moment, I feel tremendously stupid since I cannot get ETE to do what I want. I try to format the newick tree in the attachment to something remotely similar as in the pdf.
First of all, I want to get rid of the "circles". If I use node["size"] = 0, all branches automatically get the length 0.
If I try to scale the branch length with TS.scale = 100 (I tried several orders of magnitude), The tree loses its height completely. ???
If I show the scale, instead of 0.2 or something, it computes 38000000. ?
It basically sums down to the fact, that I am unable to find the right values for the tree to look only remotely similar to what I want it to look like.
Can you provide me with a pointer to what I might change?
All the best!
Here is my code:
from ete2 import Tree, faces, AttrFace, TreeStyle, NodeStyle, TextFace
def treestyledef():
TS = TreeStyle()
TS.mode = "r" #rectangular
TS.root_opening_factor = 0.75
#TS.min_leaf_separation = 100 # pixels
#TS.extra_branch_line_type = 0 # 0=solid, 1=dashed, 2=dotted
TS.show_scale = True
TS.show_leaf_name = False
TS.scale = 38000000
TS.optimal_scale_level = "mid"
TS.show_leaf_name = False
#TS.force_topology = True
return TS
def nodestyledef(plant, PlantLib):
node = NodeStyle()
node["fgcolor"] = PlantLib[plant]
node["shape"] = "circle"
node["size"] = 1
#node.opacity = 0
node["vt_line_color"] = PlantLib[plant]
node["hz_line_color"] = PlantLib[plant]
node["vt_line_width"] = 0
node["hz_line_width"] = 0
node["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted
node["hz_line_type"] = 0
return node
def PlantLibraryColors():
PlantLib = {}
PlantLib["Aco"] = "Red"
PlantLib["Ara"] = "LightCoral"
PlantLib["Brapa"] = "LightSalmon"
PlantLib["Bdist"] = "LimeGreen"
PlantLib["Cpapa"] = "HotPink"
PlantLib["Gmax"] = "DeepPink"
PlantLib["Malus"] = "OrangeRed"
PlantLib["Mimulus"] = "DarkOrange"
PlantLib["Mtrun"] = "DarkKhaki"
PlantLib["Osati"] = "SeaGreen"
PlantLib["Ptrich"] = "BlueViolet"
PlantLib["Slyco"] = "Purple"
PlantLib["Sphureja"] = "Indigo"
PlantLib["Tcacao"] = "SaddleBrown"
PlantLib["Vvini"] = "DarkBlue"
PlantLib["zm"] = "DarkGreen"
PlantLib["Musa"] = "Lime"
PlantLib["Pdacty"] = "LightGreen"
PlantLib["Picabi"] = "DarkCyan"
PlantLib["Ptaeda"] = "MediumAquamarine"
PlantLib["Bvulg"] = "DarkRed"
PlantLib["Taesti"] = "Olive"
PlantLib["Turu"] = "OliveDrab"
PlantLib["Dmel"] = "Black"
PlantLib["Drerio"] = "Black"
PlantLib["hs"] = "Black"
PlantLib["Mumu"] = "Black"
PlantLib["Bmori"] = "Black"
PlantLib["none"] = "Black"
return PlantLib
t = Tree("28plants_060id_LINERTs_MUSCLEcrop_example_tree.newick")
#t = Tree("28plants_060id_LINERTs_MUSCLEcrop_tree.newick")
PlantLib = PlantLibraryColors()
# Colors all nodes black
for node_p in t.traverse("postorder"):
node = nodestyledef("none", PlantLib)
node_p.img_style = node
# Colors the nodes according to plant species of the leaves
for key in PlantLib:
node = nodestyledef(key, PlantLib)
for node_p in t.traverse("postorder"):
length = 0
for leaf in node_p.iter_leaves():
length += 1
count = 0
for leaf in node_p.iter_leaves():
if key in leaf.name:
leaf.img_style = node
count += 1
if count == length:
#node_p.set_style = node
node_p.img_style = node
name = leaf.name.strip("'").split('|')[0]
font = TextFace(name)
font.fgcolor = PlantLib[key]
font.fsize = 6
font.ftype = "Consolas"
TS = treestyledef()
t.show(tree_style=TS)
#t.render("mytree.png", w=600, tree_style=TS, units="dpi")