TargetedSpectraExtractor#

class pyopenms.TargetedSpectraExtractor#

Bases: DefaultParamHandler

Filter, annotate, pick, and score spectra based on a target list

This class processes spectra from DDA experiments against a target transition list. It provides a complete pipeline from raw spectra to scored, selected spectra.

Workflow: 1. annotateSpectra() - Match spectra to targets by precursor MZ and RT 2. pickSpectrum() - Smooth and pick peaks 3. scoreSpectra() - Score by TIC, FWHM, SNR with configurable weights 4. selectSpectra() - Choose the best spectrum per transition

Or use extractSpectra() for the full pipeline in one call.

Example usage:

from pyopenms import *

# Load experiment and targets
exp = MSExperiment()
MzMLFile().load("experiment.mzML", exp)
targets = TargetedExperiment()
TraMLFile().load("targets.traML", targets)

# Extract matching spectra
extractor = TargetedSpectraExtractor()
extracted, features = extractor.extractSpectra(exp, targets, True)

print(f"Found {len(extracted)} matching spectra")
__init__() → None#
__init__(arg: pyopenms.TargetedSpectraExtractor, /) → None

Methods

__init__()

annotateSpectra(spectra, targeted_exp, ...)

Overloaded function.

constructTransitionsList(ms1_features, ...)

Construct a transition list from MS1 and MS2 features

extractSpectra(experiment, targeted_exp, ...)

Overloaded function.

getDefaultParameters(params)

Overloaded function.

getDefaults()

Returns the default parameters

getName()

Returns the name

getParameters()

Returns the parameters

getSubsections()

mergeFeatures(fmap_input, fmap_output)

Merge features from input to output map

pickSpectrum(spectrum, picked_spectrum)

Smooth and pick peaks from a spectrum

scoreSpectra(annotated_spectra, ...)

Overloaded function.

searchSpectrum(feat_map, feat_map_output[, ...])

Search accurate masses and add identification (peptide hits) as features/sub-features

selectSpectra(scored_spectra, features, ...)

Overloaded function.

setName(name)

Sets the name

setParameters(param)

Sets the parameters

storeSpectraMSP(filename, experiment)

Store spectra in MSP format

annotateSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum], targeted_exp: pyopenms.TargetedExperiment, features: pyopenms.FeatureMap, compute_features: bool) → list[pyopenms.MSSpectrum]#
annotateSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum], targeted_exp: pyopenms.TargetedExperiment) → list[pyopenms.MSSpectrum]
annotateSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum], ms1_features: pyopenms.FeatureMap, ms2_features: pyopenms.FeatureMap) → list[pyopenms.MSSpectrum]

Overloaded function.

  1. annotateSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum], targeted_exp: pyopenms.TargetedExperiment, features: pyopenms.FeatureMap, compute_features: bool) -> list[pyopenms.MSSpectrum]

Filters and annotates those spectra that could potentially match the transitions of the target list

Spectra within the precursor RT window and m/z tolerance of a transition are kept and annotated with the related transition’s name.

Parameters:
  • spectra – The spectra to filter

  • targeted_exp – The target list

  • features – A FeatureMap which will contain information about the name, precursor RT and precursor MZ of the matched transition

  • compute_features – If False, features will be ignored

Returns:

The spectra annotated with the related transition’s name

  1. annotateSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum], targeted_exp: pyopenms.TargetedExperiment) -> list[pyopenms.MSSpectrum]

Filters and annotates those spectra that could potentially match the transitions of the target list (without features)

Parameters:
  • spectra – The spectra to filter

  • targeted_exp – The target list

Returns:

The spectra annotated with the related transition’s name

  1. annotateSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum], ms1_features: pyopenms.FeatureMap, ms2_features: pyopenms.FeatureMap) -> list[pyopenms.MSSpectrum]

Annotates the MS2 spectra with the likely MS1 feature that it was derived from

Parameters:
  • spectra – The spectra to filter

  • ms1_features – The MS1 features

  • ms2_features – The MS2 features (filled by this method)

Returns:

The resulting annotated spectra

constructTransitionsList(ms1_features: pyopenms.FeatureMap, ms2_features: pyopenms.FeatureMap, t_exp: pyopenms.TargetedExperiment) → None#

Construct a transition list from MS1 and MS2 features

Parameters:
  • ms1_features – MS1 feature map

  • ms2_features – MS2 feature map

  • t_exp – Output TargetedExperiment

extractSpectra(experiment: pyopenms.MSExperiment, targeted_exp: pyopenms.TargetedExperiment, compute_features: bool) → tuple#
extractSpectra(experiment: pyopenms.MSExperiment, targeted_exp: pyopenms.TargetedExperiment) → list[pyopenms.MSSpectrum]
extractSpectra(experiment: pyopenms.MSExperiment, ms1_features: pyopenms.FeatureMap) → list[pyopenms.MSSpectrum]
extractSpectra(experiment: pyopenms.MSExperiment, ms1_features: pyopenms.FeatureMap, extracted_features: pyopenms.FeatureMap) → list[pyopenms.MSSpectrum]

Overloaded function.

  1. extractSpectra(experiment: pyopenms.MSExperiment, targeted_exp: pyopenms.TargetedExperiment, compute_features: bool) -> tuple

Complete pipeline: annotate, pick, score, and select spectra

Runs the full extraction workflow in a single call.

Parameters:
  • experiment – The input experiment

  • targeted_exp – The target list

  • compute_features – If False, no features are extracted

Returns:

Tuple of (extracted_spectra, extracted_features)

  1. extractSpectra(experiment: pyopenms.MSExperiment, targeted_exp: pyopenms.TargetedExperiment) -> list[pyopenms.MSSpectrum]

Complete extraction pipeline (without features)

Parameters:
  • experiment – The input experiment

  • targeted_exp – The target list

Returns:

The spectra related to the transitions

  1. extractSpectra(experiment: pyopenms.MSExperiment, ms1_features: pyopenms.FeatureMap) -> list[pyopenms.MSSpectrum]

Complete extraction pipeline using an MS1 feature map

Parameters:
  • experiment – The input experiment

  • ms1_features – The MS1 features map

Returns:

The spectra related to the transitions

  1. extractSpectra(experiment: pyopenms.MSExperiment, ms1_features: pyopenms.FeatureMap, extracted_features: pyopenms.FeatureMap) -> list[pyopenms.MSSpectrum]

Complete extraction pipeline using an MS1 feature map

Parameters:
  • experiment – The input experiment

  • ms1_features – The MS1 features map

  • extracted_features – Output features related to the extracted spectra

Returns:

The spectra related to the transitions

getDefaultParameters(params: pyopenms.Param) → None#
getDefaultParameters() → pyopenms.Param

Overloaded function.

  1. getDefaultParameters(params: pyopenms.Param) -> None

Get default parameters (fills output param)

  1. getDefaultParameters() -> pyopenms.Param

Get default parameters (returns Param)

getDefaults() → pyopenms.Param#

Returns the default parameters

getName() → str#

Returns the name

getParameters() → pyopenms.Param#

Returns the parameters

getSubsections() → list[str]#
mergeFeatures(fmap_input: pyopenms.FeatureMap, fmap_output: pyopenms.FeatureMap) → None#

Merge features from input to output map

Parameters:
  • fmap_input – Input feature map

  • fmap_output – Output feature map (modified in place)

pickSpectrum(spectrum: pyopenms.MSSpectrum, picked_spectrum: pyopenms.MSSpectrum) → None#

Smooth and pick peaks from a spectrum

Applies Gaussian or Savitzky-Golay smoothing followed by peak picking.

Parameters:
  • spectrum – Input spectrum

  • picked_spectrum – Output picked spectrum

scoreSpectra(annotated_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], picked_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], features: pyopenms.FeatureMap, compute_features: bool) → list[pyopenms.MSSpectrum]#
scoreSpectra(annotated_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], picked_spectra: collections.abc.Sequence[pyopenms.MSSpectrum]) → list[pyopenms.MSSpectrum]

Overloaded function.

  1. scoreSpectra(annotated_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], picked_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], features: pyopenms.FeatureMap, compute_features: bool) -> list[pyopenms.MSSpectrum]

Score spectra based on TIC, FWHM, and SNR

Scores are computed using configurable weights for each metric.

Parameters:
  • annotated_spectra – The annotated spectra to score (for TIC and SNR)

  • picked_spectra – The picked peaks found on each of the annotated spectra (for FWHM)

  • features – The score information is also added to this FeatureMap; picked peaks’ FWHMs are saved in the features’ subordinates

  • compute_features – If False, features will be ignored

Returns:

The scored spectra (a copy of annotated_spectra with the added score information)

  1. scoreSpectra(annotated_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], picked_spectra: collections.abc.Sequence[pyopenms.MSSpectrum]) -> list[pyopenms.MSSpectrum]

Score spectra based on TIC, FWHM, and SNR (without feature map)

Scores are computed using configurable weights for each metric.

Parameters:
  • annotated_spectra – The annotated spectra to score (for TIC and SNR)

  • picked_spectra – The picked peaks found on each of the annotated spectra (for FWHM)

Returns:

The scored spectra (a copy of annotated_spectra with the added score information)

searchSpectrum(feat_map: pyopenms.FeatureMap, feat_map_output: pyopenms.FeatureMap, add_unidentified_features: bool = False) → None#

Search accurate masses and add identification (peptide hits) as features/sub-features

Parameters:
  • feat_map – The feature map to search in

  • feat_map_output – The output feature map, with peptide identification as sub features (modified in place)

  • add_unidentified_features – Adds unidentified features to the feature map

selectSpectra(scored_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], features: pyopenms.FeatureMap, selected_features: pyopenms.FeatureMap, compute_features: bool) → list[pyopenms.MSSpectrum]#
selectSpectra(scored_spectra: collections.abc.Sequence[pyopenms.MSSpectrum]) → list[pyopenms.MSSpectrum]

Overloaded function.

  1. selectSpectra(scored_spectra: collections.abc.Sequence[pyopenms.MSSpectrum], features: pyopenms.FeatureMap, selected_features: pyopenms.FeatureMap, compute_features: bool) -> list[pyopenms.MSSpectrum]

Select the highest scoring spectrum for each transition

Parameters:
  • scored_spectra – Input annotated and scored spectra

  • features – Input features

  • selected_features – Output selected features

  • compute_features – If False, selected_features will be ignored

Returns:

The selected spectra

  1. selectSpectra(scored_spectra: collections.abc.Sequence[pyopenms.MSSpectrum]) -> list[pyopenms.MSSpectrum]

Select the highest scoring spectrum for each transition (without features)

Parameters:

scored_spectra – Input annotated and scored spectra

Returns:

The selected spectra

setName(name: str) → None#

Sets the name

setParameters(param: pyopenms.Param) → None#

Sets the parameters

storeSpectraMSP(filename: str, experiment: pyopenms.MSExperiment) → None#

Store spectra in MSP format

Parameters:
  • filename – Output filename

  • experiment – Experiment to store