Esempio n. 1
0
 def build(self):
     (sx, sy) = self._srcchgset.position()
     h_offset = self._srcchgset.tag_offset(self._h)
     self._position = (sx + (self._srcchgset.extent()[0])/2,
                       sy - (3*self._h)/2 + h_offset)
     x = self._position[0]+(self._w-self._tw)/2
     y = self._position[1]
     r = UNIT/2
     rect = SVG.rect(x,y,self._tw,self._h,
                     self._srcchgset.strokecolor(),
                     self._srcchgset.fillcolor(), 
                     self._srcchgset.strokewidth())
     rect.attributes['rx'] = r
     rect.attributes['ry'] = r        
     rect.attributes['opacity'] = str(self._opacity/100.0) 
     text = SVG.text(self._position[0]+self._w/2, 
                     self._position[1]+self._h/2+UNIT/4,
                     "%s" % self._title.encode('utf-8'), 
                     self._srcchgset.fontsize(), 
                     self._srcchgset.fontname())
     txc = SvgColor('white')
     text.attributes['style'] = 'fill:%s; text-anchor: middle' % txc.rgb()
     name = self._title.encode('utf-8').replace('/','')
     g = SVG.group('grp%d' % self._revision, elements=[rect, text])
     link = "%s/changeset/%d" % (self._parent.urlbase(), self._revision)
     self._link = SVG.link(link, elements=[g])
     self._link.attributes['id'] = 'rev%d' % self._revision
     self._link.attributes['style'] = \
         'color: %s; background-color: %s' % \
             (self._srcchgset.fillcolor(), self._srcchgset.strokecolor())
Esempio n. 2
0
 def build(self):
     self._position = self._parent.position()
     x = self._position[0] + (self._w - self._tw) / 2
     y = self._position[1]
     r = UNIT / 2
     rect = SVG.rect(x, y, self._tw, self._h, self._parent.fillcolor(),
                     self._parent.strokecolor(), self._parent.strokewidth())
     rect.attributes['rx'] = r
     rect.attributes['ry'] = r
     text = SVG.text(self._position[0] + +self._w / 2,
                     self._position[1] + self._h / 2 + UNIT / 6,
                     "/%s" % self._title.encode('utf-8'),
                     self._parent.fontsize(), self._parent.fontname())
     text.attributes['style'] = 'text-anchor: middle'
     name = self._title.encode('utf-8').replace('/', '')
     g = SVG.group('grp%s' % name, elements=[rect, text])
     href = Href(self._parent.urlbase())
     self._link = SVG.link(plink(href.browser(self._title)), elements=[g])
Esempio n. 3
0
 def build(self):
     self._position = self._parent.position()
     x = self._position[0]+(self._w-self._tw)/2
     y = self._position[1]
     r = UNIT/2
     rect = SVG.rect(x,y,self._tw,self._h,
                     self._parent.fillcolor(), 
                     self._parent.strokecolor(), 
                     self._parent.strokewidth())
     rect.attributes['rx'] = r
     rect.attributes['ry'] = r        
     text = SVG.text(self._position[0]++self._w/2, 
                     self._position[1]+self._h/2+UNIT/6,
                     "/%s" % self._title.encode('utf-8'), 
                     self._parent.fontsize(), self._parent.fontname())
     text.attributes['style'] = 'text-anchor: middle'
     name = self._title.encode('utf-8').replace('/','')
     g = SVG.group('grp%s' % name, elements=[rect, text])
     href = Href(self._parent.urlbase())
     self._link = SVG.link(plink(href.browser(self._title)), elements=[g])
Esempio n. 4
0
    def getElements( self, node_id, x, y, x_label = None, y_label = None):

        e = NodeDecorator.getElements( self, node_id, x, y )

        if x_label == None: x_label = x
        if y_label == None: y_label = y        
        
        t = self.mTree.node(node_id).data.taxon        
        species = self.mExtractSpecies(t)
        
        if species not in self.mMapSpecies2Colour:
            self.mMapSpecies2Colour[species] = COLOURS[len(self.mMapSpecies2Colour) % len(COLOURS) ]

        if species in self.mMapSpecies2Name:
            tx = re.sub( species, "%s" % self.mMapSpecies2Name[species], t)
        else:
            tx = t

        colour = self.getColour( node_id, x, y )
        
        if self.mPlotLabel:
            ee = SVGdraw.text( x_label, y_label,
                               tx,
                               self.mFontSize,
                               self.mFont,
                               stroke = "rgb(%i,%i,%i)" % colour,
                               text_anchor = "left" )

            if self.mMapTaxon2URL != None:
                url = self.mMapTaxon2URL(t)
                if url:
                    l = SVGdraw.link( url )
                    l.addElement( ee )
                    e.append( l )
                else:
                    e.append(ee)
            else:
                e.append( ee )
        return e
    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 = []

        if not link_to_previous:
            self.mPreviousPoints = {}

        ########################################################
        ########################################################
        ########################################################            
        ## convert gene list to a set of 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, chr) )

        ########################################################
        ########################################################
        ########################################################            
        ## 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()

        self.mPreviousMin = mi
        self.mPreviousMax = ma
        self.mPreviousCis = cis
        
        self.mRadiusMax = max(self.mRadius, self.mRadiusMax)

        ########################################################
        ########################################################
        ########################################################            
        ## draw points 
        ########################################################                    
        link_colour = master_colour
        link_rad_width = self.mLinkRadStrokeWidth
        link_arc_width = self.mLinkArcStrokeWidth
        new_points = {}
        for pos1, pos2, gene, quality, chr 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 = self.mLinkColourSymbolMasked
                link_colour = self.mLinkColourMasked
                link_rad_width = self.mLinkStrokeWidthMasked
                link_arc_width = self.mLinkStrokeWidthMasked
            else:
                colour = master_colour

            if gene in self.mPreviousPoints:
                continue
            
            new_points[gene] = (x, y, angle, quality, chr)
            
            if symbol == "circle":
                ee = SVGdraw.circle( x, y, self.mLinkSymbolSize,
                                     fill = "rgb(%i,%i,%i)" % colour,
                                     stroke="black",
                                     stroke_width = self.mLinkStrokeWidthSymbol )
            elif symbol == "rect":
                ee =  SVGdraw.rect( x-self.mLinkSymbolSize/2, y-self.mLinkSymbolSize/2,
                                    self.mLinkSymbolSize, self.mLinkSymbolSize,
                                    fill = "rgb(%i,%i,%i)" % colour,
                                    stroke="black",
                                    stroke_width = self.mLinkStrokeWidthSymbol )

            if url:
                e = SVGdraw.link( url % gene )
                e.addElement( ee )
            else:
                e = ee
                
            self.addWheelElement( e )                
            
        ########################################################
        ########################################################
        ########################################################
        ## write all arcs in between old points and new points
        ## cis:   circular arc
        ## trans: radial arc
        ########################################################   

        angles = []
        
        for x1,y1,angle1,quality1,chr1 in new_points.values():

            ## reduce clutter by not writing arc to the same angle
            for x2,y2,angle2,quality2,chr2 in self.mPreviousPoints.values():

                for a in angles:
                    if a - self.mAngleResolution < angle2 < a + self.mAngleResolution:
                        break
                else:
                    angles.append( angle2 )

                    d = SVGdraw.pathdata( x1, y1 )

                    if chr1 == chr2:
                        d.relellarc( self.mRadius, self.mRadius, 0, 0, 1, x2-x1, y2-y1 )
                        link_width = link_rad_width
                    else:
                        d.relellarc( self.mRadius * 2, self.mRadius * 2, 0, 0, 0, x2-x1, y2-y1 )
                        link_width = link_arc_width
                        
                    e = SVGdraw.path( d,
                                      fill = "none",
                                      stroke = "rgb(%i,%i,%i)" % link_colour,
                                      stroke_width = link_width )

                    self.addWheelElement(e, self.mPlaneLinks)


        ## plot lines between new points
        new_genes = new_points.keys()

        for g1 in range(len(new_genes)-1):
            
            x1,y1,angle1,quality1,chr1 = new_points[new_genes[g1]]
            
            for g2 in range(g1+1, len(new_genes)):
                
                x2,y2,angle2,quality2,chr2 = new_points[new_genes[g2]]

                for a in angles:
                    if a - self.mAngleResolution < angle2 < a + self.mAngleResolution:
                        break
                else:
                    angles.append( angle2 )

                    d = SVGdraw.pathdata( x1, y1 )

                    if chr1 == chr2:
                        d.relellarc( self.mRadius, self.mRadius, 0, 0, 1, x2-x1, y2-y1 )
                        link_width = link_rad_width                        
                    else:
                        d.relellarc( self.mRadius * 2, self.mRadius * 2, 0, 0, 0, x2-x1, y2-y1 )
                        link_width = link_arc_width                        

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

                    self.addWheelElement(e, self.mPlaneLinks)
                
        ## add new points to old points
        for k, v in new_points.items():
            self.mPreviousPoints[k] = v
Esempio n. 6
0
 def build(self):
     SvgBaseChangeset.build(self)
     (fgc, bgc) = (self._strokecolor, self._fillcolor)
     txc = self._textcolor
     if 'firstchangeset' in self._classes:
         (fgc, bgc) = (bgc, fgc)
     if 'lastchangeset' in self._classes:
         bgc = SvgColor('black')
         txc = SvgColor('white')
         
     widgets = []
     if self._shape == 'circle':
         widgets.append(SVG.circle(self._position[0], self._position[1],
                                   self._radius, bgc, fgc,
                                   self._parent.strokewidth()))
         if self._enhance:
             (x,y) = self._position
             (d,hr) = (self._radius*SQRT3/2, self._radius/2)
             widgets.append(SVG.line(x-d,y-hr,x+d,y-hr, 
                                     fgc, self._parent.strokewidth()))
             widgets.append(SVG.line(x-d,y+hr,x+d,y+hr, 
                                     fgc, self._parent.strokewidth()))
                           
     elif self._shape == 'square':
         r = UNIT/6
         size = self._radius-r
         widgets.append(SVG.rect(self._position[0]-size, 
                                 self._position[1]-size,
                                 2*size, 2*size, bgc, fgc,
                                 self._parent.strokewidth()))
         outline.attributes['rx'] = r
         outline.attributes['ry'] = r        
         
     elif self._shape == 'hexa':
         (x,y) = self._position
         (r,hr) = (self._radius, self._radius/2)
         pd = SVG.pathdata()
         pd.move(x,y-r)
         pd.line(x+r,y-hr)
         pd.line(x+r,y+hr)
         pd.line(x,y+r)
         pd.line(x-r,y+hr)
         pd.line(x-r,y-hr)
         pd.line(x,y-r)
         widgets.append(SVG.path(pd, bgc, fgc, 
                                 self._parent.strokewidth()))
     else:
         raise AssertionError, \
               "unsupported changeset shape (%d)" % self._revision
     title = SVG.text(self._position[0], 
                      self._position[1] + UNIT/6,
                      str(self._revision), 
                      self._parent.fontsize(), self._parent.fontname())
     title.attributes['style'] = 'fill:%s; text-anchor: middle' % txc.rgb()
     widgets.append(title)
     g = SVG.group('grp%d' % self._revision, elements=widgets)
     link = "%s/changeset/%d" % (self._parent.urlbase(), self._revision)
     self._link = SVG.link(link, elements=[g])
     if self._revision:
         self._link.attributes['style'] = \
             'color: %s; background-color: %s' % \
                 (self._strokecolor, self._fillcolor)
         self._link.attributes['id'] = 'rev%d' % self._revision
         self._link.attributes['class'] = ' '.join(self._classes)