def _setOutputDevice(self, fn, height, width):
     from proto.RSetup import r
     if fn.endswith('.pdf'):
         # self.LINE_HEIGHT = self.POINT_SIZE
         r.pdf(fn,
               height=height * 1.0 / 72,
               width=width * 1.0 / 72,
               pointsize=self.POINT_SIZE)
     elif fn.endswith('.png'):
         # if any(x > 800 for x in [width, height]):
         #     if self.HIGH_DEF_COLORS:
         #         picType = 'png16m'
         #     else:
         #         picType = 'png256'
         #
         #     # self.LINE_HEIGHT = self.POINT_SIZE
         #     r.bitmap(fn, height=height, width=width, units='px', type=picType, pointsize=self.POINT_SIZE)
         # else:
         # self.LINE_HEIGHT = self.POINT_SIZE * 1.38 # for r.png(). Don't know why
         r.png(filename=fn,
               height=height,
               width=width,
               units='px',
               pointsize=self.POINT_SIZE,
               res=72,
               type='cairo')
     else:
         raise ShouldNotOccurError
Esempio n. 2
0
 def openRFigure(self, h=600, w=800):
     from proto.RSetup import r
     r.png(filename=self.getDiskPath(True),
           height=h,
           width=w,
           units='px',
           pointsize=12,
           res=72)
Esempio n. 3
0
    def makeTrackImage(cls, res, fn, main):
        from proto.RSetup import r
        resDictKey = 'Result'
        POINT_SIZE = 12
        LINE_HEIGHT = POINT_SIZE * 1.38
        
        ensurePathExists(fn)
        bmpFn = fn 

        width = 1000
        height = 30 *min(100, len(res))
        picType = 'png256'
        r.png(filename=bmpFn, height=max([200, height]), width=width, units='px', pointsize=POINT_SIZE, res=72)
        if resDictKey is not None:
            xlab = res.getLabelHelpPair(resDictKey)[0]
        else:
            xlab = None
        
        
        rCode = ''' par(mar=c(4.2, 0.2, 0.2, 14.2))\n
        plot.new()\n
            plot.window(xlim=c(0,%i),ylim=c(0,%i))\n
            axis(1)\n
            axis(4, at=((1:%i)*30)-21, lab=c(%s), las=1)\n
            %s
        '''
        
        yFloor = 1
        rectTemplate = 'rect(%f,%i,%f,%i, col="%s", border="%s")\n'
        rectVals = []
        globRes = res.getGlobalResult()
        visRes = globRes.values()[0]
        rawData = visRes.getAllTrackViews()
        
        yLabels = []
        maxVal = max([tv._bpSize() for tv in rawData])
        halfMax = maxVal/2
        for tv in rawData:
            yLabels.append('"'+tv.genomeAnchor.chr+': %s"'% ':'.join(str(tv.genomeAnchor).split()[0].split(':')[1:]))
            startArr, endArr = tv.startsAsNumpyArray(),tv.endsAsNumpyArray()
            if tv.normalizeRows:
                normalizer = 1000.0/tv._bpSize() if len(endArr)>0 else 0
                maxVal = 1000
                rectVals.append(rectTemplate % (0, yFloor+8, 1000, yFloor+8, 'lightgray', 'lightgray') )
                
                rectVals += [rectTemplate % (start*normalizer, yFloor, end*normalizer, yFloor+15, 'red', 'red') for start, end in zip(startArr, endArr)]
                
            else:
                extra1=extra2 = 0
                if tv.centerRows:
                    halfBin = tv._bpSize()/2
                    extra1 = halfMax-halfBin
                    extra2 = halfMax+halfBin
                    
                rectVals.append(rectTemplate % (0+extra1, yFloor+8, extra2 if tv.centerRows else tv._bpSize()  , yFloor+5, 'lightgray', 'lightgray') )
                rectVals += [rectTemplate % (start+extra1, yFloor, end+extra1, yFloor+15, 'red', 'red') for start, end in zip(startArr, endArr)]
            yFloor+=30
        
        if len(rectTemplate)>0:
            
            rScript = rCode % (maxVal, height, len(yLabels), ','.join(yLabels), '\n'.join(rectVals))
            r(rScript)