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)
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 ts = TreeStyle() ts.layout_fn = mylayout t.render("img_faces.png", w=600, tree_style = ts)
# Center text according to masterItem size tw = text.boundingRect().width() th = text.boundingRect().height() center = masterItem.boundingRect().center() text.setPos(center.x()-tw/2, center.y()-th/2) return masterItem def master_ly(node): if node.is_leaf(): # Create an ItemFAce. First argument must be the pointer to # the constructor function that returns a QGraphicsItem. It # will be used to draw the Face. Next arguments are arbitrary, # and they will be forwarded to the constructor Face function. F = faces.DynamicItemFace(ugly_name_face, 100, 50) faces.add_face_to_node(F, node, 0, position="aligned") t = Tree() t.populate(8, reuse_names=False) ts = TreeStyle() ts.layout_fn = master_ly ts.title.add_face(faces.TextFace("Drawing your own Qt Faces", fsize=15), 0) t.render("item_faces.png", h=400, tree_style=ts) # The interactive features are only available using the GUI t.show(tree_style=ts)
style1["fgcolor"] = "#0f0f0f" style1["size"] = 0 style1["vt_line_color"] = "#ff0000" style1["hz_line_color"] = "#ff0000" style1["vt_line_width"] = 2 style1["hz_line_width"] = 2 style1["vt_line_type"] = 2 # 0 solid, 1 dashed, 2 dotted style1["hz_line_type"] = 2 t.children[0].img_style = style1 t.children[1].img_style = style1 # Set dashed blue lines in all leaves style2 = NodeStyle() style2["fgcolor"] = "#000000" style2["shape"] = "circle" style2["vt_line_color"] = "#0000aa" style2["hz_line_color"] = "#0000aa" style2["vt_line_width"] = 2 style2["hz_line_width"] = 2 style2["vt_line_type"] = 1 # 0 solid, 1 dashed, 2 dotted style2["hz_line_type"] = 1 for l in t.iter_leaves(): l.img_style = style2 ts = TreeStyle() ts.layout_fn = layout ts.show_leaf_name = False t.render("node_style.png", w=400, tree_style=ts)
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 ts = TreeStyle() ts.layout_fn = mylayout t.render("img_faces.png", w=600, tree_style=ts)
T.opacity = 0.8 # And place as a float face over the tree faces.add_face_to_node(T, node, 1, position="aligned") # Random tree t = Tree() t.populate(20, random_branches=True) # Some random features in all nodes for n in t.traverse(): n.add_features(weight=random.randint(0, 50)) # Create an empty TreeStyle ts = TreeStyle() # Set our custom layout function ts.layout_fn = layout # Draw a tree ts.mode = "c" # We will add node names manually ts.show_leaf_name = False # Show branch data ts.show_branch_length = True ts.show_branch_support = True t.render("tree_faces.png", w=600, dpi=300, tree_style=ts) t.show(tree_style=ts)
from ete_dev import Tree t = Tree() # Generate a random tree with 50 leaves t.populate(50) # Render tree in png and pdf format using the default size t.render("./random_tree.png") t.render("./random_tree.pdf") # Render tree in pdf setting a custom width. height will be imputed t.render("./random_tree.pdf", w=300) # Render tree in pdf setting a custom height. Width will be imputed t.render("./random_tree.pdf", h=600) # Render tree in pdf setting a custom width and height t.render("./random_tree.pdf", w=300, h=300)
t.add_face(bottom_c0_r0, column=0, position="branch-bottom") t.add_face(bottom_c0_r1, column=0, position="branch-bottom") a = t&"a" a.set_style(NodeStyle()) a.img_style["bgcolor"] = "lightgreen" b = t&"b" b.set_style(NodeStyle()) b.img_style["bgcolor"] = "indianred" c = t&"c" c.set_style(NodeStyle()) c.img_style["bgcolor"] = "lightblue" t.set_style(NodeStyle()) t.img_style["bgcolor"] = "lavender" t.img_style["size"] = 12 for leaf in t.iter_leaves(): leaf.img_style["size"] = 12 leaf.add_face(right_c0_r0, 0, "branch-right") leaf.add_face(aligned_c0_r1, 0, "aligned") leaf.add_face(aligned_c0_r0, 0, "aligned") leaf.add_face(aligned_c1_r1, 1, "aligned") leaf.add_face(aligned_c1_r0, 1, "aligned") ts = TreeStyle() ts.show_scale = False t.render("face_positions.png", w=800, tree_style=ts)
], [160, 170, "^", 50, 14, "black", "yellow", None], [172, 180, "v", 20, 12, "black", "rgradient:orange", None], [185, 190, "o", 12, 12, "black", "brown", "Arial|12|white|Domain"], [198, 200, "<>", 15, 15, "black", "rgradient:gold", None], [210, 240, "compactseq", 2, 10, None, None, None], [300, 320, "seq", 20, 20, None, None, "Courier|10|red|TestName"], [ 340, 350, "<>", 15, 15, "black", "rgradient:black", "Arial|12|black|HOLASEQ" ], ] # Create a random tree and add to each leaf a random set of motifs # from the original set t = Tree() t.populate(20) for l in t.iter_leaves(): # For each leaf, we create a random list of motifs from the original list. seq_motifs = sample(motifs, randint(2, len(motifs))) # And we add it as a Sequence Motif Face. seqFace = SeqMotifFace(seq, seq_motifs, intermotif_format="line", seqtail_format="compactseq") seqFace.margin_bottom = 4 f = l.add_face(seqFace, 0, "aligned") t.render("seq_motif_faces.png", w=1000) #t.show()
# n.size = (10, 10) # n2.size = (10, 70) # n3.size = (40, 40) # n4.size = (10, 10) #n2.size = 10 #n3.size = 10 #n5.size = 10 #n2.dist = 0.1 #n2.size = 1 #n3.size = 1 #n2.dist = 0.5 #t.populate(100)#, random_branches=True) #t.write(outfile="test.nw") ts.layout_fn = layout2 t.show(tree_style=ts) ts.scale = 1 sys.exit() t.show(tree_style=ts) for x in xrange(30): t = Tree() t.dist = 0 t.populate(100, random_branches=True) t.render("/tmp/kk.png", tree_style=ts) sys.exit() ts.layout_fn = layout t.show(tree_style=ts) ts.mode = "r" t.show(tree_style=ts)
C.opacity = 0.3 # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float") # Random tree t = Tree() t.populate(20, random_branches=True) # Some random features in all nodes for n in t.traverse(): n.add_features(weight=random.randint(0, 50)) # Create an empty TreeStyle ts = TreeStyle() # Set our custom layout function ts.layout_fn = layout # Draw a tree ts.mode = "c" # We will add node names manually ts.show_leaf_name = False # Show branch data ts.show_branch_length = True ts.show_branch_support = True t.render("bubble_map.png", w=600, dpi=300, tree_style=ts) # t.show(tree_style=ts)
# n4.size = (10, 10) #n2.size = 10 #n3.size = 10 #n5.size = 10 #n2.dist = 0.1 #n2.size = 1 #n3.size = 1 #n2.dist = 0.5 #t.populate(100)#, random_branches=True) #t.write(outfile="test.nw") ts.layout_fn = layout2 t.show(tree_style=ts) ts.scale = 1 sys.exit() t.show(tree_style=ts) for x in xrange(30): t = Tree() t.dist = 0 t.populate(100, random_branches=True) t.render("/tmp/kk.png", tree_style=ts) sys.exit() ts.layout_fn = layout t.show(tree_style=ts) ts.mode = "r" t.show(tree_style=ts)
# Set dashed blue lines in all leaves nst1 = NodeStyle() nst1["bgcolor"] = "LightSteelBlue" nst2 = NodeStyle() nst2["bgcolor"] = "Moccasin" nst3 = NodeStyle() nst3["bgcolor"] = "DarkSeaGreen" nst4 = NodeStyle() nst4["bgcolor"] = "Khaki" t = Tree("((((a1,a2),a3), ((b1,b2),(b3,b4))), ((c1,c2),c3));") n1 = t.get_common_ancestor("a1", "a2", "a3") n1.set_style(nst1) n2 = t.get_common_ancestor("b1", "b2", "b3", "b4") n2.set_style(nst2) n3 = t.get_common_ancestor("c1", "c2", "c3") n3.set_style(nst3) n4 = t.get_common_ancestor("b3", "b4") n4.set_style(nst4) ts = TreeStyle() ts.layout_fn = layout ts.show_leaf_name = False ts.mode = "c" t.render("node_background.png", w=400, tree_style=ts) t.show(tree_style=ts)