def get_all_scans(self, instrument_type=None): if instrument_type is None: instrument_type = self.instrument_type yvals_summed = np.zeros_like(self.bin_centres) zvals_summed = [] # MALDI if instrument_type in ["LDI+", "LDI-"]: for fcn in range(self.n_functions): for i in range(self.stats_in_functions[fcn]['n_scans']): yvals = self.get_scan_data(fcn, i) xpos, ypos = self.get_scan_headers(fcn, i) # DESI elif instrument_type in ["ES+", "ES-"]: fcn = 0 n_scans = self.stats_in_functions[fcn]['n_scans'] ms_DF = np.zeros((n_scans, len(self.bin_centres))) msBinDict = dict.fromkeys(range(n_scans)) for scan in range(self.stats_in_functions[fcn]['n_scans']): yvals = self.get_scan_data(fcn, scan) xpos, ypos = self.get_scan_headers(fcn, scan) ms_DF[int(scan), :] = yvals msBinDict[int(scan)] = { 'xval': str2num(xpos), 'yval': str2num(ypos) } yvals_summed = np.add(yvals, yvals_summed) zvals_summed.append(np.sum(yvals)) print(ms_DF.shape) return ms_DF, msBinDict, yvals_summed, zvals_summed
def onReplotRectanglesDT_MZ(self, evt): """ This function replots the rectangles in the RT window during Linear DT mode """ count = self.peaklist.GetItemCount() currentDoc = self.presenter.currentDoc if currentDoc == "Current documents": return document = self.presenter.documentsDict[currentDoc] # Replot RT for current document msX = document.massSpectrum['xvals'] msY = document.massSpectrum['yvals'] try: xlimits = document.massSpectrum['xlimits'] except KeyError: xlimits = [ document.parameters['startMS'], document.parameters['endMS'] ] # Change panel and plot self.presenter.view.panelPlots.mainBook.SetSelection( self.config.panelNames['MS']) name_kwargs = {"document": document.title, "dataset": "Mass Spectrum"} self.presenter.view.panelPlots.on_plot_MS(msX, msY, xlimits=xlimits, **name_kwargs) if count == 0: return ymin = 0 height = 1.0 last = self.peaklist.GetItemCount() - 1 # Iterate over the list and plot rectangle one by one for row in range(count): xmin = str2num(self.peaklist.GetItem(itemId=row, col=0).GetText()) xmax = str2num(self.peaklist.GetItem(itemId=row, col=1).GetText()) width = xmax - xmin if row == last: self.presenter.addRectMS(xmin, ymin, width, height, color=self.config.annotColor, alpha=(self.config.annotTransparency / 100), repaint=True) else: self.presenter.addRectMS(xmin, ymin, width, height, color=self.config.annotColor, alpha=(self.config.annotTransparency / 100), repaint=False)
def on_apply(self, evt): """Update values on event""" if self.block_update: return self.config.extract_dtms_mzStart = str2num( self.mz_min_value.GetValue()) self.config.extract_dtms_mzEnd = str2num(self.mz_max_value.GetValue()) self.config.extract_dtms_mzBinSize = str2num( self.mz_bin_value.GetValue()) self._update_msg_bar() if evt is not None: evt.Skip()
def onSetupParameters(self, evt): self.importEvent = True self.origami_select_value.SetValue(self.itemInfo['select']) self.origami_filename_value.SetValue(self.itemInfo['document']) try: charge = str2int(self.itemInfo['charge']) ion_centre = (str2num(self.itemInfo['mzStart']) + str2num(self.itemInfo['mzEnd'])) / 2 mw = (ion_centre - self.config.elementalMass['Hydrogen'] * charge) * charge ion_value = (u"%s ~%.2f Da") % (self.itemInfo['ionName'], mw) self.origami_ion_value.SetValue(ion_value) except: self.origami_ion_value.SetValue(self.itemInfo['ionName']) self.origami_charge_value.SetValue(str(self.itemInfo['charge'])) self.origami_label_value.SetValue(self.itemInfo['label']) self.origami_colormap_value.SetStringSelection(self.itemInfo['colormap']) self.origami_mask_value.SetValue(self.itemInfo['mask']) self.origami_transparency_value.SetValue(self.itemInfo['alpha']) self.origami_color_value.SetBackgroundColour(self.itemInfo['color']) self.origami_min_threshold_value.SetValue(self.itemInfo['min_threshold']) self.origami_max_threshold_value.SetValue(self.itemInfo['max_threshold']) if self.itemInfo['parameters'] != None: self.origami_method_value.SetStringSelection(self.itemInfo['parameters']['method']) self.origami_startScan_value.SetValue(str(self.itemInfo['parameters'].get('firstVoltage', ''))) self.origami_scansPerVoltage_value.SetValue(str(self.itemInfo['parameters'].get('spv', ''))) self.origami_startVoltage_value.SetValue(str(self.itemInfo['parameters'].get('startV', ''))) self.origami_endVoltage_value.SetValue(str(self.itemInfo['parameters'].get('endV', ''))) self.origami_stepVoltage_value.SetValue(str(self.itemInfo['parameters'].get('stepV', ''))) self.origami_exponentialIncrement_value.SetValue(str(self.itemInfo['parameters'].get('expIncrement', ''))) self.origami_exponentialPercentage_value.SetValue(str(self.itemInfo['parameters'].get('expPercent', ''))) self.origami_boltzmannOffset_value.SetValue(str(self.itemInfo['parameters'].get('dx', ''))) else: self.origami_startScan_value.SetValue(str(self.config.origami_startScan)) self.origami_scansPerVoltage_value.SetValue(str(self.config.origami_spv)) self.origami_startVoltage_value.SetValue(str(self.config.origami_startVoltage)) self.origami_endVoltage_value.SetValue(str(self.config.origami_endVoltage)) self.origami_stepVoltage_value.SetValue(str(self.config.origami_stepVoltage)) self.origami_exponentialIncrement_value.SetValue(str(self.config.origami_exponentialIncrement)) self.origami_exponentialPercentage_value.SetValue(str(self.config.origami_exponentialPercentage)) self.origami_boltzmannOffset_value.SetValue(str(self.config.origami_boltzmannOffset)) self.origami_method_value.SetStringSelection(self.config.origami_acquisition) try: self.origami_method_value.SetStringSelection(self.itemInfo['method']) except: pass self.enableDisableBoxes(evt=None) self.importEvent = False
def onRemoveDuplicates(self, evt): """ This function removes duplicates from the list Its not very efficient! """ columns = self.peaklist.GetColumnCount() rows = self.peaklist.GetItemCount() tempData = [] # Iterate over row and columns to get data for row in range(rows): tempRow = [] for col in range(columns): item = self.peaklist.GetItem(itemId=row, col=col) # We want to make sure certain columns are numbers if col == 0 or col == 1 or col == 2 or col == 3: itemData = str2num(item.GetText()) if itemData == None: itemData = 0 tempRow.append(itemData) else: tempRow.append(item.GetText()) tempData.append(tempRow) tempData.sort() tempData = list(item for item, _ in itertools.groupby(tempData)) rows = len(tempData) self.peaklist.DeleteAllItems() print('Removing duplicates') for row in range(rows): self.peaklist.Append(tempData[row]) if evt is None: return else: evt.Skip()
def OnGetItemInformation(self, itemID, return_list=False): # get item information information = { 'start': str2int( self.peaklist.GetItem( itemID, self.config.driftTopColNames['start']).GetText()), 'end': str2int( self.peaklist.GetItem( itemID, self.config.driftTopColNames['end']).GetText()), 'scans': str2int( self.peaklist.GetItem( itemID, self.config.driftTopColNames['end']).GetText()), 'drift_voltage': str2num( self.peaklist.GetItem( itemID, self.config.driftTopColNames['drift_voltage']).GetText()), 'document': self.peaklist.GetItem( itemID, self.config.driftTopColNames['filename']).GetText() } if return_list: start = information['start'] end = information['end'] scans = information['scans'] drift_voltage = information['drift_voltage'] document = information['document'] return start, end, scans, drift_voltage, document return information
def onReplotRectanglesDT_RT(self, evt): """ This function replots the rectangles in the RT window during Linear DT mode """ count = self.peaklist.GetItemCount() currentDoc = self.presenter.currentDoc if currentDoc == "Current documents": return document = self.presenter.documentsDict[currentDoc] # Replot RT for current document rtX = document.RT['xvals'] rtY = document.RT['yvals'] xlabel = document.RT['xlabels'] color = document.lineColour style = document.style # Change panel and plot self.presenter.view.panelPlots.mainBook.SetSelection( self.config.panelNames['RT']) self.presenter.onPlotRT2(rtX, rtY, xlabel, color, style) if count == 0: return ymin = 0 height = 1.0 last = self.peaklist.GetItemCount() - 1 # Iterate over the list and plot rectangle one by one for row in range(count): xmin = str2num(self.peaklist.GetItem(itemId=row, col=0).GetText()) xmax = str2num(self.peaklist.GetItem(itemId=row, col=1).GetText()) width = xmax - xmin if row == last: self.presenter.addRectRT(xmin, ymin, width, height, color=self.config.annotColor, alpha=(self.config.annotTransparency / 100), repaint=True) else: self.presenter.addRectRT(xmin, ymin, width, height, color=self.config.annotColor, alpha=(self.config.annotTransparency / 100), repaint=False)
def onApply(self, evt): self.onCheckID() if self.importEvent: return self.parent.peaklist.CheckItem(self.itemInfo['id'], self.origami_select_value.GetValue()) self.parent.peaklist.SetStringItem(self.itemInfo['id'], self.config.peaklistColNames['charge'], self.origami_charge_value.GetValue()) self.parent.peaklist.SetStringItem(self.itemInfo['id'], self.config.peaklistColNames['colormap'], self.origami_colormap_value.GetStringSelection()) self.parent.peaklist.SetStringItem(self.itemInfo['id'], self.config.peaklistColNames['mask'], num2str(self.origami_mask_value.GetValue())) self.parent.peaklist.SetStringItem(self.itemInfo['id'], self.config.peaklistColNames['alpha'], num2str(self.origami_transparency_value.GetValue())) self.parent.peaklist.SetStringItem(self.itemInfo['id'], self.config.peaklistColNames['method'], self.origami_method_value.GetStringSelection()) self.parent.peaklist.SetStringItem(self.itemInfo['id'], self.config.peaklistColNames['label'], self.origami_label_value.GetValue()) if self.itemInfo['parameters'] == None: self.itemInfo['parameters'] = {} self.itemInfo['parameters']['firstVoltage'] = str2int(self.origami_startScan_value.GetValue()) self.itemInfo['parameters']['startV'] = str2num(self.origami_startVoltage_value.GetValue()) self.itemInfo['parameters']['endV'] = str2num(self.origami_endVoltage_value.GetValue()) self.itemInfo['parameters']['stepV'] = str2num(self.origami_stepVoltage_value.GetValue()) self.itemInfo['parameters']['spv'] = str2int(self.origami_scansPerVoltage_value.GetValue()) self.itemInfo['parameters']['expIncrement'] = str2num(self.origami_exponentialIncrement_value.GetValue()) self.itemInfo['parameters']['expPercent'] = str2num(self.origami_exponentialPercentage_value.GetValue()) self.itemInfo['parameters']['dx'] = str2num(self.origami_boltzmannOffset_value.GetValue()) # update ion information self.itemInfo['charge'] = self.origami_charge_value.GetValue() self.itemInfo['colormap'] = self.origami_colormap_value.GetStringSelection() self.itemInfo['mask'] = self.origami_mask_value.GetValue() self.itemInfo['alpha'] = self.origami_transparency_value.GetValue() self.itemInfo['label'] = self.origami_label_value.GetValue() self.itemInfo['min_threshold'] = self.origami_min_threshold_value.GetValue() self.itemInfo['max_threshold'] = self.origami_max_threshold_value.GetValue() # update ion value try: charge = str2int(self.itemInfo['charge']) ion_centre = (str2num(self.itemInfo['mzStart']) + str2num(self.itemInfo['mzEnd'])) / 2 mw = (ion_centre - self.config.elementalMass['Hydrogen'] * charge) * charge ion_value = (u"%s ~%.2f Da") % (self.itemInfo['ionName'], mw) self.origami_ion_value.SetValue(ion_value) except: self.origami_ion_value.SetValue(self.itemInfo['ionName']) self.OnAssignColor(evt=None) self.parent.onUpdateDocument(itemInfo=self.itemInfo, evt=None) if evt != None: evt.Skip()
def importConfig(self, fileName=None, e=None): """ Imports config from a file """ if not os.path.isfile(fileName): print('not a path') return f = open(fileName, 'r') for line in f: if len(line.split()) > 1: if line.startswith("iPolarity "): self.iPolarity = str(line.split()[1]) if line.startswith("iActivationZone "): self.iActivationZone = str(line.split()[1]) if line.startswith("iActivationMode "): self.iActivationMode = str(line.split()[1]) if line.startswith("iSPV "): self.iSPV = str2int(line.split()[1]) if line.startswith("iScanTime "): self.iScanTime = str2int(line.split()[1]) if line.startswith("iStartVoltage "): self.iStartVoltage = str2num(line.split()[1]) if line.startswith("iEndVoltage "): self.iEndVoltage = str2num(line.split()[1]) if line.startswith("iStepVoltage "): self.iStepVoltage = str2num(line.split()[1]) if line.startswith("iExponentPerct "): self.iExponentPerct = str2num(line.split()[1]) if line.startswith("iExponentIncre "): self.iExponentIncre = str2num(line.split()[1]) if line.startswith("iBoltzmann "): self.iBoltzmann = str2num(line.split()[1]) # if line.startswith("wrensPath "): # self.wrensPath = str(line.split(" ")[1::]) # print(self.wrensPath, os.path.isabs(self.wrensPath)) if line.startswith("wrensLinearName "): self.wrensLinearName = str(line.split()[1]) if line.startswith("wrensExponentName "): self.wrensExponentName = str(line.split()[1]) if line.startswith("wrensBoltzmannName "): self.wrensBoltzmannName = str(line.split()[1]) if line.startswith("wrensUserDefinedName "): self.wrensUserDefinedName = str(line.split()[1]) if line.startswith("wrensResetName "): self.wrensResetName = str(line.split()[1]) self.wrensLinearPath = "".join( ['"', self.wrensRunnerPath, '" ', self.wrensLinearName, ' "']) self.wrensExponentPath = "".join( ['"', self.wrensRunnerPath, '" ', self.wrensExponentName, ' "']) self.wrensBoltzmannPath = "".join( ['"', self.wrensRunnerPath, '" ', self.wrensBoltzmannName, ' "']) self.wrensUserDefinedPath = "".join( ['"', self.wrensRunnerPath, '" ', self.wrensUserDefinedName, ' "']) self.wrensResetPath = "".join( ['"', self.wrensRunnerPath, '" ', self.wrensResetName, ' "'])
def updateMS(self, evt): self.config.compare_massSpectrum = [self.msSpectrum1_value.GetStringSelection(), self.msSpectrum2_value.GetStringSelection()] self.config.lineTransparency_MS1 = str2num(self.msSpectrum1_transparency.GetValue())/100 self.config.lineStyle_MS1 = self.msSpectrum1_lineStyle_value.GetStringSelection() self.config.lineTransparency_MS2 = str2num(self.msSpectrum2_transparency.GetValue())/100 self.config.lineStyle_MS2 = self.msSpectrum2_lineStyle_value.GetStringSelection() self.config.compare_massSpectrumParams['preprocess'] = self.preprocess_check.GetValue() self.config.compare_massSpectrumParams['inverse'] = self.inverse_check.GetValue() self.config.compare_massSpectrumParams['normalize'] = self.normalize_check.GetValue() self.config.compare_massSpectrumParams['subtract'] = self.subtract_check.GetValue() label_1 = self.label1_value.GetValue() if label_1 == "": label_1 = self.msSpectrum1_value.GetStringSelection() label_2 = self.label2_value.GetValue() if label_2 == "": label_2 = self.msSpectrum2_value.GetStringSelection() self.config.compare_massSpectrumParams['legend'] = [label_1, label_2] if evt != None: evt.Skip()
def OnGetItemInformation(self, itemID, return_list=False): # get item information information = { 'start': str2num( self.peaklist.GetItem( itemID, self.config.driftBottomColNames['start']).GetText()), 'end': str2num( self.peaklist.GetItem( itemID, self.config.driftBottomColNames['end']).GetText()), 'intensity': str2num( self.peaklist.GetItem( itemID, self.config.driftBottomColNames['intensity']).GetText()), 'charge': str2int( self.peaklist.GetItem( itemID, self.config.driftBottomColNames['charge']).GetText()), 'document': self.peaklist.GetItem( itemID, self.config.driftBottomColNames['filename']).GetText() } if return_list: start = information['start'] end = information['end'] intensity = information['intensity'] charge = information['charge'] document = information['document'] return start, end, intensity, charge, document return information
def OnSortByColumn(self, column): """ Sort data in peaklist based on pressed column """ # Check if it should be reversed if self.lastColumn == None: self.lastColumn = column elif self.lastColumn == column: if self.reverse == True: self.reverse = False else: self.reverse = True else: self.reverse = False self.lastColumn = column columns = self.peaklist.GetColumnCount() rows = self.peaklist.GetItemCount() tempData = [] # Iterate over row and columns to get data for row in range(rows): tempRow = [] for col in range(columns): item = self.peaklist.GetItem(itemId=row, col=col) # We want to make sure the first 3 columns are numbers if col == 0 or col == 1 or col == 2: itemData = str2num(item.GetText()) if itemData == None: itemData = 0 tempRow.append(itemData) elif col == 3: itemData = str2int(item.GetText()) if itemData == None: itemData = 0 tempRow.append(itemData) else: tempRow.append(item.GetText()) tempData.append(tempRow) # Sort data tempData.sort(key=itemgetter(column), reverse=self.reverse) # Clear table and reinsert data self.peaklist.DeleteAllItems() for row in range(rows): self.peaklist.Append(tempData[row])