TransWikia.com

How to use pyopenms.FeatureFindingMetabo() for peak picking in pyOpenMS?

Bioinformatics Asked on August 22, 2021

I found this 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")

2 Answers

My minimal procedure based on the code that @deeenes 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

Answered by Sören on August 22, 2021

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++.

Answered by deeenes on August 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP