def test(self): # Text faces I = TreeImage() I.mode = "rect" I.aligned_header.add_face(self.headerF, 0) I.aligned_header.add_face(self.headerF, 1) I.aligned_header.add_face(self.headerF, 2) I.aligned_header.add_face(self.headerF, 3) I.aligned_foot.add_face(self.footF, 0) I.aligned_foot.add_face(self.footF, 1) I.aligned_foot.add_face(self.footF, 2) I.aligned_foot.add_face(self.footF, 3) I.draw_aligned_faces_as_grid = True t = Tree() t.dist = 0 t.populate(10) style = NodeStyleDict() style["fgcolor"] = "#ff0000" style["size"] = 20 style.add_fixed_face(self.fixedF, "branch-right", 0) t.img_style = style t.render("./test.svg", layout=mylayout, tree_style=I) t.show(mylayout, tree_style=I) t.show(mylayout2, tree_style=I)
def get_example_tree(): # Create a random tree and add to each leaf a random set of motifs # from the original set t = Tree() t.populate(10) # for l in t.iter_leaves(): # seq_motifs = [list(m) for m in motifs] #sample(motifs, randint(2, len(motifs))) # seqFace = SeqMotifFace(seq, seq_motifs, intermotif_format="line", # seqtail_format="compactseq", scale_factor=1) # seqFace.margin_bottom = 4 # f = l.add_face(seqFace, 0, "aligned") ts = TreeStyle() ts.layout_fn = layout t.show(tree_style=ts) return t, ts
for i, name in enumerate(set(node.get_leaf_names())): if i > 0 and i % 2 == 0: col += 1 # Add the corresponding face to the node if name.startswith("Dme"): faces.add_face_to_node(flyFace, node, column=col) elif name.startswith("Dre"): faces.add_face_to_node(fishFace, node, column=col) elif name.startswith("Mms"): faces.add_face_to_node(mouseFace, node, column=col) elif name.startswith("Ptr"): faces.add_face_to_node(chimpFace, node, column=col) elif name.startswith("Hsa"): faces.add_face_to_node(humanFace, node, column=col) elif name.startswith("Cfa"): faces.add_face_to_node(dogFace, node, column=col) # Modifies this node's style node.img_style["size"] = 16 node.img_style["shape"] = "sphere" node.img_style["fgcolor"] = "#AA0000" # If leaf is "Hsa" (h**o sapiens), highlight it using a # different background. if node.is_leaf() and node.name.startswith("Hsa"): node.img_style["bgcolor"] = "#9db0cf" # And, finally, Visualize the tree using my own layout function t.show(mylayout)
import sys from ete_dev import Tree, faces, TreeStyle, COLOR_SCHEMES sys.path.insert(0, "./") def layout(node): if node.is_leaf(): F= faces.PieChartFace([10,10,10,10,10,10,10,10,10,4,6], colors=COLOR_SCHEMES["set3"], width=100, height=100) F.border.width = None F.opacity = 0.8 faces.add_face_to_node(F,node, 0, position="branch-right") F.background.color = "indianred" x = faces.TextFace("hola") faces.add_face_to_node(x,node, 1, position="branch-right") x.background.color = "blue" else: F= faces.BarChartFace([40,20,70,100,30,40,50,40,70,12], min_value=0, colors=COLOR_SCHEMES["spectral"]) faces.add_face_to_node(F,node, 0, position="branch-top") t = Tree() ts = TreeStyle() ts.layout_fn = layout ts.mode = "r" ts.show_leaf_name = False t.populate(10) t.show(tree_style=ts)
col = 0 for i, name in enumerate(set(node.get_leaf_names())): if i>0 and i%2 == 0: col += 1 # Add the corresponding face to the node if name.startswith("Dme"): faces.add_face_to_node(flyFace, node, column=col) elif name.startswith("Dre"): faces.add_face_to_node(fishFace, node, column=col) elif name.startswith("Mms"): faces.add_face_to_node(mouseFace, node, column=col) elif name.startswith("Ptr"): faces.add_face_to_node(chimpFace, node, column=col) elif name.startswith("Hsa"): faces.add_face_to_node(humanFace, node, column=col) elif name.startswith("Cfa"): faces.add_face_to_node(dogFace, node, column=col) # Modifies this node's style node.img_style["size"] = 16 node.img_style["shape"] = "sphere" node.img_style["fgcolor"] = "#AA0000" # If leaf is "Hsa" (h**o sapiens), highlight it using a # different background. if node.is_leaf() and node.name.startswith("Hsa"): node.img_style["bgcolor"] = "#9db0cf" # And, finally, Visualize the tree using my own layout function t.show(mylayout)
aligned_c0_r0 = TextFace("aligned_col0_row0") aligned_c0_r1 = TextFace("aligned_col0_row1") aligned_c1_r0 = TextFace("aligned_col1_row0") aligned_c1_r1 = TextFace("aligned_col1_row1") t.add_face(right_c0_r1, column=1, position="branch-right") t.add_face(right_c0_r0, column=0, position="branch-right") t.add_face(right_c1_r2, column=2, position="branch-right") t.add_face(right_c1_r1, column=1, position="branch-right") t.add_face(right_c1_r0, column=0, position="branch-right") t.add_face(top_c0_r1, column=1, position="branch-top") t.add_face(top_c0_r0, column=0, position="branch-top") t.add_face(bottom_c0_r0, column=0, position="branch-bottom") t.add_face(bottom_c1_r0, column=1, position="branch-bottom") for leaf in t.iter_leaves(): leaf.add_face(aligned_c0_r1, 0, "aligned") leaf.add_face(aligned_c0_r0, 0, "aligned") leaf.add_face(aligned_c1_r1, 0, "aligned") leaf.add_face(aligned_c1_r0, 0, "aligned") t.show()
global CONT if CONT >= len(chars): CONT = 0 if node.is_leaf(): node.img_style["size"] = 0 F2= AttrFace("name", tight_text=True) F= TextFace(chars[CONT], tight_text=True) F.inner_border.width = 0 F2.inner_border.width = 0 #faces.add_face_to_node(F ,node, 0, position="branch-right") faces.add_face_to_node(F2 ,node, 1, position="branch-right") CONT += 1 t = Tree() t.populate(20, random_branches=True) ts = TreeStyle() ts.layout_fn = layout ts.mode = "c" ts.show_leaf_name = False temp_tface = TreeFace(t, ts) n = main_tree.add_child() n.add_face(temp_tface, 0, "aligned") # MAIN TREE ms = TreeStyle() ms.mode = "r" ms.show_leaf_name = False main_tree.show(tree_style=ms)
#node.img_style["bgcolor"] = random_color() #Tree().show() ts = TreeStyle() ts.mode = "c" ts.layout_fn = layout ts.show_leaf_name = False ts.arc_span = 340 ts.arc_start = -70 #ts.allow_face_overlap = True #ts.show_branch_length = True ts.draw_guiding_lines = False ts.optimal_scale_level = "mid" ts.extra_branch_line_color = "red" ts.root_opening_factor = 0.50 ts.show_border = True ts.scale = None t = Tree() t.populate(200, random_branches=True, branch_range=(0, 0)) t.dist = 0.0 dists = [n.dist for n in t.traverse() if n.dist != 0] #print max(dists), min(dists) t.write(outfile="test.nw") #for s in [5, None]: # ts.scale = s # t.render("img_scale_%s.png" %s, tree_style = ts, w=600) t.show(tree_style=ts)
t.add_face(fixed, column=1, position="branch-right") # Bind the precomputed style to the root node # ETE 2.1 has now support for general image properties I = TreeStyle() # You can add faces to the tree image (without any node # associated). They will be used as headers and foot notes of the # aligned columns (aligned faces) I.aligned_header.add_face(t1, column = 0) I.aligned_header.add_face(t1, 1) I.aligned_header.add_face(t1, 2) I.aligned_header.add_face(t1, 3) t1.hz_align = 1 # 0 left, 1 center, 2 right t1.border.width = 1 I.aligned_foot.add_face(t2, column = 0) I.aligned_foot.add_face(t2, 1) I.aligned_foot.add_face(t2, 2) I.aligned_foot.add_face(t2, 3) t2.hz_align = 1 # Set tree image style. Note that aligned header and foot is only # visible in "rect" mode. I.mode = "r" #(rectangular) I.tree_width= 50 t.show(mylayout, tree_style=I)
motifs = [ # seq.start, seq.end, shape, width, height, fgcolor, bgcolor [120, 130, ">", 34, 13, "black", "red", None], [145, 150, "<", 60, 5, "black", "green", None], [10, 30, "o", 100, 10, "black", "rgradient:blue", None], [20, 50, "[]", 100, 10, "blue", "pink", None], [55, 80, "()", 100, 10, "blue", "rgradient:purple", None], [160, 170, "^", 50, 14, "black", "yellow", None], [172, 180, "v", 20, 12, "black", "rgradient:orange", None], [185, 190, "o", 12, 12, "black", "brown", None], [198, 200, "<>", 15, 15, "black", "rgradient:gold", None], [210, 240, "compactseq", 2, 10, None, None, None], [300, 320, "seq", 10, 10, None, None, None], [340, 350, "<>", 15, 15, "black", "rgradient:black", None], ] # Show usage help for SeqMotifFace print SeqMotifFace.__doc__ # Create a random tree and add to each leaf a random set of motifs # from the original set t = Tree() t.populate(40) for l in t.iter_leaves(): seq_motifs = sample(motifs, randint(2, len(motifs))) seqFace = SeqMotifFace(seq, seq_motifs, intermotif_format="line", seqtail_format="compactseq") seqFace.margin_bottom = 4 f = l.add_face(seqFace, 0, "aligned") t.show()
I.aligned_foot.add_face(faces.TextFace("FO1"), 1) I.aligned_foot.add_face(faces.TextFace("FO1"), 2) I.aligned_foot.add_face(faces.TextFace("F1"), 3) I.aligned_foot.add_face(faces.TextFace("FO1"), 4) I.legend.add_face(faces.CircleFace(30, random_color(), "sphere"), 0) I.legend.add_face(faces.CircleFace(30, random_color(), "sphere"), 0) I.legend.add_face(faces.TextFace("HOLA"), 1) I.legend.add_face(faces.TextFace("HOLA"), 1) # Creates a random tree with 10 leaves t2 = Tree() t2.populate(10) # Creates a fixed NodeStyle object containing a TreeFace (A tree image # as a face within another tree image) # t.add_face(faces.TreeFace(t2, I), "branch-right", 0) # Attach the fixed style to the first child of the root node # t.children[0].img_style = style I.rotation = 90 I.mode = "c" t.show(tree_style=I) #t.render("/home/jhuerta/test.svg", img_properties=I) #t.render("/home/jhuerta/test.pdf", img_properties=I) #t.render("/home/jhuerta/test.png", img_properties=I) #t.render("/home/jhuerta/test.ps", img_properties=I) #os.system("inkscape /home/jhuerta/test.svg") #I.mode = "c" #t.show(img_properties=I)
I.aligned_foot.add_face( faces.TextFace("FO1"), 2 ) I.aligned_foot.add_face( faces.TextFace("F1"), 3 ) I.aligned_foot.add_face( faces.TextFace("FO1"), 4 ) I.legend.add_face(faces.CircleFace(30, random_color(), "sphere"), 0) I.legend.add_face(faces.CircleFace(30, random_color(), "sphere"), 0) I.legend.add_face(faces.TextFace("HOLA"), 1) I.legend.add_face(faces.TextFace("HOLA"), 1) # Creates a random tree with 10 leaves t2 = Tree() t2.populate(10) # Creates a fixed NodeStyle object containing a TreeFace (A tree image # as a face within another tree image) # t.add_face(faces.TreeFace(t2, I), "branch-right", 0) # Attach the fixed style to the first child of the root node # t.children[0].img_style = style I.rotation = 90 I.mode = "c" t.show(tree_style=I) #t.render("/home/jhuerta/test.svg", img_properties=I) #t.render("/home/jhuerta/test.pdf", img_properties=I) #t.render("/home/jhuerta/test.png", img_properties=I) #t.render("/home/jhuerta/test.ps", img_properties=I) #os.system("inkscape /home/jhuerta/test.svg") #I.mode = "c" #t.show(img_properties=I)