OpenMS
Loading...
Searching...
No Matches
FeatureMapping Class Reference

Helper utilities for matching MS2 spectra to LC-MS features by precursor (m/z, RT). More...

#include <OpenMS/ANALYSIS/MAPMATCHING/FeatureMapping.h>

Classes

class  FeatureMappingInfo
 Input bundle: feature maps and a spatial index over them. More...
 
class  FeatureToMs2Indices
 Output bundle: per-feature MS2 spectrum indices + the list of unassigned MS2 spectra. More...
 

Static Public Member Functions

static FeatureToMs2Indices assignMS2IndexToFeature (const MSExperiment &spectra, const FeatureMappingInfo &fm_info, const double &precursor_mz_tolerance, const double &precursor_rt_tolerance, bool ppm)
 Assign each MS2 spectrum to the feature whose precursor matches it best.
 

Detailed Description

Helper utilities for matching MS2 spectra to LC-MS features by precursor (m/z, RT).

The class is a thin namespace holding two nested record types and one static algorithm:

A typical caller builds a FeatureMappingInfo once (loading the maps and constructing the kd-tree), then calls assignMS2IndexToFeature per MS run. The kd-tree must be built from the same maps stored in feature_maps so that the indices returned by range queries refer back into the caller-visible feature pointers.

Workflows that use this include SIRIUS export and other "annotate MS2 with quantified feature" pipelines.


Class Documentation

◆ OpenMS::FeatureMapping::FeatureMappingInfo

class OpenMS::FeatureMapping::FeatureMappingInfo

Input bundle: feature maps and a spatial index over them.

feature_maps owns the raw FeatureMap objects (one per input run); kd_tree is a KDTreeFeatureMaps pre-populated with the same features and provides fast (RT, m/z) range queries. The caller is responsible for keeping the two consistent (i.e. building the kd-tree from the same maps stored here).

Collaboration diagram for FeatureMapping::FeatureMappingInfo:
[legend]
Class Members
vector< FeatureMap > feature_maps feature data, one map per input run
KDTreeFeatureMaps kd_tree (RT, m/z) kd-tree referencing the features in feature_maps

◆ OpenMS::FeatureMapping::FeatureToMs2Indices

class OpenMS::FeatureMapping::FeatureToMs2Indices

Output bundle: per-feature MS2 spectrum indices + the list of unassigned MS2 spectra.

Keys of assignedMS2 are non-owning pointers into the FeatureMap data held by the FeatureMappingInfo passed to assignMS2IndexToFeature; the values are spectrum indices into the spectra input. unassignedMS2 holds the indices of MS2 spectra that had at least one precursor but no feature inside the tolerance window (MS2 spectra without a precursor are silently dropped and appear in neither container).

Collaboration diagram for FeatureMapping::FeatureToMs2Indices:
[legend]
Class Members
map< const BaseFeature *, vector< size_t > > assignedMS2 MS2 spectrum indices grouped by the feature they were assigned to.
vector< size_t > unassignedMS2 Indices of MS2 spectra that had a precursor but no feature inside the tolerance window.

Member Function Documentation

◆ assignMS2IndexToFeature()

static FeatureToMs2Indices assignMS2IndexToFeature ( const MSExperiment spectra,
const FeatureMappingInfo fm_info,
const double &  precursor_mz_tolerance,
const double &  precursor_rt_tolerance,
bool  ppm 
)
static

Assign each MS2 spectrum to the feature whose precursor matches it best.

For every MS2 spectrum in spectra:

  • Spectra at MS level != 2 are skipped.
  • Spectra with no precursor are silently dropped (not added to unassignedMS2).
  • Spectra with at least one precursor are matched against features in fm_info.kd_tree using a rectangular tolerance window: RT: precursor_rt_tolerance (absolute, around the spectrum's RT) m/z: precursor_mz_tolerance (ppm if ppm is true, otherwise Th, around the first precursor's m/z) Features from any map are eligible (the kd-tree query is run with include_features_from_same_map = true).
  • If no feature falls in the window, the spectrum index is appended to unassignedMS2.
  • If several features fall in the window, the one with the smallest absolute m/z difference to the precursor wins (RT is not used as a tie-breaker).
  • Only the first precursor of the spectrum is considered (chimeric / multi-precursor spectra are matched against precursors()[0] only).

The result groups spectrum indices by their winning feature; each spectrum index appears at most once in either the assigned or the unassigned collection.

Parameters
[in]spectraRun-level spectrum container (MS1 and MS2 mixed; MS2 spectra are processed).
[in]fm_infoFeature maps + kd-tree bundle (the kd-tree must reference fm_info.feature_maps).
[in]precursor_mz_toleranceHalf-width of the m/z tolerance window (ppm if ppm, else Th).
[in]precursor_rt_toleranceHalf-width of the RT tolerance window in seconds (absolute).
[in]ppmIf true, interpret precursor_mz_tolerance as ppm; otherwise as Th.
Returns
Mapping result containing one entry per matched feature plus the list of unassigned MS2 spectra.