def ly_block_alg(node): if node.is_leaf(): if 'sequence' in node.features: seqFace = SeqMotifFace(node.sequence, []) # [10, 100, "[]", None, 10, "black", "rgradient:blue", "arial|8|white|domain Name"], motifs = [] last_lt = None for c, lt in enumerate(node.sequence): if lt != '-': if last_lt is None: last_lt = c if c + 1 == len(node.sequence): start, end = last_lt, c motifs.append([ start, end, "()", 0, 12, "slategrey", "slategrey", None ]) last_lt = None elif lt == '-': if last_lt is not None: start, end = last_lt, c - 1 motifs.append([ start, end, "()", 0, 12, "grey", "slategrey", None ]) last_lt = None seqFace = SeqMotifFace(node.sequence, motifs, intermotif_format="line", seqtail_format="line", scale_factor=ALG_SCALE) add_face_to_node(seqFace, node, ALG_START_COL, aligned=True)
def my_layout(node): name = getattr(node, attribute_name) try: kmer_full = locale.format("%d", int(node.kmers_full), grouping=True), except AttributeError: kmer_full = None try: kmer_reduced = locale.format("%d", int(node.kmers_reduced), grouping=True) except AttributeError: kmer_reduced = None if kmer_full is None: if kmer_reduced is None: t = name else: t = "{} [red. {}]".format(name, kmer_reduced) else: if kmer_reduced is None: t = "{} [full {}]".format(name, kmer_full) else: t = "{} [full {} & red. {}]".format(name, kmer_full, kmer_reduced) f = ete3.TextFace(t, tight_text=True) ete3.add_face_to_node(f, node, column=0, position="branch-right")
def my_layout(node): #coloca o nome em cada nó node.name F = TextFace( node.name.replace("*", "\n"), tight_text=True) #substitui onde tem estrela p quebra de linha add_face_to_node(F, node, column=0, position="branch-right") F.rotation = -90 #rotação do nome no nó
def mylayout(node): # If node is a leaf if node.is_leaf(): # And a line profile add_face_to_node(profileFace, node, 0, aligned=True) node.img_style["size"] = 0 add_face_to_node(nameFace, node, 1, aligned=True)
def my_layout(node): if node.is_leaf() and any( [node.name == x.split(';')[-1] for x in selection['Taxonomy_UniEuk']]): F = ete3.TextFace(node.name, tight_text=True, fgcolor='red') else: F = ete3.TextFace(node.name, tight_text=True) ete3.add_face_to_node(F, node, column=0, position="branch-right")
def ly_block_alg(node): if node.is_leaf(): if 'sequence' in node.features: seqFace = SeqMotifFace(node.sequence, []) # [10, 100, "[]", None, 10, "black", "rgradient:blue", "arial|8|white|domain Name"], motifs = [] last_lt = None for c, lt in enumerate(node.sequence): if lt != '-': if last_lt is None: last_lt = c if c+1 == len(node.sequence): start, end = last_lt, c motifs.append([start, end, "()", 0, 12, "slategrey", "slategrey", None]) last_lt = None elif lt == '-': if last_lt is not None: start, end = last_lt, c-1 motifs.append([start, end, "()", 0, 12, "grey", "slategrey", None]) last_lt = None seqFace = SeqMotifFace(node.sequence, motifs, intermotif_format="line", seqtail_format="line", scale_factor=ALG_SCALE) add_face_to_node(seqFace, node, ALG_START_COL, aligned=True)
def ly_leaf_names(node): if node.is_leaf(): spF = TextFace(node.species, fsize=10, fgcolor='#444444', fstyle='italic', ftype='Helvetica') add_face_to_node(spF, node, column=0, position='branch-right') if hasattr(node, 'genename'): geneF = TextFace(" (%s)" %node.genename, fsize=8, fgcolor='#777777', ftype='Helvetica') add_face_to_node(geneF, node, column=1, position='branch-right')
def custom_layout(node): if node.is_leaf(): aligned_name_face = TextFace(node.name, fgcolor='olive', fsize=14) add_face_to_node(aligned_name_face, node, column=2, position='aligned') name_face = TextFace(node.name, fgcolor='#333333', fsize=11) add_face_to_node(name_face, node, column=2, position='branch-right') node.img_style['size'] = 0 if node.name in tip2info: # For some reason img urls are very slow! #img_face = ImgFace(tip2info[node.name][0], is_url=True) #add_face_to_node(img_face, node, column=4, position='branch-right') habitat_face = TextFace(tip2info[node.name][2], fsize=11, fgcolor='white') habitat_face.background.color = 'steelblue' habitat_face.margin_left = 3 habitat_face.margin_top = 3 habitat_face.margin_right = 3 habitat_face.margin_bottom = 3 add_face_to_node(habitat_face, node, column=3, position='aligned') else: node.img_style['size'] = 4 node.img_style['shape'] = 'square' if node.name: name_face = TextFace(node.name, fgcolor='grey', fsize=10) name_face.margin_bottom = 2 add_face_to_node(name_face, node, column=0, position='branch-top') if node.support: support_face = TextFace(node.support, fgcolor='indianred', fsize=10) add_face_to_node(support_face, node, column=0, position='branch-bottom')
def tree_profile_layout(node): if node.is_leaf( ): # the aligned leaf is "column 0", thus traits go to column+1 node.set_style( ns1) ## may be postponed to when we have ancestral states ete3.add_face_to_node(ete3.AttrFace("name", fsize=label_font_size, text_suffix=" "), node, 0, position="aligned") for column, (rgb_val, lab) in enumerate( zip(d_seq[node.name], d_seq_lab[ node.name])): ## colour of csv.loc[node.name, "adm2"] label = { "text": lab[:10], "color": "Black", "fontsize": label_font_size - 1 } ete3.add_face_to_node(ete3.RectFace(50, 10, fgcolor=rgb_val, bgcolor=rgb_val, label=label), node, column + 1, position="aligned") else: node.set_style(ns2)
def my_layout(node): F = TextFace("\t" + node.name, tight_text=True, fstyle="bold", fsize=40, fgcolor="black") F.rotation = 90 add_face_to_node(F, node, column=0, position="branch-bottom")
def my_layout(node): F = TextFace(node.name, tight_text=True) F.fsize=6 F.margin_left=5 F.margin_right=5 F.margin_top=0 F.margin_bottom=15 F.rotation=-90 add_face_to_node(F, node, column=0, position="branch-right")
def branch_category_layout(node): nstyle = ete3.NodeStyle() nstyle['size'] = 0 nstyle["hz_line_width"] = nstyle["vt_line_width"] = 1 nstyle["hz_line_color"] = node.color nstyle["vt_line_color"] = node.color nlabel = node.name+'|'+str(node.numerical_label) nlabelFace = ete3.TextFace(nlabel, fsize=4, fgcolor=node.color) ete3.add_face_to_node(face=nlabelFace, node=node, column=1, aligned=False, position="branch-right") node.set_style(nstyle)
def my_layout(node): # print(dir(node)) # if node.nodetype == 'leaf': # node_face = TextFace(node.name, tight_text=True) # node_face.background.color = "LightGreen" # # elif node.nodetype == 'node': if not node.is_leaf(): node_face = TextFace(node.name, tight_text=True) add_face_to_node(node_face, node, column=0)
def _node_layout(node): global _circle_tested node.img_style["size"] = 0 if node.is_leaf(): if node.name not in annotation: print('Got unknown leaf "%s"' % (node.name)) return size = annotation[node.name] else: children = COMMA.join(sorted([leaf.name for leaf in node])) if children not in annotation: print('Got unknown node ' + children) return size = annotation[children] dimension = 4 * math.sqrt(size) labeld = { 'text': "%d" % (size), 'color': 'white', 'font': 'Helvetica', 'size': 8 } if size % 2: clabel = dict(labeld) if size == 35: if not _circle_tested: _circle_tested = True clabel['text'] = 'Ly' clabel['size'] = 12 thisFace = ete.CircleFace(dimension / 2, "steelblue", "circle", label=clabel) elif size == 43: clabel['size'] = 6 del clabel['color'] thisFace = ete.CircleFace(dimension / 2, "steelblue", "sphere", label=clabel) else: thisFace = ete.CircleFace(dimension / 2, "steelblue", "sphere", label="%d" % (size)) else: thisFace = ete.RectFace(dimension, dimension, 'green', 'blue', label=labeld) thisFace.opacity = 0.7 ete.add_face_to_node(thisFace, node, column=0, position="float") textF = ete.TextFace(str(size), fsize=12, fgcolor="steelblue") ete.add_face_to_node(textF, node, column=0, position="aligned")
def branch_state_layout(node): nstyle = ete3.NodeStyle() nstyle['size'] = 0 nstyle["hz_line_width"] = nstyle["vt_line_width"] = 1 nstyle["hz_line_color"] = node.color nstyle["vt_line_color"] = node.color if node.is_leaf(): nlabel = str(node.state)+'|'+node.name else: nlabel = str(node.state) nlabelFace = ete3.TextFace(nlabel, fsize=6, fgcolor=node.color) ete3.add_face_to_node(face=nlabelFace, node=node, column=1, aligned=False, position="branch-right") node.set_style(nstyle)
def my_layout(node): F = TextFace(node.name, tight_text=True, penwidth=5, fsize=12) if node.name is not 'a': add_face_to_node(F, node, column=0, position="branch-right") node.set_style(ns) if node.name in families: G = TextFace(families[node.name], fstyle='italic') add_face_to_node(G, node, column=0, position="branch-right") node.set_style(ns) if node.name in dict_genera: H = TextFace(dict_genera[node.name], fstyle='italic') add_face_to_node(H, node, column=0, position="branch-right") node.set_style(ns) if node.name in dict_species: I = TextFace(dict_species[node.name], fstyle='italic') add_face_to_node(I, node, column=0, position="branch-right") node.set_style(ns) if node.name == 'sumatrana': dict_species[node.name] = '(Sumatran Torrent Frog)' # if node.is_leaf(): # node.img_style["size"] = 0 # img = ImgFace('/home/stine/Desktop/{}.jpg'.format(node.name)) # add_face_to_node(img, node, column=0, aligned=True) for n in Anura.iter_search_nodes(): if n.dist > 1: n.img_style = ns
def add_img(node): nodeimg = getattr(node, 'img', None) if nodeimg: if nodeimg.startswith('//'): nodeimg = 'https:' + nodeimg #await ? ete3.add_face_to_node(ete3.ImgFace( nodeimg, width=int(node.imgwidth), height=int(node.imgheight), is_url=True), node, column=1, position='branch-right')
def mylayout(node): node.set_style(ns) if not node.is_leaf(): ete3.add_face_to_node(ete3.TextFace(node.name), node, column=0, position='branch-top') ete3.add_face_to_node(ete3.TextFace('\n'.join( getattr(node, 'info', []))), node, column=0, position='branch-bottom') if node.support <= 0.5: node.set_style(dashed_branch) add_img(node)
def ly_tax_labels(node): if node.is_leaf(): c = LABEL_START_COL largest = 0 for tname in TRACKED_CLADES: if hasattr(node, "named_lineage") and tname in node.named_lineage: linF = TextFace(tname, fsize=10, fgcolor='white') linF.margin_left = 3 linF.margin_right = 2 linF.background.color = lin2color[tname] add_face_to_node(linF, node, c, position='aligned') c += 1 for n in range(c, len(TRACKED_CLADES)): add_face_to_node(TextFace('', fsize=10, fgcolor='slategrey'), node, c, position='aligned') c+=1
def ly_leaf_names(node): if node.is_leaf(): spF = TextFace(node.species, fsize=10, fgcolor='#444444', fstyle='italic', ftype='Helvetica') add_face_to_node(spF, node, column=0, position='branch-right') if hasattr(node, 'genename'): geneF = TextFace(" (%s)" % node.genename, fsize=8, fgcolor='#777777', ftype='Helvetica') add_face_to_node(geneF, node, column=1, position='branch-right')
def ly_basic(node): if node.is_leaf(): node.img_style['size'] = 0 else: node.img_style['size'] = 0 node.img_style['shape'] = 'square' if len(MIXED_RES) > 1 and hasattr(node, "tree_seqtype"): if node.tree_seqtype == "nt": node.img_style["bgcolor"] = "#CFE6CA" ntF = TextFace("nt", fsize=6, fgcolor='#444', ftype='Helvetica') add_face_to_node(ntF, node, 10, position="branch-bottom") if len(NPR_TREES) > 1 and hasattr(node, "tree_type"): node.img_style['size'] = 4 node.img_style['fgcolor'] = "steelblue" node.img_style['hz_line_width'] = 1 node.img_style['vt_line_width'] = 1
def myLayout(node): if node.is_leaf(): node.img_style['size'] = 0 genome_name, gene_name = node.name.split('_') node.name = genome_table.loc[genome_name, 'organism_name'] ete3.add_face_to_node(nameFaces[genome_table.loc[genome_name, 'phylum']], node, 2, aligned=True) elif node.is_root(): node.img_style['size'] = 0 else: if node.support >= 90: node.img_style['size'] = 5 node.img_style['fgcolor'] = '#a20417' else: node.img_style['size'] = 0
def layout(node): node.img_style["size"] = 0 #add boostrap in not-leaf nodes if not node.is_leaf(): boostFace = faces.TextFace(node.support, fgcolor="grey", fsize=34) add_face_to_node(boostFace, node, column=0, position="branch-top") if node.is_leaf(): #get taxid and name taxid = (node.name.split('.')[0]) seq_name = (node.name.split('.')[1]) #add predicted name (eggnog-mapper) try: pred_name = predict_name[node.name] predNameFace = faces.TextFace(pred_name, fgcolor="salmon", fsize=34) predNameFace.margin_right = 20 predNameFace.margin_left = 20 add_face_to_node(predNameFace, node, column=2, position="branch-right") except: predNameFace = faces.TextFace('--', fgcolor="salmon", fsize=34) add_face_to_node(predNameFace, node, column=2, position="branch-right") #add sequence name (seq_name) seqNameFace = faces.TextFace(seq_name, fgcolor="grey", fsize=34) add_face_to_node(seqNameFace, node, column=1, position="branch-right") #get scientific name from taxid sp_name = ncbi.get_taxid_translator([(node.name.split('.')[0])]) node.name = sp_name[int(taxid)] #add alignment seqFace = SeqMotifFace(node.sequence, gap_format="blank") add_face_to_node(seqFace, node, column=3, position="aligned")
def _node_layout(node): global _circle_tested node.img_style["size"] = 0 if node.is_leaf(): if node.name not in annotation: print('Got unknown leaf "%s"' % (node.name)) return size = annotation[node.name] else: children = COMMA.join(sorted([leaf.name for leaf in node])) if children not in annotation: print('Got unknown node ' + children) return size = annotation[children] dimension = 4*math.sqrt(size) labeld = { 'text' : "%d" % (size), 'color' : 'white', 'font' : 'Helvetica', 'size' : 8 } if size % 2: clabel = dict(labeld) if size == 35: if not _circle_tested: _circle_tested = True clabel['text'] = 'Ly' clabel['size'] = 12 thisFace = ete.CircleFace(dimension/2, "steelblue", "circle", label=clabel) elif size == 43: clabel['size'] = 6 del clabel['color'] thisFace = ete.CircleFace(dimension/2, "steelblue", "sphere", label=clabel) else: thisFace = ete.CircleFace(dimension/2, "steelblue", "sphere", label="%d" % (size)) else: thisFace = ete.RectFace(dimension, dimension, 'green', 'blue', label=labeld) thisFace.opacity = 0.7 ete.add_face_to_node(thisFace, node, column=0, position="float") textF = ete.TextFace(str(size), fsize=12, fgcolor="steelblue") ete.add_face_to_node(textF, node, column=0, position="aligned")
def ly_tax_labels(node): if node.is_leaf(): c = LABEL_START_COL largest = 0 for tname in TRACKED_CLADES: if hasattr(node, "named_lineage") and tname in node.named_lineage: linF = TextFace(tname, fsize=10, fgcolor='white') linF.margin_left = 3 linF.margin_right = 2 linF.background.color = lin2color[tname] add_face_to_node(linF, node, c, position='aligned') c += 1 for n in range(c, len(TRACKED_CLADES)): add_face_to_node(TextFace('', fsize=10, fgcolor='slategrey'), node, c, position='aligned') c += 1
def my_layout_extended(node): N = TextFace(int(node.numbers), fsize=1) # , tight_text=True) # N = AttrFace(node.numbers, fsize=1, tight_text=True) add_face_to_node(N, node, column=1, position="branch-right") style = NodeStyle() if node.name == "N0": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N0"] elif node.name == "N1": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N1"] elif node.name == "N2": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N2"] elif node.name == "N3": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N3"] elif node.name == "N4": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N4"] elif node.name == "N5": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N5"] elif node.name == "N6": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N6"] elif node.name == "N7": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N7"] elif node.name == "N8": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N8"] elif node.name == "N9": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N9"] elif node.name == "N10": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N10"] elif node.name == "N11": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N11"] elif node.name == "N12": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N12"] elif node.name == "N13": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N13"] elif node.name == "N14": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N14"] elif node.name == "N15": style["fgcolor"] = style["hz_line_color"] = color_dictionary["N15"] node.set_style(style)
def my_layout(node): # # add names to all nodes (not just to leaf nodes) # ete3/test/test_treeview/face_rotation.py F = TextFace(node.name, tight_text=True) add_face_to_node(F, node, column=0, position="branch-right") # # add branch lengths # ete3/treeview/qt4_render.py if not node.is_root(): bl_face = AttrFace("dist", fsize=8, ftype="Arial", fgcolor="black", formatter="%0.3g") # # This is a failed attempt to center the branch length text on the branch. #a = 1 # 0 left, 1 center, 2 right #bl_face.hz_align = a #bl_face.vt_align = a #add_face_to_node(bl_face, node, column=0, aligned=True, position="branch-top") add_face_to_node(bl_face, node, column=0, position="branch-top") # # I guess we also have to explicitly add the alignment column # if we are overriding the layout function. # ete3/treeview/layouts.py : phylogeny(node) if hasattr(node, 'sequence'): seq_face = SequenceFace(node.sequence, seqtype='nt', fsize=13) seq_face.margin_left = 4 add_face_to_node(seq_face, node, column=1, aligned=True)
def leaf_style(node, seqmeta, tp_colors, highlight_node=None): name = node.name + " (mf={}) ".format(round(float(seqmeta['mut_freq']), 3)) F = ete3.faces.TextFace(name, fsize=9) ete3.add_face_to_node(F, node, column=1, position='branch-right') ## Style the node with color corresponding to timepoint nstyle = ete3.NodeStyle() #if node.name == highlight_node: #nstyle['fgcolor'] = 'brown' #else: #nstyle['fgcolor'] = tp_colors[seqmeta['timepoint']] nstyle['size'] = 0 node.set_style(nstyle) # Style the node with color corresponding to timepoint if False: nstyle = ete3.NodeStyle() if node.name == highlight_node: nstyle['fgcolor'] = 'brown' else: nstyle['fgcolor'] = tp_colors[seqmeta['timepoint']] nstyle['size'] = 14 node.set_style(nstyle) timepoints = filter( lambda x: x, seqmeta.get('cluster_timepoints', seqmeta['timepoints']).split(':')) duplicities = [ int(n) for n in seqmeta.get('cluster_timepoint_multiplicities', seqmeta['timepoint_multiplicities']).split(':') if n ] multiplicity = int( seqmeta.get('cluster_multiplicity', seqmeta['multiplicity'])) percents = [d * 100 / multiplicity for d in duplicities] colors = [tp_colors[t] for t in timepoints] pie_node = ete3.PieChartFace(percents, width=scale_node(multiplicity), height=scale_node(multiplicity), colors=colors, line_color='black') ete3.add_face_to_node(pie_node, node, column=0)
def layout(node): """ layout for ete2 tree plotting fig """ if node.is_leaf(): nameF = ete3.TextFace(node.name, tight_text=False, fgcolor="#262626", fsize=8) ete3.add_face_to_node(nameF, node, column=0, position="aligned") node.img_style["size"] = 0 else: if not node.is_root(): node.img_style["size"] = 0 node.img_style["shape"] = 'square' node.img_style["fgcolor"] = "#262626" if "quartets_total" in node.features: ete3.add_face_to_node(ete2.PieChartFace( percents=[float(node.quartets_sampled_prop), 100-float(node.quartets_sampled_prop)], width=15, height=15, colors=PIECOLORS), node, column=0, position="float-behind") if "bootstrap" in node.features: ete3.add_face_to_node(ete2.AttrFace( "bootstrap", fsize=7, fgcolor='red'), node, column=0, position="branch-top") else: node.img_style["size"] = 0 if node.is_root(): node.img_style["size"] = 0 node.img_style["shape"] = 'square' node.img_style["fgcolor"] = "#262626"
def my_layout(node): seqmeta = annotations.get(node.name) # handle leaves if seqmeta and not re.compile("naive").match(node.name): leaf_style(node, seqmeta, tp_colors, highlight_node) # Deal with naive and true internal nodes else: # Have to set all node sizes to 0 or we end up distorting the x-axis nstyle = ete3.NodeStyle() nstyle['size'] = 0 node.set_style(nstyle) # Highlight just those nodes in the seedlineage which have nonzero branch lengths, or bad things if node in seed_lineage and node.dist > 0: position = "float" # Note; we use circleface instead of node style to avoid borking the x-axis circle_face = ete3.CircleFace(radius=5, color='brown', style="circle") ete3.add_face_to_node(circle_face, node, column=0, position=position)
def my_layout(node): N = TextFace(node.numbers, tight_text=True) add_face_to_node(N, node, column=1, position="branch-right") style = NodeStyle() if node.name == "N0": style["fgcolor"] = style["hz_line_color"] = "red" elif node.name == "N1": style["fgcolor"] = style["hz_line_color"] = "lime" elif node.name == "N2": style["fgcolor"] = style["hz_line_color"] = "cyan" elif node.name == "N3": style["fgcolor"] = style["hz_line_color"] = "plum" elif node.name == "N4": style["fgcolor"] = style["hz_line_color"] = "lightsalmon" elif node.name == "N5": style["fgcolor"] = style["hz_line_color"] = "indigo" elif node.name == "N6": style["fgcolor"] = style["hz_line_color"] = "royalblue" elif node.name == "N7": style["fgcolor"] = style["hz_line_color"] = "olive" node.set_style(style)
def custom_layout(node): if node.is_leaf(): aligned_name_face = TextFace(node.name, fgcolor='olive', fsize=14) add_face_to_node(aligned_name_face, node, column=2, position='aligned') name_face = TextFace(node.name, fgcolor='#333333', fsize=11) add_face_to_node(name_face, node, column=2, position='branch-right') node.img_style['size'] = 0 else: node.img_style['size'] = 4 node.img_style['shape'] = 'square' if node.name: name_face = TextFace(node.name, fgcolor='grey', fsize=10) name_face.margin_bottom = 2 add_face_to_node(name_face, node, column=0, position='branch-top') if node.support: support_face = TextFace(node.support, fgcolor='indianred', fsize=10) add_face_to_node(support_face, node, column=0, position='branch-bottom')
def rotation_layout(node): if node.is_leaf(): if node.name == 'X': F = TextFace(node.name, tight_text=True, fgcolor='Blue') F.rotation = 90 add_face_to_node(F, node, column=0, position="branch-right") elif node.name == 'Y': F = TextFace(node.name, tight_text=True, fgcolor='Red') F.rotation = 90 add_face_to_node(F, node, column=0, position="branch-right") elif node.name == 'A': F = TextFace("") add_face_to_node(F, node, column=0, position="branch-right") else: F = TextFace(node.name, tight_text=True, fgcolor='Green') F.rotation = 90 add_face_to_node(F, node, column=0, position="branch-right")
def rotation_layout(node): if node.is_leaf(): F = TextFace(node.name, tight_text=True) F.rotation = randint(0, 360) add_face_to_node(TextFace("third" ), node, column=8, position="branch-right") add_face_to_node(TextFace("second" ), node, column=2, position="branch-right") add_face_to_node(F, node, column=0, position="branch-right") F.border.width = 1 F.inner_border.width = 1
def ly_supports(node): if not node.is_leaf() and node.up: supFace = TextFace("%0.2g" %(node.support), fsize=7, fgcolor='indianred') add_face_to_node(supFace, node, column=0, position='branch-top')
def layout(node): if node.is_leaf(): seqFace = SeqMotifFace(seq, motifs, scale_factor=1) add_face_to_node(seqFace, 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