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 get_tree(tree1, abundance):

    for n in tree1.iter_leaves():

        face1 = CircleFace(abundance[n.name][0],
                           abundance[n.name][1],
                           style='sphere')
        face2 = TextFace(n.name,
                         ftype='Verdana',
                         fsize=10,
                         fgcolor='black',
                         penwidth=0,
                         fstyle='normal',
                         tight_text=False,
                         bold=False)
        face1.opacity = 0.9

        n.add_face(face1, column=0)
        n.add_face(
            face2, column=0,
            position="branch-right")  #branch-top branch-bottom branch-right

    tree1.ladderize()

    ts = TreeStyle()
    ts.mode = 'r'
    ts.scale = scale1
    ts.show_leaf_name = False

    return tree1, ts
예제 #3
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")
예제 #4
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(n):
    nstyle_bg = NodeStyle()
    nstyle_bg["size"] = 0
    n.set_style(nstyle_bg)
    if n.calibration_red:
        n.set_style(nstyle_bg)
        C = CircleFace(radius=8, color="red", style="sphere")
#        C = RectFace(width=20, height=5, fgcolor="red", bgcolor="red")
        # Let's make the sphere transparent
        C.opacity = 0.7
        # place as a float face over the tree
        faces.add_face_to_node(C, n, 0, position="float")
#        faces.add_face_to_node(C, n, 0, position="branch-right")
    if n.calibration_blue:
        n.set_style(nstyle_bg)
        C = CircleFace(radius=8, color="blue", style="sphere")
#        C = RectFace(width=20, height=5, fgcolor="red", bgcolor="red")
        # Let's make the sphere transparent
        C.opacity = 0.7
        # place as a float face over the tree
        faces.add_face_to_node(C, n, 0, position="float")
예제 #6
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")
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 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")
예제 #9
0
def mk_bilan_tree(tree, bilan_nodesWithTransitions, output):
    d_nodesWithTransitions = {}
    for x in bilan_nodesWithTransitions:
        if x in d_nodesWithTransitions:
            d_nodesWithTransitions[x] += 1
        else:
            d_nodesWithTransitions[x] = 1

    for n in tree.traverse():
        if n.ND in d_nodesWithTransitions:
            n.set_style(nstyle_T2)
            C = CircleFace(radius=d_nodesWithTransitions[n.ND] * 2,
                           color="RoyalBlue",
                           style="sphere",
                           label=str(d_nodesWithTransitions[n.ND]))
            C.opacity = 0.5
            n.add_face(C, 0, position="float")
        else:
            n.set_style(nstyle)

    tree.render(output, tree_style=tree_style)
예제 #10
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")
예제 #11
0
    def plot_tree(self,
                  output_filepath,
                  time_series_info=None,
                  tree_style='horizontal_right',
                  leaf_size_map_to=None,
                  show_leaf_names=False,
                  color_branches_by=None,
                  line_width=1,
                  start_color='red',
                  end_color='purple',
                  ladderize=True):
        """
		This method plots the phylogenetic tree as a dendogram. Uses the ete3 package to do this.
		output_filepath - This is the path to the output image file.
		time_series_info - This tells where the information of time-point can be found (if at all) in each of the element IDs. Acceptable values are:
			None - (default) This means there is no time information in the tree
			'start_of_id' - This means the time info is at the very beginning of each element ID, and is separated by a '_'. For example: '45.3_blahblahblah' would have a time point of 45.3.
		tree_style - This give the style of tree plotting, i.e. circular, horizontal, etc. Acceptable values are:
			'half_circle' - Tree is plotted as a half circle, where branches are radiating outward and upward.
			'horizontal_right' - Tree is plotted as a normal dendogram where branching occurs from left to right.
		leaf_size_map_to - If defined (default, None), this will inform what attribute of the node the leaf size maps to. Acceptable values are:
			None - No leaf size info. All leaves the same size
			'count' - leaf size proportional to the count attribute
			'freq' - leaf size proportional to the freq attribute
		show_leaf_names - If True (default, False), then will plot the names of each of the leafs of the tree.
		color_branches_by - If defined (default, None) this will give how the leaf branches will be colored, if at all. Acceptable values are:
			None - Default. No branch coloring
			'time_point' - This means that the branches will be colored according to the 'time_point' attribute of each leaf node. There must be a 'time_point' attribute in the leaf nodes for this to work. So, one should run the 'add_time_info' method before doing this. Alternatively, one can define the 'time_series_info' parameter for this method, and this will be taken care of.
			any other string - This will give the name of any other attribute of the leaf nodes for which to map the value to the leaf branch color.
		then this will instruct to color the different time-points with different colors. This is ignored if 'time_series_info' is False
		line_width - controls the line width. Default, 1
		start_color - This gives the staring color. This should be a string the spells out the name of a color. Most simple colors should be fine. Uses the 'Color' module from 'colour'.
		end_color - This gives the ending color. This should be a string the spells out the name of a color. Most simple colors should be fine. Uses the 'Color' module from 'colour'. The colors used for each unique attribute that gives the colors will span the spectrom from 'start_color' to 'end_color'.
		ladderize - If True (default), this will ladderize the tree. That is it will sort the partitions of the internal nodes based upon number of decendant nodes in the child nodes.
		"""
        if not self.time_points and time_series_info:
            self.add_time_info(time_series_info=time_series_info)
        #set time-point colors, if desired
        if color_branches_by:
            start_color = Color(start_color)
            end_color = Color(end_color)
            if color_branches_by == 'time_point' and time_series_info:
                colors = list(
                    start_color.range_to(end_color, len(self.time_points)))
                hex_colors = [i.hex_l for i in colors]
                tpoint_to_color_dic = {}
                for index, i in enumerate(sorted(self.time_points)):
                    tpoint_to_color_dic[i] = hex_colors[index]
            else:
                #check if attribute already exists in the tree data. if not, add it
                for leaf in self.tree:
                    if not color_branches_by in leaf.features:
                        self.add_attribute_to_leaves(
                            attribute_name=color_branches_by)
                    break
                colors = list(
                    start_color.range_to(
                        end_color,
                        len(self.extra_leaf_features[color_branches_by])))
                hex_colors = [i.hex_l for i in colors]
                attribute_to_color_dic = {}
                for index, i in enumerate(
                        sorted(self.extra_leaf_features[color_branches_by])):
                    attribute_to_color_dic[i] = hex_colors[index]
        #set node styles
        most_dist_leaf, size_to_tree_size_scaler = self.tree.get_farthest_leaf(
        )  #need to scale sizes by the length (divergence) of the tree
        for node in self.tree.traverse():
            node_style = NodeStyle()
            #do stuff to leaf nodes
            if node.is_leaf():
                if color_branches_by:
                    if color_branches_by == 'time_point':
                        color = tpoint_to_color_dic[node.time_point]
                    else:
                        color = attribute_to_color_dic[getattr(
                            node, color_branches_by)]
                else:
                    color = Color('black')
                    color = color.hex_l
                node_style['hz_line_color'] = color
                node_style['vt_line_color'] = color
                if leaf_size_map_to:
                    if leaf_size_map_to == 'count':
                        radius = size_to_tree_size_scaler * 100 * math.log(
                            node.count)
                    elif leaf_size_map_to == 'freq':
                        radius = size_to_tree_size_scaler * 100 * node.freq
                    c = CircleFace(radius=radius, color=color, style='circle')
                    c.opacity = 0.3
                    node.add_face(c, 0, position='branch-right')
                    node_style['size'] = 0
            node_style[
                'hz_line_width'] = size_to_tree_size_scaler * 10 * line_width
            node_style[
                'vt_line_width'] = size_to_tree_size_scaler * 10 * line_width
            node.set_style(node_style)
        #set tree style
        tree_steeze = TreeStyle()
        if tree_style == 'half_circle':
            tree_steeze.mode = 'c'
            tree_steeze.arc_start = -180
            tree_steeze.arc_span = 180
        elif tree_style == 'horizontal_right':
            pass
        if show_leaf_names:
            tree_steeze.show_leaf_name = True
        else:
            tree_steeze.show_leaf_name = False
        self.tree.ladderize()
        self.tree.render(output_filepath,
                         w=700,
                         h=700,
                         units='mm',
                         tree_style=tree_steeze)
        return