def drawRef2(rexps, exps, options, outfile, numCats): options.out = outfile fig, pdf = libplot.initImage( 8.0, 10.0, options ) axes = fig.add_axes( [0.12, 0.14, 0.85, 0.8] ) if len(rexps) < 1: return sampleNotherRefmapped = [] ref = '' for sample in rexps: if sample == 'average': continue e = rexps[sample] ref = e.ref sampleNotherRefmapped.append( (sample, e.total) ) otherRefName = libplot.properName( ref ) #Set title: #axes.set_title("Mapability of C. Ref. in Comparison to %s" % otherRefName) #HACK axes.set_title("Mapability of C. Ref. in Comparison to GRCh37 haplotypes") sampleNotherRefmapped = sorted( sampleNotherRefmapped, key=lambda item: item[1], reverse=True ) samples = [ item[0] for item in sampleNotherRefmapped] samples.append( 'average' ) xdata = range( 0, len(samples) ) colors = libplot.getColors4() c = -1 #c = 0 lines = [] #titleDict = {'mapped':'Mapped', 'uniquelyMapped':'Uniquely Mapped', 'properlyPaired':'Properly Paired', 'uniquelyMappedAndProperlyPaired':'Uniquely Mapped And Properly Paired', 'snps':'Snp'} titleDict = {'mapped':'Mapped', 'properlyPaired':'Properly Paired', 'uniquelyMapped':'Uniquely Mapped', 'uniquelyMappedAndProperlyPaired':'Uniquely Mapped And Properly Paired'} ydataList, miny, maxy = getData2(samples, rexps, exps, titleDict.keys()) #ydataList, miny, maxy = getData2(samples, exps, titleDict.keys()) #refs = sorted( ydataList.keys() ) offset = 0.12 scale = -1 if miny > 1000: scale = len( str(int(miny)) ) - 1 linenames = [] categories = ["mapped", "properlyPaired", "uniquelyMapped", "uniquelyMappedAndProperlyPaired"] cats = categories[:numCats] for i, key in enumerate( cats ): xdatai = [ x + offset*i for x in xdata ] ydata = ydataList[key] if scale > 0: ydata = [ float(y)/10**scale for y in ydata ] c += 1 l = axes.plot( xdatai, ydata, color=colors[c], marker='.', markersize=16.0, linestyle='none') lines.append(l) linenames.append( titleDict[key] ) if scale > 0: miny = float(miny)/10**scale maxy = float(maxy)/10**scale #Draw horizontal line at y = 0: xmin = -0.4 xmax = len(samples) - 1 + offset*len(linenames) + offset axes.plot( [xmin, xmax], [0,0], color="#6B6B6B", linewidth=0.005) fontP = FontProperties() fontP.set_size('x-small') yrange = maxy - miny miny = miny - yrange*0.05 maxy = maxy + yrange*0.2 #Draw vertical lines to separate each sample: for i in xrange(1, len(samples)): d = (1 - offset*len(linenames))/2.0 x = [i - d, i - d] y = [miny , maxy] axes.plot(x,y, color="#CCCCCC", linewidth=0.005) axes.set_xlim(xmin, xmax ) axes.set_ylim( miny, maxy ) #HACK: #axes.set_ylim( -2, 0 ) libplot.editSpine( axes ) axes.set_xticks( [ i + offset*(len(linenames)/2.0) for i in range(0, len(samples))] ) axes.set_xticklabels( samples ) for label in axes.xaxis.get_ticklabels(): label.set_rotation(90) axes.xaxis.set_ticks_position( 'bottom' ) axes.yaxis.set_ticks_position( 'left' ) legend = pyplot.legend( lines, linenames, numpoints=1, loc='upper right', prop=fontP) legend._drawFrame = False axes.set_xlabel( 'Samples' ) axes.set_ylabel( 'Percentage of mapping difference between C. Ref. and %s' % otherRefName) #NEED TO DO #axes.set_ylabel( 'Percentage of mapping difference between C. Ref. and GRCh37 haplotypes') if scale > 0: axes.set_ylabel( 'Event counts (x%d)' %(10**scale) ) #axes.xaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) axes.yaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) libplot.writeImage( fig, pdf, options )
def drawPlot(rexps, exps, options, outfile, type): options.out = outfile fig, pdf = libplot.initImage( 8.0, 10.0, options ) axes = fig.add_axes( [0.12, 0.14, 0.85, 0.8] ) #Set title: titleDict = {'mapped':'Mapped reads', 'uniquelyMapped':'Uniquely Mapped Reads', 'properlyPaired':'Properly Paired Reads', 'uniquelyMappedAndProperlyPaired':'Uniquely Mapped And Properly Paired Reads', 'snps':'SNPs'} axes.set_title( titleDict[type] ) if len(rexps) < 1: return sampleNotherRefmapped = [] ref = '' for sample in rexps: if sample == 'average': continue exp = rexps[sample] ref = exp.ref sampleNotherRefmapped.append( (sample, exp.total) ) otherRefName = libplot.properName( ref ) sampleNotherRefmapped = sorted( sampleNotherRefmapped, key=lambda item: item[1], reverse=True ) samples = [ item[0] for item in sampleNotherRefmapped] samples.append( 'average' ) xdata = range( 0, len(samples) ) colors = libplot.getColors4() #c = -1 c = 0 lines = [] ydataList, miny, maxy = getData(samples, exps, rexps, type) #print ydataList refs = sorted( ydataList.keys() ) #miny = float('inf') #maxy = 0 #offset = 0.075 offset = 0.12 #if type != 'snps': # offset = 0 #axes.set_yscale('log') scale = -1 if miny > 1000: scale = len( str(int(miny)) ) - 1 #Draw line connecting the data for each sample (each bin): binXdataList = [ [] for x in xdata ] binYdataList = [ [] for x in xdata ] for i, ref in enumerate(refs): xdatai = [ x + offset*i for x in xdata ] ydata = ydataList[ref] if scale > 0: ydata = [ float(y)/10**scale for y in ydata ] for j, x in enumerate(xdatai): binXdataList[j].append(x) binYdataList[j].append( ydata[j] ) for i in xrange( len(binXdataList) ): axes.plot( binXdataList[i], binYdataList[i], color="#CCCCCC", linestyle='-', linewidth=0.005 ) #Draw main plots: for i, ref in enumerate(refs): xdatai = [ x + offset*i for x in xdata ] ydata = ydataList[ref] if scale > 0: ydata = [ float(y)/10**scale for y in ydata ] c += 1 l = axes.plot( xdatai, ydata, color=colors[c], marker='.', markersize=16.0, linestyle='none') lines.append(l) if scale > 0: miny = float(miny)/10**scale maxy = float(maxy)/10**scale #Draw horizontal line at y = 0: xmin = -0.4 xmax = len(samples) - 1 + offset*len(refs) + offset axes.plot( [xmin, xmax], [0,0], color="#6B6B6B", linewidth=0.005) fontP = FontProperties() fontP.set_size('x-small') yrange = maxy - miny miny = miny - yrange*0.05 maxy = maxy + yrange*0.2 #Draw vertical lines to separate each sample: #for i in xrange(1, len(samples)): # d = (1 - offset*len(refs))/2.0 # x = [i - d, i - d] # y = [miny , maxy] # axes.plot(x,y, color="#CCCCCC", linewidth=0.005) axes.set_xlim(xmin, xmax ) axes.set_ylim( miny, maxy ) libplot.editSpine( axes ) axes.set_xticks( [ i + offset*(len(refs)/2.0) for i in range(0, len(samples))] ) axes.set_xticklabels( samples ) for label in axes.xaxis.get_ticklabels(): label.set_rotation(90) axes.xaxis.set_ticks_position( 'bottom' ) axes.yaxis.set_ticks_position( 'left' ) properRefs = [] for r in refs: if re.search('cactusRef', r): r = r.lstrip('cactusRef') properRefs.append( "%s %s" %(libplot.properName('cactusRef'), r)) else: properRefs.append( libplot.properName(r) ) legend = pyplot.legend( lines,properRefs, numpoints=1, loc='best', prop=fontP) legend._drawFrame = False axes.set_xlabel( 'Samples' ) axes.set_ylabel( 'Percentage of mapping difference between C. Ref. and %s' % otherRefName) if scale > 0: axes.set_ylabel( 'Event counts (x%d)' %(10**scale) ) #axes.xaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) axes.yaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) libplot.writeImage( fig, pdf, options )