To stupid to find good parameters for a pretty tree

119 views
Skip to first unread message

Tony Hei

unread,
Aug 12, 2013, 6:54:24 AM8/12/13
to eteto...@googlegroups.com
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")








28plants_060id_LINERTs_MUSCLEcrop_example_tree.newick
plantLINEs_Tony.pdf

Jaime Huerta Cepas

unread,
Aug 12, 2013, 7:35:31 AM8/12/13
to eteto...@googlegroups.com
Hi tony, the problem with branch lengths is due to the format of your newick tree. some symbols like ": ( [ ] ) " are not allowed to be part of node names (quotation marks have no effect). The parser is somehow reading part of the node name as the branch length. I have edited your file and replaces : by _, so now the tree looks nicer.

cheers,
J


--
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+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

28plants_060id_LINERTs_MUSCLEcrop_example_tree.newick
tony.py
mytree.png

Tony Hei

unread,
Aug 12, 2013, 3:28:13 PM8/12/13
to eteto...@googlegroups.com
Hello!

Wow! Thank you so much, this is awesome! I would have never guessed that this was the reason! I have been really frustrated, but now I can happily go to bed!

And thank you for the script, it works really well! I changed the part with the internal nodes as you have indicated and now it does exactly what I want it to do!

All the best,

Tony


Reply all
Reply to author
Forward
0 new messages