def extract_peaks(file,time_range): peak_data = {} run = pymzml.run.Reader(file) peak_data[file] = {} print(file) for spec in run: if spec.get('filter string')!= None and spec.get('total ion current') != None and spec.get('scan time') >= time_range[0] and spec.get('scan time') <= time_range[1]: if spec.get('filter string') in peak_data[file]: peak_data[file][spec.get('filter string')]['scan_count'] += 1 peak_data[file][spec.get('filter string')]['scan'] = mspy.combine(peak_data[file][spec.get('filter string')]['scan'], np.array(spec.peaks)) else: peak_data[file][spec.get('filter string')] = {} peak_data[file][spec.get('filter string')]['scan_count'] = 1 peak_data[file][spec.get('filter string')]['scan'] = np.array(spec.peaks) for scan in peak_data[file].keys(): peak_data[file][scan]['scan'] = mspy.reduce(peak_data[file][scan]['scan']) peak_data[file][scan]['scan'] = mspy.multiply(peak_data[file][scan]['scan'],y=1.0/peak_data[file][scan]['scan_count']) with open(file+scan+'.np', 'wb') as f: np.save(f,peak_data[file][scan]['scan'])
def makeProfile(self): """Generate pattern profile.""" self.currentPatternProfile = None self.currentPatternPeaks = None self.currentPatternScan = None # check pattern if self.currentPattern == None: return # get selected charge charge = 0 if self.currentIon != None: charge = self.currentIon[3] # make profile self.currentPatternProfile = mspy.profile( peaklist=self.currentPattern, fwhm=config.massCalculator['patternFwhm'], points=20, model=config.massCalculator['patternPeakShape'], ) # get scale and shift for specified intensity and baseline basepeak = mspy.basepeak(self.currentPatternProfile) scale = (config.massCalculator['patternIntensity'] - config.massCalculator['patternBaseline'] ) / self.currentPatternProfile[basepeak][1] shift = config.massCalculator['patternBaseline'] # rescale profile self.currentPatternProfile = mspy.multiply(self.currentPatternProfile, y=scale) self.currentPatternProfile = mspy.offset(self.currentPatternProfile, y=shift) # make real peaklist from profile peaklist = [] for isotope in mspy.maxima(self.currentPatternProfile): mz = isotope[0] centroid = mspy.centroid(self.currentPatternProfile, isotope[0], isotope[1] * 0.99) if abs(mz - centroid) < config.massCalculator['patternFwhm'] / 20: mz = centroid peak = mspy.peak(mz=mz, ai=isotope[1], base=shift, charge=charge) peaklist.append(peak) peaklist = mspy.peaklist(peaklist) # make individual peak shapes self.currentPatternPeaks = [] if config.massCalculator['patternShowPeaks']: # gaussian shape if config.massCalculator['patternPeakShape'] == 'gaussian': for isotope in self.currentPattern: peak = mspy.gaussian( x=isotope[0], minY=shift, maxY=isotope[1] * scale + shift, fwhm=config.massCalculator['patternFwhm']) self.currentPatternPeaks.append(peak) # lorentzian shape elif config.massCalculator['patternPeakShape'] == 'lorentzian': for isotope in self.currentPattern: peak = mspy.lorentzian( x=isotope[0], minY=shift, maxY=isotope[1] * scale + shift, fwhm=config.massCalculator['patternFwhm']) self.currentPatternPeaks.append(peak) # gauss-lorentzian shape elif config.massCalculator[ 'patternPeakShape'] == 'gausslorentzian': for isotope in self.currentPattern: peak = mspy.gausslorentzian( x=isotope[0], minY=shift, maxY=isotope[1] * scale + shift, fwhm=config.massCalculator['patternFwhm']) self.currentPatternPeaks.append(peak) # make scan object self.currentPatternScan = mspy.scan(profile=self.currentPatternProfile, peaklist=peaklist)
def makeProfile(self): """Generate pattern profile.""" self.currentPatternProfile = None self.currentPatternPeaks = None self.currentPatternScan = None # check pattern if self.currentPattern == None: return # get selected charge charge = 0 if self.currentIon != None: charge = self.currentIon[3] # make profile self.currentPatternProfile = mspy.profile( peaklist = self.currentPattern, fwhm = config.massCalculator['patternFwhm'], points = 20, model = config.massCalculator['patternPeakShape'], ) # get scale and shift for specified intensity and baseline basepeak = mspy.basepeak(self.currentPatternProfile) scale = (config.massCalculator['patternIntensity'] - config.massCalculator['patternBaseline']) / self.currentPatternProfile[basepeak][1] shift = config.massCalculator['patternBaseline'] # rescale profile self.currentPatternProfile = mspy.multiply(self.currentPatternProfile, y=scale) self.currentPatternProfile = mspy.offset(self.currentPatternProfile, y=shift) # make real peaklist from profile peaklist = [] for isotope in mspy.maxima(self.currentPatternProfile): mz = isotope[0] centroid = mspy.centroid(self.currentPatternProfile, isotope[0], isotope[1]*0.99) if abs(mz-centroid) < config.massCalculator['patternFwhm']/20: mz = centroid peak = mspy.peak( mz = mz, ai = isotope[1], base = shift, charge = charge ) peaklist.append(peak) peaklist = mspy.peaklist(peaklist) # make individual peak shapes self.currentPatternPeaks = [] if config.massCalculator['patternShowPeaks']: # gaussian shape if config.massCalculator['patternPeakShape'] == 'gaussian': for isotope in self.currentPattern: peak = mspy.gaussian( x = isotope[0], minY = shift, maxY = isotope[1]*scale+shift, fwhm = config.massCalculator['patternFwhm'] ) self.currentPatternPeaks.append(peak) # lorentzian shape elif config.massCalculator['patternPeakShape'] == 'lorentzian': for isotope in self.currentPattern: peak = mspy.lorentzian( x = isotope[0], minY = shift, maxY = isotope[1]*scale+shift, fwhm = config.massCalculator['patternFwhm'] ) self.currentPatternPeaks.append(peak) # gauss-lorentzian shape elif config.massCalculator['patternPeakShape'] == 'gausslorentzian': for isotope in self.currentPattern: peak = mspy.gausslorentzian( x = isotope[0], minY = shift, maxY = isotope[1]*scale+shift, fwhm = config.massCalculator['patternFwhm'] ) self.currentPatternPeaks.append(peak) # make scan object self.currentPatternScan = mspy.scan(profile=self.currentPatternProfile, peaklist=peaklist)