예제 #1
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")
예제 #2
0
def duploss(node):
    if hasattr(node, 'dup'):
        node.add_face(AttrFace('dup', fsize=5, fgcolor='blue'),
                      column=0,
                      position="branch-bottom")
    if hasattr(node, 'loss'):
        node.add_face(AttrFace('loss', fsize=5, fgcolor='red'),
                      column=0,
                      position="branch-bottom")
예제 #3
0
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")
예제 #4
0
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")
예제 #5
0
 def base_node_style(self):
     from ete3 import NodeStyle, AttrFace
     nstyle = NodeStyle()
     nstyle["shape"] = "sphere"
     nstyle["size"] = 2
     nstyle["fgcolor"] = "black"
     for n in self.tree.traverse():
         n.set_style(nstyle)
         if re.match('.*fasta', n.name):
             nf = AttrFace('name', fsize=8)
             nf.margin_right = 150
             nf.margin_left = 3
             n.add_face(nf, column=0)
     self.log.info("Applied base node style")
예제 #6
0
    def diamond_layout(node):
        # Run the layout passed in first before
        # filling in the heatmap
        layout(node)

        N = AttrFace("name", fsize=label_size, fgcolor=labelcolor)

        # background colors
        c, found = _get_node_color(bgcolors, node, "")
        if found:
            nst = NodeStyle()
            nst["bgcolor"] = c
            node.set_style(nst)

        if node.name in collapsed_nodes:
            # scaling factor for approximating subtree depth
            depth = node.get_farthest_leaf(topology_only=True)
            w = depth[1] * depth_scaling
            # scaling factor for approximating for subtree width
            h = len(node) * breadth_scaling
            c, _ = _get_node_color(cladecolors, node, "#0000FF")

            C = CollapsedDiamondFace(width=w, height=h, color=c)
            node.img_style['draw_descendants'] = False

            # And place as a float face over the tree
            faces.add_face_to_node(C, node, 0, position="float")
            faces.add_face_to_node(N, node, 1, position="float")
        else:
            faces.add_face_to_node(N, node, 0)
예제 #7
0
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 writeTrees(trees, label):
    ts = TreeStyle()
    ts.show_leaf_name = False
    ts.show_branch_length = False
    ts.branch_vertical_margin = 20
    ts.scale = 0.05
    outtrees = open(lengthdir + label + ".newick", "w")
    #round the branch lengths
    for index, tree in enumerate(trees):
        #print(tree)
        for branch in tree.traverse():
            branch.dist = round(branch.dist)
        line = tree.write(format=1)
        outtrees.write(line + "\n")
        if (showTrees):
            for branch in tree.traverse():
                if branch.dist != 0:
                    text_face = TextFace(str(round(branch.dist, 2)), fsize=30)
                    branch.add_face(text_face, column=1, position="branch-top")
                elif branch.name != "":
                    name_face = AttrFace("name", fsize=30)
                    branch.add_face(name_face,
                                    column=0,
                                    position="branch-right")
                else:
                    print("Branch found of length zero but not a tip in tree",
                          label)
                    print(branch)
            filename = label
            if len(trees) > 1:
                filename += "_" + str(index)
            filename += ".png"
            tree.render(lengthdir + filename, tree_style=ts)
            #foo()
    outtrees.close()
예제 #9
0
 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"
예제 #10
0
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")
예제 #11
0
def ColorCodedNode (node):
    if node.is_leaf():
        ColorCode=PhenoDict[node.name]
        
        if ColorCode == '1':
            #Name=faces.AttrFace('name',fsize='20',fgcolor="Blue")
            #NameFace=TextFace(Name)
            faces.add_face_to_node(AttrFace('name',fsize=20,fgcolor='blue'), node, column=0,aligned=True)
            #faces.add_face_to_node(TextFace(text='marker1',fsize=10,fgcolor='black'), node, column=1,position='aligned')
            faces.add_face_to_node(ProfileFace(1, -1, 0, width=200, height=40, style='heatmap', colorscheme=2),node,column=1,position='aligned')
        elif ColorCode == '2':
            #Name=faces.AttrFace('name',fsize='20',fgcolor="Red")
            #NameFace=TextFace(Name)
            faces.add_face_to_node(AttrFace("name",fsize=20,fgcolor='red'), node, column=0,aligned=True)
            faces.add_face_to_node(ProfileFace(1, -1, 0, width=200, height=40, style='heatmap', colorscheme=2),node,column=1,position='aligned')
        elif ColorCode == '-9':
            faces.add_face_to_node(AttrFace("name",fsize=20,fgcolor='black'), node, column=0,aligned=True)
            faces.add_face_to_node(ProfileFace(1, -1, 0, width=200, height=40, style='heatmap', colorscheme=2),node,column=1,position='aligned')
예제 #12
0
파일: layouts.py 프로젝트: josenavas/gneiss
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")
예제 #13
0
def queryNode(leaf):
	nsQuery = NodeStyle()
	nsQuery["fgcolor"] = "red"
	nsQuery["shape"] = "sphere"
	nsQuery["size"] = 9
	nsQuery["hz_line_type"] = 1
	nsQuery["hz_line_color"] = "red"
	faceQuery = AttrFace("name", fsize=9, fstyle="italic", text_prefix=" ")
	leaf.set_style(nsQuery)
	leaf.add_face(faceQuery, column=0, position="branch-right")
예제 #14
0
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")
예제 #15
0
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")
예제 #16
0
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")
예제 #17
0
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")
예제 #18
0
def layout(node):
    global f1_lst
    global f2_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 f1_lst:
            C = CircleFace(radius=5, color="darkred", style="sphere")
            faces.add_face_to_node(C, node, 1, position="aligned")
        if node.name in f2_lst:
            C = CircleFace(radius=5, color="RoyalBlue", style="sphere")
            faces.add_face_to_node(C, node, 2, position="aligned")
예제 #19
0
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 layout(node):
     if node.is_leaf():
         N = AttrFace("name", 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 1/gini index
         circle_face = CircleFace(radius=node.weight,
                                  color="RoyalBlue",
                                  style="sphere")
         circle_face.hz_align = 2
         circle_face.opacity = 0.3
         text_face = TextFace(text=node.name)
         faces.add_face_to_node(circle_face, node, 0, position="float")
         faces.add_face_to_node(text_face, node, 0, position="float")
예제 #21
0
 def my_layout(node):
     if hasattr(node, 'has_face'):
         return
     if node.is_leaf():
         # If terminal node, draws its name
         name_face = AttrFace("name", fsize=12)
         node.add_face(name_face, column=0, position="branch-right")
     else:
         # If internal node, draws label with smaller font size
         if node.name == 'root':
             label = 'root'
         else:
             label = str(mut_order[int(node.name)])
         name_face = TextFace(label, fsize=10)
         node.add_face(name_face, column=0, position="branch-top")
     node.add_feature('has_face', 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")
예제 #23
0
def writeTrees(trees, label):
    """
    Now that we have branch lengths, write out new Newick trees with the
    branch lengths included.  Note that ete3 does not seem to write out
    the length of the root automatically, so we add it in by hand.
    """
    ts = TreeStyle()
    ts.show_leaf_name = False
    ts.show_branch_length = False
    ts.branch_vertical_margin = 20
    ts.scale = 0.05
    outtrees = open(lengthdir + label + ".newick", "w")
    for index, tree in enumerate(trees):
        #print(tree)
        #If needed:  round the branch lengths
        #        for branch in tree.traverse():
        #            branch.dist = round(branch.dist)
        line = tree.write(format=1)
        rootlen = round(tree.get_tree_root().dist)
        line = line[:-1] + ":" + str(rootlen) + ";"
        outtrees.write(line + "\n")
        if (showTrees):
            for branch in tree.traverse():
                if branch.name != "":
                    name_face = AttrFace("name", fsize=30)
                    branch.add_face(name_face,
                                    column=0,
                                    position="branch-right")
                if branch.dist != 0:
                    if branch.name == "":
                        text_face = TextFace(str(round(branch.dist, 2)),
                                             fsize=30)
                        branch.add_face(text_face,
                                        column=1,
                                        position="branch-top")
                else:
                    print("Branch found of length zero but not a tip in tree",
                          label)
                    print(branch)
            filename = label
            if len(trees) > 1:
                filename += "_" + str(index)
            filename += ".png"
            tree.render(lengthdir + filename, tree_style=ts)
            #foo()
    outtrees.close()
예제 #24
0
def species_colouring(node):
	
	if node.is_leaf() and not node.name.isdigit() and not node.name is '' and not getattr(node,"evoltype", None) == "L":
		#node.name [Protein_id]_[hit (can contain underscores) ]_[number]_[position]
		frag = node.name.split('_')
		protein_id = frag[0]
		species_id = ''.join(filter(str.isalpha, protein_id))
		ns = NodeStyle()
		#if protein_id in protein_dict:
		#	protein_face = CircleFace(8, protein_dict[protein_id], style='circle', label=None)
		#	faces.add_face_to_node(protein_face, node, column=1)
		if species_id in species_mapping:
			ns['fgcolor'] = species_mapping[species_id]['colour']
			ns['size'] = 12
		node.name = protein_id+' '+frag[-2]+' ('+frag[-1]+')' #last and second to last elements.
		name_face = AttrFace("name", fsize=8)
		faces.add_face_to_node(name_face, node, column=0, position="branch-right")
		node.set_style(ns)
def layout(node):
    if node.is_leaf():
        N = AttrFace("sci_name", fsize=30)
        faces.add_face_to_node(N, node, 0, position="branch-right")
        circle = RectFace(100, 100, "black", "black")

        faces.add_face_to_node(circle, position="aligned", column=0, node=node)
        if "coli" in node.sci_name:
            circle = RectFace(100, 100, "red", "red")
            faces.add_face_to_node(circle,
                                   position="aligned",
                                   column=1,
                                   node=node)
        if "Salm" in node.sci_name:
            circle = RectFace(100, 100, "blue", "blue")
            faces.add_face_to_node(circle,
                                   position="aligned",
                                   column=2,
                                   node=node)
예제 #26
0
    def sel_mylayout(node):
        node.set_style(my_node_style)

        if node.is_leaf():
            # add names in larger font + italics
            species_name = AttrFace("name", fsize=12, fstyle="italic")
            add_face_to_node(species_name,
                             node,
                             column=0,
                             position="branch-right")
            # add absence/presence matrix
            for i, value in enumerate(getattr(node, "profile", [])):
                if value > 0:
                    color = "#FF0000"
                else:
                    color = "#EEEEEE"
                my_face = CircleFace(8, color, style="circle")
                my_face.margin_right = 3
                my_face.margin_bottom = 3
                add_face_to_node(my_face, node, position="aligned", column=i)
예제 #27
0
 def layout(node):
     node.img_style = ns
     if node.is_leaf():
         faces.add_face_to_node(AttrFace(
             'fullname',
             fsize=14,
             fgcolor=(MARKED_NODE_COLOR if
                      (node.name in colors
                       or node.fullname in colors) else 'black')),
                                node,
                                0,
                                position="aligned")
         if hasattr(node, "sequence") and node.sequence:
             seqface = SequenceFace(node.sequence,
                                    "codon",
                                    fsize=13,
                                    codontable=codontable,
                                    col_w=RES_COL_WIDTH,
                                    bg_colors=codon_col,
                                    black_out=node.edlist)
             faces.add_face_to_node(seqface, node, 1, position="aligned")
예제 #28
0
def ts_layout(node, fgcolor='#FF4ba6', fsize=12):
    '''
    Please set up as the following code shows:

    ```py
    ts = TreeStyle()
    ts.mode = 'r' # 'c'
    ts.min_leaf_separation = 40
    # ts.branch_vertical_margin = 20
    # Do not add leaf names automatically
    ts.show_leaf_name = False
    ts.show_scale = False
    ts.optimal_scale_level = 'mid'
    ts.margin_top = 5
    ts.margin_left = 5
    ts.margin_right = 5
    # Use my custom layout
    ts.layout_fn = ts_layout
    ```
    '''
    node.img_style["size"] = 2
    node.img_style["shape"] = "circle"
    node.img_style["fgcolor"] = fgcolor
    if node.is_leaf():
        # If terminal node, draws its name
        name_face = AttrFace("name", fsize=fsize)  # fgcolor="royalblue"
        name_face.margin_left = 3
        faces.add_face_to_node(name_face,
                               node,
                               column=0,
                               position="branch-right")
    elif not node.is_root():
        # If internal node, draws label with smaller font size
        name_face = AttrFace("name", fsize=fsize)
        name_face.margin_left = 2
        name_face.margin_bottom = 2
        # Adds the name face to the image at the preferred position
        faces.add_face_to_node(name_face,
                               node,
                               column=0,
                               position="branch-top")
예제 #29
0
파일: layouts.py 프로젝트: josenavas/gneiss
def default_layout(node):
    """
    Specifies the layout for the ete.TreeStyle object.

    Parameters
    ----------
    node: ete.Tree
        Input node for specifying which attributes.
    """
    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="Red", style="sphere")
        # Let's make the sphere transparent
        C.opacity = 0.5
        # Rotate the faces by 90*
        C.rotation = 90
        # And place as a float face over the tree
        faces.add_face_to_node(C, node, 0, position="float")
예제 #30
0
def layout(node):
    # Add node name to laef nodes
    N = AttrFace("name", fsize=9, fgcolor="black")
    faces.add_face_to_node(N, node, 0)