Example #1
0
    def _add_label(self, group: Group, v_offset: int) -> Group:
        acc = Text(self.full_description, 5, 20 + v_offset)
        if self.prefix == "knownclusterblast":
            desc = "%80s (%s), %s" % (self.description, self.similarity_string,
                                      self.cluster_type)
            acc = Text(
                '<a xlink:href="https://mibig.secondarymetabolites.org/go/' +
                self.accession +
                '/%s" target="_blank">' % self.ref_cluster_number +
                self.accession + '</a>: ' + desc, 5, 20 + v_offset)
        elif self.prefix == "general":
            acc = Text(
                '<a xlink:href="https://antismash-db.secondarymetabolites.org/go/'
                + self.accession +
                '/%s" target="_blank">' % self.ref_cluster_number +
                self.full_description.replace(":", "</a>:", 1), 5,
                20 + v_offset)
        # Don't do any linking for subclusterblast

        acc.set_class("clusterblast-acc")
        group.addElement(acc)
        group.setAttribute('label', self.accession)
        group.setAttribute('description', self.full_description)
        group.set_class('clusterblast-cluster')
        return group
Example #2
0
    def makePathInsertionsGroup(self) -> G:
        part = self.cn_doc.part
        id_coords = self.mapIdnumsToYcoords()
        _BW = self._base_width
        _hBW = _BW/2
        _BH = self._base_height
        _hBH = _BH/2
        _pX = self.PATH_X_PADDING + self._path_radius_scaled*3

        g = G()
        g.setAttribute('id', "PathInsertions")
        g.setAttribute('font-size', "5")
        g.setAttribute("font-family", "'SourceSansPro-Regular'")
        g.setAttribute("text-anchor", "middle")

        insertions = self.cn_doc.insertions

        for id_num in sorted(insertions.keys(), reverse=True):
            fwd_ins_y = id_coords[id_num] - _BH
            rev_ins_y = id_coords[id_num]
            for ins_idx, ins_len, fwd_col, rev_col in insertions[id_num][::-1]:
                ins_g = G()
                ins_g.setAttribute('id', "Ins %s[%s]" % (id_num, ins_idx))
                ins_x = _BW*ins_idx + _pX
                ins_fwd, ins_rev = part.hasStrandAtIdx(id_num, ins_idx)
                if ins_fwd:
                    u = Use()
                    u.setAttribute('xlink:href', '#insertion')
                    u.setAttribute('x', ins_x)
                    u.setAttribute('y', fwd_ins_y)
                    fwd_style = 'fill:none; stroke:%s; stroke-width:2' % fwd_col
                    u.set_style(fwd_style)
                    ins_g.addElement(u)
                    t = Text('%s' % ins_len, ins_x+_hBW, fwd_ins_y)
                    t.set_style('fill:#999999')
                    ins_g.addElement(t)
                if ins_rev:
                    u = Use()
                    u.setAttribute('xlink:href', '#insertion')
                    u.setAttribute('x', ins_x)
                    u.setAttribute('y', rev_ins_y)
                    rev_style = 'fill:none; stroke:%s; stroke-width:2' % rev_col
                    u.set_style(rev_style)
                    u.set_transform('rotate(180,%s,%s)' % (ins_x+_hBW, rev_ins_y+_hBH))
                    ins_g.addElement(u)
                    t = Text('%s' % ins_len, ins_x+_hBW, rev_ins_y+_BH*1.3)
                    t.set_style('fill:#999999')
                    ins_g.addElement(t)
                g.addElement(ins_g)
        # print(g.getXML())
        return g
Example #3
0
    def get_svg_groups(self, h_offset: int = 0, v_offset: int = 0, scaling: float = 1.,
                       screenwidth: int = 1024, colours: Dict[str, str] = None,
                       overview: bool = False, prefix: str = "dummy") -> List[Group]:
        """ Returns all SVG elements required to draw the Cluster """
        if not colours:
            colours = {}
        groups = []
        group = Group()
        acc = Text(self.description, 5, 20)
        acc.set_class("clusterblast-acc")
        group.addElement(acc)
        line_y = 35 + v_offset
        group.addElement(ShapeBuilder().createLine(10, line_y, 10 + (screenwidth * 0.75),
                                                   line_y, strokewidth=1, stroke="grey"))
        group.setAttribute('label', self.description)
        group.set_class('clusterblast-cluster')
        groups.append(group)

        base = line_y + 5
        offset = h_offset + 10 - self.start  # 10 for margin
        for index, gene in enumerate(self.genes):
            arrow = gene.get_arrow_polygon(scaling=scaling, offset=offset,
                                           base=base, colour=colours.get(gene.name, "white"))
            arrow.set_id("%s-%s_q%s_%s_%s" % (prefix, self.query_cluster_number, index, self.rank, "all"))
            group.addElement(arrow)
        return groups
Example #4
0
 def _draw_text(self, my_text, rect, style, center_text=False):
     my_text = self._encode_text(my_text)
     x, y = self._calc_text_pos(rect, center_text)
     label = Text(my_text, x, y)
     label.set_style(style.getStyle())
     label.set_lengthAdjust("spacingAndGlyphs")
     return label
Example #5
0
    def makePathSequencesGroup(self) -> G:
        """
        Creates and returns a 'G' object for Path oligo sequences.
        """
        _BW = self._base_width
        _BH = self._base_height
        _pX = self.PATH_X_PADDING + self._path_radius_scaled*3
        id_coords = self.mapIdnumsToYcoords()
        oligo_list = self.cn_doc.getOligoList()

        g = G()
        g.setAttribute('id', 'PathOligoSequences')
        g.setAttribute('font-size', '8')
        g.setAttribute('font-family', 'Monaco')

        i = 0
        for color, is_circular, strands in oligo_list:
            g_oligo = G()
            g_oligo.setAttribute('id', "oligo_seq_%s" % i)
            i += 1
            for id_num, idx5, idx3, isfwd, seq in strands:
                x = _pX + idx5*_BW + _BW/4 if isfwd else _pX + idx5*_BW - _BW/4
                y = id_coords[id_num] - _BH*1.1 if isfwd else id_coords[id_num] + _BH*2.2
                t = Text('%s' % seq, x, y)
                t.set_style('fill:%s66' % color)
                strand_width = (idx3-idx5+1)*_BW if isfwd else (idx5-idx3+1)*_BW
                t.setAttribute('textLength', strand_width)
                if not isfwd:
                    t.set_transform('rotate(180,%s,%s)' % (x+_BW/2, y-_BH/2))

                g_oligo.addElement(t)
            g.addElement(g_oligo)
        return g
Example #6
0
 def _add_label(self, group: Group, v_offset: int) -> Group:
     acc = Text(self.full_description, 5, 20 + v_offset)
     if self.accession.startswith('BGC'):
         acc = Text('<a xlink:href="http://mibig.secondarymetabolites.org/repository/'
                    + self.accession + '/index.html#cluster-1" target="_blank">'
                    + self.accession + '</a>: '
                    + "%80s (%s)" % (self.description, self.similarity), 5, 20 + v_offset)
     elif self.accession.split("_")[0] in get_antismash_db_accessions():
         acc = Text('<a xlink:href="http://antismash-db.secondarymetabolites.org/output/'
                    + self.accession + '/index.html#cluster-%s" target="_blank">' % self.ref_cluster_number[1:]
                    + self.full_description.replace(":", "</a>:"), 5, 20 + v_offset)
     acc.set_class("clusterblast-acc")
     group.addElement(acc)
     group.setAttribute('label', self.accession)
     group.setAttribute('description', self.full_description)
     group.set_class('clusterblast-cluster')
     return group
Example #7
0
 def makePathVhLabelGroup(self) -> G:
     """
     Creates and returns a 'G' object for Path VirtualHelix Labels.
     """
     g = G()
     g.setAttribute('id', "VirtualHelixLabels")
     g.setAttribute('font-size', "%s" % self._path_vh_fontsize)
     if self.useCS6font:
         g.setAttribute("font-family", "'SourceSansPro-Regular'")
     else:
         g.setAttribute("font-family", "'Source Sans Pro', sans-serif")
     g.setAttribute("text-anchor", "middle")
     for i in range(len(self.cn_doc.vh_order)):
         id_num = self.cn_doc.vh_order[i]
         x = self.PATH_X_PADDING
         y = self.PATH_Y_PADDING + self._path_vh_margin*i + self._path_radius_scaled/2.
         t = Text('%s' % id_num, x, y)
         t.setAttribute('id', "label_"+self.cn_doc.vh_props['name'][id_num])
         g.addElement(t)
     return g
Example #8
0
 def makeSliceVhLabelGroup(self, transform) -> G:
     """
     Creates and returns a 'G' object for Slice VirtualHelix Labels.
     """
     _SLICE_SCALE = self._scale
     g = G()
     g.setAttribute('id', "VirtualHelixLabels")
     g.setAttribute('font-size', "%s" % self._slice_vh_fontsize)
     if self.useCS6font:
         g.setAttribute("font-family", "'SourceSansPro-Regular'")
     else:
         g.setAttribute("font-family", "'Source Sans Pro', sans-serif")
     g.setAttribute("text-anchor", "middle")
     for id_num in self.cn_doc.vh_order[::-1]:
         vh_x, vh_y = self.cn_doc.vh_origins[id_num]
         x = vh_x  # + self.cn_doc.x_offset
         y = -vh_y + self.cn_doc.vh_radius/2.
         t = Text('%s' % id_num, x*_SLICE_SCALE, y*_SLICE_SCALE - 1)
         t.setAttribute('id', "label_"+self.cn_doc.vh_props['name'][id_num])
         g.addElement(t)
     g.set_transform(transform)
     return g
Example #9
0
 def _text(self, the_text, x, y):
     encoded_text = self._encode_text(the_text)
     return Text(encoded_text, x, y)
def draw_bits_as_string(svg, id, x, y, prefix, numBits, bits):
    ob = SvgText(prefix + ":" + bits_to_string(numBits, bits), x, y, id=id)
    ob.set_style(nameStyle)
    svg.addElement(ob)
def draw_bits(svg, id, x, y, prefix, numBits, bits, activeBits=None):
    # prefix is assumed to be a single character

    if (showBitsAs == "text"):
        draw_bits_as_string(svg, id, x, y, prefix, numBits, bits)
        return

    ob = SvgText(prefix, x, y, id=id)
    ob.set_style(nameStyle)
    svg.addElement(ob)

    x += dc.bitPrefixSkip
    y -= dc.bitHgt - 1

    if (activeBits == None):
        infBit = 1

    for bitNum in range(numBits):
        bitPos = numBits - 1 - bitNum
        bit = bits & (1 << bitPos)
        if (activeBits != None):
            infBit = activeBits & (1 << bitPos)

        if (bitGroupSizes == None): groupNum = 0
        else: groupNum = bitNum // bitGroupSizes[0]
        bitX = bitNum * dc.bitWdt + groupNum * dc.bitGroupSepWdt

        ob = SvgRect(x + bitX,
                     y,
                     dc.bitWdt,
                     dc.bitHgt,
                     id="%s_bit%d" % (id, bitNum))
        ob.set_stroke(dc.bitOutlineColor)
        ob.set_stroke_width(dc.bitOutlineThickness)
        if (infBit == 0): ob.set_fill(dc.bitXColor)
        elif (bit == 0): ob.set_fill(dc.bit0Color)
        else: ob.set_fill(dc.bit1Color)
        svg.addElement(ob)