def layout(node): if node.is_leaf(): pretty_name = names[node.name] if node.name in names else node.name # derp = AttrFace("name", fsize=10, ftype="Arial", fgcolor="black") pretty_name_face = faces.TextFace(pretty_name) pretty_name_face.margin_left = 5 faces.add_face_to_node(pretty_name_face, node, column=0)
def layout(node): ## if node.is_leaf() and 'showname' in node.features: ## # Add node name to laef nodes ## N = AttrFace("name", fsize=14, fgcolor="black") ## faces.add_face_to_node(N, node, 0) if "Rsize" in node.features: # Creates a sphere face whose size is proportional to node's # feature "Rsize" C = CircleFace(radius=node.Rsize * 3, color="RoyalBlue", style="sphere") # make the sphere transparent C.opacity = 0.9 # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float") if "Rpearsize" in node.features: # Creates a sphere face whose size is proportional to node's # feature "Rpearsize" C = CircleFace(radius=node.Rpearsize * 3, color="lightgreen", style="sphere") # make the sphere transparent C.opacity = 0.9 # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float")
def mylayout(node): # Internal Node formatting nstyle = NodeStyle() nstyle["size"] = 0 nstyle["vt_line_width"] = 2 nstyle["hz_line_width"] = 2 if node.is_leaf(): circle_face = CircleFace(10, color_dict[node.name], style='circle') faces.add_face_to_node(circle_face, node, position="branch-right", column=0) text_face = TextFace(meta_dict[node.name][0]) text_face.fgcolor = color_dict[node.name] faces.add_face_to_node(text_face, node, position="branch-right", column=1) node.set_style(nstyle) elif node.is_root(): node.dist = 0 node.set_style(nstyle) else: node.set_style(nstyle)
def my_layout(node): N = None # If user specified labels are specified add these: if 'node_label' in tree_features: for t in tree_features['node_label']: node_attr = ifhasthenget(node, t) if node_attr and to_string(node_attr): if t == 'name' and hasattr(node, 'cl'): continue textface = to_string(node_attr) N = TextFace(textface, fsize=12, fgcolor='black') if 'e-' in textface and to_float( textface ): # Stupid exception because ete3 rendering doesn't understand scientific notation N = TextFace('%2.1e ' % to_float(textface), fsize=12, fgcolor='black') # Add default values: elif not no_default and node.frequency > 1 and not hasattr(node, 'cl'): N = TextFace( node.frequency, fsize=12, fgcolor='black') # Default: use node frequency as TextFace if N is not None: N.rotation = -90 faces.add_face_to_node(N, node, 0, position='branch-top')
def layout(node): """ Helper function to annotate nodes with scientific name :param node: A node instance of a ete3.Tree :return: Annotated node with sci_name """ faces.add_face_to_node(TextFace(node.sci_name), node, 0)
def my_layout(node): style = NodeStyle() style["size"] = 0 style["vt_line_color"] = "#A0A0A0" style["hz_line_color"] = "#A0A0A0" style["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted style["hz_line_type"] = 0 node.set_style(style) if node.is_leaf(): name_face = AttrFace("name", fsize=8, ftype="Times") else: name_face = TextFace(node.name, fsize=18, ftype="Times") if node.node_type == Sum: for child in node.children: label = TextFace(round(child.support, 3), fsize=6) child.add_face(label, column=1, position="branch-bottom") if show_ids: node.add_face(AttrFace("id", fsize=6), column=1, position="branch-top") faces.add_face_to_node(name_face, node, column=1, position="branch-right")
def treeLayout(self, node): if node.is_leaf(): faces.add_face_to_node(AttrFace("name"), node, column=0) else: node.img_style["size"] = 4 node.img_style["shape"] = "sphere" node.img_style["fgcolor"] = "#AA0000"
def barchart_layout(node, name='name', width=20, height=40, colors=None, min_value=0, max_value=1, fsize=14, fgcolor="black"): if colors is None: colors = ['#0000FF'] if node.is_leaf(): # Add node name to leaf nodes N = AttrFace("name", fsize=fsize, fgcolor=fgcolor) faces.add_face_to_node(N, node, 0) if "weight" in node.features: # Creates a sphere face whose size is proportional to node's # feature "weight" if (isinstance(node.weight, int) or isinstance(node.weight, float)): weight = [node.weight] else: weight = node.weight C = BarChartFace(values=weight, width=width, height=height, colors=['#0000FF'], min_value=min_value, max_value=max_value) # Let's make the sphere transparent C.opacity = 0.5 # Rotate the faces by 270* C.rotation = 270 # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float")
def mylayout(node): if node.is_leaf(): longNameFace = faces.TextFace(code_name[node.name], fsize=15, fgcolor="green") faces.add_face_to_node(longNameFace, node, column=0)
def tree_layout(node): """ TODO """ if node.is_leaf(): nameSize = 14 nameColor = '#009000' relAbundSize = 10 else: nameSize = 10 nameColor = '#303030' relAbundSize = 8 nameFace = faces.TextFace(node.name, fsize=nameSize, fgcolor=nameColor) nameFace.margin_bottom = 5 nameFace.margin_right = 10 nameFace.margin_left = 5 faces.add_face_to_node(nameFace, node, column=0, position='branch-top') relAbundFace = faces.TextFace(node.rel_abund, fsize=relAbundSize, fgcolor='#2148c8') relAbundFace.margin_top = 5 relAbundFace.margin_left = 5 faces.add_face_to_node(relAbundFace, node, column=0, position='branch-bottom')
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")
def layout(node): if node.is_leaf(): N = AttrFace("name", fsize=10, fgcolor="black") faces.add_face_to_node(N, node, 0) if "weight" in node.features: C = CircleFace(radius=node.weight, color="blue", style="sphere") C.opacity = 0.3 faces.add_face_to_node(C, node, 0, position="float")
def layout(node): if not node.is_leaf(): size = random.randint(20,50) F= faces.PieChartFace([10,20,60,10], colors=COLOR_SCHEMES[random.sample(schema_names, 1)[0]], width=size, height=size) F.border.width = None F.opacity = 0.6 faces.add_face_to_node(F,node, 0, position="float")
def mylayout(node): #if node.name != 'L': file = 'tmp/%s.png' % node.name new_face = faces.ImgFace(file) new_face.rotable = True new_face.rotation = -90 #new_face.margin_top = 50 new_face.margin_left = 15 faces.add_face_to_node(new_face, node, column=0 , position='branch-top')
def barchart_layout(node, name='name', width=20, height=40, colors=None, min_value=0, max_value=1, fsize=14, fgcolor="black", alpha=0.5, rotation=270): """ Specifies the layout for the ete.TreeStyle object. Parameters ---------- node: ete.Tree Input node for specifying which attributes. name: str, optional Attribute to look up the name of the node. width: int, optional Width of the barchart. height: int, optional Height of the barchart. colors: list of str, optional List of HTML colors to color the barchart values. min_value: int, optional Minimum value to set the scale of the chart. max_value: int, optional Maximum value to set the scale of the chart. fsize: int, optional Font size on the leafs. fgcolor: str, optional Font color of the leafs. alpha: float, optional Transparency of the barchart. rotation: int, optional Orientation of the barchart. """ if colors is None: colors = ['#0000FF'] if node.is_leaf(): # Add node name to leaf nodes N = AttrFace("name", fsize=fsize, fgcolor=fgcolor) faces.add_face_to_node(N, node, 0) if "weight" in node.features: # Creates a sphere face whose size is proportional to node's # feature "weight" if (isinstance(node.weight, int) or isinstance(node.weight, float)): weight = [node.weight] else: weight = node.weight C = BarChartFace(values=weight, width=width, height=height, colors=colors, min_value=min_value, max_value=max_value) # Let's make the sphere transparent C.opacity = alpha # Rotate the faces by 270* C.rotation = rotation # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float")
def _tree_layout(node): try: from ete3 import AttrFace, faces except ImportError: print("Please install ete3 to use this functionality") sys.exit(1) if node.is_leaf(): nameFace = AttrFace("name", fsize=24, ftype="Nimbus Sans L") faces.add_face_to_node(nameFace, node, 10, position="branch-right")
def layout(node): global represent_lst if node.is_leaf(): N = AttrFace("name", fsize=14, fgcolor="black") # can be "sci_name" faces.add_face_to_node(N, node, 0) if node.name in represent_lst: C = CircleFace(radius=5, color="black", style="sphere") faces.add_face_to_node(C, node, 1, position="aligned")
def tree_layout(node): """ side function for tree layouts (following ete3 manual) :param node: :return: """ if node.is_leaf(): color = get_color(node.name) N = ete3.faces.TextFace(node.name, fsize=10, fgcolor=color) faces.add_face_to_node(N, node, 0)
def layout(node): if node.is_leaf(): longNameFace = faces.TextFace(code_name[node.name], fsize=15, fgcolor="green") faces.add_face_to_node(longNameFace, node, column=0) if "weight" in node.features: C = CircleFace(radius=node.weight, color="blue", style="sphere") C.opacity = 0.3 faces.add_face_to_node(C, node, 0, position="float")
def layout(node): #print(node) if (len(node.get_ancestors()) < 4): print(node.name) n = AttrFace("name", fsize=9) n.margin_top = 10 n.margin_bottom = 0 n.margin_left = 10 faces.add_face_to_node(n, node, 0, position="float") tf = TextFace(len(node.get_leaves()), fsize=12) faces.add_face_to_node(tf, node, 0, position="float")
def layout(node): if not node.is_leaf(): size = random.randint(20, 50) F = faces.PieChartFace([10, 20, 60, 10], colors=COLOR_SCHEMES[random.sample( schema_names, 1)[0]], width=size, height=size) F.border.width = None F.opacity = 0.6 faces.add_face_to_node(F, node, 0, position="float")
def layout(node): # if node.is_leaf(): # # Add node name to leaf nodes # N = AttrFace("name", fsize=14, fgcolor="black") # faces.add_face_to_node(N, node, 0) if "weight" in node.features: # Creates a sphere face whose size is proportional to node's # feature "weight" C = CircleFace(radius=node.weight, color="RoyalBlue", style="sphere") # Let's make the sphere transparent C.opacity = 0.6 # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float")
def test_layout_phylo_nt(node): ''' layout for CodemlTree ''' if hasattr(node, "collapsed"): if node.collapsed == 1: node.img_style["draw_descendants"]= False if node.is_leaf(): if hasattr (node, "sequence"): seqface = MySequenceFace(node.sequence, "nt", fsize=10, col_w=11, interactive=True) faces.add_face_to_node(seqface, node, 1, aligned=True)
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) if "weight" in node.features: # Creates a sphere face whose size is proportional to node's # feature "weight" C = CircleFace(radius=node.weight, color="RoyalBlue", style="sphere") # Let's make the sphere transparent C.opacity = 0.3 # And place as a float face over the tree faces.add_face_to_node(C, node, 0, position="float")
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 layout(node): if node.is_leaf(): if node.name=="A": node.color="Blue" node.attr2="Green" elif node.name=="B": node.color="Red" node.attr2="Orange" else: node.color="Grey" node.attr2="Yellow" faces.add_face_to_node( CircleFace(radius=5, color=node.color), node, column=1) faces.add_face_to_node( RectFace(width=10, height=10, fgcolor=node.attr2, bgcolor=node.attr2), node, column=2)
def phyparts_pie_layout(mynode): if mynode.name in phyparts_pies: pie = faces.PieChartFace( phyparts_pies[mynode.name], #colors=COLOR_SCHEMES["set1"], colors=["blue", "green", "red", "dark gray"], width=50, height=50) pie.border.width = None pie.opacity = 0.5 faces.add_face_to_node(pie, mynode, 0, position="branch-right") concord_text = faces.TextFace(str(int(concord_dict[mynode.name])) + ' ', fsize=20) conflict_text = faces.TextFace(str(int(conflict_dict[mynode.name])) + ' ', fsize=20) faces.add_face_to_node(concord_text, mynode, 0, position="branch-top") faces.add_face_to_node(conflict_text, mynode, 0, position="branch-bottom") else: F = faces.TextFace(mynode.name, fsize=20) faces.add_face_to_node(F, mynode, 0, position="aligned")
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 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(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 my_layout(node): """Customise the layout of a tree node Args: node (node): tree node """ if node.is_leaf(): # If terminal node, draws its name name_face = AttrFace("name") else: # If internal node, draws label with smaller font size name_face = AttrFace("name", fsize=10) # Adds the name face to the image at the preferred position faces.add_face_to_node(name_face, node, column=0, position="branch-right")
def test_layout_phylo_nt(node): ''' layout for CodemlTree ''' if hasattr(node, "collapsed"): if node.collapsed == 1: node.img_style["draw_descendants"] = False if node.is_leaf(): if hasattr(node, "sequence"): seqface = MySequenceFace(node.sequence, "nt", fsize=10, col_w=11, interactive=True) faces.add_face_to_node(seqface, node, 1, aligned=True)
def layout(node): if node.is_leaf(): if "Russia/" in node.name: Rudesc = faces.AttrFace("name", fsize=10) Rudesc.margin_left = 25 faces.add_face_to_node(Rudesc, node, 0, aligned=True) else: if "_" in node.name: node.name = node.name.replace("_", " ") countrydesc = faces.AttrFace("name", fsize=10) countrydesc.margin_left = 5 countrydesc.margin_bottom = 10 countrydesc.margin_top = 5 countrydesc.margin_right = 5 faces.add_face_to_node(countrydesc, node, 0, aligned=False)
def test_layout_phylo_aa_motif(node): ''' layout for CodemlTree ''' if hasattr(node, "collapsed"): if node.collapsed == 1: node.img_style["draw_descendants"]= False special_col = [[10,100],[150,1000],[1000,2000],[3000,4990]] if node.is_leaf(): if hasattr (node, "sequence"): seqface = MySequenceFace(node.sequence, "aa", fsize=10,special_col=special_col, alt_col_w=3, col_w=11, interactive=True) faces.add_face_to_node(seqface, node, 1, aligned=True)
def layout_idtree(node): nstyle = NodeStyle() nstyle["size"] = 1 node.set_style(nstyle) if node.is_leaf(): # Add node name to leaf nodes N = AttrFace("name", fsize=14, fgcolor="black") faces.add_face_to_node(N, node, 0, position='aligned') if not node.is_root(): # Creates a sphere face whose size is proportional to node's # feature "weight" TN = TextFace(str(node.ID), fsize=12) faces.add_face_to_node(TN, node, 1, position="branch-right")
def my_layout(node): if node.is_leaf(): # If terminal node, draws its name name_face = AttrFace("name", ftype="Roboto", fgcolor='#191919') name_face.margin_right = 10 name_face.margin_left = 10 else: # If internal node, draws label with smaller font size name_face = AttrFace("name", fsize=10, ftype="Roboto", fgcolor='#191919') name_face.margin_right = 10 name_face.margin_left = 10 # Adds the name face to the image at the preferred position faces.add_face_to_node(name_face, node, column=0, position="branch-right")
def mylayout(node): if node.is_leaf(): # faces.add_face_to_node(nameFace, node, column=0) node.img_style["size"] = 80 node.img_style["shape"] = "sphere" node.img_style["fgcolor"] = "#000000" L = node.name.split(' ') if len(L) > 1: img_name = os.path.join(g_suncg_object_path, L[1], "rgb_img", "8_rotation.png") objectFace = faces.ImgFace(img_name) faces.add_face_to_node(objectFace, node, column=0) else: node.img_style["size"] = 80 node.img_style["shape"] = "sphere" node.img_style["fgcolor"] = "#AA0000"
def layout(node): # If node is a leaf, add the nodes name and a its scientific name if node.is_leaf(): F = faces.DynamicItemFace(scientific_name_face) if F.node == "DAR34208_Raffaelea_kilii_sp._nov.": F.background = "Black" faces.add_face_to_node( F, node, 0, ) F.margin_left = 10 faces.add_face_to_node( F, node, 0, )
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 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=50, height=50 ) F.border.width = None F.opacity = 0.8 faces.add_face_to_node(F, node, 0, position="branch-right") F = faces.PieChartFace( [10, 20, 5, 5, 60], colors=COLOR_SCHEMES[random.sample(schema_names, 1)[0]], width=100, height=40 ) F.border.width = None F.opacity = 0.8 faces.add_face_to_node(F, node, 0, position="branch-right") else: F = faces.BarChartFace( [40, 20, 70, 100, 30, 40, 50, 40, 70, -12], min_value=-12, colors=COLOR_SCHEMES["spectral"], labels="aaa,bbb,cccccc,dd,eeee,ffff,gg,HHH,II,JJJ,KK".split(","), label_fsize=10, scale_fsize=10, ) faces.add_face_to_node(F, node, 0, position="branch-top") F.background.color = "#eee"
def phyparts_pie_layout(mynode): if mynode.name in phyparts_pies: pie= faces.PieChartFace(phyparts_pies[mynode.name], #colors=COLOR_SCHEMES["set1"], colors = args.colors, width=50, height=50) pie.border.width = None pie.opacity = 1 faces.add_face_to_node(pie,mynode, 0, position="branch-right") concord_text = faces.TextFace(str(int(concord_dict[mynode.name]))+' ',fsize=20) conflict_text = faces.TextFace(str(int(conflict_dict[mynode.name]))+' ',fsize=20) faces.add_face_to_node(concord_text,mynode,0,position = "branch-top") faces.add_face_to_node(conflict_text,mynode,0,position="branch-bottom") else: F = faces.TextFace(mynode.name,fsize=20) faces.add_face_to_node(F,mynode,0,position="aligned")
def layout(node): node.img_style['size'] = 0 node.img_style['vt_line_width'] = 0 node.img_style['hz_line_width'] = 0 if "bgcolor" in node.features: node.img_style['bgcolor'] = node.bgcolor if node.is_leaf(): if not args.no_names: name = faces.TextFace(node.sci_name, fsize=12, fstyle='italic') faces.add_face_to_node(name, node, 0, aligned=True) fake = faces.TextFace(" ") fake.background.color = "white" faces.add_face_to_node(fake, node, 1, aligned=True) # fake else: if not args.no_internal_names and node.get_distance(tNCBI, topology_only=True) < 3: name = faces.TextFace(node.sci_name, fsize=12, fstyle='italic') faces.add_face_to_node(name, node, 0, position='branch-top')
def layout(node): ''' The layout function for exporting treees ''' # Label the leaves if node.is_leaf(): faces.add_face_to_node(TextFace( getattr(node, TAXA_FEATURE)[-1], fgcolor=('blue' if getattr(node, GROUP_FEATURE) == interest_group else 'black')), node, column=0) pval = float(getattr(node, CORRECTED_P_VAL_FEATURE)) pval_color = get_color(pval) faces.add_face_to_node(RectFace(10, 10, fgcolor='Black', bgcolor=pval_color), node, column=1, aligned=True) faces.add_face_to_node( TextFace(' {0:0.5f} {1}'.format( float(getattr(node, CORRECTED_P_VAL_FEATURE)), getattr(node, OTU_FEATURE))), node, column=2, aligned=True)
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)
def layout(node): if node.is_leaf(): N = AttrFace("name", fsize=30) faces.add_face_to_node(N, node, 0, position="aligned")
def node_text_layout(mynode): F = faces.TextFace(mynode.name,fsize=20) faces.add_face_to_node(F,mynode,0,position="branch-right")
def sphere_map(node): # Creates a random color sphere face that will be floating over nodes bubble = faces.CircleFace(random.randint(5,40), random_color(), "sphere") bubble.opacity = 0.7 faces.add_face_to_node(bubble, node, 0, position="float")
def leaf_name(node): if node.is_leaf(): nameF = faces.AttrFace("name") nameF.border.width = 1 faces.add_face_to_node(nameF, node, 0, position="branch-right")
def layout(node): faces.add_face_to_node(AttrFace("name"), node, column=0, position="branch-right")
def test(node): if node.is_leaf(): faces.add_face_to_node(faces.AttrFace("name"), node, 0, position="aligned")
def custom_layout(self,node): if node.is_leaf(): aligned_name_face = TextFace(node.name, fgcolor='olive', fsize=12) aligned_name_face.margin_top = 5 aligned_name_face.margin_right = 5 aligned_name_face.margin_left = 5 aligned_name_face.margin_bottom = 5 aligned_name_face.hz_align = 0 #0 = left, 1 = center, 2 = right add_face_to_node(aligned_name_face, node, column=2, position='aligned') #name_face = TextFace(node.name, fgcolor='#333333', fsize=11) #name_face.margin_top = 3 #name_face.margin_right = 3 #name_face.margin_left = 3 #name_face.margin_bottom = 3 #add_face_to_node(name_face, node, column=2, position='branch-right') node.img_style['size'] = 0 #--------------------------------------------- #displaying extra categorical and numeric data if (node.name in self._tip2info): column_no = 3 for headerIndex, dataheader in enumerate(self._tip2headers): extra_data = self._tip2info[node.name][headerIndex] if isinstance( extra_data, ( int, float ) ): extra_face = BarChartFace([extra_data], width=100,height=25,colors=[self._tip2color[node.name][headerIndex]],labels=[dataheader],min_value=0.0,max_value=self._tip_max) else: extra_face = TextFace(extra_data, fsize=11, fgcolor='black') extra_face.background.color = self._tip2color[node.name][headerIndex] extra_face.margin_left = 5 extra_face.margin_top = 5 extra_face.margin_right = 5 extra_face.margin_bottom = 5 add_face_to_node(extra_face, node, column=column_no, position='aligned') #add_face_to_node(extra_face, node, column=column_no, aligned = True, position='branch-right') column_no += 1 else: #print "No data available" column_no = 3 for headerIndex, dataheader in enumerate(self._tip2headers): extra_face = TextFace("No data available", fsize=10, fgcolor='black') extra_face.margin_left = 5 extra_face.margin_top = 5 extra_face.margin_right = 5 extra_face.margin_bottom = 5 add_face_to_node(extra_face, node, column=column_no, position='aligned') column_no += 1 image_col_no = column_no #---------------------------------------------- if (node.name in self._img_chk_list): if self._img_data_dic[node.name] is not None: img_face = ImgFace(self._img_data_dic[node.name], is_url=True) #img_face = ImgFace(self._tip2info[node.name][0], is_url=True) #img_path = os.path.join("file:///home/tayeen/TayeenFolders/TreeViewer/WebTreeApp/newplugin_test/data/", "328653.jpg") #img_face = ImgFace(img_path, is_url=True) img_face.margin_top = 10 img_face.margin_right = 10 img_face.margin_left = 10 img_face.margin_bottom = 10 #add_face_to_node(img_face, node, column=3, position='branch-right') #add_face_to_node(img_face, node, column=3, aligned= True, position='branch-right') else: img_path = os.path.join("file://"+image_path, "ina.jpg") img_face = ImgFace(img_path, is_url=True) #add_face_to_node(img_face, node, column=5, position='branch-right') add_face_to_node(img_face, node, column=image_col_no, position='aligned') else: #node is not a leaf node.img_style['size'] = 4 node.img_style['shape'] = 'square' if node.name and self._custom_options["draw_internal"]: name_face = TextFace(node.name, fgcolor='grey', fsize=10) name_face.margin_top = 4 name_face.margin_right = 4 name_face.margin_left = 4 name_face.margin_bottom = 4 add_face_to_node(name_face, node, column=0, position='branch-top') if node.name in self._node2label: label_face = TextFace(self._node2label[node.name], fgcolor='DarkGreen', fsize=10) label_face.margin_top = 4 label_face.margin_right = 4 label_face.margin_left = 4 label_face.margin_bottom = 4 add_face_to_node(label_face, node, column=0, position="branch-top") if node.support and self._custom_options["draw_support"]: support_face = TextFace(node.support, fgcolor='indianred', fsize=10) support_face.margin_top = 4 support_face.margin_right = 4 support_face.margin_left = 4 support_face.margin_bottom = 4 add_face_to_node(support_face, node, column=0, position='branch-bottom') 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 # 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 #parse all nodes features if hasattr(node, "bh_bgcolor"): node.img_style["bgcolor"]= node.bh_bgcolor if hasattr(node, "bh_size"): node.img_style["size"]= node.bh_size if hasattr(node, "lh_color"): node.img_style['hz_line_color'] = node.lh_color node.img_style["vt_line_color"] = node.lh_color if hasattr(node, "lh_width"): node.img_style['hz_line_width'] = node.lh_width node.img_style['vt_line_width'] = node.lh_width if hasattr(node, "lh_width") and hasattr(node, "lh_color"): for n in node.iter_descendants(): n.img_style['hz_line_color'] = node.lh_color n.img_style["vt_line_color"] = node.lh_color n.img_style['hz_line_width'] = node.lh_width n.img_style['vt_line_width'] = node.lh_width
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) descFace.margin_top = 10 descFace.margin_bottom = 10 descFace.border.margin = 1 # 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 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