def scatter_plot(self, gene_id_list, output_fname='/tmp/scatter_plot.ps'): """ 02-15-06 1st gene is regarded as X, all others genes are treated as Y """ vector_list = [] #gene_id_list may contain some inexistent genes real_gene_id_list = [] for gene_id in gene_id_list: if gene_id in self.gene_id2expr_array: real_gene_id_list.append(gene_id) vector_list.append(self.gene_id2expr_array[gene_id]) else: sys.stderr.write("%s doesn't appear in the dataset\n"%(gene_id)) if len(real_gene_id_list)>0: r.postscript("%s"%output_fname) axis_range = self.get_min_max(vector_list) no_of_curves = 1 #counting starts from 1st gene itself. no_of_curves += 1 r.plot(vector_list[0], vector_list[1], xlab='value of %s'%real_gene_id_list[0], xlim=axis_range, ylim=axis_range, \ ylab='other genes values', col=no_of_curves) for i in range(2, len(vector_list)): no_of_curves += 1 r.points(vector_list[0], vector_list[i], col=no_of_curves) r.legend(axis_range[1], axis_range[1], gene_id_list, col=range(1, no_of_curves+1), lty=1, xjust=1) r.dev_off() return output_fname else: return None
def plotSkByAtom(self, col='green', pch='x', function=numpy.average, **other): from rpy import r for kmag, SkArray in zip(self.kmags(), self.SkArraysByAtom()): if function is not None: SkArray = function(SkArray) try: len_ = len(SkArray) except: len_ = 1 r.points(x=[kmag]*len_, y=SkArray, col=col, pch=pch, **other)
def plot_boxplot_r(self, filename=None, n_highest_weights=1, n_highest_weights_for_quantity=1, weight_threshold=None, logy=False): from rpy import r logstring = '' if logy: logstring='y' if filename is not None: r.pdf(file=filename) for var, values in self.values_from_mr.iteritems(): plot_one_boxplot_r(values, var, logstring) if values.ndim == 1: v = resize(values, (1, values.size)) else: v = values ivar = self.get_index_for_quantity(var) if weight_threshold is not None: for i in range(0, v.shape[0]): iw = self.get_index_of_component_weights_over_threshold(ivar, weight_threshold) if iw.size > 0: r.points(i+1, v[i:(i+iw.size),iw], col='yellow', cex=0.5) iw = self.get_index_of_weights_over_threshold(weight_threshold) if iw.size > 0: r.points(i+1, v[i:(i+iw.size),iw], col='blue', cex=0.5) if n_highest_weights_for_quantity > 0: for i in range(0, v.shape[0]): r.points(i+1, v[i,self.get_index_of_n_highest_component_weights(ivar, n_highest_weights_for_quantity)], col='green', cex=0.5) if n_highest_weights > 0: for i in range(0, v.shape[0]): r.points(i+1, v[i,self.get_index_of_n_highest_weights(n_highest_weights)], col='red', cex=0.5) if filename is not None: r.dev_off()
def plotArray(self, hitDataParam, filename, plotDir=None, labeledPosD=None, title='', type='png', label_colors = True, colVecL=None, legend_plot = False, legend_filename=None, control_color='black', numeric_as_int = False, grid=True, max_val=0.3, min_val=0.0, cut_data = True): if plotDir is None: plotDir = self.plotDir full_filename = os.path.join(plotDir, filename) #hitData = copy.deepcopy(hitDataParam) hitData = hitDataParam #nrow = len(hitData) #ncol = len(hitData[0]) nrow = self.nb_row ncol = self.nb_col xL = range(1, self.nb_col + 1) yL = range(1, self.nb_row + 1) rdev = plot_utilities.RDevice(name = full_filename, title=title, plotType=type, width=640, height=250) if label_colors: # in this case, the data is considered to consist of labels labelL = [] for i in range(nrow): for j in range(ncol): if hitData[i][j] not in labelL: labelL.append(hitData[i][j]) if colVecL is None: colVecL = r.rainbow(len(labelL)) colBreaksL = range(len(colVecL) + 1) if legend_plot: self.plotLabelLegend(colVecL, plotType=type, filename=legend_filename) else: # in this case, the data is numeric. if cut_data: max_rel_cell_count = max_val min_rel_cell_count = 0.0 for i in range(nrow): for j in range(ncol): hitData[i][j] = max(min_rel_cell_count, min(max_rel_cell_count, hitData[i][j])) else: max_rel_cell_count = max([max(x) for x in hitData.tolist() ]) min_rel_cell_count = min([min(x) for x in hitData.tolist() ]) if numeric_as_int: nb_colors = max_rel_cell_count else: nb_colors = 500 if colVecL is None: pattern = [(0,0,0),(0.7,0,0),(1,1,0),(1,1,1)] colVecL = colors.make_colors(pattern, nb_colors) colBreaksL = [1.0/ (len(colVecL) - 1) * x * (max_rel_cell_count - min_rel_cell_count) + min_rel_cell_count for x in range(len(colVecL) + 1)] if legend_plot: self.plotNumLegend(colVecL, colBreaksL, 16, filename=legend_filename, type=type, int_labels=numeric_as_int, legendDir = plotDir) axisSize = .8 r("par(mar=c(1.6,1.6,0.1,0.1))") r.image(xL, yL, r.t(hitData), axes = False, ann=False, cex=1, col=colVecL, breaks=colBreaksL) r.box() if not labeledPosD is None: for label in labeledPosD.keys(): posL = labeledPosD[label] if len(posL) > 0: xlL = [(int(x)-1) % self.nb_col + 1 for x in posL] ylL = [(int(x)-1) / self.nb_col + 1 for x in posL] r.points(xlL, ylL, pch=label, col=control_color, cex=axisSize) print print xlL print ylL print # grid if grid: for i in range(self.nb_col): r.abline(h=i+.5, lty=3, lwd=1, col='grey') for i in range(self.nb_row): r.abline(v=i+.5, lty=3, lwd=1, col='grey') r.axis(1, at=xL, labels=[str(x) for x in xL], tick=False, line=-1.0, cex_axis=axisSize) r.axis(2, at=yL, labels=[str(y) for y in yL], tick=False, line=-1.0, cex_axis=axisSize) rdev.close() return
def plotBundle(self, bundleD, full_filename, colorsD=None, bundlePointsD=None, legendL=None, title=None, y_max=None): if y_max is None: y_max = 0.4 if legendL is None: legendL = bundleD.keys() legendL.sort() if title is None: title = 'data' bundleIdL = bundleD.keys() bundleIdL.sort() if colorsD is None: colorsL = r.rainbow(len(bundleIdL)) colorsD = dict(zip(bundleIdL, colorsL)) colorsL = [colorsD[x] for x in bundleIdL] time_min = min([len(bundleD[x]) for x in bundleD.keys()]) timeVec = [0.5 * x for x in range(time_min)] try: r.png(full_filename, width=800, height=600) oldPar = r.par(xpd = True, mar = [x + y for (x,y) in zip(r.par()['mar'], [0,0,0,6])]) print 'plot %s' % full_filename r.plot(timeVec, timeVec, type='n', main=title, ylim=(0, y_max), xlab="time in hours after transfection", ylab="Relative Cell Counts", pch=20, lwd=1, lty = 1, cex=1.0, cex_lab=1.2, cex_main=1.5) for bundleId in bundleIdL: if not bundlePointsD is None: r.points(timeVec, bundlePointsD[bundleId], col=colorsD[bundleId], pch=20, lwd=1) r.lines(timeVec, bundlePointsD[bundleId], col=colorsD[bundleId], lwd=1, lty = 1) r.lines(timeVec, bundleD[bundleId], col=colorsD[bundleId], lwd=3, lty = 1) r.legend(max(timeVec) * 1.1, y_max, legend=legendL, fill=colorsL, cex=1.0, bg= 'whitesmoke') r.par(oldPar) r.grid(col="darkgrey") r.dev_off() except: r.dev_off() print full_filename + ' has not been printed.' return
print "top modes:" print "%6s %6s %7s %9s"%('kmag', 'Sk', 'kmag/L', 'L/kmag') for Sk, kmag in zip(v_sk, v_kmag)[-10:]: print "%6.3f %6.3f %7.5f %9.5f"%(kmag, Sk, kmag/L, L/kmag) r.plot(v_kmag, v_sk, xlab="", ylab="", type="l", ylim=(0., 15) #ylim=(0., 15000) ) # plots a line at each k-vector point. for kmag in v_kmag: r.abline(v=kmag, lty=3, col="lightgray") # plots each individual k-vector for kmag, SkArray in zip(v_kmag, StructCorr.SkArrays()): r.points(x=[kmag]*len(SkArray), y=SkArray, col="blue", pch="x") # plots the standard deviation of the by-kvector lists. for kmag, SkArray in zip(v_kmag, StructCorr.SkArrays()): r.points(x=kmag, y=numpy.std(SkArray), col="red", pch="s") # plots it using the average of all k-vectors -- this should line up # exactly #for kmag, SkArray in zip(v_kmag, StructCorr.SkArrays()): # r.points(x=kmag, y=numpy.average(SkArray), # col="green", pch="x") import code ; code.interact(local=locals(), banner="" )
def plot(outfile, data, out_format='png'): w = int(round(len(data)/4.0)) if out_format == 'png': r.png(outfile, width=w*100, height=1000, res=72) elif out_format == 'pdf': r.pdf(outfile, width=w, height=10) else: raise Exception('Unrecognised format: ' + str(out_format)) print("total: " + str(len(data))) series = [] points = {'translate': [], 'preprocessing': []} for dat in data: points['translate'].append(float(dat['translate'])) points['preprocessing'].append(float(dat['preprocessing'])) xlabels = [] for k, v in data[0].iteritems(): if k not in ["problem", 'translate', 'preprocessing']: series.append(k) points[k] = [] index = 0 for dat in data: for k in series: if dat[k] != 'no-plan': points[k].append(float(dat[k]) + \ points['translate'][index] + \ points['preprocessing'][index]) else: points[k].append(-1000) xlabels.append(dat['problem']) index += 1 max_value = max(iter([max(iter(points[k])) for k in series])) yrange = (0, max_value) legend_labels = [] x = [i for i in range(1,len(points['translate'])+1)] y = [-1000 for i in x] r.par(mar=(7,5,4,2)) r.plot(x, y, main='', xlab="", ylab='', xaxt='n', yaxt='n', pch=0, ylim=yrange, mgp=(5,1,0)) r.mtext("Problem", side=1, line=5) r.mtext("CPU Time (s)", side=2, line=3) pch_start = 1 pch_index = pch_start # plotting "translate" #r.plot(x, points['translate'], main='', # xlab='', ylab='Time (s)', # xaxt='n', yaxt='n', # pch=0, ylim=yrange) #legend_labels.append('translate') r.lines(x, points['translate'], lty=1) # preprocessing -- Removed since it's insignificant #r.points(x, points['preprocessing'], pch=pch_index) #pch_index =+ 1 # planner output for k in series: if k != 'translate' and k != 'preporcessing': r.points(x, points[k], pch=pch_index) pch_index += 1 legend_labels.append("FD+" + k.upper()) # put x-axis labels for i in range(0, len(xlabels)): r.axis(side=1, at=i+1, labels=xlabels[i], las=2) # put y-axis labels base, step = get_y_step(max_value) print("base: " + str(base) + " -- step: " + str(step)) y = base for i in range(0, step): r.axis(side=2, at=y, labels=str(y), las=2) y += base # legend r.legend(1, max_value, legend_labels, pch=[i for i in range(pch_start, pch_index)]) r.dev_off()
def plot(outfile, data, out_format='png'): w = int(round(len(data) / 4.0)) if out_format == 'png': r.png(outfile, width=w * 100, height=1000, res=72) elif out_format == 'pdf': r.pdf(outfile, width=w, height=10) else: raise Exception('Unrecognised format: ' + str(out_format)) print("total: " + str(len(data))) series = [] points = {'translate': [], 'preprocessing': []} for dat in data: points['translate'].append(float(dat['translate'])) points['preprocessing'].append(float(dat['preprocessing'])) xlabels = [] for k, v in data[0].iteritems(): if k not in ["problem", 'translate', 'preprocessing']: series.append(k) points[k] = [] index = 0 for dat in data: for k in series: if dat[k] != 'no-plan': points[k].append(float(dat[k]) + \ points['translate'][index] + \ points['preprocessing'][index]) else: points[k].append(-1000) xlabels.append(dat['problem']) index += 1 max_value = max(iter([max(iter(points[k])) for k in series])) yrange = (0, max_value) legend_labels = [] x = [i for i in range(1, len(points['translate']) + 1)] y = [-1000 for i in x] r.par(mar=(7, 5, 4, 2)) r.plot(x, y, main='', xlab="", ylab='', xaxt='n', yaxt='n', pch=0, ylim=yrange, mgp=(5, 1, 0)) r.mtext("Problem", side=1, line=5) r.mtext("CPU Time (s)", side=2, line=3) pch_start = 1 pch_index = pch_start # plotting "translate" #r.plot(x, points['translate'], main='', # xlab='', ylab='Time (s)', # xaxt='n', yaxt='n', # pch=0, ylim=yrange) #legend_labels.append('translate') r.lines(x, points['translate'], lty=1) # preprocessing -- Removed since it's insignificant #r.points(x, points['preprocessing'], pch=pch_index) #pch_index =+ 1 # planner output for k in series: if k != 'translate' and k != 'preporcessing': r.points(x, points[k], pch=pch_index) pch_index += 1 legend_labels.append("FD+" + k.upper()) # put x-axis labels for i in range(0, len(xlabels)): r.axis(side=1, at=i + 1, labels=xlabels[i], las=2) # put y-axis labels base, step = get_y_step(max_value) print("base: " + str(base) + " -- step: " + str(step)) y = base for i in range(0, step): r.axis(side=2, at=y, labels=str(y), las=2) y += base # legend r.legend(1, max_value, legend_labels, pch=[i for i in range(pch_start, pch_index)]) r.dev_off()