Answers.Body: <p>This is a draft answer, if the OP still need needs I will extend it later.</p>
  <p>Me too I found the documentation and examples of <code>pyopenms</code> very scarce. At the same time  OpenMS is huge, sometimes you find key information not in various other sources instead of the official documentation. This is especially true if it comes to metabolomics.</p>
  <p>We built a Python OpenMS lipidomics LC MS/MS preprocessing pipeline, contained in this file:
  <a href="https://github.com/saezlab/lipyd/blob/master/src/lipyd/msproc.py" rel="nofollow noreferrer">https://github.com/saezlab/lipyd/blob/master/src/lipyd/msproc.py</a></p>
  <p>The top class is the one called <code>MSPreprocess</code>, it implements the workflow, the other classes implement its steps.</p>
  <p>Briefly, you start from profile mode mzML files, then</p>
  <ol>
  <li>Peak picking with PeakPickerHiRes results centroided data</li>
  <li>FeatureFindingMetabo assembles the traces in a metabolomics
  compatible way</li>
  <li>A MapAlignment algorithm alignes the traces across
  scans</li>
  <li>A FeatureGrouping algorithm alignes the features across multiple experiments</li>
  </ol>
  <p>Our software mentioned above (<code>lipyd</code>) outputs data frames from the m/z, RT and intensity.</p>
  <p>About <code>OpenMS</code> I can recommend to read the <code>C++</code> code and docs. The Python classes and methods are automatically built minimal wrappers, everything works the same way as in <code>C++.</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-29T03:02:29.073Z
Answers.Text: Hi, thank you for sharing the link. I will have a look at it.  Do you mind sharing what version of pyopenms was used here?
Answers.UserDisplayName: Soerendip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-29T18:06:12.467Z
Answers.Text: I only know both `openms` and `pyopenms` on my computer are `2.5.0`, and I think I haven't updated them since last summer
Answers.UserDisplayName: deeenes
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-31T19:55:26.723Z
Answers.Text: It's hard to understand what is going on and when FeatureFinderMetabo is called and with which arguments. As it is so encapsulated in the method_key wrapper.
Answers.UserDisplayName: Soerendip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-31T22:46:43.487Z
Answers.Text: Anyway, it was super helpful. I composed my own answer out of your code, which is more concise. You could comment on that in case I made a mistake or forgot something.
Answers.UserDisplayName: Soerendip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-16T22:12:15.470Z
Answers.LastActivityDate: 2020-07-16T22:12:15.470Z
Answers.UserDisplayName: deeenes
Answers.Body: <p>My minimal procedure based on the code that @deeenes shared for a single file. Comments to improve this solution are highly appreciated:</p>
  <pre><code>files = list_of_filenames
  
  feature_map = oms.FeatureMap()
  mass_traces = []
  mass_traces_split = []
  mass_traces_filtered  = []
  
  exp = oms.MSExperiment()
  
  options = oms.PeakFileOptions()
  options.setMSLevels([1])
  
  fh = oms.MzXMLFile()
  fh.setOptions(options)
  
  # Peak map
  peak_map = oms.PeakMap()
  
  file = files[0]
  
  print('# Filename:', basename(file))
  fh.load(file, exp)
  
  print('# Spectra:', len( exp.getSpectra() ))
  print('# Chromatograms:', len( exp.getChromatograms() ) )
  
  for chrom in exp.getChromatograms():
      peak_map.addChrom(chrom)
      
  for spec in exp.getSpectra():
      peak_map.addSpectrum(spec)
  
  mass_trace_detect = oms.MassTraceDetection()
  mass_trace_detect.run(peak_map, mass_traces, 100000)
  
  print('# Mass traces:', len(mass_traces) )
  
  elution_peak_detection = oms.ElutionPeakDetection()
  elution_peak_detection.detectPeaks(mass_traces, mass_traces_split)
  print('# Mass traces split:', len(mass_traces_split) )
  
  
  
  feature_finding_metabo = oms.FeatureFindingMetabo()
  feature_finding_metabo.run(
              mass_traces_split,
              feature_map,
              mass_traces_filtered)
  
  print('# Mass traces filtered:', len(mass_traces_filtered) )
  print('# Features:', feature_map.size() )
  
  oms.FeatureXMLFile().store('FeatureFindingMetabo.featureXML', feature_map)
  
  &gt;&gt;&gt;
  # Filename: CA_1.mzXML
  # Spectra: 989
  # Chromatograms: 0
  # Mass traces: 18476
  # Mass traces split: 25194
  # Mass traces filtered: 0
  # Features: 23549
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-31T21:29:53.087Z
Answers.LastActivityDate: 2020-08-31T22:47:16.880Z
Answers.LastEditDate: 2020-08-31T22:47:16.880Z
Answers.UserDisplayName: Soerendip
Body: <p>I found <a href="https://pyopenms.readthedocs.io/en/latest/feature_detection.html?highlight=featurefinder" rel="nofollow noreferrer">this</a> documentation on pyOpenMS mass spec library. I want to try different peak picking algorithms. Unfortunately, the docs are not very detailed and don't show how to use the other peak picking algorithms and the codebase itself is also quite cryptic for me.</p>
  <p>Any idea how to use, for example, the FeatureFindingMetabo algorithm insead of the centroided one?</p>
  <pre><code>from urllib.request import urlretrieve
  # from urllib import urlretrieve  # use this code for Python 2.x
  gh = &quot;https://raw.githubusercontent.com/OpenMS/OpenMS/develop&quot;
  urlretrieve (gh +&quot;/src/tests/topp/FeatureFinderCentroided_1_input.mzML&quot;, &quot;feature_test.mzML&quot;)
  
  from pyopenms import *
  
  # Prepare data loading (save memory by only
  # loading MS1 spectra into memory)
  options = PeakFileOptions()
  options.setMSLevels([1])
  fh = MzMLFile()
  fh.setOptions(options)
  
  # Load data
  input_map = MSExperiment()
  fh.load(&quot;feature_test.mzML&quot;, input_map)
  input_map.updateRanges()
  
  ff = FeatureFinder()
  ff.setLogType(LogType.CMD)
  
  # Run the feature finder
  name = &quot;centroided&quot;
  features = FeatureMap()
  seeds = FeatureMap()
  params = FeatureFinder().getParameters(name)
  ff.run(name, input_map, features, params, seeds)
  
  features.setUniqueIds()
  fh = FeatureXMLFile()
  fh.store(&quot;output.featureXML&quot;, features)
  print(&quot;Found&quot;, features.size(), &quot;features&quot;)
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-16T21:59:42.783Z
Comments.Text: Hi Sören, We build a Python pipeline with `FeatureFinderMetabo`, it was like a year ago so I can not recall the details right now, but you can see the entire thing here: https://github.com/saezlab/lipyd/blob/master/src/lipyd/msproc.py
  If you will be still having issues, maybe in the weekend I can check it again.
Comments.UserDisplayName: deeenes
Tags: <python>
Title: How to use pyopenms.FeatureFindingMetabo() for peak picking in pyOpenMS?
ThreadText: # How to use pyopenms.FeatureFindingMetabo() for peak picking in pyOpenMS?
  
  (Asked by: username_0 on 2020-07-14)
  
  I found [this](https://pyopenms.readthedocs.io/en/latest/feature_detection.html?highlight=featurefinder) documentation on pyOpenMS mass spec library. I want to try different peak picking algorithms. Unfortunately, the docs are not very detailed and don't show how to use the other peak picking algorithms and the codebase itself is also quite cryptic for me.
  
  Any idea how to use, for example, the FeatureFindingMetabo algorithm insead of the centroided one?
  
  ```
  from urllib.request import urlretrieve
  # from urllib import urlretrieve  # use this code for Python 2.x
  gh = "https://raw.githubusercontent.com/OpenMS/OpenMS/develop"
  urlretrieve (gh +"/src/tests/topp/FeatureFinderCentroided_1_input.mzML", "feature_test.mzML")
  
  from pyopenms import *
  
  # Prepare data loading (save memory by only
  # loading MS1 spectra into memory)
  options = PeakFileOptions()
  options.setMSLevels([1])
  fh = MzMLFile()
  fh.setOptions(options)
  
  # Load data
  input_map = MSExperiment()
  fh.load("feature_test.mzML", input_map)
  input_map.updateRanges()
  
  ff = FeatureFinder()
  ff.setLogType(LogType.CMD)
  
  # Run the feature finder
  name = "centroided"
  features = FeatureMap()
  seeds = FeatureMap()
  params = FeatureFinder().getParameters(name)
  ff.run(name, input_map, features, params, seeds)
  
  features.setUniqueIds()
  fh = FeatureXMLFile()
  fh.store("output.featureXML", features)
  print("Found", features.size(), "features")
  
  ```
  
  **Tags:** python
  
  > **Comments:**
  > **username_1**: Hi Sören, We build a Python pipeline with `FeatureFinderMetabo`, it was like a year ago so I can not recall the details right now, but you can see the entire thing here: https://github.com/saezlab/lipyd/blob/master/src/lipyd/msproc.py If you will be still having issues, maybe in the weekend I can check it again.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-07-16. Score: 1
  
  This is a draft answer, if the OP still need needs I will extend it later.
  
  Me too I found the documentation and examples of `pyopenms` very scarce. At the same time OpenMS is huge, sometimes you find key information not in various other sources instead of the official documentation. This is especially true if it comes to metabolomics.
  
  We built a Python OpenMS lipidomics LC MS/MS preprocessing pipeline, contained in this file:
  <https://github.com/saezlab/lipyd/blob/master/src/lipyd/msproc.py>
  
  The top class is the one called `MSPreprocess`, it implements the workflow, the other classes implement its steps.
  
  Briefly, you start from profile mode mzML files, then
  
  1. Peak picking with PeakPickerHiRes results centroided data
  2. FeatureFindingMetabo assembles the traces in a metabolomics
     compatible way
  3. A MapAlignment algorithm alignes the traces across
     scans
  4. A FeatureGrouping algorithm alignes the features across multiple experiments
  
  Our software mentioned above (`lipyd`) outputs data frames from the m/z, RT and intensity.
  
  About `OpenMS` I can recommend to read the `C++` code and docs. The Python classes and methods are automatically built minimal wrappers, everything works the same way as in `C++.`
  
  > **Comments:**
  > **username_0**: Hi, thank you for sharing the link. I will have a look at it.  Do you mind sharing what version of pyopenms was used here?  
  > **username_1**: I only know both `openms` and `pyopenms` on my computer are `2.5.0`, and I think I haven't updated them since last summer  
  > **username_0**: It's hard to understand what is going on and when FeatureFinderMetabo is called and with which arguments. As it is so encapsulated in the method_key wrapper.  
  > **username_0**: Anyway, it was super helpful. I composed my own answer out of your code, which is more concise. You could comment on that in case I made a mistake or forgot something.  
  
  ---
  
  ### Answer by username_0 on 2020-08-31. Score: 0
  
  My minimal procedure based on the code that @username_1 shared for a single file. Comments to improve this solution are highly appreciated:
  
  ```
  files = list_of_filenames
  
  feature_map = oms.FeatureMap()
  mass_traces = []
  mass_traces_split = []
  mass_traces_filtered  = []
  
  exp = oms.MSExperiment()
  
  options = oms.PeakFileOptions()
  options.setMSLevels([1])
  
  fh = oms.MzXMLFile()
  fh.setOptions(options)
  
  # Peak map
  peak_map = oms.PeakMap()
  
  file = files[0]
  
  print('# Filename:', basename(file))
  fh.load(file, exp)
  
  print('# Spectra:', len( exp.getSpectra() ))
  print('# Chromatograms:', len( exp.getChromatograms() ) )
  
  for chrom in exp.getChromatograms():
      peak_map.addChrom(chrom)
      
  for spec in exp.getSpectra():
      peak_map.addSpectrum(spec)
  
  mass_trace_detect = oms.MassTraceDetection()
  mass_trace_detect.run(peak_map, mass_traces, 100000)
  
  print('# Mass traces:', len(mass_traces) )
  
  elution_peak_detection = oms.ElutionPeakDetection()
  elution_peak_detection.detectPeaks(mass_traces, mass_traces_split)
  print('# Mass traces split:', len(mass_traces_split) )
  
  feature_finding_metabo = oms.FeatureFindingMetabo()
  feature_finding_metabo.run(
              mass_traces_split,
              feature_map,
              mass_traces_filtered)
  
  print('# Mass traces filtered:', len(mass_traces_filtered) )
  print('# Features:', feature_map.size() )
  
  oms.FeatureXMLFile().store('FeatureFindingMetabo.featureXML', feature_map)
  
  >>>
  # Filename: CA_1.mzXML
  # Spectra: 989
  # Chromatograms: 0
  # Mass traces: 18476
  # Mass traces split: 25194
  # Mass traces filtered: 0
  # Features: 23549
  
  ```
  
  
  ---
  
  