def detect_peaks_gcms_centroid(ms_experiment, parameters, debug=False): """ Applicable to centroided experiments, also see https://abibuilder.informatik.uni-tuebingen.de/archive/openms/Documentation/nightly/html/a16103.html :param ms_experiment: :param parameters: :return: """ print(f"Detecting peaks with {GCMSPeakDetectionMethod.CENTROIDED}") ff = oms.FeatureFinder() if not debug: ff.setLogType(oms.LogType.NONE) else: ff.setLogType(oms.LogType.CMD) # Run the feature finder name = "centroided" pdm_name = GCMSPeakDetectionMethod.CENTROIDED.name parameters['detection_mode'] = name parameters['pdm_name'] = pdm_name # name = parameters['detection_mode'] features = oms.FeatureMap() seeds = oms.FeatureMap() ff_params = oms.FeatureFinder().getParameters(name) ff.run(name, ms_experiment, features, ff_params, seeds) # features.setUniqueIds() features.ensureUniqueId() fh = oms.FeatureXMLFile() feature_storage_path = f"{parameters['input_filename']}_output.featureXML" fh.store(feature_storage_path, features) parameters['feature_storage'] = feature_storage_path print("Found", features.size(), "features") return parameters
def run_ff(self, exp: ms.MSExperiment, type: str = 'centroided') -> ms.FeatureMap: """Runs an existing OpenMS feature finder on an experiment. Keyword arguments: exp: the experiment to run the existing feature finder on type: the name of the existing feature finder to run Returns: the features in the experiment. """ if type == 'multiplex': return self.run_ffm(exp) ff = ms.FeatureFinder() ff.setLogType(ms.LogType.NONE) features, seeds = ms.FeatureMap(), ms.FeatureMap() params = ms.FeatureFinder().getParameters( type) # default (Leon's) (modified) params.__setitem__(b'mass_trace:min_spectra', 7) # 10 (5) (7) params.__setitem__(b'mass_trace:max_missing', 1) # 1 (2) (1) params.__setitem__(b'seed:min_score', 0.65) # 0.8 (0.5) (0.65) params.__setitem__(b'feature:min_score', 0.6) # 0.7 (0.5) (0.6) exp.updateRanges() ff.run(type, exp, features, params, seeds) features.setUniqueIds() return features
def run_feature_finder_centroided_on_experiment(input_map): """Function that runs FeatureFinderCentroided on the given input map. Args: input_map (MSExperiment): An OpenMS MSExperiment object. Returns: FeatureMap: A FeatureMap containing the found features from the given experiment. """ # Load data input_map.updateRanges() ff = ms.FeatureFinder() ff.setLogType(ms.LogType.CMD) # Run the feature finder name = 'centroided' features = ms.FeatureMap() seeds = ms.FeatureMap() params = ms.FeatureFinder().getParameters(name) params.__setitem__(b'mass_trace:min_spectra', 5) params.__setitem__(b'mass_trace:max_missing', 2) params.__setitem__(b'seed:min_score', 0.5) params.__setitem__(b'feature:min_score', 0.5) ff.run(name, input_map, features, params, seeds) features.setUniqueIds() return features
def detect_peaks_gcms_peak_picker_wavelet(ms_experiment, parameters): """ Use isotop wavelet to process raw data - can perform poorly on centroided data https://abibuilder.informatik.uni-tuebingen.de/archive/openms/Documentation/nightly/html/a16159.html TODO use "corrected" intensity_type :param ms_experiment: :param parameters: :return: """ #set estimate_peak_width to true # Run the feature finder name = "peak_picker_wavelet" parameters['detection_mode'] = name # outdated code in https://github.com/OpenMS/pyopenms-extra/blob/master/src/examples/peakpicker_scipyFFT.py # pick spectrum ff = oms.FeatureFinder() ff.setLogType(oms.LogType.NONE) algo_name = oms.FeatureFinderAlgorithmIsotopeWavelet().getProductName() # picker = oms.FeatureFinderAlgorithmIsotopeWavelet() feature_map = oms.FeatureMap() seeds = oms.FeatureMap() # seeds = FeatureMap() algo_params = ff.getParameters(algo_name) ff.run(algo_name, ms_experiment, feature_map, algo_params, seeds) feature_map.setUniqueIds() parameters = default_store_feature_xml(feature_map, parameters) return parameters
def setup_feature_finder(self): # setting up the FeatureFinder self.seeds = oms.FeatureMap() self.ff = oms.FeatureFinder() self.features = oms.FeatureMap() self.ff.setLogType(oms.LogType.CMD)
def set_feature_finder_param(self): self.ff_param = self.ff_param or {} self.ff_param = dict(( param.encode('ascii') if hasattr(param, 'encode') else param, value, ) for param, value in iteritems(self.ff_param)) extra_param = dict(( (b'mass_trace:min_spectra', self.feature_min_spectra), (b'feature:min_rt_span', self.feature_min_rt_span), (b'feature:max_rt_span', self.feature_max_rt_span), )) extra_param.update(self.ff_param) self.ff_param = extra_param self.ff_type = oms.FeatureFinderAlgorithmPicked().getProductName() self.ff_param_oms = oms.FeatureFinder().getParameters(self.ff_type) all_param = self.ff_param_oms.keys() for param, value in iteritems(self.ff_param): if param not in all_param: self._log('Warning: unknown parameter for ' 'pyopenms.FeatureFinder: `%s`' % param.decode('ascii')) continue self.ff_param_oms.setValue(param, value)
def run_featurefinder_centroided(input_map, params, seeds, out_path): ff = pms.FeatureFinder() ff.setLogType(pms.LogType.CMD) features = pms.FeatureMap() name = pms.FeatureFinderAlgorithmPicked.getProductName() ff.run(name, input_map, features, params, seeds) fh = pms.FeatureXMLFile() fh.store(out_path, features)
def mgf(self): """ Opens an mzML file. """ options = oms.PeakFileOptions() options.setMSLevels([2]) self.mzml = oms.MzMLFile() self.mzml.setOptions(options) self.exp = oms.MSExperiment() self.mzml.load(self.fname, self.exp) self.feature_finder = oms.FeatureFinder() self.ffname = 'centroided' self.features = oms.FeatureMap() self.seeds = oms.FeatureMap() self.params = oms.FeatureFinder().getParameters(self.ffname) self.feature_finder.run( self.ffname, self.exp, self.features, self.params, self.seeds, ) self.features.setUniqueIds()
def detect_peaks_gcms_isotopewavelet(ms_experiment, parameters, debug=False): """ Use isotop wavelet to process raw data - can perform poorly on centroided data - also see https://abibuilder.informatik.uni-tuebingen.de/archive/openms/Documentation/nightly/html/a16105.html TODO use "corrected" intensity_type :param ms_experiment: :param parameters: :return: """ print(f"Detecting peaks with {GCMSPeakDetectionMethod.ISOTOPEWAVELET}") ff = oms.FeatureFinder() if not debug: ff.setLogType(oms.LogType.NONE) else: ff.setLogType(oms.LogType.CMD) # Run the feature finder name = "isotope_wavelet" pdm_name = GCMSPeakDetectionMethod.ISOTOPEWAVELET.name parameters['detection_mode'] = name parameters['pdm_name'] = pdm_name # name = parameters['detection_mode'] features = oms.FeatureMap() seeds = oms.FeatureMap() ff_params = ff.getParameters(name) # complains about "the extremal length of the wavelet is larger (47661) than the number of data points" # wavelet_length is defined by mz_cutoff / min_spacing # hr_data must be true if high-resolution data (orbitrap, FTICR) # hr_data parameter for isotopewavelet function is_hr_data = parameters.get("hr_data", False) if is_hr_data: hr_key = b"hr_data" # hr_data takes extremely long - >= 2h per measurement of (!)32MB - there are way larger spectra... ff_params.setValue(hr_key, b"true") ff.run(name, ms_experiment, features, ff_params, seeds) features.setUniqueIds() fh = oms.FeatureXMLFile() feature_storage_path = f"{parameters['input_filename']}_output.featureXML" fh.store(feature_storage_path, features) parameters['feature_storage'] = feature_storage_path print("Found", features.size(), "features") return parameters
def testFeatureFinder(): """ @tests: FeatureFinder.__init__ FeatureFinder.endProgress FeatureFinder.getLogType FeatureFinder.getParameters FeatureFinder.run FeatureFinder.setLogType FeatureFinder.setProgress FeatureFinder.startProgress """ ff = pyopenms.FeatureFinder() name = pyopenms.FeatureFinderAlgorithmPicked.getProductName() ff.run(name, pyopenms.MSExperiment(), pyopenms.FeatureMap(), pyopenms.Param(), pyopenms.FeatureMap()) _testProgressLogger(ff) p = ff.getParameters(name) _testParam(p)
def run_featurefinder_centroided(input_path, params, seeds, out_path): fh = pms.MzMLFile() options = pms.PeakFileOptions() options.setMSLevels([1,1]) fh.setOptions(options) input_map = pms.MSExperiment() fh.load(input_path, input_map) input_map.updateRanges() ff = pms.FeatureFinder() ff.setLogType(pms.LogType.CMD) features = pms.FeatureMap() name = pms.FeatureFinderAlgorithmPicked.getProductName() ff.run(name, input_map, features, params, seeds) features.setUniqueIds() addDataProcessing(features, params, pms.ProcessingAction.QUANTITATION) fh = pms.FeatureXMLFile() fh.store(out_path, features)
def main(): parser = argparse.ArgumentParser(description="FeatureFinderCentroided") parser.add_argument("-in", action="store", type=str, dest="in_", metavar="input_file", ) parser.add_argument("-seeds", action="store", type=str, metavar="seeds_file", ) parser.add_argument("-out", action="store", type=str, metavar="output_file", ) parser.add_argument("-ini", action="store", type=str, metavar="ini_file", ) parser.add_argument("-dict_ini", action="store", type=str, metavar="python_dict_ini_file", ) parser.add_argument("-write_ini", action="store", type=str, metavar="ini_file", ) parser.add_argument("-write_dict_ini", action="store", type=str, metavar="python_dict_ini_file", ) args = parser.parse_args() run_mode = args.in_ is not None and args.out is not None\ and (args.ini is not None or args.dict_ini is not None) write_mode = args.write_ini is not None or args.write_dict_ini is not None ok = run_mode or write_mode if not ok: parser.error("either specify -in, -out and -(dict)ini for running " "the peakpicker\nor -write(dict)ini for creating std " "ini file") name = pms.FeatureFinderAlgorithmPicked.getProductName() defaults = pms.FeatureFinder().getParameters(name) write_requested = writeParamsIfRequested(args, defaults) if not write_requested: updateDefaults(args, defaults) seeds = pms.FeatureMap() if args.seeds: fh = pms.FeatureXMLFile() fh.load(args.seeds, seeds) run_featurefinder_centroided(args.in_, defaults, seeds, args.out)