Пример #1
0
    def style_and_render_tree(self, file_types=["svg"]):
        from ete3 import TreeStyle, TextFace, CircleFace

        ts = TreeStyle()
        title_face = TextFace(f"{genus} {snakemake.config['species']}", fsize=20)
        title_face.margin_bottom = 10
        ts.title.add_face(title_face, column=0)
        ts.branch_vertical_margin = 10
        ts.show_leaf_name = True
        # Legend
        ts.legend.add_face(TextFace(""), column=1)
        for category in ["Allowed", "Deviations", "Filtered", "Color"]:
            category = TextFace(category, fsize=8, bold=True)
            category.margin_bottom = 2
            category.margin_right = 40
            ts.legend.add_face(category, column=1)
        for i, criteria in enumerate(CRITERIA, 2):
            title = criteria.replace("_", " ").title()
            title = TextFace(title, fsize=8, bold=True)
            title.margin_bottom = 2
            title.margin_right = 40
            cf = CircleFace(4, COLORS[criteria], style="sphere")
            cf.margin_bottom = 5
            filtered_count = len(
                list(filter(None, self.failed_report.criteria == criteria))
            )
            filtered = TextFace(filtered_count, fsize=8)
            filtered.margin_bottom = 5
            allowed = TextFace(self.allowed[criteria], fsize=8)
            allowed.margin_bottom = 5
            allowed.margin_right = 25
            # TODO Prevent tolerance from rendering as a float
            tolerance = TextFace(self.tolerance[criteria], fsize=8)
            tolerance.margin_bottom = 5
            ts.legend.add_face(title, column=i)
            ts.legend.add_face(allowed, column=i)
            ts.legend.add_face(tolerance, column=i)
            ts.legend.add_face(filtered, column=i)
            ts.legend.add_face(cf, column=i)
        for f in file_types:
            out_tree = os.path.join(self.paths.qc, "tree.{}".format(f))
            self.tree.render(out_tree, tree_style=ts)
Пример #2
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)
Пример #3
0
 def style_and_render_tree(self, file_types=["svg"]):
     from ete3 import TreeStyle, TextFace, CircleFace
     ts = TreeStyle()
     title_face = TextFace(self.name.replace('_', ' '), fsize=20)
     title_face.margin_bottom = 10
     ts.title.add_face(title_face, column=0)
     ts.branch_vertical_margin = 10
     ts.show_leaf_name = False
     # Legend
     ts.legend.add_face(TextFace(""), column=1)
     for category in ["Allowed", "Tolerance", "Filtered", "Color"]:
         category = TextFace(category, fsize=8, bold=True)
         category.margin_bottom = 2
         category.margin_right = 40
         ts.legend.add_face(category, column=1)
     for i, criteria in enumerate(self.criteria, 2):
         title = criteria.replace("_", " ").title()
         title = TextFace(title, fsize=8, bold=True)
         title.margin_bottom = 2
         title.margin_right = 40
         cf = CircleFace(4, self.colors[criteria], style="sphere")
         cf.margin_bottom = 5
         filtered_count = len(
             list(filter(None, self.failed_report.criteria == criteria)))
         filtered = TextFace(filtered_count, fsize=8)
         filtered.margin_bottom = 5
         allowed = TextFace(self.allowed[criteria], fsize=8)
         allowed.margin_bottom = 5
         allowed.margin_right = 25
         tolerance = TextFace(self.tolerance[criteria], fsize=8)
         tolerance.margin_bottom = 5
         ts.legend.add_face(title, column=i)
         ts.legend.add_face(allowed, column=i)
         ts.legend.add_face(tolerance, column=i)
         ts.legend.add_face(filtered, column=i)
         ts.legend.add_face(cf, column=i)
     for f in file_types:
         out_tree = os.path.join(self.qc_results_dir, 'tree.{}'.format(f))
         self.tree.render(out_tree, tree_style=ts)
         self.log.info("tree.{} generated".format(f))