OpenMS
Loading...
Searching...
No Matches
MassTraceDetection.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Erhan Kenar, Holger Franken, Mohammed Alhigaylan $
7// --------------------------------------------------------------------------
8
9#pragma once
10
16
17#include <vector>
18
19namespace OpenMS
20{
21
22 /*
23 @brief A mass trace extraction method that gathers peaks similar in m/z and moving along retention time.
24
25 Peaks of a @ref MSExperiment are sorted by their intensity and stored in a
26 list of potential chromatographic apex positions. Only peaks that are above
27 the noise threshold (user-defined) are analyzed and only peaks that are n
28 times above this minimal threshold are considered as apices. This saves
29 computational resources and decreases the noise in the resulting output.
30
31 Starting with these, mass traces are extended in- and decreasingly in
32 retention time. During this extension phase, the centroid m/z is computed
33 on-line as an intensity-weighted mean of peaks.
34
35 The extension phase ends when either the frequency of gathered peaks drops
36 below a threshold (min_sample_rate, see @ref MassTraceDetection parameters)
37 or when the number of missed scans exceeds a threshold
38 (trace_termination_outliers, see @ref MassTraceDetection parameters).
39
40 Finally, only mass traces that pass a filter (a certain minimal and maximal
41 length as well as having the minimal sample rate criterion fulfilled) get
42 added to the result.
43
44 @htmlinclude OpenMS_MassTraceDetection.parameters
45
46 @ingroup Quantitation
47 */
48 class OPENMS_DLLAPI MassTraceDetection :
50 public ProgressLogger
51 {
52 public:
55 {
57 SAMPLE_RATE
58 };
59
62
65
75 void run(const PeakMap &, std::vector<MassTrace> &, const Size max_traces = 0);
76
78 void run(PeakMap::ConstAreaIterator & begin, PeakMap::ConstAreaIterator & end, std::vector<MassTrace> & found_masstraces);
79
81 bool hasFwhmMz() const { return has_fwhm_mz_; }
82 bool hasFwhmIm() const { return has_fwhm_im_; }
83 bool hasCentroidIm() const { return has_centroid_im_; }
84
87 protected:
88 void updateMembers_() override;
90 static void updateIterativeWeightedMean_(const double& added_value,
91 const double& added_intensity,
92 double& centroid_value,
93 double& prev_counter,
94 double& prev_denom);
95
96 private:
97
98 struct Apex
99 {
100 Apex(double intensity, Size scan_idx, Size peak_idx);
101 double intensity;
104 };
105
108 {
110 double mz;
111 double intensity;
112 double im;
113 bool found;
114
115 PeakCandidate() : idx(0), mz(-1.0), intensity(-1.0), im(-1.0), found(false) {}
116 };
117
120 {
124 bool active;
125
126 TraceExtensionState() : scan_counter(0), hitting_peak_count(0), consecutive_missed(0), active(true) {}
127 };
128
130 void run_(const std::vector<Apex>& chrom_apices,
131 const Size peak_count,
132 const PeakMap & work_exp,
133 const std::vector<Size>& spec_offsets,
134 std::vector<MassTrace> & found_masstraces,
135 const Size max_traces = 0);
136
138 void getIMIndices_(const PeakMap& spectra,
139 int& fwhm_meta_idx, bool& has_fwhm_mz,
140 int& im_idx, bool& has_centroid_im,
141 int& im_fwhm_idx, bool& has_fwhm_im) const;
142
145 double centroid_mz,
146 double ftl_sd,
147 double centroid_im = -1.0) const;
148
150 bool isPeakAcceptable_(const PeakCandidate& candidate,
151 double centroid_mz,
152 double ftl_sd,
153 double centroid_im,
154 Size spectrum_idx,
155 const std::vector<Size>& spec_offsets,
156 const std::vector<bool>& peak_visited) const;
157
159 void processPeak_(const PeakCandidate& candidate,
160 const MSSpectrum& spectrum,
161 std::list<PeakType>& current_trace,
162 std::vector<std::pair<Size, Size>>& gathered_idx,
163 std::vector<double>& fwhms_mz,
164 std::vector<double>& fwhms_im,
165 double& centroid_mz,
166 double& centroid_im,
167 double& prev_counter,
168 double& prev_denom,
169 double& prev_counter_im,
170 double& prev_denom_im,
171 double& ftl_sd,
172 double& intensity_so_far,
173 Size spectrum_idx,
174 bool is_upward_extension);
175
176
178 bool isTraceValid_(const std::list<PeakType>& trace,
179 Size total_scans_visited,
180 Size consecutive_missed_down,
181 Size consecutive_missed_up) const;
182
183 // Metadata availability flags – set by getIMIndices_ and valid after run_()
184 bool has_fwhm_mz_ = false;
185 bool has_fwhm_im_ = false;
186 bool has_centroid_im_ = false;
187
188 // parameter stuff
195
201
203
204 // Metadata array indices - set during run_()
205 mutable int fwhm_meta_idx_ = -1;
206 mutable int ion_mobility_idx_ = -1;
207 mutable int im_fwhm_idx_ = -1;
208 };
209}
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Forward iterator for an area of peaks in an experiment.
Definition AreaIterator.h:36
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Definition MassTraceDetection.h:51
double ion_mobility_tolerance_
Definition MassTraceDetection.h:193
PeakCandidate findBestPeak_(const MSSpectrum &spectrum, double centroid_mz, double ftl_sd, double centroid_im=-1.0) const
Find the best matching peak in a spectrum considering m/z and optionally ion mobility.
TraceTerminationCriterion trace_termination_criterion_
Definition MassTraceDetection.h:196
double noise_threshold_int_
Definition MassTraceDetection.h:191
void getIMIndices_(const PeakMap &spectra, int &fwhm_meta_idx, bool &has_fwhm_mz, int &im_idx, bool &has_centroid_im, int &im_fwhm_idx, bool &has_fwhm_im) const
Internal helper to extract and validate metadata float array indices.
double mass_error_da_
Definition MassTraceDetection.h:190
double chrom_peak_snr_
Definition MassTraceDetection.h:192
bool hasCentroidIm() const
Definition MassTraceDetection.h:83
MassTrace::MT_QUANTMETHOD quant_method_
Definition MassTraceDetection.h:194
static void updateIterativeWeightedMean_(const double &added_value, const double &added_intensity, double &centroid_value, double &prev_counter, double &prev_denom)
allows for the iterative computation of intensity weighted of a mass trace's centroid m/z or ion mobi...
MassTraceDetection()
Default constructor.
bool isPeakAcceptable_(const PeakCandidate &candidate, double centroid_mz, double ftl_sd, double centroid_im, Size spectrum_idx, const std::vector< Size > &spec_offsets, const std::vector< bool > &peak_visited) const
Check if peak candidate meets acceptance criteria.
bool hasFwhmMz() const
determine if meta array is available
Definition MassTraceDetection.h:81
Size trace_termination_outliers_
Definition MassTraceDetection.h:197
double min_trace_length_
Definition MassTraceDetection.h:199
void run_(const std::vector< Apex > &chrom_apices, const Size peak_count, const PeakMap &work_exp, const std::vector< Size > &spec_offsets, std::vector< MassTrace > &found_masstraces, const Size max_traces=0)
The internal run method.
double min_sample_rate_
Definition MassTraceDetection.h:198
void run(const PeakMap &, std::vector< MassTrace > &, const Size max_traces=0)
~MassTraceDetection() override
Default destructor.
double mass_error_ppm_
Definition MassTraceDetection.h:189
TraceTerminationCriterion
Trace termination criteria enum for performance optimization.
Definition MassTraceDetection.h:55
@ OUTLIER
Terminate when consecutive outliers exceed threshold.
Definition MassTraceDetection.h:56
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
double max_trace_length_
Definition MassTraceDetection.h:200
bool isTraceValid_(const std::list< PeakType > &trace, Size total_scans_visited, Size consecutive_missed_down, Size consecutive_missed_up) const
Check if a mass trace meets quality criteria.
bool reestimate_mt_sd_
Definition MassTraceDetection.h:202
void processPeak_(const PeakCandidate &candidate, const MSSpectrum &spectrum, std::list< PeakType > &current_trace, std::vector< std::pair< Size, Size > > &gathered_idx, std::vector< double > &fwhms_mz, std::vector< double > &fwhms_im, double &centroid_mz, double &centroid_im, double &prev_counter, double &prev_denom, double &prev_counter_im, double &prev_denom_im, double &ftl_sd, double &intensity_so_far, Size spectrum_idx, bool is_upward_extension)
Process a single peak during trace extension.
bool hasFwhmIm() const
Definition MassTraceDetection.h:82
void run(PeakMap::ConstAreaIterator &begin, PeakMap::ConstAreaIterator &end, std::vector< MassTrace > &found_masstraces)
Invokes the run method (see above) on merely a subregion of a MSExperiment map.
MT_QUANTMETHOD
Definition MassTrace.h:39
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:28
if none is found
Definition common-cmake-parameters.doxygen:76
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition MassTraceDetection.h:99
Size scan_idx
Definition MassTraceDetection.h:102
Apex(double intensity, Size scan_idx, Size peak_idx)
double intensity
Definition MassTraceDetection.h:101
Size peak_idx
Definition MassTraceDetection.h:103
Encapsulates peak finding logic for both up and down directions.
Definition MassTraceDetection.h:108
double intensity
Definition MassTraceDetection.h:111
double mz
Definition MassTraceDetection.h:110
bool found
Definition MassTraceDetection.h:113
double im
Definition MassTraceDetection.h:112
Size idx
Definition MassTraceDetection.h:109
PeakCandidate()
Definition MassTraceDetection.h:115
Encapsulates trace extension state.
Definition MassTraceDetection.h:120
bool active
Definition MassTraceDetection.h:124
Size hitting_peak_count
Definition MassTraceDetection.h:122
Size scan_counter
Definition MassTraceDetection.h:121
TraceExtensionState()
Definition MassTraceDetection.h:126
Size consecutive_missed
Definition MassTraceDetection.h:123