def extract_peaks(file,time_range): peak_data = {} run = pymzml.run.Reader(file+'.mzML') 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'] = mod_signal.combine(peak_data[file][spec.get('filter string')]['scan'], np.array(spec.peaks)) calculations.signal_filter(peak_data[file][spec.get('filter string')]['scan'],0.005) 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'] = mod_signal.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 combine(self, other): """Add data from given scan. other (mspy.scan) - scan to combine with """ # check scan if not isinstance(other, scan): raise TypeError, "Cannot combine with non-scan object!" # use profiles only if len(self.profile) or len(other.profile): # combine profiles self.profile = mod_signal.combine(self.profile, other.profile) # empty peaklist self.peaklist.empty() # use peaklists only elif len(self.peaklist) or len(other.peaklist): self.peaklist.combine(other.peaklist) # clear buffers self.reset()