def mylayout(node): # If node is a leaf if node.is_leaf(): # And a line profile faces.add_face_to_node(profileFace, node, 0, aligned=True) node.img_style["size"] = 0 faces.add_face_to_node(nameFace, node, 1, aligned=True) # If node is internal else: # If silhouette is good, creates a green bubble if node.silhouette > 0: validationFace = faces.TextFace("Silh=%0.2f" % node.silhouette, "Verdana", 10, "#056600") node.img_style["fgcolor"] = "#056600" # Otherwise, use red bubbles else: validationFace = faces.TextFace("Silh=%0.2f" % node.silhouette, "Verdana", 10, "#940000") node.img_style["fgcolor"] = "#940000" # Sets node size proportional to the silhouette value. node.img_style["shape"] = "sphere" if node.silhouette <= 1 and node.silhouette >= -1: node.img_style["size"] = 15 + int((abs(node.silhouette) * 10)**2) # If node is very internal, draw also a bar diagram # with the average expression of the partition faces.add_face_to_node(validationFace, node, 0) if len(node) > 100: faces.add_face_to_node(cbarsFace, node, 1)
def ncbi_layout(node): npr_layout(node) global name2color if node.is_leaf(): tax_pos = 10 if hasattr(node, "lineage"): for tax, k in zip(node.lineage, node.named_lineage): f = faces.TextFace("%10s" % k, fsize=15) try: color = name2color[k] except KeyError: name2color[k] = color = treeview.main.random_color() #if hasattr(node, "broken_groups") and tax in node.broken_groups: f.background.color = color faces.add_face_to_node(f, node, tax_pos, position="aligned") tax_pos += 1 f = faces.AttrFace("spname", fsize=15) faces.add_face_to_node(f, node, 10, position="branch-right") else: if getattr(node, "broken_groups", None): for broken in node.broken_groups: f = faces.TextFace(broken, fsize=10, fgcolor="red") faces.add_face_to_node(f, node, 1, position="branch-bottom") if hasattr(node, "changed"): if node.changed == "yes": node.img_style["bgcolor"] = "indianred" else: node.img_style["bgcolor"] = "white"
def layout(node): node.img_style["size"] = 5 node.img_style["hz_line_width"] = 0 node.img_style["vt_line_width"] = 0 if node.is_leaf(): f = faces.AttrFace("name", fgcolor="steelblue", fsize=20) faces.add_face_to_node(f, node, 0, position="aligned") f = faces.AttrFace("name", fsize=15) faces.add_face_to_node(f, node, 0, position="branch-right") else: f = faces.TextFace("uno", fsize=8) for x in xrange(random.randint(1, 5)): faces.add_face_to_node(f, node, 0, position="branch-top") f = faces.TextFace("otromassssssssssss", fsize=8) for x in xrange(random.randint(1, 5)): faces.add_face_to_node(f, node, 0, position="branch-bottom") f = faces.CircleFace(20, "red") f.opacity = 0.3 faces.add_face_to_node(f, node, 0, position="float") f = faces.CircleFace(23, "blue") f.opacity = 0.3 faces.add_face_to_node(f, node, 0, position="float-behind")
def mylayout(node): # If node is a leaf, add the nodes name and a its scientific # name if node.is_leaf(): # Add an static face that handles the node name faces.add_face_to_node(nameFace, node, column=0) # We can also create faces on the fly longNameFace = faces.TextFace(code2name[node.name]) faces.add_face_to_node(longNameFace, node, column=0) # text faces support multiline. We add a text face # with the whole description of each leaf. descFace = faces.TextFace(code2desc[node.name], fsize=10) # Note that this faces is added in "aligned" mode faces.add_face_to_node(descFace, node, column=0, aligned=True) # Sets the style of leaf nodes node.img_style["size"] = 12 node.img_style["shape"] = "circle" #If node is an internal node else: # Sets the style of internal nodes node.img_style["size"] = 6 node.img_style["shape"] = "circle" node.img_style["fgcolor"] = "#000000" # If an internal node contains more than 4 leaves, add the # images of the represented species sorted in columns of 2 # images max. if len(node) >= 4: 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"
def layout(node): node.img_style["size"] = random.randint(5,100) node.img_style["hz_line_width"] = 5 node.img_style["vt_line_width"] = 10 if node.is_leaf(): #node.img_style["size"] = random.randint(50, 50) f = faces.TextFace("alignedFace", fsize=8, fgcolor="blue") #f = faces.AttrFace("name", fsize=random.randint(20,20)) faces.add_face_to_node(f, node, 0, position="aligned") f.border.width = 0 #f = faces.CircleFace(20, "red") #f = faces.AttrFace("name", fsize=20) f = faces.TextFace("NAME", fsize=10) #faces.add_face_to_node(f, node, 0, position="branch-right") f.border.width = 0
def load_model(node, model): ''' supra specia action link to evolutionnary model ''' model = model['loadmodel'] T = node.get_tree_root() model = T._models[model] T.change_dist_to_evol('bL', model, True) if model.properties['typ'] == 'site': model.set_histface(up=False, typ='protamine', lines=[1.0, 0.3], col_lines=['black', 'grey']) I = TreeImageProperties() I.aligned_foot.add_face(model.properties['histface'], 1) application.set_img_properties(I) elif (model.properties['typ'] == 'branch_ancestor'): I = TreeImageProperties() for n in sorted(T.get_descendants() + [T], key=lambda x: x.paml_id): if n.is_leaf(): continue anc_face = faces.SequenceFace(n.sequence, 'aa', fsize=11) I.aligned_foot.add_face(anc_face, 1) I.aligned_foot.add_face( faces.TextFace('paml_id: #%d ' % (n.paml_id), fsize=8), 0) application.set_img_properties(I) else: application.set_img_properties(None)
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 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")
def aligned_faces(node): if node.is_leaf(): for i in xrange(3): F = faces.TextFace("ABCDEFGHIJK"[0:random.randint(1, 11)]) F.border.width = 1 F.border.line_style = 1 F.inner_background.color = "lightgreen" F.border.width = 1 F.inner_border.width = 1 F.background.color = "darkgreen" F.border.width = 2 F.vt_align = random.randint(0, 4) F.hz_align = random.randint(0, 4) F.margin_bottom = random.randint(1, 20) F.margin_right = random.randint(1, 20) F.margin_left = random.randint(1, 20) F.margin_top = random.randint(1, 20) faces.add_face_to_node(F, node, i, position="aligned") if random.randint(0, 1): faces.add_face_to_node(F, node, i, position="aligned")
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
def main_layout(node): ''' Main layout function. It controls what is shown in tree images. ''' # Add faces to leaf nodes. This allows me to add the faces from # the global variable LEAVE_FACES, which is set by the application # controler according to the arguments passed through the URL. if node.is_leaf(): for f, fkey, pos in LEAVE_FACES: if hasattr(node, fkey): faces.add_face_to_node(f, node, column=pos, position="branch-right") else: # Add special faces on collapsed nodes if hasattr(node, "hide") and int(node.hide) == 1: node.img_style["draw_descendants"] = False collapsed_face = faces.TextFace(\ " %s collapsed leaves." %len(node), \ fsize=10, fgcolor="#444", ftype="Arial") faces.add_face_to_node(collapsed_face, node, 0) else: node.img_style["draw_descendants"] = True # Set node aspect. This controls which node features are used to # control the style of the tree. You can add or modify this # features, as well as their behaviour if node.is_leaf(): node.img_style["shape"] = "square" node.img_style["size"] = 4 else: node.img_style["size"] = 8 node.img_style["shape"] = "sphere" # Evoltype: [D]uplications, [S]peciations or [L]osess. if hasattr(node, "evoltype"): if node.evoltype == 'D': node.img_style["fgcolor"] = "#1d176e" node.img_style["hz_line_color"] = "#1d176e" node.img_style["vt_line_color"] = "#1d176e" elif node.evoltype == 'S': node.img_style["fgcolor"] = "#FF0000" node.img_style["line_color"] = "#FF0000" elif node.evoltype == 'L': node.img_style["fgcolor"] = "#777777" node.img_style["vt_line_color"] = "#777777" node.img_style["hz_line_color"] = "#777777" node.img_style["line_type"] = 1 # If no evolutionary information, set a default style else: node.img_style["fgcolor"] = "#000000" node.img_style["vt_line_color"] = "#000000" node.img_style["hz_line_color"] = "#000000" # Parse node features features and conver them into styles. This # must be done like this, since current ete version does not allow # modifying style outside the layout function. if hasattr(node, "bsize"): node.img_style["size"] = int(node.bsize) if hasattr(node, "shape"): node.img_style["shape"] = node.shape if hasattr(node, "bgcolor"): node.img_style["bgcolor"] = node.bgcolor if hasattr(node, "fgcolor"): node.img_style["fgcolor"] = node.fgcolor
def codeml_clean_layout(node): ''' layout for CodemlTree ''' for f, fkey, pos in LEAVE_FACES: if hasattr(node, fkey): if not (fkey == 'name' and node.name == 'NoName'): if node.is_leaf(): faces.add_face_to_node(f, node, column=pos, position="branch-right") elif fkey == 'species': if node.species != "Unknown": faces.add_face_to_node(faces.TextFace( ' (%s)' % (node.species), fsize=6, fgcolor="#787878"), node, -1, position="branch-bottom") else: faces.add_face_to_node(f, node, column=pos, position="branch-bottom") if hasattr(node, 'dN'): faces.add_face_to_node(faces.TextFace('%.4f' % (node.w), fsize=6, fgcolor="#7D2D2D"), node, 0, position="branch-top") faces.add_face_to_node(faces.TextFace('%.2f/%.2f' % (100 * node.dN, 100 * node.dS), fsize=6, fgcolor="#787878"), node, 0, position="branch-bottom") if not node.is_leaf(): node.img_style["shape"] = "sphere" node.img_style["size"] = 5 # Add special faces on collapsed nodes if hasattr(node, "hide") and int(node.hide) == 1: node.img_style["draw_descendants"] = False collapsed_face = faces.TextFace(\ " %s collapsed leaves." %len(node), \ fsize=10, fgcolor="#444", ftype="Arial") faces.add_face_to_node(collapsed_face, node, 0) else: node.img_style["draw_descendants"] = True else: node.img_style["size"] = 2 node.img_style["shape"] = "square" if hasattr(node, "sequence"): seqface = faces.SequenceFace(node.sequence, "aa", 11) faces.add_face_to_node(seqface, node, 1, aligned=True) leaf_color = "#000000" node.img_style["fgcolor"] = leaf_color if hasattr(node, "bsize"): node.img_style["size"] = int(node.bsize) if hasattr(node, "shape"): node.img_style["shape"] = node.shape if hasattr(node, "bgcolor"): node.img_style["bgcolor"] = node.bgcolor if hasattr(node, "fgcolor"): node.img_style["fgcolor"] = node.fgcolor
from ete_dev import TreeStyle from ete_dev import EvolTree from ete_dev import faces tree = EvolTree("data/S_example/measuring_S_tree.nw") tree.link_to_alignment('data/S_example/alignment_S_measuring_evol.fasta') print tree print '\n Running free-ratio model with calculation of ancestral sequences...' tree.run_model('fb_anc') #tree.link_to_evol_model('/tmp/ete2-codeml/fb_anc/out', 'fb_anc') I = TreeStyle() I.force_topology = False I.draw_aligned_faces_as_table = True I.draw_guiding_lines = True I.guiding_lines_type = 2 I.guiding_lines_color = "#CCCCCC" for n in sorted(tree.get_descendants() + [tree], key=lambda x: x.node_id): if n.is_leaf(): continue anc_face = faces.SequenceFace(n.sequence, 'aa', fsize=10, bg_colors={}) I.aligned_foot.add_face(anc_face, 1) I.aligned_foot.add_face( faces.TextFace('node_id: #%d ' % (n.node_id), fsize=8), 0) print 'display result of bs_anc model, with ancestral amino acid sequences.' tree.show(tree_style=I) print '\nThe End.'
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) I.draw_aligned_faces_as_table = True def test(node): if node.is_leaf(): faces.add_face_to_node(faces.AttrFace("name"), node, 0, position="aligned") I.aligned_header.add_face(faces.TextFace("H1"), 0) I.aligned_header.add_face(faces.TextFace("H1"), 1) I.aligned_header.add_face(faces.TextFace("H1"), 2) I.aligned_header.add_face(faces.TextFace("H1111111111111"), 3)