def drawN50data( axes, samples, options ): #key can be 'blockN50', 'sequenceN50', 'contigPathN50', or 'scaffolfPathN50' keys = options.keys colors = libplot.getColors6() #markers = [".", "s", "^", "--"] c = -1 lines = [] for key in keys: ydata = [] for sample in samples: y = int(sample.attrib[ key ]) ydata.append( y ) if options.logscale: ydata = log10( array(ydata) ) c += 1 l = axes.plot( ydata, color=colors[c], marker=".", markersize=10.0, linestyle='none' ) lines.append(l) libplot.editSpine( axes ) pyplot.xlabel( 'Samples' ) if options.logscale: pyplot.ylabel( 'Log 10 of N50' ) else: pyplot.ylabel( 'N50' ) return lines
def drawPlot(exps, options, outfile, type): options.out = outfile fig, pdf = libplot.initImage( 11.2, 10.0, options ) axes = fig.add_axes( [0.12, 0.18, 0.85, 0.75] ) #Set title: titleDict = {'tpfn':'Indel Overlap with dbSNP', 'tp':'True Positives According to dbSNP', 'tp2':'Indel Overlap with dbSNP', 'fn':'False Negatives According to dbSNP', 'total':'Total Indels Called'} axes.set_title( titleDict[type] ) if 'All' not in exps: return samples = getSamplesOrder( exps['All'], type ) if len( samples ) < 1: return samples.append('average') if type != 'fn': samples.append('reference') samples.append('panTro3') xdata = range( 0, len(samples) ) colors = libplot.getColors6() c = -1 lines = [] pointsize = 10.0 offset = 0.15 #exporder = ['All', 'No repeats', 'Wobble', 'Wobble, No repeats'] exporder = ['Wobble', 'Wobble, No repeats', 'All', 'No repeats'] if type == 'fn': exporder = ['Wobble', 'All'] elif type == 'total': exporder = ['All', 'No repeats'] elif type == 'tp2' or type == 'tpfn': exporder = ['Wobble', 'Wobble, No repeats'] #pointsize = 16.0 #offset = 0.3 #Get ydata ydataList, ymin, ymax = getData(samples, exps, type, exporder) scale = -1 if ymin > 1000: scale = len( str(int(ymin)) ) -1 if scale > 0: for exp in ydataList: ydataList[exp] = [ float(y)/10**scale for y in ydataList[exp]] if type == 'tpfn': for j,t in enumerate(['tp', 'fn']): for i, exp in enumerate(exporder): if i > 0 and t == 'fn': continue if t == 'tp': xdatai = [x + offset*(j*2+i) for x in xdata] else: xdatai = [x + offset*(j*2+i) for x in xdata[: len(xdata) -3]] ydata = ydataList["%s.%s" %(exp,t)] c +=1 lines.append(axes.plot(xdatai, ydata, color=colors[c], marker='.', markersize=pointsize, linestyle='none')) else: for i, exp in enumerate(exporder): xdatai = [x + offset*i for x in xdata] ydata = ydataList[exp] c += 1 l = axes.plot(xdatai, ydata, color=colors[c], marker='.', markersize=pointsize, linestyle='none') if type == 'fn': c += 1 lines.append(l) xmin = -0.4 xmax = len(samples) - 1 + offset*len(exps) + offset*3 fontP = FontProperties() fontP.set_size('x-small') if scale > 0: ymin = float(ymin)/10**scale ymax = float(ymax)/10**scale datarange = ymax -ymin ymin = ymin - datarange*0.01 ymax = ymax + datarange*0.01 #Draw vertical lines to separate each sample: for i in xrange(1, len(samples)): d = (1 - offset*len(exporder))/2.0 x = [i - d, i - d] y = [ymin , ymax] axes.plot(x,y, color="#CCCCCC", linewidth=0.005) axes.set_xlim(xmin, xmax) axes.set_ylim(ymin, ymax) libplot.editSpine( axes ) axes.set_xticks( [ i + offset*(len(exps)/2-1) for i in range(0, len(samples))] ) axes.set_xticklabels( [ libplot.properName(s) for s in samples] ) for label in axes.xaxis.get_ticklabels(): label.set_rotation(90) axes.xaxis.set_ticks_position( 'bottom' ) axes.yaxis.set_ticks_position( 'left' ) if type == 'tp': legend = pyplot.legend(lines, ['All', 'No repeats', 'No wobble', 'No wobble, No repeats'], numpoints=1, loc='best', prop=fontP) elif type == 'fn': legend = pyplot.legend( lines, ['All', 'No wobble'], numpoints=1, loc='best', prop=fontP) elif type == 'tpfn': legend = pyplot.legend(lines, ['All, TP', 'No repeats, TP', 'All, FN'], numpoints=1, loc='best', prop=fontP) elif type == 'tp2': legend = pyplot.legend( lines, ['All', 'No repeats'], numpoints=1, loc='best', prop=fontP) else: legend = pyplot.legend( lines, exporder, numpoints=1, loc='best', prop=fontP) legend._drawFrame = False axes.set_xlabel( 'Samples' ) ylabel = "Percentage" if type == 'total': ylabel = 'Number of indels' if scale > 0: ylabel += '(x%d)' %10**scale axes.set_ylabel(ylabel) axes.yaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) libplot.writeImage( fig, pdf, options )
def drawPlot2(exps, options, outfile, type): options.out = outfile fig, pdf = libplot.initImage( 11.2, 10.0, options ) #Set title: titleDict = {'total':'Total Indels Called'} if 'All' not in exps: return samples = getSamplesOrder( exps['All'], type ) if len( samples ) < 1: return samples.append('average') samples.append('reference') samples.append('panTro3') xdata = range( 0, len(samples) ) colors = libplot.getColors6() c = -1 lines = [] pointsize = 10.0 offset = 0.15 exporder = ['All', 'No repeats'] #Get ydata ydataList, ymin, ymax = getData(samples, exps, type, exporder) yrange = ymax - ymin #Get normal range and outlier range: normalvals, outliers = getOutliers(ydataList) minNormal = min(normalvals) - 0.05*yrange maxNormal = max(normalvals) + 0.05*yrange minOutlier = min(outliers) - 0.05*yrange maxOutlier = max(outliers) + 0.05*yrange if minNormal< 0: minNormal = -0.5 #Set up the axes ax, ax2 = setAxes(fig, maxOutlier - minOutlier, maxNormal - minNormal) scale = -1 if minNormal > 1000: scale = len( str(int(minNormal)) ) -1 if scale > 0: for exp in ydataList: ydataList[exp] = [ float(y)/10**scale for y in ydataList[exp]] #PLOT for i, exp in enumerate(exporder): xdatai = [x + offset*i for x in xdata] ydata = ydataList[exp] c += 1 #Outlier plot l = ax.plot(xdatai, ydata, color=colors[c], marker='.', markersize=pointsize, linestyle='none') lines.append(l) #Normal range plot ax2.plot(xdatai, ydata, color=colors[c], marker='.', markersize=pointsize, linestyle='none') xmin = -0.4 xmax = len(samples) - 1 + offset*len(exps) + offset*3 fontP = FontProperties() fontP.set_size('x-small') if scale > 0: minNormal = float(minNormal)/10**scale maxNormal = float(maxNormal)/10**scale minOutlier = float(minOutlier)/10**scale maxOutlier = float(maxOutlier)/10**scale #Draw the Discontinue sign: d = 0.2 #how big to make the diagonal lines in axes coordinates if scale == -1: d = 50 ax.plot( (-1, 0), (minOutlier +d, minOutlier - d), color = "k", clip_on=False ) ax2.plot( (-1, 0), (maxNormal +d, maxNormal - d), color = "k", clip_on=False ) #Draw vertical lines to separate each sample: for i in xrange(1, len(samples)): d = (1 - offset*len(exporder))/2.0 x = [i - d, i - d] y = [minNormal , maxOutlier] ax.plot(x,y, color="#CCCCCC", linewidth=0.005) ax2.plot(x,y, color="#CCCCCC", linewidth=0.005) xticklabels = [libplot.properName(s) for s in samples] #Set limit for the top plot (outlier) ax.set_ylim(minOutlier, maxOutlier) ax.set_xlim(xmin, xmax) ax.set_xticks( [ i + offset*(len(exps)/2-1) for i in range(0, len(samples))] ) dummyxticklabels = [ "" for l in xticklabels ] ax.set_xticklabels(dummyxticklabels) #Make sure the y ticks of the top plot is the same with the bottom plot: step = 2 if scale == -1: step = 500 ytickpositions = [] ytickpos = 0 while ytickpos < maxOutlier: if ytickpos >= minOutlier: ytickpositions.append(ytickpos) ytickpos += step ax.set_yticks(ytickpositions) #Set limit for the bottom plot: ax2.set_ylim(minNormal, maxNormal) ax2.set_xlim(xmin, xmax) #Hide the spines between ax and ax2: ax.spines['bottom'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('none') ax2.spines['top'].set_visible(False) ax2.spines['right'].set_visible(False) ax2.xaxis.tick_bottom() ax2.yaxis.set_ticks_position( 'left' ) ax2.set_xticks( [ i + offset*(len(exps)/2-1) for i in range(0, len(samples))] ) ax2.set_xticklabels( xticklabels ) for label in ax2.xaxis.get_ticklabels(): label.set_rotation(75) legend = pyplot.legend( lines, exporder, numpoints=1, loc='upper left', prop=fontP) legend._drawFrame = False ax2.set_xlabel( 'Samples' ) ylabel = 'Number of indels' if scale > 0: ylabel += '(x%d)' %10**scale ax2.set_ylabel(ylabel) ax.set_title( titleDict[type] ) ax.yaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) ax2.yaxis.grid(b=True, color="#CCCCCC", linestyle='-', linewidth=0.005) libplot.writeImage( fig, pdf, options )
def drawCompareN50data( axes, xsamples, ysamples, options ): keys = options.keys lineNames = [] colors = libplot.getColors6() c = -1 lines = [] xrefname = xsamples[0].attrib[ 'referenceName' ] yrefname = ysamples[0].attrib[ 'referenceName' ] minval = inf maxval = 0 for key in keys: xdata = [] ydata = [] for xsample in xsamples: name = xsample.attrib[ 'sampleName' ] if name == yrefname: continue ysample = getSample( ysamples, name ) if ysample == None: sys.stderr.write( "%s has %s sample, but %s doesn't\n" % (xrefname, name, yrefname) ) continue xval = int(xsample.attrib[key]) yval = int(ysample.attrib[key]) if xval > 0 and yval > 0: xdata.append(xval) ydata.append(yval) #xdata.append( int(xsample.attrib[ key ]) ) #ydata.append( int(ysample.attrib[ key ]) ) if len(xdata) == 0: continue if options.logscale: xdata = log10( array(xdata) ) ydata = log10( array(ydata) ) c += 1 l = axes.plot( xdata, ydata, color=colors[c], marker=".", markersize=10.0, linestyle='none' ) lines.append(l) lineNames.append( key ) currmax = max( xdata.max(), ydata.max() ) if maxval < currmax: maxval = currmax currmin = min( xdata.min(), ydata.min() ) if minval > currmin: minval = currmin if minval == -inf: minval = 0 #Draw y=x line span = maxval - minval #print "MaxVal: %f, MinVal: %f. Span: %f" % (maxval, minval, span) x = [ minval - span*0.1, maxval + span*0.1 ] y = [ minval - span*0.1, maxval + span*0.1 ] axes.plot( x, y, color="0.9" ) libplot.editSpine( axes ) if options.logscale: #pyplot.ylabel( 'Log 10 of N50' ) pyplot.xlabel( "%s (Log 10)" % libplot.properName(xrefname) ) pyplot.ylabel( "%s (Log 10)" %libplot.properName(yrefname) ) return lines, lineNames, maxval, minval