Esempio n. 1
0
    def get_pairing_contents(self, index: int, width: int, height: int) -> str:
        """ Generate an SVG comparing the query to a single hit cluster

            Arguments:
                index: the index of the hit
                width: the width of the SVG
                height: the height of the SVG

            Returns:
                a string containing the SVG XML
        """
        svg = Svg(x=0, y=0, width=width, height=height)
        viewbox = "0 0 %d %d" % (width, height)
        svg.set_viewBox(viewbox)
        svg.set_preserveAspectRatio("none")
        max_length = max([len(self.query_cluster), len(self.hits[index])])
        scaling = (width - 20) / max_length
        for i, cluster in enumerate([self.query_cluster, self.hits[index]]):
            for group in cluster.get_svg_groups(
                    v_offset=50 * i,
                    h_offset=(max_length - len(cluster)) // 2,
                    scaling=scaling,
                    colours=self.colour_lookup):
                svg.addElement(group)
        return svg.getXML()
Esempio n. 2
0
    def get_overview_contents(self, width: int, height: int) -> str:
        """ Generate an SVG comparing the query to all hit cluster

            Arguments:
                width: the width of the SVG
                height: the height of the SVG

            Returns:
                a string containing the SVG XML
        """
        svg = Svg(x=0, y=0, width=width, height=height)
        viewbox = "0 0 %d %d" % (width, height)
        svg.set_viewBox(viewbox)
        svg.set_preserveAspectRatio("none")
        scaling = (width - 20) / self.max_length  # -20 for margins
        offset = (self.max_length - len(self.query_cluster)) // 2
        for group in self.query_cluster.get_svg_groups(
                h_offset=offset,
                scaling=scaling,
                colours=self.colour_lookup,
                overview=True,
                prefix=self.prefix):
            svg.addElement(group)
        for index, cluster in enumerate(self.hits):
            for group in cluster.get_svg_groups(
                    v_offset=50 * (index + 1),
                    h_offset=(self.max_length - len(cluster)) // 2,
                    scaling=scaling,
                    colours=self.colour_lookup,
                    overview=True,
                    prefix=self.prefix):
                svg.addElement(group)
        return svg.getXML()