def plotCodeHash(fastq_file, numReads): codeHash = findIndexCode(fastq_file, numReads) f = pylab.figure(figsize=(10, 5)) a = f.add_subplot(111) a.bar(range(len(codeHash.keys())), [codeHash[i] for i in qMS.sort_nicely(codeHash.keys())], align='center') a.set_xticks(range(len(codeHash.keys()))) a.set_xticklabels(qMS.sort_nicely(codeHash.keys()), rotation=90) a.set_xlim(-0.5, len(codeHash.keys()))
def writeSummaryCSV(self, path): csvDict = {} proteins = qMS.sort_nicely(sorted(set(self.dataFrame[PROTEINHEADER].values))) fractions = qMS.sort_nicely(sorted(set(self.dataFrame[FILENAMEHEADER].values))) for frac in fractions: csvDict[frac] = pandas.Series([self.dataFrame[(self.dataFrame[FILENAMEHEADER] == frac) & \ (self.dataFrame[PROTEINHEADER] == i)] \ ['currentCalc'].median() for i in proteins], index=proteins) summaryDF = pandas.DataFrame(csvDict, columns = fractions) summaryDF.to_csv(path)
def calc_lists(self): self.savedListItems = numpy.array(qMS.sort_nicely(list(self.dataFrame[(self.dataFrame[FILENAMEHEADER] == self.currentRow[FILENAMEHEADER]) & \ (self.dataFrame['allClear'] == True)][UIDHEADER].values))) self.filteredListItems = numpy.array(qMS.sort_nicely(list(self.dataFrame[(self.dataFrame[FILENAMEHEADER] == self.currentRow[FILENAMEHEADER]) & \ (self.dataFrame['allClear'] == False)][UIDHEADER].values))) self.savedList.Set(self.savedListItems) self.filteredList.Set(self.filteredListItems) self.savedList.SetStringSelection(self.currentRow[UIDHEADER]) self.filteredList.SetStringSelection(self.currentRow[UIDHEADER]) self.datasetsListItems = qMS.sort_nicely(list(self.dataFrame[FILENAMEHEADER].unique())) self.datasetsList.Set(self.datasetsListItems) self.datasetsList.SetStringSelection(self.currentRow[FILENAMEHEADER])
def plotPoolBar(data, keys, colors, title, figname=None, barNames=None, sortingKey=0, figSize=(10,4)): """plotPoolBar plots a poolSizDict datastructure as bar graphs A pointer to the figure is returned :param poolSizeDict: a dictionary of dictionaries of the values to be plotted. Example generated by fitPoolSizes :type poolSizeDict: a dict of dicts: Should be of the form {entry name : {valueName1 : entryValue1, valueName2 : entryValue2} :param keys: a list of keys to be plotted :type keys: list of strings :param colors: a list of colors to be plotted :type colors: list of strings :param title: the title of the plot :type title: string :param offset: a float offset factor if you want to alter the values uniformly :type offset: float :param figname: the full path/name to save the file :type figname: string :param barNames: a list of the keys from the dictionary to be plotted (if None, all will be plotted) :type barNames: a list of strings :param sortingKey: the index of the key to sort on (will be sorted highest to lowest in value) :type sortingKey: int :returns: the figure generated. If figname!=None, a figure is also saved """ bar = pylab.figure(figsize=figSize) barax = bar.add_subplot(111) bars = len(barNames) ind = numpy.arange(bars) width = 0.9/len(keys) sortedTuples = [] if barNames is None: barNames = data.keys() barNames = qMS.sort_nicely(barNames) for name in barNames: myTuple = [name] for k in keys: myTuple.append(data[name][k]) sortedTuples.append(myTuple) sortedTuples = sorted(sortedTuples, key=lambda pool:pool[sortingKey], reverse=True) names = [i[0] for i in sortedTuples] rects = [] for b in range(0,len(keys)): vs = [i[b+1] for i in sortedTuples] xs = ind+width*b rects.append(barax.bar(xs, vs, width, color=colors[b])) barax.set_xticks(ind+0.5) barax.set_xticklabels([i[4:] for i in names], rotation='vertical', horizontalalignment='center', verticalalignment='top') barax.set_xlim([0,len(ind)]) barax.set_ylabel('fit pool size (P)') barax.tick_params(axis='y', direction='out') barax.tick_params(axis='x', direction='out') barax.xaxis.tick_bottom() barax.yaxis.tick_left() #barax.set_ylim([0,6.5]) barax.set_title(title) bar.tight_layout() if not (figname is None): pylab.savefig(figname) return bar
def on_datasetsBoxClick(self, event): if not (self.datasetsList.GetStringSelection() is u''): pickedDataset = self.datasetsList.GetStringSelection() pickedUID = qMS.sort_nicely(list(self.dataFrame[(self.dataFrame[FILENAMEHEADER] == pickedDataset) & \ (self.dataFrame['allClear'] == True)][UIDHEADER].values))[0] self.currentRow = self.dataFrame[self.dataFrame[UIDHEADER] == pickedUID].iloc[0] self.resetFilterRanges() self.calc_filters() self.redrawAll()
def plotMRMCsv(df, samples = None, sampleField='File Name', colors=None, labelHash=None, yAxisLabel=None, legendLoc = 'upper center', areaField = 'Area', num = ['light '], den = ['heavy '], proteins = None, alpha=1.0, markersize=10, title=None, legendBBox = (0.5, 1.0), proteinField = 'Protein Name', median = True, medianMarker = '-', legend=True, legendCols=5, normProtein=None, medianMarkerInc = 2.5, normSample=None, yAxis=None, yMin = 0.0, yMax = 10.0, yTicks=2, figSize=(15,5), grid=False, scaleProt=None, markeredgewidth=1.0): df.loc[:,'currentCalc'] = mrmTools.calcValue(df, num, den, field=areaField) #print 'running code' if scaleProt is None: scaleProt = {} if samples is None: samples = qMS.sort_nicely(list(df[sampleField].unique())) if colors is None: colors = pylab.cm.jet([float(i)/float(len(samples)) for i in range(len(samples))]) if proteins is None: proteins = qMS.sort_nicely(list(df[proteinField].unique())) if yAxis is None: interval = (yMax*1.0-yMin)/(yTicks+1.0) yAxis = [yMin+i*interval for i in range(0,yTicks+2)] if labelHash is None: labelHash = {i:i for i in samples} for i in proteins: if i not in scaleProt.keys(): scaleProt[i] = 1.0 if not normSample is None: sampDF = df[df[sampleField]==normSample] normValue = 1.0 if not normProtein is None: normValue = sampDF[sampDF[proteinField]==normProtein]['currentCalc'].median() for p in proteins: scaleProt[p] = (sampDF[sampDF[proteinField]==p]['currentCalc']/normValue).median() xOffset = 1.0/(len(samples)+1) f = pylab.figure(figsize=figSize) ax = f.add_subplot(111) for i, s in enumerate(samples): sampDF = df[df[sampleField]==s] ax.plot(numpy.NaN, numpy.NaN, marker = 'o', color=colors[i], label=labelHash[s], markersize=markersize*1.5, markeredgewidth=markeredgewidth) if not normProtein is None: normValue = sampDF[sampDF[proteinField]==normProtein]['currentCalc'].median() else: normValue = 1.0 for j, p in enumerate(proteins): ax.plot([float(j+(i+1)*xOffset)]*len(sampDF[sampDF[proteinField]==p]), sampDF[sampDF[proteinField]==p]['currentCalc']/(normValue*scaleProt[p]), 'o', alpha=alpha, color=colors[i], markersize=markersize, markeredgewidth=markeredgewidth) if median: try: ax.plot(float(j+(i+1)*xOffset), sampDF[sampDF[proteinField]==p]['currentCalc'].median()/(normValue*scaleProt[p]), marker='_', mew=markersize/3, color='black', markersize=markersize*medianMarkerInc) #print str(s) + '\t' + str(p) + '\t' + str(sampDF[sampDF[proteinField]==p]['currentCalc'].median()/(normValue*scaleProt[p])) except: print 'error' if legend: ax.legend(ncol=legendCols, loc=legendLoc, bbox_to_anchor=legendBBox, fancybox=True, shadow=False) ax.set_ylim(yMin, yMax) ax.set_yticks(yAxis) pylab.xticks(range(len(proteins)), proteins, rotation=45) pylab.xlim(0, len(proteins)) if grid: pylab.grid() cleanAxis(ax, ticksOnly=True) if not title is None: ax.set_title(title) if not yAxisLabel is None: ax.set_ylabel(yAxisLabel) return ax
def proteinScatterPlot(yDataDict, xData, xMin=0, xMax=None, yMin=-0.1, yMax=10, title=None, xLabel=None, yLabel=None, colors=None, figSize=(10,10), markerSize=10, legend=False, alpha=1.0, marker='o', linestyle=None, xTicks=None, legendLoc='upper left', legendCols=2, axes=None): """proteinScatterPlot is a makes a scatter plot out of ydata with a fixed x. Useful for the standard curve stuff or gradients. :param yDataDict: a dictionary of values to be plotted on the y axis (keys are protein names, values are numpy arrays of values) :type yDataDict: a dictionary of numpy arrays (keys=protein names) :param xData: a list of the xvalues (same for all proteins) :type xData: a list of floats :param xMin: float of minimum x value :type xMin: float :param yMin: float of minimum y value :type yMin: float :param xMax: float of maximum x value :type xMax: float :param yMax: float of maximum y value :type yMax: float :param title: the plot title :type title: string :param xlabel: the plot xlabel :type xlabel: string :param ylabel: the plot ylabel :type ylabel: string :param colors: a list of colors to be used :type colors: list of colors :param figSize: the figure size (list - (10,10)) :type figSize: list of floats :param markerSize: the size of the dots :type markerSize: float :param legend: a bool of whether to have a legend :type legend: bool :param linestyle: the connector line style :type linestyle: the connector line style :param xTicks: a list of the xTicks :type xTicks: a list of floats :param legendloc: a string of where to locate the legend :type legendloc: string :param legendCols: the number of columns in the legend :type legendCols: int :returns: the plotted axis """ if xMax is None: xMax = max(xData) if colors is None: colors = [pylab.cm.jet(float(i)/float(len(yDataDict))) for i in range(len(yDataDict))] if axes is None: scat = pylab.figure(figsize=figSize) scatAx = scat.add_subplot(111) else: scatAx=axes for i,p in enumerate(qMS.sort_nicely(yDataDict.keys())): if not (linestyle is None): scatAx.plot(xData, yDataDict[p], c=colors[i], linestyle=linestyle, label=p, marker=marker, markersize=markerSize, alpha=alpha) else: scatAx.plot(xData, yDataDict[p], c=colors[i], markersize=markerSize, marker=marker, label=p, alpha=alpha) scatAx.set_title(title, multialignment='center') scatAx.set_xlabel(xLabel) scatAx.set_ylabel(yLabel) scatAx.set_xlim([xMin,xMax]) scatAx.set_ylim([yMin,yMax]) if xTicks is None: scatAx.set_xticks([0,xMax/4,xMax/4*2,xMax/4*3,xMax]) else: scatAx.set_xticks(xTicks) scatAx.set_yticks([0,yMax/4,yMax/4*2,yMax/4*3,yMax]) if legend: pylab.legend(loc=legendLoc, ncol=legendCols, scatterpoints=1) scatAx.yaxis.tick_left() scatAx.xaxis.tick_bottom() pylab.tight_layout() return scatAx
def plotStatsDict(statsDict, name='', proteins=None, offset=0.0, markerSize=12, color='#e31a1c', yMax=1.5, alpha=1.0, median=False, figSize = (22,5), noFill=False, mew=1, yMin=-0.05, highlightMed=False, hms=2, hmFilled=True, xTickLabels=None): """plotStatsDataStruct plots the contents of a stats dictionary. proteins to be plotted are listed in the non-redundent list, proteins. The data is in statsDict, the name is in in name. Decent colors are red (['#ae2221', '#d72c2b', '#e78180']) and blue (['#25557d', '#3170a4', '#5696cc']) :param statsDict: a dictionary (easily created by qMS.calcStatsDict) :type statsDict: dictionary with keys of proteins names and values of numpy arrays of calcValues :param name: the name of the dataset :type name: string :param proteins: a non-redudent list of the protein names to use (should be the IDs in dataByProtein). If none is given, all of the keys will be plotted. :type proteins: list :param offset: where to center the point (x axis), scales 0 (left edge; default) to 1.0 (right edge) :type offset: float :param markerSize: size of the dots (default = 12) :type markerSize: int :param color: color for the dataset (default #e31a1c) :type color: color :param yMax: the max value for the y axis :type yMax: float :param median: bool to plot only the median values :type median: bool :returns: a pyplot axis with the data plotted """ if proteins is None: proteins = qMS.sort_nicely(statsDict.keys()) if xTickLabels is None: xTickLabels = [item for item in proteins] if hmFilled: medColor=color else: medColor='none' if noFill: edgeColor=color color='none' else: edgeColor='black' xAxis = range(1,len(proteins)+1) fig = pylab.figure(figsize=figSize) ax = fig.add_subplot(111) xs = [] ys = [] for x in xAxis: p = proteins[x-1] if p in statsDict.keys(): if median: xs.append(x+offset) ys.append(numpy.median(statsDict[p])) else: for v in statsDict[p]: xs.append(x+offset) ys.append(v) pylab.grid(b=True, which='major', color='grey', linestyle='--', axis='y', linewidth=1.5, alpha=0.5) pylab.grid(b=True, which='major', color='grey', linestyle='-', axis='x', linewidth=1.5, alpha=0.75) ax.plot(xs, ys, 'o', mfc=color, markeredgecolor=edgeColor, mew=mew, markersize=markerSize, label=name, alpha=alpha) if highlightMed: mx = [] my = [] for x in xAxis: p = proteins[x-1] if p in statsDict.keys(): mx.append(x+offset) my.append(numpy.median(statsDict[p])) ax.plot(mx, my, '_', color='black', markeredgecolor='black', mew=2, markersize=markerSize*hms) pylab.xticks(xAxis, xTickLabels, rotation=45) pylab.xlim(1, len(proteins)+1) #################################### #################################### if yMin == -0.05: sub = 0.0 else: sub = yMin pylab.yticks([0, (yMax-sub)/5.0, 2*(yMax-sub)/5.0, 3*(yMax-sub)/5.0, 4*(yMax-sub)/5.0, (yMax-sub)]) pylab.ylim(yMin, yMax) ax.set_axisbelow(True) return ax
def plotMRMScatterPlot(df, samples=None, labelHash=None, yAxisLabel=None, proteins=None, alpha=1.0, legend=True, legendCols=5, median=True, grid=True, yAxis=None, num=['light '], den=['heavy '], yTicks=4, sampleLocations=None, sampleField='File Name', ax=None, medianMarkerInc=1.25, colors=None, figSize=(10,10), markersize=10, fitLine=False, fitR2=False, medianColor='black', yMin=0, yMax=10, xMin=None, xMax=None, title=None, zOrder=None, medianOnly=None, proteinNameHeader = 'Protein Name'): df.loc[:,'currentCalc'] = mrmTools.calcValue(df, num, den) if samples is None: samples = qMS.sort_nicely(list(df[sampleField].unique())) if proteins is None: proteins = qMS.sort_nicely(list(df[proteinNameHeader].unique())) if colors is None: colors = pylab.cm.jet([float(i)/float(len(proteins)) for i in range(len(proteins))]) if yAxis is None: interval = (yMax*1.0-yMin)/(yTicks+1.0) yAxis = [yMin+i*interval for i in range(0,yTicks+2)] if labelHash is None: labelHash = {i:i for i in proteins} if sampleLocations is None: sampleLocations = {samples[i]:i for i in range(len(samples))} if xMin is None: xMin = min(sampleLocations.values()) if xMax is None: xMax = max(sampleLocations.values()) if zOrder is None: zOrder = [i*2+1 for i in range(len(proteins))] if medianOnly is None: medianOnly = [False]*len(proteins) if ax is None: f = pylab.figure(figsize=figSize) ax = f.add_subplot(111) for i, p in enumerate(proteins): protDF = df[df[proteinNameHeader] == p] ax.plot(numpy.NaN, numpy.NaN, marker = 'o', color=colors[i], label=labelHash[p], markersize=markersize*1.5) ysFit = [] xsFit = [] for j, s in enumerate(samples): if not medianOnly[i]: ax.plot([float(sampleLocations[s])]*(len(protDF[protDF[sampleField] == s])), protDF[protDF[sampleField]==s]['currentCalc'], 'o', alpha=alpha, color=colors[i], markersize=markersize, zorder=zOrder[i]) if median: marker='_' mew=markersize/3 zorder=100 if medianColor is None: medianColor = colors[i] if medianOnly[i]: marker='o' medianColor=colors[i] mew = 0 zorder=zOrder[i] ax.plot(sampleLocations[s], protDF[protDF[sampleField]==s]['currentCalc'].median(), marker=marker, mew=mew, color=medianColor, markersize=markersize*medianMarkerInc, zorder=zorder) ysFit.append(protDF[protDF[sampleField]==s]['currentCalc'].median()) xsFit.append(sampleLocations[s]) if fitLine: pFit = numpy.polyfit(xsFit, ysFit, 1) xsFit.append(xMin) xsFit.append(xMax) ax.plot(numpy.array(xsFit), pFit[0]*numpy.array(xsFit)+pFit[1], '-', color=colors[i], zorder=zOrder[i]-1) if legend: ax.legend(ncol=legendCols, loc='upper center', bbox_to_anchor=(0.5, 1.0), fancybox=True, shadow=False) ax.set_ylim(yMin, yMax) ax.set_yticks(yAxis) pylab.xticks(sampleLocations.values()) ax.set_xlim(xMin, xMax) if grid: pylab.grid() cleanAxis(ax, ticksOnly=True) if not title is None: ax.set_title(title) if not yAxisLabel is None: ax.set_ylabel(yAxisLabel) return ax
LargeSubunit = ['BSubL01', 'BSubL02', 'BSubL03', 'BSubL04', 'BSubL05', 'BSubL06', 'BSubL09', 'BSubL10', 'BSubL11', 'BSubL12', 'BSubL13', 'BSubL14', 'BSubL15', 'BSubL16', 'BSubL17', 'BSubL18', 'BSubL19', 'BSubL20', 'BSubL21', 'BSubL22', 'BSubL23', 'BSubL24', 'BSubL27', 'BSubL28', 'BSubL29', 'BSubL30', 'BSubL31a', 'BSubL32', 'BSubL33a', 'BSubL34', 'BSubL35', 'BSubL36'] Inter45S = ['BSubL01', 'BSubL02', 'BSubL03', 'BSubL04', 'BSubL05', 'BSubL06', 'BSubL10', 'BSubL11', 'BSubL12', 'BSubL13', 'BSubL14', 'BSubL15', 'BSubL17', 'BSubL18', 'BSubL19', 'BSubL20', 'BSubL21', 'BSubL22', 'BSubL23', 'BSubL24', 'BSubL29', 'BSubL30'] AllSubunits = LargeSubunit + SmallSubunit rootPath = '/home/jhdavis/McMasterMSUDataSets/45Svs50S/' figWidth = 22 ##########Open Files########## files50SIF2 = qMS.sort_nicely([i for i in glob.glob(rootPath+'45Sfiltered/*.csv')]) files45S = qMS.sort_nicely([i for i in glob.glob(rootPath+'50Sfiltered/*.csv')]) filesMy70S = qMS.sort_nicely([i for i in glob.glob(rootPath+'my70Sfiltered/*.csv')]) filesMy50S = qMS.sort_nicely([i for i in glob.glob(rootPath+'my50Sfiltered/*.csv')]) files50SIF2Pulse = qMS.sort_nicely([i for i in glob.glob(rootPath+'45Sfiltered/pulse/*.csv')]) files45SPulse = qMS.sort_nicely([i for i in glob.glob(rootPath+'50Sfiltered/pulse/*.csv')]) names50SIF2 = qMS.sort_nicely([i.split('/')[-1] for i in glob.glob(rootPath+'45Sfiltered/*.csv')]) names45S = qMS.sort_nicely([i.split('/')[-1] for i in glob.glob(rootPath+'50Sfiltered/*.csv')]) namesMy70S = qMS.sort_nicely([i.split('/')[-1] for i in glob.glob(rootPath+'my70Sfiltered/*.csv')]) namesMy50S = qMS.sort_nicely([i.split('/')[-1] for i in glob.glob(rootPath+'my50Sfiltered/*.csv')]) names50SIF2Pulse = qMS.sort_nicely([i.split('/')[-1] for i in glob.glob(rootPath+'45Sfiltered/pulse/*.csv')])
'BSubL12', 'BSubL13', 'BSubL14', 'BSubL15', 'BSubL17', 'BSubL18', 'BSubL19', 'BSubL20', 'BSubL21', 'BSubL22', 'BSubL23', 'BSubL24', 'BSubL29', 'BSubL30'] AllSubunits = LargeSubunit + SmallSubunit doublingTime_10 = 92 doublingTime_1000 = 47 path = '/home/jhdavis/McMasterMSUDataSets/PulseLabeling/2013_05_28-MSUPulse/filtered/' figWidth = 11 global currentPool currentPool = 0.0 ##########Open Files########## files = qMS.sort_nicely([i.split('/')[-1] for i in glob.glob(path+'*.csv')]) reds = ['#fee5d9', '#fcbba1', '#fc9272', '#fb6a4a', '#de2d26', '#a50f15'] blues = ['#eff3ff', '#c6dbef', '#93cae1', '#6baed6', '#3182bd', '#08519c'] names70S_10 = [path+n for n in files[0:6]] names70S_1000 = [path+n for n in files[6:12]] namesInter_10 = [path+n for n in files[12:17]] namesInter_1000 = [path+n for n in files[18:]] times10 = [22, 49, 66, 88, 110, 132] times1000 = [11, 22, 33, 44, 55, 66] labels10 = ['10 $\mu$M, 22 min', '10 $\mu$M, 49 min', '10 $\mu$M, 66 min', '10 $\mu$M, 88 min', '10 $\mu$M, 110 min', '10 $\mu$M, 132 min'] labels1000 = ['1 mM, 11 min', '1 mM, 22 min', '1 mM, 33 min', '1 mM, 44 min', '1 mM, 55 min', '1 mM, 66 min']
import matplotlib.pyplot as pylab import glob import qMS import vizLib path = '/home/jhdavis/muspulsePeaks/' fileList = glob.glob(path+'*.txt') fileList = qMS.sort_nicely(fileList) fileList.reverse() print fileList pylab.close('all') vizLib.plotMSSpectra3D(fileList, listOfNames=None, listOfColors=None, gridLines=False, yMin=0.5, yMax=5.5, legend=False, normalizeToN15=False, subtractRef=None, lw=3) #vizLib.plotMSSpectra3D(fileList, listOfNames=None, listOfColors=None, gridLines=True, yMin=0.5, yMax=8.5, legend=False, normalizeToN15=False, subtractRef=7) vizLib.plotMSSpectra3D(fileList, listOfNames=None, listOfColors=None, gridLines=False, yMin=0.5, yMax=5.5, legend=False, normalizeToN15=True, lw=3) pylab.tight_layout() pylab.show()
def readMRMCSV(path, l="light ", h="heavy ", fileNameHeader="File Name"): fileName = path.split("/")[-1].split(".") dataFrame = pandas.read_csv(path) s = "_" dataFrame["shortName"] = dataFrame[fileNameHeader].str.split(".").str[0] dataFrame["UID"] = ( dataFrame["shortName"] + s + dataFrame["Protein"] + s + dataFrame["Begin Pos"].map(str) + s + dataFrame["End Pos"].map(str) + s + dataFrame[l + "Precursor Mz"].map(str).str.split(".").str[0] + s + dataFrame["Product Charge"].map(str) + s + dataFrame["Fragment Ion"].str[-3:] ) dataFrame["TID"] = ( dataFrame["Protein"] + s + dataFrame["Begin Pos"].map(str) + s + dataFrame["End Pos"].map(str) + s + dataFrame[l + "Precursor Mz"].map(str).str.split(".").str[0] + s + dataFrame["Product Charge"].map(str) + s + dataFrame["Fragment Ion"].str[-3:] ) dataFrame["PID"] = ( dataFrame["shortName"] + s + dataFrame["Protein"] + s + dataFrame["Begin Pos"].map(str) + s + dataFrame["End Pos"].map(str) + s + dataFrame[l + "Precursor Mz"].map(str).str.split(".").str[0] ) dataFrame[l + "AdjArea"] = dataFrame[l + "Area"] - dataFrame[l + "Background"] dataFrame.loc[dataFrame[l + "AdjArea"] < 0, l + "AdjArea"] = 0 dataFrame[h + "AdjArea"] = dataFrame[h + "Area"] - dataFrame[h + "Background"] dataFrame.loc[dataFrame[h + "AdjArea"] < 0, h + "AdjArea"] = 0 dataFrame["currentCalc"] = calcValue(dataFrame, [l], [h]) dataFrame["ratio"] = calcValue(dataFrame, [l], [h]) dataFrame = dataFrame[pandas.notnull(dataFrame[fileNameHeader])] positionOtherDict = { key: int(value) + 1 for value, key in enumerate(qMS.sort_nicely(sorted(set(dataFrame["Protein"].values)))) } positionLookupOther = pandas.Series(positionOtherDict) dataFrame["otherpos"] = positionLookupOther[dataFrame["Protein"]].values dataFrame["handDelete"] = False dataFrame["handSave"] = False dataFrame["PPMtranLH"] = abs(dataFrame[l + "Mass Error PPM"] - dataFrame[h + "Mass Error PPM"]) dataFrame["PPMtranTRANALL_light"] = abs(dataFrame[l + "Mass Error PPM"] - dataFrame[l + "Average Mass Error PPM"]) dataFrame["PPMtranTRANALL_heavy"] = abs(dataFrame[h + "Mass Error PPM"] - dataFrame[h + "Average Mass Error PPM"]) dataFrame["PPMtranTRANALL"] = dataFrame[["PPMtranTRANALL_light", "PPMtranTRANALL_heavy"]].max(axis=1) dataFrame["RTdsLH"] = abs(dataFrame[l + "Retention Time"] - dataFrame[h + "Retention Time"]) dataFrame["RTdsTRANALL_light"] = abs(dataFrame[l + "Retention Time"] - dataFrame[l + "Best Retention Time"]) dataFrame["RTdsTRANALL_heavy"] = abs(dataFrame[h + "Retention Time"] - dataFrame[h + "Best Retention Time"]) dataFrame["RTdsTRANALL"] = dataFrame[["RTdsTRANALL_light", "RTdsTRANALL_heavy"]].max(axis=1) dataFrame["RTpepTRANALL_light"] = abs( dataFrame[l + "Retention Time"] - dataFrame["Average Measured Retention Time"] ) dataFrame["RTpepTRANALL_heavy"] = abs( dataFrame[h + "Retention Time"] - dataFrame["Average Measured Retention Time"] ) dataFrame["RTpepTRANALL"] = dataFrame[["RTpepTRANALL_light", "RTpepTRANALL_heavy"]].max(axis=1) if not "priorFilter" in dataFrame.columns: dataFrame["priorFilter"] = True if not "allClear" in dataFrame.columns: dataFrame["allClear"] = dataFrame["priorFilter"] for p in list(dataFrame["Protein"].unique()): peptides = list(dataFrame.loc[dataFrame["Protein"] == p, "Peptide Modified Sequence"].unique()) for n, pep in enumerate(peptides): l = float(len(peptides)) ind = n / l dataFrame.loc[(dataFrame["Peptide Modified Sequence"] == pep) & (dataFrame["Protein"] == p), "colOff"] = ind dataFrame["currentPosDataset"] = dataFrame["otherpos"] positionFileDict = { key: int(value) + 1 for value, key in enumerate(qMS.sort_nicely(sorted(dataFrame[fileNameHeader].unique()))) } positionFileLookup = pandas.Series(positionFileDict) dataFrame["currentPosProtein"] = positionFileLookup[dataFrame[fileNameHeader]].values dataFrame.loc[dataFrame["currentCalc"] == numpy.inf, "allClear"] = False return dataFrame
namesList=None, normalization=normalization, offset=offset, normProtein=normProtein) namesList = [[filesToPlot[i], plotNames[i]] for i in range(0, len(plotNames))] plotDataSetsStatsDictDict(correctedStats, yLabel, subunits=subunits, saveName=saveName, yMax=yMax, median=median, namesList=namesList, colors=colors, figSize=figSize, markerSize=markerSize, noFill=noFill, mew=mew, legendLoc=legendLoc, legendCols=legendcols, title=title, legend=legend) ##################Initialize Varibles########################### if __name__ == "__main__": vizLib.setRcs(scale=15, legendScale=15) rootPath = '/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/' filesRefSet = qMS.sort_nicely([i for i in glob.glob(rootPath+'refSets/*.csv')]) filesStdCurve = qMS.sort_nicely([i for i in glob.glob(rootPath+'stdCurve/*.csv')]) filesWTGrad = qMS.sort_nicely([i for i in glob.glob(rootPath+'wtGradient/*.csv')]) files1hrGrad = qMS.sort_nicely([i for i in glob.glob(rootPath+'1hrGradient/*.csv')]) files6hrGrad = qMS.sort_nicely([i for i in glob.glob(rootPath+'6hrGradient/*.csv')]) ''' print [i.split('/')[-1] for i in filesRefSet] print [i.split('/')[-1] for i in filesStdCurve] print [i.split('/')[-1] for i in filesWTGrad] print [i.split('/')[-1] for i in files1hrGrad] print [i.split('/')[-1] for i in files6hrGrad] ''' figWidth = 22 largeSubunit = qMSDefs.positionLabels50S[1:]
def create_main_panel(self, df, dp, fn, pulse=False, varLab=False, fsize=1.0, size=1.0): """ Creates the main panel with all the controls on it: * mpl canvas * mpl navigation toolbar * Control panel for interaction """ self.lastHistField = 'rtDiff' if pulse: self.lastHistField = 'FRC_NX' self.fsize = fsize self.size = size self.SetFont(wx.Font(10*size, wx.SWISS, wx.NORMAL, wx.NORMAL, False,'MS Shell Dlg 2')) self.calcNum = ["AMP_U"] self.calcDen = ["AMP_U", "AMP_S"] self.currentDirectory = os.getcwd() self.dataFrame = df self.dataFrame['minIntensity'].replace([-numpy.inf, numpy.inf], numpy.nan, inplace=True) self.dataFrame['minIntensity'].fillna(0, inplace=True) self.dataFrame['currentPosDataset'] = self.dataFrame['currentPos'] frh = {'ppmDiff_low':-100, 'ppmDiff_high':100, 'ppm_n14_low':-100, 'ppm_n14_high':100, 'ppm_n15_low':-100, 'ppm_n15_high':100, 'resid':100, 'ratio_low': 0, 'ratio_high':1000} self.filterRangeHash = {i:frh for i in list(self.dataFrame[FILENAMEHEADER].unique())} positionFileDict = {key:int(value)+1 for value,key in enumerate(qMS.sort_nicely(sorted(self.dataFrame[FILENAMEHEADER].unique())))} positionFileLookup = pandas.Series(positionFileDict) self.dataFrame['currentPosProtein']=positionFileLookup[self.dataFrame[FILENAMEHEADER]].values self.positionLabelsDataset = [i[:3] for i in qMS.sort_nicely(sorted(set(self.dataFrame[PROTEINHEADER].values)))] self.positionLabelsProtein = [i.split('.')[0] for i in qMS.sort_nicely(sorted(set(self.dataFrame[FILENAMEHEADER].values)))] startDataset = qMS.sort_nicely(sorted(self.dataFrame[FILENAMEHEADER].unique()))[0] self.datasetView = self.dataFrame[self.dataFrame[FILENAMEHEADER] == startDataset] startUID = qMS.sort_nicely(list(self.datasetView[self.datasetView['allClear'] == True][UIDHEADER].values))[0] self.currentRow = self.datasetView[self.datasetView[UIDHEADER] == startUID].iloc[0] self.proteinView = self.dataFrame[self.dataFrame[PROTEINHEADER] == self.currentRow[PROTEINHEADER]] self.datapath = dp self.datafile = fn self.pulse=pulse self.varLab=varLab self.figdim = FIGSIZE*fsize self.panel = wx.Panel(self) '''Create the figure panels''' self.figLeft = Figure((self.figdim, self.figdim)) self.canvasLeft = FigCanvas(self.panel, wx.ID_ANY, self.figLeft) self.figRight = Figure((self.figdim, self.figdim)) self.canvasRight = FigCanvas(self.panel, wx.ID_ANY, self.figRight) gsLeft = gridspec.GridSpec(6,3) gsRight = gridspec.GridSpec(5,25) self.PLPlotDataset = self.figLeft.add_subplot(gsLeft[:4, :]) self.hist1 = self.figLeft.add_subplot(gsLeft[4,0]) self.hist2 = self.figLeft.add_subplot(gsLeft[4,1]) self.hist3 = self.figLeft.add_subplot(gsLeft[5,0]) self.hist4 = self.figLeft.add_subplot(gsLeft[5,1]) self.hist5 = self.figLeft.add_subplot(gsLeft[4,2]) self.hist6 = self.figLeft.add_subplot(gsLeft[5,2]) self.PNGPlot = self.figRight.add_subplot(gsRight[:3, 1:]) self.PLPlotProtein = self.figRight.add_subplot(gsRight[3:, :]) '''Create the list boxes''' self.datasetsList = wx.ListBox(self.panel, id=26, choices=[], style=wx.LB_SINGLE, name='Dataset', size=(100*size,100*size)) self.savedList = wx.ListBox(self.panel, id=26, choices=[], style=wx.LB_SINGLE, name='Saved', size=(100*size,100*size)) self.filteredList = wx.ListBox(self.panel, id=26, choices=[], style=wx.LB_SINGLE, name='Filtered', size=(100*size,100*size)) '''Create the buttons''' self.toolbarLeft = NavigationToolbar(self.canvasLeft) self.toolbarRight = NavigationToolbar(self.canvasRight) self.cb_grid = wx.CheckBox(self.panel, wx.ID_ANY, label="Grid", style=wx.ALIGN_RIGHT) self.hideCheck = wx.CheckBox(self.panel, wx.ID_ANY, label="Hide", style=wx.ALIGN_RIGHT) self.zoomCheck = wx.CheckBox(self.panel, wx.ID_ANY, label="Zoom", style=wx.ALIGN_RIGHT) self.priorFilters = wx.CheckBox(self.panel, wx.ID_ANY, label="oFilt") self.exportButton = wx.Button(self.panel, wx.ID_ANY, "Export") self.openButton = wx.Button(self.panel, wx.ID_ANY, "Open") self.calcButton = wx.Button(self.panel, wx.ID_ANY, "Calc", size=(57*size,40)) self.lowCheckNum = wx.CheckBox(self.panel, wx.ID_ANY, label="low") if self.pulse: self.midCheckNum = wx.CheckBox(self.panel, wx.ID_ANY, label="mid") self.highCheckNum = wx.CheckBox(self.panel, wx.ID_ANY, label="high") self.lowCheckDen = wx.CheckBox(self.panel, wx.ID_ANY, label="low") if self.pulse: self.midCheckDen = wx.CheckBox(self.panel, wx.ID_ANY, label="mid") self.highCheckDen = wx.CheckBox(self.panel, wx.ID_ANY, label="high") self.proteinZoomOn = wx.CheckBox(self.panel, wx.ID_ANY, label="pZoom", style=wx.ALIGN_RIGHT) self.proteinZoomRangeBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.handSaveOn = wx.CheckBox(self.panel, wx.ID_ANY, label="save") self.handDeleteOn = wx.CheckBox(self.panel, wx.ID_ANY, label="delete") self.ppmDiff_range_button = wx.Button(self.panel, wx.ID_ANY, "PPM diff",size=(75*size,-1)) self.N14_range_button = wx.Button(self.panel, wx.ID_ANY, "14N PPM", size=(75*size,-1)) self.N15_range_button = wx.Button(self.panel, wx.ID_ANY, "15N PPM", size=(75*size,-1)) self.resid_range_button = wx.Button(self.panel, wx.ID_ANY, "resid.", size=(70*size,-1)) self.ratio_range_button = wx.Button(self.panel, wx.ID_ANY, "cc", size=(80*size,-1)) self.minInt_range_button = wx.Button(self.panel, wx.ID_ANY, "minInt", size=(80*size,-1)) self.lastHist_range_button = wx.Button(self.panel, wx.ID_ANY, self.lastHistField, size=(80*size,-1)) self.ppmDiffRangeBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.N14RangeBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.N15RangeBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.residRangeBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.ratioLimBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.minIntLimBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) self.lastHistLimBypass = wx.TextCtrl(self.panel, size=(75*size,-1),style=wx.TE_PROCESS_ENTER) '''lay out the buttons''' self.vbox = wx.BoxSizer(wx.VERTICAL) self.figbox = wx.BoxSizer(wx.HORIZONTAL) self.figbox.Add(self.canvasLeft, 0) self.listBox = wx.BoxSizer(wx.VERTICAL) self.datasetsListBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'datasets'), wx.HORIZONTAL) self.datasetsListBox.Add(self.datasetsList, 1, flag=wx.GROW) self.savedListBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'saved fits'), wx.HORIZONTAL) self.savedListBox.Add(self.savedList, 1, flag=wx.GROW) self.filteredListBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'filtered fits'), wx.HORIZONTAL) self.filteredListBox.Add(self.filteredList, 1, flag=wx.GROW) self.listBox.Add(self.datasetsListBox, 1, flag=wx.GROW) self.listBox.Add(self.savedListBox, 1, flag=wx.GROW) self.listBox.Add(self.filteredListBox, 1, flag=wx.GROW) self.figbox.Add(self.listBox, 1, flag=wx.GROW) self.figbox.Add(self.canvasRight, 0) self.vbox.Add(self.figbox, 0, flag = wx.GROW) #new horizontal box self.toolNumBox = wx.BoxSizer(wx.HORIZONTAL) #add toolbar, draw, grid and exportto hbox self.imageToolsBoxL = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'image tools'), wx.HORIZONTAL) self.toolbarSubunits = wx.BoxSizer(wx.VERTICAL) self.toolbarSubunits.Add(self.toolbarLeft, 0, flag=wx.ALIGN_LEFT) self.imageToolsBoxL.Add(self.toolbarSubunits, 0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER) self.imageCheckToolsBox = wx.BoxSizer(wx.VERTICAL) self.imageCheckToolsBox.Add(self.cb_grid, 0, flag=wx.ALIGN_RIGHT) self.imageCheckToolsBox.Add(self.hideCheck, 0, flag=wx.ALIGN_RIGHT) self.imageCheckToolsBox.Add(self.zoomCheck, 0, flag=wx.ALIGN_RIGHT) self.imageToolsBoxL.Add(self.imageCheckToolsBox, 0, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) self.toolNumBox.Add(self.imageToolsBoxL, 0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER) #add open and export buttons self.fileToolsBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'file tools'), wx.VERTICAL) self.fileToolsBox.Add(self.openButton, 0, flag=wx.ALIGN_LEFT) self.fileToolsBox.Add(self.exportButton, 0, flag=wx.ALIGN_LEFT) self.toolNumBox.Add(self.fileToolsBox, 0, flag=wx.ALIGN_LEFT | wx.GROW) #add calculate button self.calcNBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'calcDist'), wx.VERTICAL) self.calcNBox.Add(self.calcButton, flag=wx.ALIGN_TOP) self.calcNBox.Add(self.priorFilters, 0, flag=wx.ALIGN_LEFT) self.toolNumBox.Add(self.calcNBox, 0, flag=wx.ALIGN_RIGHT | wx.GROW) #add numerator box to hbox self.numBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'num'), wx.VERTICAL) self.numBox.Add(self.lowCheckNum, 0, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) if self.pulse: self.numBox.Add(self.midCheckNum, 0, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) self.numBox.Add(self.highCheckNum, 0,flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) self.toolNumBox.Add(self.numBox, 0, flag=wx.ALIGN_RIGHT | wx.GROW) #add denominator box to hbox self.denBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'den'), wx.VERTICAL) self.denBox.Add(self.lowCheckDen, 0, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) if self.pulse: self.denBox.Add(self.midCheckDen, 0, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) self.denBox.Add(self.highCheckDen, 0,flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER) self.toolNumBox.Add(self.denBox, 0, flag=wx.ALIGN_RIGHT | wx.GROW) self.imageToolsBoxR = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'image tools'), wx.HORIZONTAL) self.imageToolsBoxR.Add(self.toolbarRight, 0, flag=wx.ALIGN_RIGHT) self.zoomBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'zoom tools'), wx.VERTICAL) self.zoomBox.Add(self.proteinZoomOn, 0, flag=wx.ALIGN_LEFT) self.zoomBox.Add(self.proteinZoomRangeBypass, 0, flag=wx.ALIGN_LEFT) self.handBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,'hand tools'), wx.VERTICAL) self.handBox.Add(self.handSaveOn, 0, flag=wx.ALIGN_LEFT) self.handBox.Add(self.handDeleteOn, 0, flag=wx.ALIGN_LEFT) self.expandBox = wx.BoxSizer(wx.HORIZONTAL) self.toolNumBox.Add(self.handBox, 0, flag=wx.ALIGN_LEFT) self.toolNumBox.Add(self.zoomBox, 0, flag=wx.ALIGN_LEFT) self.toolNumBox.Add(self.expandBox, 1, flag=wx.GROW) self.toolNumBox.Add(self.imageToolsBoxR, 0, flag=wx.ALIGN_RIGHT | wx.GROW) #add hbox to vbox self.vbox.Add(self.toolNumBox, 0, flag = wx.GROW) # Sliders for setting the various cutoffs self.filterBox = wx.StaticBoxSizer(wx.StaticBox(self.panel,wx.ID_ANY,), wx.HORIZONTAL) flags = wx.ALIGN_LEFT | wx.ALIGN_CENTER self.filterBox.Add(self.ppmDiff_range_button, 0, flag=flags) self.filterBox.Add(self.ppmDiffRangeBypass, 0, flag=flags) self.filterBox.Add(self.N14_range_button, 0, flag=flags) self.filterBox.Add(self.N14RangeBypass, 0, flag=flags) self.filterBox.Add(self.N15_range_button, 0, flag=flags) self.filterBox.Add(self.N15RangeBypass, 0, flag = flags) self.filterBox.Add(self.resid_range_button, 0, flag=flags) self.filterBox.Add(self.residRangeBypass, 0, flag = flags) self.filterBox.Add(self.ratio_range_button, 0, flag=flags) self.filterBox.Add(self.ratioLimBypass, 0, flag = flags) self.filterBox.Add(self.minInt_range_button, 0, flag=flags) self.filterBox.Add(self.minIntLimBypass, 0, flag = flags) self.filterBox.Add(self.lastHist_range_button, 0, flag=flags) self.filterBox.Add(self.lastHistLimBypass, 0, flag = flags) self.vbox.Add(self.filterBox, 0, flag = wx.ALIGN_LEFT | wx.TOP) self.panel.SetSizer(self.vbox) self.vbox.Fit(self) '''bind events for buttons''' self.canvasLeft.mpl_connect('pick_event', self.pickScatterPointDataset) self.canvasRight.mpl_connect('pick_event', self.pickScatterPointProtein) self.exportButton.Bind(wx.EVT_BUTTON, self.on_export_button) self.openButton.Bind(wx.EVT_BUTTON, self.on_open_button) self.calcButton.Bind(wx.EVT_BUTTON, self.on_recalc) self.cb_grid.Bind(wx.EVT_CHECKBOX, self.on_redraw) self.hideCheck.Bind(wx.EVT_CHECKBOX, self.on_redraw) self.zoomCheck.Bind(wx.EVT_CHECKBOX, self.on_redraw) self.proteinZoomOn.Bind(wx.EVT_CHECKBOX, self.on_redraw) self.priorFilters.Bind(wx.EVT_CHECKBOX, self.on_recalc) self.ppmDiff_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.N14_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.N15_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.resid_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.ratio_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.minInt_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.lastHist_range_button.Bind(wx.EVT_BUTTON, self.on_filt_button) self.handSaveOn.Bind(wx.EVT_CHECKBOX, self.on_filt_button) self.handDeleteOn.Bind(wx.EVT_CHECKBOX, self.on_filt_button) self.datasetsList.Bind(wx.EVT_LISTBOX, self.on_datasetsBoxClick) self.savedList.Bind(wx.EVT_LISTBOX, self.on_savedBoxClick) self.filteredList.Bind(wx.EVT_LISTBOX, self.on_filteredBoxClick) self.panel.Bind(wx.EVT_KEY_UP, self.on_key_press)