コード例 #1
0
ファイル: plot_synteny.py プロジェクト: CGATOxford/Optic
    def writeGrid(self):
        """add grid lines."""

        min_x = self.mHeaderWidth
        max_x = min_x + self.mDataWidth
        min_y = self.mHeaderHeight
        max_y = min_y + self.mDataHeight

        for contig in self.mSortedContigs1:
            if contig not in self.mMapContig2Start1:
                continue
            x = self.mMapContig2Start1[contig]

            e = SVGdraw.line(min_x + x, min_y, min_x + x, max_y,
                             stroke="rgb(%i,%i,%i)" % GREEN,
                             )
            self.addElement(e)

        self.addElement(SVGdraw.line(max_x, min_y, max_x, max_y,
                                     stroke="rgb(%i,%i,%i)" % GREEN))

        for contig in self.mSortedContigs2:
            if contig not in self.mMapContig2Start2:
                continue
            y = self.mMapContig2Start2[contig]
            e = SVGdraw.line(min_x, min_y + y, max_x, min_y + y,
                             stroke="rgb(%i,%i,%i)" % GREEN,
                             )
            self.addElement(e)

        self.addElement(SVGdraw.line(min_x, max_y, max_x, max_y,
                                     stroke="rgb(%i,%i,%i)" % GREEN))
コード例 #2
0
    def writeGrid(self):
        """add grid lines."""

        min_x = self.mHeaderWidth
        max_x = min_x + self.mDataWidth
        min_y = self.mHeaderHeight
        max_y = min_y + self.mDataHeight

        for contig in self.mSortedContigs1:
            if contig not in self.mMapContig2Start1:
                continue
            x = self.mMapContig2Start1[contig]

            e = SVGdraw.line(
                min_x + x,
                min_y,
                min_x + x,
                max_y,
                stroke="rgb(%i,%i,%i)" % GREEN,
            )
            self.addElement(e)

        self.addElement(
            SVGdraw.line(max_x,
                         min_y,
                         max_x,
                         max_y,
                         stroke="rgb(%i,%i,%i)" % GREEN))

        for contig in self.mSortedContigs2:
            if contig not in self.mMapContig2Start2:
                continue
            y = self.mMapContig2Start2[contig]
            e = SVGdraw.line(
                min_x,
                min_y + y,
                max_x,
                min_y + y,
                stroke="rgb(%i,%i,%i)" % GREEN,
            )
            self.addElement(e)

        self.addElement(
            SVGdraw.line(min_x,
                         max_y,
                         max_x,
                         max_y,
                         stroke="rgb(%i,%i,%i)" % GREEN))
コード例 #3
0
ファイル: SVGTree.py プロジェクト: Charlie-George/cgat
    def getElements(self, node_id, x, y1, y2):

        e = []
        e.append(SVGdraw.line(x, y1, x, y2,
                              stroke="rgb(%i,%i,%i)" % BLACK,
                              stroke_width=1))
        return e
コード例 #4
0
ファイル: plot_multiple_synteny.py プロジェクト: yangjl/cgat
    def addGroupStart(self, x, y, contig, start):
        """plot start of contig."""

        t = "%s:%i" % (contig, start)
        max_x = x + len(t) * self.contigFontSize * self.mFontFactor

        ## plot line
        e = SVGdraw.line(
            x,
            y,
            max_x,
            y,
            stroke="rgb(%i,%i,%i)" % BLACK,
        )

        self.addElement(e)
        e = SVGdraw.text(x,
                         y,
                         t,
                         self.contigFontSize,
                         self.contigFont,
                         stroke="rgb(%i,%i,%i)" % BLACK,
                         text_anchor="left")

        self.addElement(e)

        return max_x
コード例 #5
0
ファイル: SVGTree.py プロジェクト: Charlie-George/cgat
    def getElements(self, node_id, x1, x2, y):

        e = []
        if not self.mNoBranch:
            e.append(SVGdraw.line(x1, y, x2, y,
                                  stroke="rgb(%i,%i,%i)" % BLACK,
                                  stroke_width=1))
        return e
コード例 #6
0
ファイル: plot_duplications.py プロジェクト: lesheng/cgat
    def writeFooter(self):
        """write footer.

        The footer contains the legend.
        """
        current_x = self.mFooterFrom
        current_y = self.mHeaderHeight + self.mDataHeight + 2 * self.mSeparator

        self.mFooterBoxSize = 30
        self.mNumTicks = 20
        for x in range(len(self.mColourThresholds)):

            e = SVGdraw.rect(current_x,
                             current_y,
                             self.mFooterBoxSize,
                             self.mFooterBoxSize,
                             fill="rgb(%i,%i,%i)" % self.mColours[x],
                             stroke="rgb(%i,%i,%i)" % self.mColours[x])

            self.addElement(e)

            if x % self.mNumTicks == 0:

                e = SVGdraw.line(current_x,
                                 current_y,
                                 current_x,
                                 current_y + self.mFooterBoxSize,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=5)
                self.addElement(e)

                e = SVGdraw.text(current_x,
                                 current_y - self.mFooterBoxSize,
                                 self.mFormatNumberLegend %
                                 self.mColourThresholds[x],
                                 self.mFooterFontSize,
                                 self.mFooterFont,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 text_anchor="start")
                self.addElement(e)

            current_x += self.mFooterBoxSize

        ###########################################################
        if self.mFooter:

            current_y += max(self.mFooterFontSize,
                             self.mMaxBoxSize) + self.mSeparator

            e = SVGdraw.text(self.mPageWidth / 2,
                             current_y + self.mFooterFontSize,
                             self.mFooter,
                             self.mFooterFontSize,
                             self.mFooterFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="middle")

            self.addElement(e)
コード例 #7
0
ファイル: plot_duplications.py プロジェクト: lesheng/cgat
    def writeFooter(self):
        """write footer.

        The footer contains the legend.
        """
        current_x = self.mFooterFrom
        current_y = self.mHeaderHeight + self.mDataHeight + 2 * self.mSeparator

        self.mFooterBoxSize = 30
        self.mNumTicks = 20
        for x in range(len(self.mColourThresholds)):

            e = SVGdraw.rect(current_x,
                             current_y,
                             self.mFooterBoxSize,
                             self.mFooterBoxSize,
                             fill="rgb(%i,%i,%i)" % self.mColours[x],
                             stroke="rgb(%i,%i,%i)" % self.mColours[x])

            self.addElement(e)

            if x % self.mNumTicks == 0:

                e = SVGdraw.line(current_x,
                                 current_y,
                                 current_x,
                                 current_y + self.mFooterBoxSize,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=5)
                self.addElement(e)

                e = SVGdraw.text(current_x,
                                 current_y - self.mFooterBoxSize,
                                 self.mFormatNumberLegend % self.mColourThresholds[
                                     x],
                                 self.mFooterFontSize,
                                 self.mFooterFont,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 text_anchor="start")
                self.addElement(e)

            current_x += self.mFooterBoxSize

        ###########################################################
        if self.mFooter:

            current_y += max(self.mFooterFontSize,
                             self.mMaxBoxSize) + self.mSeparator

            e = SVGdraw.text(self.mPageWidth / 2,
                             current_y + self.mFooterFontSize,
                             self.mFooter,
                             self.mFooterFontSize,
                             self.mFooterFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="middle")

            self.addElement(e)
コード例 #8
0
ファイル: go2svg.py プロジェクト: gsc0107/cgat
    def writeGrid(self):
        """add grid lines."""

        if self.mRowTicks:

            start_x = 0,
            end_x = self.mDataWidth + self.mSeparator + self.mHeaderWidth
            current_y = self.mHeaderHeight + self.mSeparator / \
                2 + self.mRowTicks * self.mRowHeight

            for x in range(self.mRowTicks, len(self.mRowNames),
                           self.mRowTicks):

                e = SVGdraw.line(start_x,
                                 current_y,
                                 end_x,
                                 current_y,
                                 stroke="rgb(%i,%i,%i)" % BLACK)

                self.mElements.append(e)

                current_y += self.mRowTicks * self.mRowHeight

        if self.mColTicks:

            start_y = self.mHeaderHeight + self.mSeparator / 2
            end_y = start_y + self.mDataHeight

            current_x = self.mColTicks * self.mColWidth - self.mColWidth / 2

            for x in range(self.mColTicks, len(self.mColNames),
                           self.mColTicks):

                e = SVGdraw.line(current_x,
                                 start_y,
                                 current_x,
                                 end_y,
                                 stroke="rgb(%i,%i,%i)" % BLACK)

                self.mElements.append(e)

                current_x += self.mColTicks * self.mColWidth
コード例 #9
0
ファイル: go2svg.py プロジェクト: CGATOxford/cgat
    def writeGrid(self):
        """add grid lines."""

        if self.mRowTicks:

            start_x = 0,
            end_x = self.mDataWidth + self.mSeparator + self.mHeaderWidth
            current_y = self.mHeaderHeight + self.mSeparator / \
                2 + self.mRowTicks * self.mRowHeight

            for x in range(self.mRowTicks, len(self.mRowNames),
                           self.mRowTicks):

                e = SVGdraw.line(start_x,
                                 current_y,
                                 end_x,
                                 current_y,
                                 stroke="rgb(%i,%i,%i)" % BLACK)

                self.mElements.append(e)

                current_y += self.mRowTicks * self.mRowHeight

        if self.mColTicks:

            start_y = self.mHeaderHeight + self.mSeparator / 2
            end_y = start_y + self.mDataHeight

            current_x = self.mColTicks * self.mColWidth - self.mColWidth / 2

            for x in range(self.mColTicks, len(self.mColNames),
                           self.mColTicks):

                e = SVGdraw.line(current_x,
                                 start_y,
                                 current_x,
                                 end_y,
                                 stroke="rgb(%i,%i,%i)" % BLACK)

                self.mElements.append(e)

                current_x += self.mColTicks * self.mColWidth
コード例 #10
0
ファイル: SVGTree.py プロジェクト: Charlie-George/cgat
    def getElements(self, node_id, x1, x2, y):

        e = []
        e.append(SVGdraw.line(x1, y, x2, y,
                              stroke="rgb(%i,%i,%i)" % BLACK,
                              stroke_width=1))

        e += self.mDecorator1.getElements(node_id, x1, x2, y)
        e += self.mDecorator2.getElements(node_id, x1, x2, y + self.mFontSize)

        return e
コード例 #11
0
ファイル: SVGTree.py プロジェクト: santayana/cgat
    def getElements(self, node_id, x, y1, y2):

        e = []
        e.append(
            SVGdraw.line(x,
                         y1,
                         x,
                         y2,
                         stroke="rgb(%i,%i,%i)" % BLACK,
                         stroke_width=1))
        return e
コード例 #12
0
ファイル: SVGTree.py プロジェクト: santayana/cgat
    def getElements(self, node_id, x1, x2, y):

        e = []
        if not self.mNoBranch:
            e.append(
                SVGdraw.line(x1,
                             y,
                             x2,
                             y,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1))
        return e
コード例 #13
0
ファイル: SVGDuplicationsWheel.py プロジェクト: BioXiao/cgat
    def writeScale(self):
        """write scales."""

        current_x = self.mScaleX
        current_y = self.mScaleY + self.mScaleHeight

        nboxes = len(self.mColourThresholds)
        # box size for legend in x-direction
        # subtract size of right-most axis label so that it takes the
        # same width as self.mDataWidth.
        box_size_x = math.ceil((self.mDataWidth -
                                (self.mScaleFontSize * len(
                                    self.mFormatNumberLegend %
                                    self.mColourThresholds[-1]))) / nboxes)

        # change font size such that it labels will fit between tick-marks
        self.mScaleFontSize = min(self.mScaleFontSize,
                                  (box_size_x * self.mScaleNumTicks * 1.5) /
                                  len(self.mFormatNumberLegend %
                                      self.mColourThresholds[-1]))

        for x in range(nboxes):

            e = SVGdraw.rect(current_x,
                             current_y,
                             box_size_x,
                             self.mScaleBoxSizeY,
                             fill="rgb(%i,%i,%i)" % self.mColours[x],
                             stroke="rgb(%i,%i,%i)" % self.mColours[x])

            self.addElement(e)

            if x % self.mScaleNumTicks == 0:

                e = SVGdraw.line(current_x,
                                 current_y,
                                 current_x,
                                 current_y + self.mScaleBoxSizeY,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=5)
                self.addElement(e)

                e = SVGdraw.text(current_x,
                                 current_y - self.mScaleBoxSizeY,
                                 self.mFormatNumberLegend % self.mColourThresholds[
                                     x],
                                 self.mScaleFontSize,
                                 self.mScaleFont,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 text_anchor="start")
                self.addElement(e)

            current_x += box_size_x
コード例 #14
0
    def writeScale(self):
        """write scales."""

        current_x = self.mScaleX
        current_y = self.mScaleY + self.mScaleHeight

        nboxes = len(self.mColourThresholds)
        # box size for legend in x-direction
        # subtract size of right-most axis label so that it takes the
        # same width as self.mDataWidth.
        box_size_x = math.ceil(
            (self.mDataWidth -
             (self.mScaleFontSize *
              len(self.mFormatNumberLegend % self.mColourThresholds[-1]))) /
            nboxes)

        # change font size such that it labels will fit between tick-marks
        self.mScaleFontSize = min(
            self.mScaleFontSize, (box_size_x * self.mScaleNumTicks * 1.5) /
            len(self.mFormatNumberLegend % self.mColourThresholds[-1]))

        for x in range(nboxes):

            e = SVGdraw.rect(current_x,
                             current_y,
                             box_size_x,
                             self.mScaleBoxSizeY,
                             fill="rgb(%i,%i,%i)" % self.mColours[x],
                             stroke="rgb(%i,%i,%i)" % self.mColours[x])

            self.addElement(e)

            if x % self.mScaleNumTicks == 0:

                e = SVGdraw.line(current_x,
                                 current_y,
                                 current_x,
                                 current_y + self.mScaleBoxSizeY,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=5)
                self.addElement(e)

                e = SVGdraw.text(current_x,
                                 current_y - self.mScaleBoxSizeY,
                                 self.mFormatNumberLegend %
                                 self.mColourThresholds[x],
                                 self.mScaleFontSize,
                                 self.mScaleFont,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 text_anchor="start")
                self.addElement(e)

            current_x += box_size_x
コード例 #15
0
ファイル: SVGTree.py プロジェクト: santayana/cgat
    def getElements(self, node_id, x1, x2, y):

        e = []
        e.append(
            SVGdraw.line(x1,
                         y,
                         x2,
                         y,
                         stroke="rgb(%i,%i,%i)" % BLACK,
                         stroke_width=1))

        e += self.mDecorator1.getElements(node_id, x1, x2, y)
        e += self.mDecorator2.getElements(node_id, x1, x2, y + self.mFontSize)

        return e
コード例 #16
0
    def plotLinksForPair(self, species1, species2, colour=BLACK, plane=0):
        """plot links."""

        if species1 not in self.mOrthologs or species2 not in self.mOrthologs:
            return

        for group1 in self.mOrthologs[species1]:
            if group1 in self.mOrthologs[species2]:
                for g1 in self.mOrthologs[species1][group1]:
                    for g2 in self.mOrthologs[species2][group1]:
                        x1, y1 = self.mMapGene2Coord[g1]
                        x2, y2 = self.mMapGene2Coord[g2]

                        e = SVGdraw.line(x1, y1, x2, y2, stroke="rgb(%i,%i,%i)" % colour)

                        self.addElement(e, plane=plane)
コード例 #17
0
    def addGroupStart(self, x, y, contig, start):
        """plot start of contig."""

        t = "%s:%i" % (contig, start)
        max_x = x + len(t) * self.contigFontSize * self.mFontFactor

        # plot line
        e = SVGdraw.line(x, y, max_x, y, stroke="rgb(%i,%i,%i)" % BLACK)

        self.addElement(e)
        e = SVGdraw.text(
            x, y, t, self.contigFontSize, self.contigFont, stroke="rgb(%i,%i,%i)" % BLACK, text_anchor="left"
        )

        self.addElement(e)

        return max_x
コード例 #18
0
ファイル: SVGDuplicationsWheel.py プロジェクト: lesheng/cgat
    def writeGrid(self):
        """add grid lines."""

        middlex = self.mDataMiddleX
        middley = self.mDataMiddleY

        # print separators
        for c in range(len(self.contigs)):

            contig = self.contigs[c]

            pos = self.getPosition(contig, "+", 0)
            angle = self.getAngle(pos)

            x, y = self.getPosOnArc(angle, self.mRadius)

            e = SVGdraw.line(middlex,
                             middley,
                             x,
                             y,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=self.mGridStrokeWidth)

            self.addElement(e, self.mPlaneGrid)

            if c < len(self.contigs) - 1:
                next_angle = self.getAngle(
                    self.getPosition(self.contigs[c + 1], "+", 0))
            else:
                next_angle = 360

            x, y = self.getPosOnArc(
                angle + float(next_angle - angle) / 2, self.mRadiusStart / 2)

            e = SVGdraw.text(x,
                             y,
                             contig,
                             self.mGridFontSize,
                             self.mGridFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="start")
            # do not rotate text:
            # transform="rotate(%i,%i,%i)" % ( angle, x, y ))

            self.addElement(e)
コード例 #19
0
    def writeGrid(self):
        """add grid lines."""

        middlex = self.mDataMiddleX
        middley = self.mDataMiddleY

        # print separators
        for c in range(len(self.contigs)):

            contig = self.contigs[c]

            pos = self.getPosition(contig, "+", 0)
            angle = self.getAngle(pos)

            x, y = self.getPosOnArc(angle, self.mRadius)

            e = SVGdraw.line(middlex,
                             middley,
                             x,
                             y,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=self.mGridStrokeWidth)

            self.addElement(e, self.mPlaneGrid)

            if c < len(self.contigs) - 1:
                next_angle = self.getAngle(
                    self.getPosition(self.contigs[c + 1], "+", 0))
            else:
                next_angle = 360

            x, y = self.getPosOnArc(
                angle + float(next_angle - angle) / 2, self.mRadiusStart / 2)

            e = SVGdraw.text(x,
                             y,
                             contig,
                             self.mGridFontSize,
                             self.mGridFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="start")
            # do not rotate text:
            # transform="rotate(%i,%i,%i)" % ( angle, x, y ))

            self.addElement(e)
コード例 #20
0
ファイル: plot_multiple_synteny.py プロジェクト: yangjl/cgat
    def plotLinksForPair(self, species1, species2, colour=BLACK, plane=0):
        """plot links."""

        if species1 not in self.mOrthologs or species2 not in self.mOrthologs:
            return

        for group1 in self.mOrthologs[species1]:
            if group1 in self.mOrthologs[species2]:
                for g1 in self.mOrthologs[species1][group1]:
                    for g2 in self.mOrthologs[species2][group1]:
                        x1, y1 = self.mMapGene2Coord[g1]
                        x2, y2 = self.mMapGene2Coord[g2]

                        e = SVGdraw.line(
                            x1,
                            y1,
                            x2,
                            y2,
                            stroke="rgb(%i,%i,%i)" % colour,
                        )

                        self.addElement(e, plane=plane)
コード例 #21
0
ファイル: plot_duplications.py プロジェクト: lesheng/cgat
    def writeGrid(self):
        """add grid lines."""

        # print last circle
        self.mRadius = self.mRadiusMax + self.mRadiusIncrement
        self.addSeparator()

        # print separators
        for contig, pos in self.contig2Position.items():

            pos = self.getPosition(contig, "+", 0)

            angle = self.getAngle(pos)

            x, y = self.getPosOnArc(angle, self.mRadius)

            e = SVGdraw.line(self.mDataMiddleX,
                             self.mDataMiddleY,
                             x,
                             y,
                             stroke="rgb(%i,%i,%i)" % BLACK)

            self.addElement(e, self.mPlaneGrid)

            x, y = self.getPosOnArc(
                angle, (self.mRadius + self.mRadiusStart) / 2)

            e = SVGdraw.text(x,
                             y,
                             contig,
                             self.mHeaderFontSize,
                             self.mHeaderFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="start",
                             transform="rotate(%i,%i,%i)" % (angle, x, y))

            self.addElement(e)
コード例 #22
0
ファイル: plot_duplications.py プロジェクト: lesheng/cgat
    def writeGrid(self):
        """add grid lines."""

        # print last circle
        self.mRadius = self.mRadiusMax + self.mRadiusIncrement
        self.addSeparator()

        # print separators
        for contig, pos in self.contig2Position.items():

            pos = self.getPosition(contig, "+", 0)

            angle = self.getAngle(pos)

            x, y = self.getPosOnArc(angle, self.mRadius)

            e = SVGdraw.line(self.mDataMiddleX,
                             self.mDataMiddleY,
                             x,
                             y,
                             stroke="rgb(%i,%i,%i)" % BLACK)

            self.addElement(e, self.mPlaneGrid)

            x, y = self.getPosOnArc(angle,
                                    (self.mRadius + self.mRadiusStart) / 2)

            e = SVGdraw.text(x,
                             y,
                             contig,
                             self.mHeaderFontSize,
                             self.mHeaderFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="start",
                             transform="rotate(%i,%i,%i)" % (angle, x, y))

            self.addElement(e)
コード例 #23
0
ファイル: plot_duplications.py プロジェクト: lesheng/cgat
    def addDuplication(self,
                       entries,
                       map_gene2pos,
                       height,
                       url=None,
                       with_separator=True,
                       link_to_previous=False,
                       quality2symbol={},
                       quality2mask={}):
        """add a dot in row/col."""

        mi, ma = None, 0

        pos = bisect.bisect(self.mColourThresholds, height)
        master_colour = self.mColours[pos]

        chrs = {}
        points = []
        for species, transcript, gene, quality in entries:

            chr, strand, first_res, last_res = map_gene2pos[gene]
            chrs[chr] = 1
            pos1 = self.getPosition(chr, strand, first_res)
            pos2 = self.getPosition(chr, strand, last_res)

            a = min(pos1, pos2)
            b = max(pos1, pos2)

            if mi is None:
                mi = a
            else:
                mi = min(a, mi)
            ma = max(b, ma)

            points.append((pos1, pos2, gene, quality))

        # decide whether we need to increment the radius
        cis = len(chrs) == 1

        old_radius = self.mRadius
        is_overlap = False
        if cis:
            if not self.mLastChr:
                self.mLastChr = chr

            if chr != self.mLastChr:
                self.mRadius = self.mRadiusFallBack
                self.mLastMax = ma
                self.mPreviousMax = ma
                self.mLastChr = chr
            else:
                if self.mPreviousMax + self.mMinDistance > mi:
                    # overlap due to close proximitiy
                    self.mRadius += self.mRadiusIncrement
                    if with_separator:
                        self.addSeparator()

                    # true overlap
                    if self.mPreviousMax > mi:
                        is_overlap = True

                elif self.mLastMax + self.mMinDistance > mi:
                    pass
                else:
                    self.mRadius = self.mRadiusFallBack

                self.mLastMax = max(self.mLastMax, ma)
        else:
            if self.mLastMax > mi:
                self.mRadius += self.mRadiusIncrement
                if with_separator:
                    self.addSeparator()

        if cis and self.mPreviousCis and (link_to_previous or is_overlap):

            # print old_x1, old_y1, old_x2, old_y2, new_x1, new_y2, new_x2,
            # new_y2
            r1 = old_radius
            r2 = self.mRadius
            old_x1, old_y1 = self.getPosOnArcForRadius(self.mPreviousMin, r1)
            old_x2, old_y2 = self.getPosOnArcForRadius(self.mPreviousMax, r1)
            new_x1, new_y1 = self.getPosOnArcForRadius(mi, r2)
            new_x2, new_y2 = self.getPosOnArcForRadius(ma, r2)

            if link_to_previous:

                # print cis, entries, chrs

                d = SVGdraw.pathdata(old_x1, old_y1)
                d.ellarc(r1, r1, 0, 0, 1, old_x2, old_y2)
                d.line(new_x2, new_y2)
                d.ellarc(r2, r2, 0, 0, 1, new_x1, new_y1)
                d.line(old_x1, old_y1)

                e = SVGdraw.path(d,
                                 fill="rgb(%i,%i,%i)" % GREY,
                                 stroke="rgb(%i,%i,%i)" % GREY,
                                 stroke_width=1)

            else:

                # get points of center
                old_x1, old_y1 = self.getPosOnArcForRadius(
                    (self.mPreviousMax + self.mPreviousMin) / 2, r1)
                new_x1, new_y1 = self.getPosOnArcForRadius((ma + mi) / 2, r2)

                # lines for interleaved spans: skip
                if not ((self.mPreviousMin < mi and self.mPreviousMax > ma) or
                        (self.mPreviousMin > mi and self.mPreviousMax < ma)):
                    ##                     d = SVGdraw.pathdata( old_x2, old_y2 )
                    ##                     d.line( new_x2, new_y2 )
                    ##                     d.move( new_x1, new_y1 )
                    ##                     d.line( old_x1, old_y1 )
                    ##                     d.move( old_x2, old_y2 )
                    # e = SVGdraw.path( d,
                    ##                                       fill = "none",
                    ##                                       stroke = "rgb(%i,%i,%i)" % BLACK,
                    # stroke_width = self.mMarkerWidth / 2 )

                    e = SVGdraw.line(old_x1,
                                     old_y1,
                                     new_x1,
                                     new_y1,
                                     fill="none",
                                     stroke="rgb(%i,%i,%i)" % GREY,
                                     stroke_width=self.mMarkerWidth / 2)
                else:
                    # lines for covering spans, as these overlaps
                    e = None


# e = SVGdraw.line( old_x1, old_y1,
##                                       new_x1, new_y1,
##                                       fill = "none",
##                                       stroke = "rgb(%i,%i,%i)" % GREY,
# stroke_width = self.mMarkerWidth / 2 )

            if e:
                self.addElement(e, self.mPlaneJoins)

        self.mPreviousMin = mi
        self.mPreviousMax = ma
        self.mPreviousCis = cis

        self.mRadiusMax = max(self.mRadius, self.mRadiusMax)

        # draw points
        link_colour = master_colour
        link_width = 10
        for pos1, pos2, gene, quality in points:

            angle = self.getAngle((pos1 + pos2) / 2)

            x, y = self.getPosOnArc(angle, self.mRadius)

            try:
                symbol = quality2symbol[quality]
            except KeyError:
                symbol = "rect"

            if quality in quality2mask:
                colour = GREY
                link_colour = GREY
                link_width = 1
            else:
                colour = master_colour

            if symbol == "circle":
                ee = SVGdraw.circle(x,
                                    y,
                                    self.mMarkerWidth,
                                    fill="rgb(%i,%i,%i)" % colour,
                                    stroke="black",
                                    stroke_width=1)
            elif symbol == "rect":
                ee = SVGdraw.rect(x - self.mMarkerWidth / 2,
                                  y - self.mMarkerWidth / 2,
                                  self.mMarkerWidth,
                                  self.mMarkerWidth,
                                  fill="rgb(%i,%i,%i)" % colour,
                                  stroke="black",
                                  stroke_width=1)

            if url:
                e = SVGdraw.link(url % gene)
                e.addElement(ee)
            else:
                e = ee
            self.addElement(e)

        angle1 = self.getAngle(mi)
        angle2 = self.getAngle(ma)

        x1, y1 = self.getPosOnArc(angle1, self.mRadius)
        x2, y2 = self.getPosOnArc(angle2, self.mRadius)

        d = SVGdraw.pathdata(x1, y1)
        if cis:
            d.ellarc(self.mRadius, self.mRadius, 0, 0, 1, x2, y2)
        else:
            d.ellarc(self.mRadius * 2, self.mRadius * 2, 0, 0, 0, x2, y2)

        e = SVGdraw.path(d,
                         fill="none",
                         stroke="rgb(%i,%i,%i)" % link_colour,
                         stroke_width=link_width)

        self.addElement(e)
コード例 #24
0
ファイル: plot_duplications.py プロジェクト: siping/cgat
    def addDuplication( self, entries, map_gene2pos, height,
                        url = None,
                        with_separator=True,
                        link_to_previous = False,
                        quality2symbol = {},
                        quality2mask = {}):
        """add a dot in row/col."""
        
        mi, ma = None, 0

        pos = bisect.bisect( self.mColourThresholds, height )
        master_colour = self.mColours[pos]
        
        chrs = {}
        points = []
        for species, transcript, gene, quality in entries:

            chr, strand, first_res, last_res = map_gene2pos[gene]
            chrs[chr] = 1
            pos1 = self.getPosition( chr, strand, first_res )
            pos2 = self.getPosition( chr, strand, last_res )

            a = min( pos1, pos2 )
            b = max( pos1, pos2 )

            if mi == None:
                mi = a
            else:
                mi = min(a, mi)
            ma = max(b, ma)
            
            points.append( (pos1, pos2, gene, quality) )

        ## decide whether we need to increment the radius
        cis = len(chrs) == 1

        old_radius = self.mRadius
        is_overlap = False
        if cis:
            if not self.mLastChr:
                self.mLastChr = chr

            if chr != self.mLastChr:
                self.mRadius = self.mRadiusFallBack
                self.mLastMax = ma
                self.mPreviousMax = ma
                self.mLastChr = chr
            else:
                if self.mPreviousMax + self.mMinDistance > mi:
                    ## overlap due to close proximitiy
                    self.mRadius += self.mRadiusIncrement
                    if with_separator: self.addSeparator()

                    ## true overlap
                    if self.mPreviousMax > mi:
                        is_overlap = True
                    
                elif self.mLastMax + self.mMinDistance > mi:
                    pass
                else:
                    self.mRadius = self.mRadiusFallBack
                    
                self.mLastMax = max(self.mLastMax, ma)
        else:
            if self.mLastMax > mi:
                self.mRadius += self.mRadiusIncrement
                if with_separator: self.addSeparator()
                
        if cis and self.mPreviousCis and (link_to_previous or is_overlap):

            # print old_x1, old_y1, old_x2, old_y2, new_x1, new_y2, new_x2, new_y2
            r1 = old_radius
            r2 = self.mRadius
            old_x1, old_y1 = self.getPosOnArcForRadius( self.mPreviousMin, r1 )
            old_x2, old_y2 = self.getPosOnArcForRadius( self.mPreviousMax, r1 )
            new_x1, new_y1 = self.getPosOnArcForRadius( mi, r2 )
            new_x2, new_y2 = self.getPosOnArcForRadius( ma, r2 )

            if link_to_previous:
                
                # print cis, entries, chrs
                
                d = SVGdraw.pathdata( old_x1, old_y1 )
                d.ellarc( r1, r1, 0, 0, 1, old_x2, old_y2 )            
                d.line( new_x2, new_y2 )
                d.ellarc( r2, r2, 0, 0, 1, new_x1, new_y1 )
                d.line( old_x1, old_y1 )
                
                e = SVGdraw.path( d,
                                  fill = "rgb(%i,%i,%i)" % GREY,
                                  stroke = "rgb(%i,%i,%i)" % GREY,
                                  stroke_width = 1 )
                
            else:

                # get points of center
                old_x1, old_y1 = self.getPosOnArcForRadius( (self.mPreviousMax + self.mPreviousMin) / 2, r1 )
                new_x1, new_y1 = self.getPosOnArcForRadius( (ma + mi) / 2, r2 )

                # lines for interleaved spans: skip
                if not ((self.mPreviousMin < mi and self.mPreviousMax > ma) or \
                        (self.mPreviousMin > mi and self.mPreviousMax < ma)) :
##                     d = SVGdraw.pathdata( old_x2, old_y2 )
##                     d.line( new_x2, new_y2 )
##                     d.move( new_x1, new_y1 )
##                     d.line( old_x1, old_y1 )
##                     d.move( old_x2, old_y2 )
##                     e = SVGdraw.path( d,
##                                       fill = "none",
##                                       stroke = "rgb(%i,%i,%i)" % BLACK,
##                                       stroke_width = self.mMarkerWidth / 2 )

                    e = SVGdraw.line( old_x1, old_y1,
                                      new_x1, new_y1,
                                      fill = "none",
                                      stroke = "rgb(%i,%i,%i)" % GREY,
                                      stroke_width = self.mMarkerWidth / 2 )
                else:
                    # lines for covering spans, as these overlaps
                    e = None
##                     e = SVGdraw.line( old_x1, old_y1,
##                                       new_x1, new_y1,
##                                       fill = "none",
##                                       stroke = "rgb(%i,%i,%i)" % GREY,
##                                       stroke_width = self.mMarkerWidth / 2 )

            if e:
                self.addElement( e, self.mPlaneJoins )
                    

        self.mPreviousMin = mi
        self.mPreviousMax = ma
        self.mPreviousCis = cis
        
        self.mRadiusMax = max(self.mRadius, self.mRadiusMax)
        
        ## draw points
        link_colour = master_colour
        link_width = 10
        for pos1, pos2, gene, quality in points:
            
            angle = self.getAngle( (pos1 + pos2) / 2 )
            
            x,y = self.getPosOnArc( angle, self.mRadius )

            try:
                symbol = quality2symbol[quality]
            except KeyError:
                symbol = "rect"

            if quality in quality2mask:
                colour = GREY
                link_colour = GREY
                link_width = 1
            else:
                colour = master_colour

            if symbol == "circle":
                ee = SVGdraw.circle( x, y, self.mMarkerWidth,
                                     fill = "rgb(%i,%i,%i)" % colour,
                                     stroke="black",
                                     stroke_width= 1)
            elif symbol == "rect":
                ee =  SVGdraw.rect( x-self.mMarkerWidth/2, y-self.mMarkerWidth/2,
                                    self.mMarkerWidth, self.mMarkerWidth,
                                    fill = "rgb(%i,%i,%i)" % colour,
                                    stroke="black",
                                    stroke_width= 1)

            if url:
                e = SVGdraw.link( url % gene )
                e.addElement( ee )
            else:
                e = ee
            self.addElement( e )                


        angle1 = self.getAngle( mi ) 
        angle2 = self.getAngle( ma )

        x1,y1 = self.getPosOnArc( angle1, self.mRadius )
        x2,y2 = self.getPosOnArc( angle2, self.mRadius )

        d = SVGdraw.pathdata( x1, y1 )
        if cis:
            d.ellarc( self.mRadius, self.mRadius, 0, 0, 1, x2, y2 )            
        else:
            d.ellarc( self.mRadius * 2, self.mRadius * 2, 0, 0, 0, x2, y2 )

        e = SVGdraw.path( d,
                          fill = "none",
                          stroke = "rgb(%i,%i,%i)" % link_colour,
                          stroke_width = link_width )

        self.addElement(e)
コード例 #25
0
ファイル: SVGTree.py プロジェクト: Charlie-George/cgat
    def writeFooter(self):
        """write footer.

        The footer contains the legend.
        """
        total_branch_length = (
            max(self.mNodeWidthsEnd) - min(self.mNodeWidthsStart)) / self.mBranchScaleFactor

        self.mFooterX = self.getHeaderWidth()
        self.mFooterY = self.getHeaderHeight(
        ) + self.mDataHeight + self.mSeparatorHeight

        ruler_start = self.mFooterX
        ruler_end = self.mFooterX + \
            int(total_branch_length * self.mBranchScaleFactor)

        if "ruler" in self.mRulerElements:
            # full length ruler with tick marks and labels
            e = SVGdraw.line(ruler_start,
                             self.mFooterY + self.mRulerTickSize + 1,
                             ruler_end,
                             self.mFooterY + self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)
            self.addElement(e)

            # get reasonable intervalls

        increment = self.mRulerIncrement * self.mBranchScaleFactor

        # adjust increment for extremely long trees
        if (ruler_end - ruler_start) / increment > 1000:
            increment = (ruler_end - ruler_start) / 1000.0
            self.mRulerIncrement = increment / self.mBranchScaleFactor

        if "right-ticks" in self.mRulerElements:

            x = ruler_end
            while x >= ruler_start:
                e = SVGdraw.line(x,
                                 self.mFooterY,
                                 x,
                                 self.mFooterY + 2 * self.mRulerTickSize + 1,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=1)
                self.addElement(e)
                x -= self.mRulerIncrement * self.mBranchScaleFactor

            self.mFooterY += 2 * self.mRulerTickSize + \
                1 + self.mSeparatorHeight

        if "left-ticks" in self.mRulerElements:

            x = ruler_start
            while x <= ruler_end:
                e = SVGdraw.line(x,
                                 self.mFooterY,
                                 x,
                                 self.mFooterY + 2 * self.mRulerTickSize + 1,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=1)
                self.addElement(e)
                x += increment

            self.mFooterY += 2 * self.mRulerTickSize + \
                1 + self.mSeparatorHeight

        if "scale" in self.mRulerElements:

            w = int(self.mRulerIncrement * self.mBranchScaleFactor)

            e = SVGdraw.line(ruler_end,
                             self.mFooterY + self.mRulerTickSize + 1,
                             ruler_end - w,
                             self.mFooterY + self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)

            self.addElement(e)

            e = SVGdraw.line(ruler_end,
                             self.mFooterY,
                             ruler_end,
                             self.mFooterY + 2 * self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)

            self.addElement(e)

            e = SVGdraw.line(ruler_end - w,
                             self.mFooterY,
                             ruler_end - w,
                             self.mFooterY + 2 * self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)

            self.addElement(e)

            e = SVGdraw.text(ruler_end - w / 2,
                             self.mFooterY + 2 * self.mRulerTickSize +
                             1 + self.mRulerFontSize,
                             self.mRulerFormat % self.mRulerIncrement,
                             self.mRulerFontSize,
                             self.mRulerFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="middle")

            self.addElement(e)
            self.mFooterY += 2 * self.mRulerTickSize + 1 + self.mRulerFontSize

        e, self.mFooterX, self.mFooterY = self.mDecoratorExternalNodes.getLegend(
            self.mFooterX, self.mFooterY)
        self.addElements(e)
        e, self.mFooterX, self.mFooterY = self.mDecoratorInternalNodes.getLegend(
            self.mFooterX, self.mFooterY)
        self.addElements(e)
コード例 #26
0
ファイル: SVGTree.py プロジェクト: santayana/cgat
    def writeFooter(self):
        """write footer.

        The footer contains the legend.
        """
        total_branch_length = (max(self.mNodeWidthsEnd) - min(
            self.mNodeWidthsStart)) / self.mBranchScaleFactor

        self.mFooterX = self.getHeaderWidth()
        self.mFooterY = self.getHeaderHeight(
        ) + self.mDataHeight + self.mSeparatorHeight

        ruler_start = self.mFooterX
        ruler_end = self.mFooterX + \
            int(total_branch_length * self.mBranchScaleFactor)

        if "ruler" in self.mRulerElements:
            # full length ruler with tick marks and labels
            e = SVGdraw.line(ruler_start,
                             self.mFooterY + self.mRulerTickSize + 1,
                             ruler_end,
                             self.mFooterY + self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)
            self.addElement(e)

            # get reasonable intervalls

        increment = self.mRulerIncrement * self.mBranchScaleFactor

        # adjust increment for extremely long trees
        if (ruler_end - ruler_start) / increment > 1000:
            increment = (ruler_end - ruler_start) / 1000.0
            self.mRulerIncrement = increment / self.mBranchScaleFactor

        if "right-ticks" in self.mRulerElements:

            x = ruler_end
            while x >= ruler_start:
                e = SVGdraw.line(x,
                                 self.mFooterY,
                                 x,
                                 self.mFooterY + 2 * self.mRulerTickSize + 1,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=1)
                self.addElement(e)
                x -= self.mRulerIncrement * self.mBranchScaleFactor

            self.mFooterY += 2 * self.mRulerTickSize + \
                1 + self.mSeparatorHeight

        if "left-ticks" in self.mRulerElements:

            x = ruler_start
            while x <= ruler_end:
                e = SVGdraw.line(x,
                                 self.mFooterY,
                                 x,
                                 self.mFooterY + 2 * self.mRulerTickSize + 1,
                                 stroke="rgb(%i,%i,%i)" % BLACK,
                                 stroke_width=1)
                self.addElement(e)
                x += increment

            self.mFooterY += 2 * self.mRulerTickSize + \
                1 + self.mSeparatorHeight

        if "scale" in self.mRulerElements:

            w = int(self.mRulerIncrement * self.mBranchScaleFactor)

            e = SVGdraw.line(ruler_end,
                             self.mFooterY + self.mRulerTickSize + 1,
                             ruler_end - w,
                             self.mFooterY + self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)

            self.addElement(e)

            e = SVGdraw.line(ruler_end,
                             self.mFooterY,
                             ruler_end,
                             self.mFooterY + 2 * self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)

            self.addElement(e)

            e = SVGdraw.line(ruler_end - w,
                             self.mFooterY,
                             ruler_end - w,
                             self.mFooterY + 2 * self.mRulerTickSize + 1,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             stroke_width=1)

            self.addElement(e)

            e = SVGdraw.text(ruler_end - w / 2,
                             self.mFooterY + 2 * self.mRulerTickSize + 1 +
                             self.mRulerFontSize,
                             self.mRulerFormat % self.mRulerIncrement,
                             self.mRulerFontSize,
                             self.mRulerFont,
                             stroke="rgb(%i,%i,%i)" % BLACK,
                             text_anchor="middle")

            self.addElement(e)
            self.mFooterY += 2 * self.mRulerTickSize + 1 + self.mRulerFontSize

        e, self.mFooterX, self.mFooterY = self.mDecoratorExternalNodes.getLegend(
            self.mFooterX, self.mFooterY)
        self.addElements(e)
        e, self.mFooterX, self.mFooterY = self.mDecoratorInternalNodes.getLegend(
            self.mFooterX, self.mFooterY)
        self.addElements(e)