示例#1
0
    def color_clade(self, clade_field, clade, color):
        """ Will highlight a certain clade by drawing a sector around the clade.
        The sector will start at the root of the clade and create an arc from the
        most to the right most tip. The sector will aslo have a defualt arc length
        equal to the distance from the root of the clade to the deepest tip..

        Parameters
        ----------
        clade : string
            The clade to highlight
        color : string (hex string)
            The color to highlight the clade with

        Returns
        -------
        return : list
            A list of all highlighted clades
        """
        if clade_field != 'None':
            c = clade
            clade_root = self.edge_metadata.loc[self.edge_metadata[clade_field] == clade]
            clade_roots_id = clade_root['Node_id'].values

            if len(clade_roots_id) == 0:
                for c in range(0, len(self.cached_clades)):
                    if clade in self.cached_clades[c]:
                        self.cached_clades[c][clade]['color'] = color
                return {"empty": []}

            i = 0
            for clade_root_id in clade_roots_id:
                clades = self.tree.find_all(clade_root_id)
                for clade in clades:
                    color_clade = self.tree.get_clade_info(clade)
                    color_clade['color'] = color
                    color_clade_s = tools.create_arc_sector(color_clade)
                    depth = len([node.name for node in clade.ancestors()])
                    self.colored_clades[c+str(i)] = {'data': color_clade_s,
                                              'depth': depth,
                                              'color': color,
                                              'node': clade}
                    i += 1
        else:
            i = 0
            clade_name = clade
            for (k,v) in self.colored_clades.items():
                if clade_name in k:
                    clade = v['node']
                    color_clade = self.tree.get_clade_info(clade)
                    color_clade['color'] = color
                    color_clade_s = tools.create_arc_sector(color_clade)
                    depth = len([node.name for node in clade.ancestors()])
                    self.colored_clades[k] = {'data': color_clade_s,
                                              'depth': depth,
                                              'color': color,
                                              'node': clade}
                    i += 1
        return self.get_colored_clade()
示例#2
0
    def refresh_clades(self):
        colored_clades = {}
        for k, v in self.colored_clades.items():
            clade_root = self.edge_metadata.loc[self.edge_metadata[
                self.clade_field] == k]
            clade_root_id = clade_root['Node_id'].values[0] if len(
                clade_root) > 0 else -1

            if clade_root_id != -1:
                clade = self.tree.find(clade_root_id)
                tips = clade.tips()
                clade_ancestor = clade.parent
                center_coords = (clade.x2, clade.y2)
                ancestor_coords = (clade_ancestor.x2 - clade.x2,
                                   clade_ancestor.y2 - clade.y2)
                points = [[tip.x2 - clade.x2, tip.y2 - clade.y2]
                          for tip in tips]
                color_clade = tools.sector_info(points, center_coords,
                                                ancestor_coords)
                color_clade['color'] = v['color']
                color_clade_s = tools.create_arc_sector(color_clade)
                depth = len([node.name for node in clade.ancestors()])
                colored_clades[k] = {
                    'data': color_clade_s,
                    'depth': depth,
                    'color': color_clade['color']
                }
        return colored_clades
示例#3
0
 def refresh_clades(self):
     colored_clades = {}
     for k, v in self.colored_clades.items():
         clade_id = self.colored_clades[k]['id']
         clade = self.tree.find(clade_id)
         color_clade = self.tree.get_clade_info(clade)
         color_clade['color'] = v['color']
         color_clade_s = tools.create_arc_sector(color_clade)
         depth = len([node.name for node in clade.ancestors()])
         colored_clades[k] = {'data': color_clade_s,
                              'depth': depth,
                              'color': color_clade['color']}
     return colored_clades
示例#4
0
    def color_clade(self, clade, color):
        """ Will highlight a certain clade by drawing a sector around the clade.
        The sector will start at the root of the clade and create an arc from the
        most to the right most tip. The sector will aslo have a defualt arc length
        equal to the distance from the root of the clade to the deepest tip..

        Parameters
        ----------
        clade : string
            The clade to highlight
        color : string (hex string)
            The color to highlight the clade with

        Returns
        -------
        return : list
            A list of all highlighted clades
        """
        # is it be safe to assume clade ids will be unique?
        c = clade
        clade_root = self.edge_metadata.loc[self.edge_metadata[
            self.clade_field] == clade]
        clade_root_id = clade_root['Node_id'].values[0] if len(
            clade_root) > 0 else -1

        if clade_root_id == -1:
            for c in range(0, len(self.cached_clades)):
                if clade in self.cached_clades[c]:
                    self.cached_clades[c][clade]['color'] = color
            return {"empty": []}

        clade = self.tree.find(clade_root_id)

        tips = clade.tips()
        clade_ancestor = clade.parent
        center_coords = (clade.x2, clade.y2)
        ancestor_coords = (clade_ancestor.x2 - clade.x2,
                           clade_ancestor.y2 - clade.y2)
        points = [[tip.x2 - clade.x2, tip.y2 - clade.y2] for tip in tips]
        color_clade = tools.sector_info(points, center_coords, ancestor_coords)
        color_clade['color'] = color
        color_clade_s = tools.create_arc_sector(color_clade)
        depth = len([node.name for node in clade.ancestors()])
        self.colored_clades[c] = {
            'data': color_clade_s,
            'depth': depth,
            'color': color
        }
        return self.get_colored_clade()
示例#5
0
 def test_create_arc_sector(self):
     tools.NUM_TRI = 1
     sector_info = {
         'theta': math.pi / 2,
         'starting_angle': 0,
         'center_x': 0,
         'center_y': 0,
         'largest_branch': 1,
         'color': 'FFFFFF'
     }
     exp_arc = [0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1]
     res_arc = tools.create_arc_sector(sector_info)
     for i in range(len(res_arc)):
         self.assertEqual(
             math.isclose(exp_arc[i], res_arc[i], abs_tol=1e-09), True)