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(): # 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 return t, ts
def get_example_tree(): # sample sequence and a list of example motif types seq = "LHGRISQQVEQSRSQVQAIGEKVSLAQAKIEKIKGSKKAIKVFSSAKYPAPERLQEYGSIFTDAQDPGLQRRPRHRIQSKQRPLDERALQEKLKDFPVCVSTKPEPEDDAEEGLGGLPSNISSVSSLLLFNTTENLYKKYVFLDPLAGAVTKTHVMLGAETEEKLFDAPLSISKREQLEQQVPENYFYVPDLGQVPEIDVPSYLPDLPGIANDLMYIADLGPGIAPSAPGTIPELPTFHTEVAEPLKVGELGSGMGAGPGTPAHTPSSLDTPHFVFQTYKMGAPPLPPSTAAPVGQGARQDDSSSSASPSVQGAPREVVDPSGGWATLLESIRQAGGIGKAKLRSMKERKLEKQQQKEQEQVRATSQGGHLMSDLFNKLVMRRKGISGKGPGAGDGPGGAFARVSDSIPPLPPPQQPQAEDEDDWES" motifs = [ # seq.start, seq.end, shape, width, height, fgcolor, bgcolor [10, 100, "[]", None, 10, "black", "rgradient:blue", "arial|8|white|domain Name"], [110, 150, "o", None, 10, "blue", "pink", None], [155, 180, "()", None, 10, "blue", "rgradient:purple", None], [160, 170, "^", None, 14, "black", "yellow", None], [172, 180, "v", None, 12, "black", "rgradient:orange", None], [185, 190, "o", None, 12, "black", "brown", None], [198, 200, "<>", None, 15, "black", "rgradient:gold", None], [210, 240, "compactseq", 2, 10, None, None, None], [300, 320, "seq", 10, 10, None, None, None], [310, 345, "<>", None, 15, "black", "rgradient:black", None], ] # 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") return t, TreeStyle()
def get_example_tree(): t = Tree() ts = TreeStyle() ts.layout_fn = layout ts.mode = "r" ts.show_leaf_name = False t.populate(10) return t, ts
def get_example_tree(): 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) return t, ts
def get_example_tree(): t = Tree() t.populate(10) ts = TreeStyle() ts.rotation = 45 ts.show_leaf_name = False ts.layout_fn = rotation_layout return t, ts
def get_example_tree(): t = Tree() ts = TreeStyle() ts.layout_fn = layout ts.mode = "c" ts.show_leaf_name = True ts.min_leaf_separation = 15 t.populate(100) return t, ts
def get_example_tree(): t = Tree() t.populate(8) # Node style handling is no longer limited to layout functions. You # can now create fixed node styles and use them many times, save them # or even add them to nodes before drawing (this allows to save and # reproduce an tree image design) # Set bold red branch to the root node style = NodeStyle() style["fgcolor"] = "#0f0f0f" style["size"] = 0 style["vt_line_color"] = "#ff0000" style["hz_line_color"] = "#ff0000" style["vt_line_width"] = 8 style["hz_line_width"] = 8 style["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted style["hz_line_type"] = 0 t.set_style(style) #Set dotted red lines to the first two branches style1 = NodeStyle() 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 return t, ts
def layout(node): if node.is_leaf(): # Add node name to laef nodes N = AttrFace("name", fsize=14, fgcolor="black") faces.add_face_to_node(N, node, 0) t = Tree() t.populate(10) T = TreeFace(t, small_ts) # Let's make the sphere transparent T.opacity = 0.8 # And place as a float face over the tree faces.add_face_to_node(T, node, 1, position="aligned")
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
def get_example_tree(): # sample sequence and a list of example motif types seq = "LHGRISQQVEQSRSQVQAIGEKVSLAQAKIEKIKGSKKAIKVFSSAKYPAPERLQEYGSIFTDAQDPGLQRRPRHRIQSKQRPLDERALQEKLKDFPVCVSTKPEPEDDAEEGLGGLPSNISSVSSLLLFNTTENLYKKYVFLDPLAGAVTKTHVMLGAETEEKLFDAPLSISKREQLEQQVPENYFYVPDLGQVPEIDVPSYLPDLPGIANDLMYIADLGPGIAPSAPGTIPELPTFHTEVAEPLKVGELGSGMGAGPGTPAHTPSSLDTPHFVFQTYKMGAPPLPPSTAAPVGQGARQDDSSSSASPSVQGAPREVVDPSGGWATLLESIRQAGGIGKAKLRSMKERKLEKQQQKEQEQVRATSQGGHLMSDLFNKLVMRRKGISGKGPGAGDGPGGAFARVSDSIPPLPPPQQPQAEDEDDWES" motifs = [ # seq.start, seq.end, shape, width, height, fgcolor, bgcolor [ 10, 100, "[]", None, 10, "black", "rgradient:blue", "arial|8|white|domain Name" ], [110, 150, "o", None, 10, "blue", "pink", None], [155, 180, "()", None, 10, "blue", "rgradient:purple", None], [160, 170, "^", None, 14, "black", "yellow", None], [172, 180, "v", None, 12, "black", "rgradient:orange", None], [185, 190, "o", None, 12, "black", "brown", None], [198, 200, "<>", None, 15, "black", "rgradient:gold", None], [210, 240, "compactseq", 2, 10, None, None, None], [300, 320, "seq", 10, 10, None, None, None], [310, 345, "<>", None, 15, "black", "rgradient:black", None], ] # 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") return t, TreeStyle()
import time from ete_dev import Tree # Creates a random tree with 10,000 leaf nodes tree = Tree() tree.populate(10000) # This code should be faster t1 = time.time() for leaf in tree.iter_leaves(): if "aw" in leaf.name: print "found a match:", leaf.name, break print "Iterating: ellapsed time:", time.time() - t1 # This slower t1 = time.time() for leaf in tree.get_leaves(): if "aw" in leaf.name: print "found a match:", leaf.name, break print "Getting: ellapsed time:", time.time() - t1 # Results in something like: # found a match: guoaw Iterating: ellapsed time: 0.00436091423035 secs # found a match: guoaw Getting: ellapsed time: 0.124316930771 secs
# faces.add_face_to_node(f, node, 0, position="branch-right") f.border.width = 0 # 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)
from ete_dev import Tree, faces, AttrFace, TreeStyle, NodeStyle def layout(node): # If node is a leaf, add the nodes name and a its scientific name if node.is_leaf(): faces.add_face_to_node(AttrFace("name"), node, column=0) t = Tree() t.populate(8) # Node style handling is no longer limited to layout functions. You # can now create fixed node styles and use them many times, save them # or even add them to nodes before drawing (this allows to save and # reproduce an tree image design) # Set bold red branch to the root node style = NodeStyle() style["fgcolor"] = "#0f0f0f" style["size"] = 0 style["vt_line_color"] = "#ff0000" style["hz_line_color"] = "#ff0000" style["vt_line_width"] = 8 style["hz_line_width"] = 8 style["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted style["hz_line_type"] = 0 t.set_style(style) #Set dotted red lines to the first two branches style1 = NodeStyle() style1["fgcolor"] = "#0f0f0f" style1["size"] = 0
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()
# 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)
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)
n = main_tree.add_child() n.add_face(temp_facet, 0, "aligned") t, ts = seq_motif_faces.get_example_tree() temp_facet = TreeFace(t, ts) n = main_tree.add_child() n.add_face(temp_facet, 0, "aligned") t, ts = barchart_and_piechart_faces.get_example_tree() temp_facet = TreeFace(t, ts) n = main_tree.add_child() n.add_face(temp_facet, 0, "aligned") # Test orphan nodes and trees with 0 branch length t, ts = Tree(), TreeStyle() t.populate(5) for n in t.traverse(): n.dist = 0 temp_tface = TreeFace(t, ts) n = main_tree.add_child() n.add_face(temp_tface, 0, "aligned") ts.optimal_scale_level = "full" temp_tface = TreeFace(t, ts) n = main_tree.add_child() n.add_face(temp_tface, 0, "aligned") ts = TreeStyle() t.populate(5) ts.mode = "c" temp_tface = TreeFace(t, ts)
#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)
# 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)
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)
def get_example_tree(): t = Tree() t.populate(10) # Margins, alignment, border, background and opacity can now be set for any face rs1 = faces.TextFace("branch-right\nmargins&borders", fsize=12, fgcolor="#009000") rs1.margin_top = 10 rs1.margin_bottom = 50 rs1.margin_left = 40 rs1.margin_right = 40 rs1.border.width = 1 rs1.background.color = "lightgreen" rs1.inner_border.width = 0 rs1.inner_border.line_style = 1 rs1.inner_border.color = "red" rs1.opacity = 0.6 rs1.hz_align = 2 # 0 left, 1 center, 2 right rs1.vt_align = 1 # 0 left, 1 center, 2 right br1 = faces.TextFace("branch-right1", fsize=12, fgcolor="#009000") br2 = faces.TextFace("branch-right3", fsize=12, fgcolor="#009000") # New face positions (branch-top and branch-bottom) bb = faces.TextFace("branch-bottom 1", fsize=8, fgcolor="#909000") bb2 = faces.TextFace("branch-bottom 2", fsize=8, fgcolor="#909000") bt = faces.TextFace("branch-top 1", fsize=6, fgcolor="#099000") # And faces can also be used as headers or foot notes of aligned # columns t1 = faces.TextFace("Header Face", fsize=12, fgcolor="#aa0000") t2 = faces.TextFace("Footer Face", fsize=12, fgcolor="#0000aa") # Attribute faces can now contain prefix and suffix fixed text aligned = faces.AttrFace("name", fsize=12, fgcolor="RoyalBlue", text_prefix="Aligned (", text_suffix=")") # horizontal and vertical alignment per face aligned.hz_align = 1 # 0 left, 1 center, 2 right aligned.vt_align = 1 # Node style handling is no longer limited to layout functions. You # can now create fixed node styles and use them many times, save them # or even add them to nodes before drawing (this allows to save and # reproduce an tree image design) style = NodeStyle() style["fgcolor"] = "Gold" style["shape"] = "square" style["size"] = 15 style["vt_line_color"] = "#ff0000" t.set_style(style) # add a face to the style. This face will be render in any node # associated to the style. fixed = faces.TextFace("FIXED branch-right", fsize=11, fgcolor="blue") 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 ts = 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) ts.aligned_header.add_face(t1, column=0) ts.aligned_header.add_face(t1, 1) ts.aligned_header.add_face(t1, 2) ts.aligned_header.add_face(t1, 3) t1.hz_align = 1 # 0 left, 1 center, 2 right t1.border.width = 1 ts.aligned_foot.add_face(t2, column=0) ts.aligned_foot.add_face(t2, 1) ts.aligned_foot.add_face(t2, 2) ts.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. ts.mode = "r" ts.scale = 10 for node in t.traverse(): # If node is a leaf, add the nodes name and a its scientific # name if node.is_leaf(): node.add_face(aligned, column=0, position="aligned") node.add_face(aligned, column=1, position="aligned") node.add_face(aligned, column=3, position="aligned") else: node.add_face(bt, column=0, position="branch-top") node.add_face(bb, column=0, position="branch-bottom") node.add_face(bb2, column=0, position="branch-bottom") node.add_face(br1, column=0, position="branch-right") node.add_face(rs1, column=0, position="branch-right") node.add_face(br2, column=0, position="branch-right") return t, 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)
def master_ly(node): random_background(node) sphere_map(node) leaf_name(node) aligned_faces(node) def tiny_ly(node): node.img_style["size"] = 2 node.img_style["shape"] = "square" size = 15 t = Tree() t.populate(size, reuse_names=False) I = TreeStyle() I.mode = "r" I.orientation = 0 I.layout_fn = master_ly I.margin_left = 100 I.margin_right = 50 I.margin_top = 100 I.arc_start = 45 I.arc_span = 360 I.margin_bottom = 50 I.show_border = True I.legend_position = 4 I.title.add_face(faces.TextFace("HOLA MUNDO", fsize=30), 0)
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)
from ete_dev import Tree # generates a random tree t = Tree() t.populate(15) print t # # # /-qogjl # /--------| # | \-vxbgp # | # | /-xyewk #---------| | # | | /-opben # | | | # | | /--------| /-xoryn # \--------| | | /--------| # | | | | | /-wdima # | | \--------| \--------| # | | | \-qxovz # | | | # | | \-isngq # \--------| # | /-neqsc # | | # | | /-waxkv # | /--------| /--------| # | | | /--------| \-djeoh # | | | | | # | | \--------| \-exmsn # \--------| |
], [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()
from ete_dev import Tree # generates a random tree t = Tree(); t.populate(15); print t # # # /-qogjl # /--------| # | \-vxbgp # | # | /-xyewk #---------| | # | | /-opben # | | | # | | /--------| /-xoryn # \--------| | | /--------| # | | | | | /-wdima # | | \--------| \--------| # | | | \-qxovz # | | | # | | \-isngq # \--------| # | /-neqsc # | | # | | /-waxkv # | /--------| /--------| # | | | /--------| \-djeoh # | | | | | # | | \--------| \-exmsn # \--------| |
def get_example_tree(): t = Tree() t.populate(10) # Margins, alignment, border, background and opacity can now be set for any face rs1 = faces.TextFace("branch-right\nmargins&borders", fsize=12, fgcolor="#009000") rs1.margin_top = 10 rs1.margin_bottom = 50 rs1.margin_left = 40 rs1.margin_right = 40 rs1.border.width = 1 rs1.background.color = "lightgreen" rs1.inner_border.width = 0 rs1.inner_border.line_style = 1 rs1.inner_border.color= "red" rs1.opacity = 0.6 rs1.hz_align = 2 # 0 left, 1 center, 2 right rs1.vt_align = 1 # 0 left, 1 center, 2 right br1 = faces.TextFace("branch-right1", fsize=12, fgcolor="#009000") br2 = faces.TextFace("branch-right3", fsize=12, fgcolor="#009000") # New face positions (branch-top and branch-bottom) bb = faces.TextFace("branch-bottom 1", fsize=8, fgcolor="#909000") bb2 = faces.TextFace("branch-bottom 2", fsize=8, fgcolor="#909000") bt = faces.TextFace("branch-top 1", fsize=6, fgcolor="#099000") # And faces can also be used as headers or foot notes of aligned # columns t1 = faces.TextFace("Header Face", fsize=12, fgcolor="#aa0000") t2 = faces.TextFace("Footer Face", fsize=12, fgcolor="#0000aa") # Attribute faces can now contain prefix and suffix fixed text aligned = faces.AttrFace("name", fsize=12, fgcolor="RoyalBlue", text_prefix="Aligned (", text_suffix=")") # horizontal and vertical alignment per face aligned.hz_align = 1 # 0 left, 1 center, 2 right aligned.vt_align = 1 # Node style handling is no longer limited to layout functions. You # can now create fixed node styles and use them many times, save them # or even add them to nodes before drawing (this allows to save and # reproduce an tree image design) style = NodeStyle() style["fgcolor"] = "Gold" style["shape"] = "square" style["size"] = 15 style["vt_line_color"] = "#ff0000" t.set_style(style) # add a face to the style. This face will be render in any node # associated to the style. fixed = faces.TextFace("FIXED branch-right", fsize=11, fgcolor="blue") 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 ts = 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) ts.aligned_header.add_face(t1, column = 0) ts.aligned_header.add_face(t1, 1) ts.aligned_header.add_face(t1, 2) ts.aligned_header.add_face(t1, 3) t1.hz_align = 1 # 0 left, 1 center, 2 right t1.border.width = 1 ts.aligned_foot.add_face(t2, column = 0) ts.aligned_foot.add_face(t2, 1) ts.aligned_foot.add_face(t2, 2) ts.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. ts.mode = "r" ts.scale = 10 for node in t.traverse(): # If node is a leaf, add the nodes name and a its scientific # name if node.is_leaf(): node.add_face(aligned, column=0, position="aligned") node.add_face(aligned, column=1, position="aligned") node.add_face(aligned, column=3, position="aligned") else: node.add_face(bt, column=0, position="branch-top") node.add_face(bb, column=0, position="branch-bottom") node.add_face(bb2, column=0, position="branch-bottom") node.add_face(br1, column=0, position="branch-right") node.add_face(rs1, column=0, position="branch-right") node.add_face(br2, column=0, position="branch-right") return t, ts
import time from ete_dev import Tree # Creates a random tree with 10,000 leaf nodes tree = Tree() tree.populate(10000) # This code should be faster t1 = time.time() for leaf in tree.iter_leaves(): if "aw" in leaf.name: print "found a match:", leaf.name, break print "Iterating: ellapsed time:", time.time()-t1 # This slower t1 = time.time() for leaf in tree.get_leaves(): if "aw" in leaf.name: print "found a match:", leaf.name, break print "Getting: ellapsed time:", time.time()-t1 # Results in something like: # found a match: guoaw Iterating: ellapsed time: 0.00436091423035 secs # found a match: guoaw Getting: ellapsed time: 0.124316930771 secs
faces.add_face_to_node(F, node, i, position="aligned") def master_ly(node): random_background(node) sphere_map(node) leaf_name(node) aligned_faces(node) def tiny_ly(node): node.img_style["size"] = 2 node.img_style["shape"] = "square" size = 15 t = Tree() t.populate(size, reuse_names=False) I = TreeStyle() I.mode = "r" I.orientation = 0 I.layout_fn = master_ly I.margin_left = 100 I.margin_right = 50 I.margin_top = 100 I.arc_start = 45 I.arc_span = 360 I.margin_bottom = 50 I.show_border = True I.legend_position = 4 I.title.add_face(faces.TextFace("HOLA MUNDO", fsize=30), 0)