def drawCompareN50Plot( options, xsamples, ysamples ): #Sort xsamples and ysamples in the order of the sampleNames: xsamples = sorted( xsamples, key=lambda s: s.attrib[ 'sampleName' ] ) if len(xsamples) < 1 or len(ysamples) < 1: return xrefname = xsamples[0].attrib[ 'referenceName' ] yrefname = ysamples[0].attrib[ 'referenceName' ] options.out = os.path.join( options.outdir, options.prefix + '_' + xrefname + '_' + yrefname ) fig, pdf = libplot.initImage( 8.0, 8.0, options ) axes = fig.add_axes( [0.12, 0.1, 0.85, 0.85] ) lines, lineNames, maxval, minval = drawCompareN50data( axes, xsamples, ysamples, options ) if len(lines) == 0: sys.stderr.write('Comparing N50 stats of %s and %s: All values are 0, no plot created\n' %(xrefname, yrefname) ) return title = "N50" #% ( libplot.properName(xrefname), libplot.properName(yrefname) ) axes.set_title(title) #Legend fontP = FontProperties() fontP.set_size( 'small' ) box = axes.get_position() axes.set_position( [box.x0, box.y0, box.width*0.8, box.height*0.8] ) legend = pyplot.legend( lines, lineNames, numpoints=1, prop=fontP, loc="best", bbox_to_anchor=(1, 0.5) ) legend._drawFrame = False libplot.setTicks( axes ) span = maxval - minval axes.set_xlim( minval - span*0.1, maxval + span*0.1 ) axes.set_ylim( minval - span*0.1, maxval + span*0.1 ) libplot.writeImage( fig, pdf, options )
def drawContiguityPlot( options, stats ): #options.out = os.path.join(options.outdir, "contiguity_" + stats.refname) #name of output file options.out = os.path.join(options.outdir, options.exp + "_" + stats.refname) #name of output file if options.includeCov: options.out = options.out + "_incCov" options.ycutoff = 0.7 #HACK else:#HACK options.ycutoff = 0.95 #HACK fig, pdf = libplot.initImage( 8.0, 10.0, options ) axes = libplot.setAxes( fig ) lines, sampleNames, ymin = drawData( axes, stats, options ) drawLegend( axes, lines, sampleNames, options ) if options.ycutoff: setAxisLimits( axes, options.ycutoff ) else: setAxisLimits( axes, ymin*0.98 ) libplot.setTicks( axes ) libplot.writeImage( fig, pdf, options )
def drawCompareData( axesList, xstats, ystats, options ): #Only draw the overlapped samples: #colors = libplot.getColors2( len(xstats) ) colors = libplot.getColors1() #colorindex = -1 #colorindex = 0 colorindex = 1 lines = [] sampleNames = [] p0axes = axesList[0] #plot 0 axes (see def 'setCompareAxes') aggData = [] #data points (buckets) of all samples minval = float('inf') for xsample in xstats: ysample = getSample( ystats, xsample.name ) if ysample is None: continue xsample, ysample = intersect(xsample, ysample) #if len(xsample) != len(ysample): # xsample, ysample = intersect(xsample, ysample) # sys.stderr.write( "Error: Two xml files do not have the same number of buckets for sample %s\n" % xsample.name ) #sys.exit( 1 ) data = [] #list of (x,y) tuples colorindex += 1 for i in range( len( xsample ) ): #each bucket if xsample[i].mid != ysample[i].mid: sys.stderr.write( "Two xml files have different buckets\n " ) sys.exit( 1 ) if options.includeCov: data.append( (xsample[i].correctPerSample, ysample[i].correctPerSample) ) else: data.append( (xsample[i].correctPerAligned, ysample[i].correctPerAligned) ) x2data = [ point[0] for point in data ] y2data = [ point[1] for point in data ] l = p0axes.plot( x2data, y2data, color=colors[colorindex], marker='.', markersize=4.0, linestyle='none' ) lines.append( l ) sampleNames.append( xsample.name ) aggData.extend( data ) minval = min( [min(x2data), min(y2data)] ) #Draw the y=x line x = [0, 1] y = [0, 1] p0axes.plot(x, y, color="#919191") fontP = FontProperties() fontP.set_size('small') libplot.editSpine( p0axes ) p0axes.set_title(options.title) p0axes.set_xlabel( libplot.properName(xstats.refname) ) p0axes.set_ylabel( libplot.properName(ystats.refname) ) libplot.setTicks( p0axes ) for l in p0axes.xaxis.get_ticklabels(): l.set_fontsize('small') for l in p0axes.yaxis.get_ticklabels(): l.set_fontsize('small') #legend: legend = p0axes.legend( lines, [ libplot.properName(n) for n in sampleNames], 'lower right', numpoints = 1, prop=fontP, ncol = 2) legend._drawFrame = False #p0axes.set_xlim( -0.005, 1.005 ) #p0axes.set_ylim( -0.005, 1.005 ) ycutoff = minval if options.ycutoff: ycutoff = options.ycutoff p0axes.set_xlim( ycutoff - (1-ycutoff)*0.02, 1 + (1 - ycutoff)*0.01 ) p0axes.set_ylim( ycutoff - (1-ycutoff)*0.02, 1 + (1 - ycutoff)*0.01 ) #box = p0axes.get_position() #p0axes.set_position([box.x0, box.y0, box.width * 0.8, box.height * 0.8]) #legend = pyplot.legend( lines, sampleNames, numpoints = 1, prop= fontP, loc="best", bbox_to_anchor=(1, 0.6)) #legend._drawFrame=False #DRAW AGGREGATE DATA (plot 1 and plot 2): nbins = 20 p1axes = axesList[1] y1min, y1max = drawAggData( p1axes, aggData, 0, 0, 1, ycutoff, nbins ) y1lim = max( abs(y1min), abs(y1max) ) p1axes.set_ylim( -y1lim*1.1, y1lim*1.1 ) p1axes.set_xlim( ycutoff - (1-ycutoff)*0.02, 1 + (1-ycutoff)*0.01 ) #p1axes.set_ylim( y1min*1.1, y1max*1.1 ) for loc, spine in p1axes.spines.iteritems(): if loc == 'left': spine.set_position( ( 'outward', 10 ) ) spine.set_color( 'none' ) p1axes.axhline( 0, color = '#000000' ) p1axes.xaxis.set_major_locator( NullLocator() ) p1axes.xaxis.set_major_formatter( NullFormatter() ) p1axes.yaxis.set_ticks([-y1lim, 0, y1lim]) for l in p1axes.yaxis.get_ticklabels(): l.set_fontsize('small') p2axes = axesList[2] x2min, x2max = drawAggData( p2axes, aggData, 1, 0, 1, ycutoff, nbins ) x2lim = max( abs(x2min), abs(x2max) ) p2axes.set_xlim( -x2lim*1.1, x2lim*1.1 ) p2axes.set_ylim( ycutoff - (1-ycutoff)*0.02, 1 + (1- ycutoff)*0.01 ) #p2axes.set_xlim( x2min*1.1, x2max*1.1 ) for loc, spine in p2axes.spines.iteritems(): if loc == 'bottom': spine.set_position( ( 'outward', 10 ) ) spine.set_color( 'none' ) p2axes.axvline( 0, color = '#000000' ) p2axes.yaxis.set_major_locator( NullLocator() ) p2axes.yaxis.set_major_formatter( NullFormatter() ) p2axes.xaxis.set_ticks([-x2lim, 0, x2lim]) for l in p2axes.xaxis.get_ticklabels(): l.set_fontsize('small') l.set_rotation( 45 ) return