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 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 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 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 layout(node): 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
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) 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 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 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): 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 layout2(node): #node.img_style["size"] = random.randint(40, 200) if hasattr(node, "size"): f = faces.PieChartFace([100], node.size[0], node.size[1], ["blue"]) faces.add_face_to_node(f, node, 0, position="branch-top") faces.add_face_to_node(f, node, 0, position="branch-bottom") #f = faces.PieChartFace([100], node.size[0]*3, node.size[0]*3, ["blue"]) #faces.add_face_to_node(f, node, 0, position="branch-right") f.border.width = 0 node.img_style["size"] = 10 node.img_style["shape"] = "square" node.img_style["bgcolor"] = random_color() node.img_style["hz_line_width"] = 0 node.img_style["vt_line_width"] = 0
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): 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 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 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 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 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 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): 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=0, colors=COLOR_SCHEMES["spectral"], labels="aaa,bbb,cccccc,dd,eeee,ffff,gg,HHH,II,JJJ,KK".split(",")) faces.add_face_to_node(F, node, 0, position="branch-top") F.background.color = "#eee"
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): 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 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 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=0, colors=COLOR_SCHEMES["spectral"], labels="aaa,bbb,cccccc,dd,eeee,ffff,gg,HHH,II,JJJ,KK".split(","), ) faces.add_face_to_node(F, node, 0, position="branch-top") F.background.color = "#eee"
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 test(node): if node.is_leaf(): faces.add_face_to_node(faces.AttrFace("name"), node, 0, position="aligned")
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 npr_layout(node): if node.is_leaf(): name = faces.AttrFace("name", fsize=12) faces.add_face_to_node(name, node, 0, position="branch-right") if hasattr(node, "sequence"): seq_face = faces.SeqFace(node.sequence, []) faces.add_face_to_node(seq_face, node, 0, position="aligned") if "alg_type" in node.features: faces.add_face_to_node(faces.AttrFace("alg_type", fsize=8), node, 0, position="branch-top") ttype = faces.AttrFace("tree_type", fsize=8, fgcolor="DarkBlue") faces.add_face_to_node(ttype, node, 0, position="branch-top") #ttype.background.color = "DarkOliveGreen" node.img_style["size"] = 20 node.img_style["fgcolor"] = "red" if "treemerger_rf" in node.features: faces.add_face_to_node(faces.AttrFace("treemerger_rf", fsize=8), node, 0, position="branch-bottom") support_radius = (1.0 - node.support) * 50 if not node.is_leaf() and support_radius > 1: support_face = faces.CircleFace(support_radius, "red") faces.add_face_to_node(support_face, node, 0, position="float-behind") support_face.opacity = 0.25 faces.add_face_to_node(faces.AttrFace("support", fsize=8), node, 0, position="branch-bottom") if "clean_alg_mean_identn" in node.features: identity = node.clean_alg_mean_identn elif "alg_mean_identn" in node.features: identity = node.alg_mean_identn if "highlighted" in node.features: node.img_style["bgcolor"] = "LightCyan" if "improve" in node.features: color = "orange" if float(node.improve) < 0 else "green" if float(node.improve) == 0: color = "blue" support_face = faces.CircleFace(200, color) faces.add_face_to_node(support_face, node, 0, position="float-behind")
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 mylayout(node): T = TestTreeview node.img_style["size"]=random.sample(range(4,30),1)[0] if node.is_leaf(): faces.add_face_to_node(T.nameF, node, column=0, position="aligned") faces.add_face_to_node(T.nameF, node, column=2, position="aligned") faces.add_face_to_node(T.nameF, node, column=3, position="aligned") else: faces.add_face_to_node(T.topF, node, column=1, position="branch-top") faces.add_face_to_node(T.topF, node, column=1, position="branch-top") faces.add_face_to_node(T.topF, node, column=1, position="branch-top") faces.add_face_to_node(T.topF, node, column=1, position="branch-top") faces.add_face_to_node(T.downF, node, column=1, position="branch-bottom") faces.add_face_to_node(T.downF, node, column=1, position="branch-bottom") faces.add_face_to_node(T.rF1, node, column=1, position="branch-right") faces.add_face_to_node(T.rF2, node, column=1, position="branch-right") faces.add_face_to_node(T.rF3, node, column=2, position="branch-right")
def npr_layout(node): if node.is_leaf(): name = faces.AttrFace("name", fsize=12) faces.add_face_to_node(name, node, 0, position="branch-right") if hasattr(node, "sequence"): seq_face = faces.SeqFace(node.sequence, []) faces.add_face_to_node(seq_face, node, 0, position="aligned") if "alg_type" in node.features: faces.add_face_to_node(faces.AttrFace("alg_type", fsize=8), node, 0, position="branch-top") ttype=faces.AttrFace("tree_type", fsize=8, fgcolor="DarkBlue") faces.add_face_to_node(ttype, node, 0, position="branch-top") #ttype.background.color = "DarkOliveGreen" node.img_style["size"] = 20 node.img_style["fgcolor"] = "red" if "treemerger_rf" in node.features: faces.add_face_to_node(faces.AttrFace("treemerger_rf", fsize=8), node, 0, position="branch-bottom") support_radius= (1.0 - node.support) * 50 if not node.is_leaf() and support_radius > 1: support_face = faces.CircleFace(support_radius, "red") faces.add_face_to_node(support_face, node, 0, position="float-behind") support_face.opacity = 0.25 faces.add_face_to_node(faces.AttrFace("support", fsize=8), node, 0, position="branch-bottom") if "clean_alg_mean_identn" in node.features: identity = node.clean_alg_mean_identn elif "alg_mean_identn" in node.features: identity = node.alg_mean_identn if "highlighted" in node.features: node.img_style["bgcolor"] = "LightCyan" if "improve" in node.features: color = "orange" if float(node.improve) < 0 else "green" if float(node.improve) == 0: color = "blue" support_face = faces.CircleFace(200, color) faces.add_face_to_node(support_face, node, 0, position="float-behind")
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 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 mylayout(node): # If node is a leaf, add the nodes name and a its scientific # name if node.is_leaf(): faces.add_face_to_node(aligned, node, column=0, position="aligned") faces.add_face_to_node(aligned, node, column=1, position="aligned") faces.add_face_to_node(aligned, node, column=3, position="aligned") else: faces.add_face_to_node(bt, node, column=0, position="branch-top") faces.add_face_to_node(bb, node, column=0, position="branch-bottom") faces.add_face_to_node(bb2, node, column=0, position="branch-bottom") faces.add_face_to_node(br1, node, column=0, position="branch-right") faces.add_face_to_node(rs1, node, column=0, position="branch-right") faces.add_face_to_node(br2, node, column=0, position="branch-right")
def layout(node): if node.is_leaf(): N = AttrFace("name", fsize=30) faces.add_face_to_node(N, node, 0, position="aligned")
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
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 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")