OpenMS
Loading...
Searching...
No Matches
MassTrace.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, Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13
14
15#include <vector>
16#include <list>
17#include <map>
18
19namespace OpenMS
20{
22
34 class OPENMS_DLLAPI MassTrace
35 {
36public:
37
38 // must match to names_of_quantmethod[]
40 MT_QUANT_AREA = 0,
43 SIZE_OF_MT_QUANTMETHOD
44 };
45 static const std::string names_of_quantmethod[SIZE_OF_MT_QUANTMETHOD];
46
48 static MT_QUANTMETHOD getQuantMethod(const std::string& val);
49
53
55 MassTrace() = default;
56
59 MassTrace(const std::list<PeakType>& trace_peaks);
60
62 MassTrace(const std::vector<PeakType>& trace_peaks);
63
65 ~MassTrace() = default;
66
68 MassTrace(const MassTrace &) = default;
69
71 MassTrace & operator=(const MassTrace &) = default;
72
74 PeakType& operator[](const Size & mt_idx);
75 const PeakType& operator[](const Size & mt_idx) const;
77
82 typedef std::vector<PeakType>::iterator iterator;
83 typedef std::vector<PeakType>::const_iterator const_iterator;
84 typedef std::vector<PeakType>::reverse_iterator reverse_iterator;
85 typedef std::vector<PeakType>::const_reverse_iterator const_reverse_iterator;
86
88 {
89 return trace_peaks_.begin();
90 }
91
93 {
94 return trace_peaks_.end();
95 }
96
98 {
99 return trace_peaks_.begin();
100 }
101
103 {
104 return trace_peaks_.end();
105 }
106
108 {
109 return trace_peaks_.rbegin();
110 }
111
113 {
114 return trace_peaks_.rend();
115 }
116
118 {
119 return trace_peaks_.rbegin();
120 }
121
123 {
124 return trace_peaks_.rend();
125 }
127
132
134 Size getSize() const
135 {
136 return trace_peaks_.size();
137 }
138
140 std::string getLabel() const
141 {
142 return label_;
143 }
144
146 void setLabel(const std::string & label)
147 {
148 label_ = label;
149 }
150
152 double getCentroidMZ() const
153 {
154 return centroid_mz_;
155 }
156
158 bool containsIMData() const
159 {
160 return has_centroid_im_;
161 }
162
164 double getCentroidIM() const
165 {
166 return centroid_im_;
167 }
168
170 double getCentroidRT() const
171 {
172 return centroid_rt_;
173 }
174
175 double getCentroidSD() const
176 {
177 return centroid_sd_;
178 }
179
180 void setCentroidSD(const double & tmp_sd)
181 {
182 centroid_sd_ = tmp_sd;
183 }
184
185 void setCentroidIM(const double & im)
186 {
187 centroid_im_ = im;
188 has_centroid_im_ = true;
189 }
190
191 double getFWHM() const
192 {
193 return fwhm_;
194 }
195
197 double getTraceLength() const
198 {
199 double length(0.0);
200
201 if (trace_peaks_.size() > 1)
202 {
203 length = std::fabs(trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT());
204 }
205
206 return length;
207 }
208
209 std::pair<Size, Size> getFWHMborders() const
210 {
211 return std::make_pair(fwhm_start_idx_, fwhm_end_idx_);
212 }
213
215 const std::vector<double>& getSmoothedIntensities() const
216 {
217 return smoothed_intensities_;
218 }
219
221 void setSmoothedIntensities(const std::vector<double> & db_vec)
222 {
223 if (trace_peaks_.size() != db_vec.size())
224 {
225 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
226 "Number of smoothed intensities deviates from mass trace size! Aborting...",StringUtils::toStr(db_vec.size()));
227 }
228
229 smoothed_intensities_ = db_vec;
230 }
231
234 {
235 if (trace_peaks_.size() <= 1) return 0.0;
236
237 return (trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT()) / (trace_peaks_.size() - 1);
238 }
240
244
247
249 double computePeakArea() const;
250
252 double computeIntensitySum() const;
253
255 Size findMaxByIntPeak(bool use_smoothed_ints = false) const;
256
260 double estimateFWHM(bool use_smoothed_ints = false);
261
264
267
269 double computeFwhmAreaSmooth() const;
270 double computeFwhmArea() const;
271 // double computeFwhmAreaSmoothRobust() const;
272 // double computeFwhmAreaRobust() const;
273
286 double getIntensity(bool smoothed) const;
287 double getMaxIntensity(bool smoothed) const;
288
292
296
298
301
303
306
309
312
315
323
326 double fwhm_mz_avg = 0;
327
330 double fwhm_im_avg = 0;
331
332private:
333
336
344 double linearInterpolationAtY_(double xA, double xB, double yA, double yB, double y_eval) const;
345
347 std::vector<PeakType> trace_peaks_;
348
350 double centroid_mz_ = 0.0;
351
353 double centroid_im_ = 0.0;
354
356 bool has_centroid_im_ = false;
357
359 double centroid_sd_ = 0.0;
360
362 double centroid_rt_ = 0.0;
363
365 std::string label_;
366
368 std::vector<double> smoothed_intensities_;
369
370 double fwhm_ = 0.0;
371 Size fwhm_start_idx_ = 0;
372 Size fwhm_end_idx_ = 0;
373
375 MT_QUANTMETHOD quant_method_ = MT_QUANT_AREA;
376
377 };
378
379}
380
Definition ConvexHull2D.h:49
Invalid value exception.
Definition Exception.h:306
A container type that gathers peaks similar in m/z and moving along retention time.
Definition MassTrace.h:35
void setSmoothedIntensities(const std::vector< double > &db_vec)
Set smoothed intensities (smoothing is done externally, e.g. by LowessSmoothing).
Definition MassTrace.h:221
double computePeakArea() const
Compute area of peaks in the mass trace.
void updateMedianMZ()
Compute & update centroid m/z as median of m/z values.
const_reverse_iterator rend() const
Definition MassTrace.h:122
void updateMedianRT()
Compute & update centroid RT as median position of intensities.
double getCentroidMZ() const
Returns the centroid m/z.
Definition MassTrace.h:152
std::vector< PeakType >::const_reverse_iterator const_reverse_iterator
Definition MassTrace.h:85
const_iterator begin() const
Definition MassTrace.h:97
void setQuantMethod(MT_QUANTMETHOD method)
determine if area or median is used for quantification
std::string label_
Trace label.
Definition MassTrace.h:365
MT_QUANTMETHOD getQuantMethod() const
check if area or median is used for quantification
Size getSize() const
Returns the number of peaks contained in the mass trace.
Definition MassTrace.h:134
Size findMaxByIntPeak(bool use_smoothed_ints=false) const
Return the index of the mass trace's highest peak within the MassTrace container (based either on raw...
PeakType & operator[](const Size &mt_idx)
Random access operator.
double getTraceLength() const
Returns the length of the trace (as difference in RT)
Definition MassTrace.h:197
double getFWHM() const
Definition MassTrace.h:191
double estimateFWHM(bool use_smoothed_ints=false)
bool containsIMData() const
Returns true if this mass trace contains ion mobility data.
Definition MassTrace.h:158
MassTrace & operator=(const MassTrace &)=default
Assignment operator.
void setCentroidIM(const double &im)
Definition MassTrace.h:185
double computeMedianIntensity_() const
median of trace intensities
MassTrace()=default
Default constructor.
std::vector< PeakType >::const_iterator const_iterator
Definition MassTrace.h:83
double getIntensity(bool smoothed) const
Returns the quantitated value of the mass trace according to the configured quantitation method (see ...
reverse_iterator rend()
Definition MassTrace.h:112
std::pair< Size, Size > getFWHMborders() const
Definition MassTrace.h:209
MassTrace(const std::vector< PeakType > &trace_peaks)
Detailed constructor for vector.
double computeFwhmAreaSmooth() const
Compute chromatographic peak area within the FWHM range.
double linearInterpolationAtY_(double xA, double xB, double yA, double yB, double y_eval) const
std::vector< PeakType >::reverse_iterator reverse_iterator
Definition MassTrace.h:84
MassTrace(const MassTrace &)=default
Copy constructor.
void setLabel(const std::string &label)
Sets label of mass trace.
Definition MassTrace.h:146
std::vector< double > smoothed_intensities_
Container for smoothed intensities. Smoothing must be done externally.
Definition MassTrace.h:368
double computeSmoothedPeakArea() const
Sum all non-negative (smoothed!) intensities in the mass trace.
const PeakType & operator[](const Size &mt_idx) const
static MT_QUANTMETHOD getQuantMethod(const std::string &val)
converts a string to enum value; returns 'SIZE_OF_MT_QUANTMETHOD' upon error
double getCentroidRT() const
Returns the centroid RT.
Definition MassTrace.h:170
double getCentroidSD() const
Definition MassTrace.h:175
void updateSmoothedWeightedMeanRT()
double computeFwhmArea() const
void updateMeanMZ()
Compute & update centroid m/z as mean of m/z values.
void updateSmoothedMaxRT()
std::string getLabel() const
Gets label of mass trace.
Definition MassTrace.h:140
std::vector< PeakType >::iterator iterator
Definition MassTrace.h:82
double getCentroidIM() const
Returns the centroid ion mobility.
Definition MassTrace.h:164
~MassTrace()=default
Destructor.
double getAverageMS1CycleTime() const
Get average scan time of mass trace.
Definition MassTrace.h:233
ConvexHull2D getConvexhull() const
Return the mass trace's convex hull.
void updateWeightedMeanRT()
Compute & update centroid RT as a intensity-weighted mean of RTs.
iterator end()
Definition MassTrace.h:92
const_iterator end() const
Definition MassTrace.h:102
reverse_iterator rbegin()
Definition MassTrace.h:107
void updateWeightedMZsd()
Compute & update m/z standard deviation of mass trace as weighted mean of m/z values.
MassTrace(const std::list< PeakType > &trace_peaks)
void setCentroidSD(const double &tmp_sd)
Definition MassTrace.h:180
iterator begin()
Definition MassTrace.h:87
const std::vector< double > & getSmoothedIntensities() const
Gets smoothed intensities (empty if no smoothing was explicitly done beforehand!).
Definition MassTrace.h:215
MT_QUANTMETHOD
Definition MassTrace.h:39
@ MT_QUANT_MEDIAN
quantify by median of intensities
Definition MassTrace.h:41
@ MT_QUANT_HEIGHT
quantify by peak height
Definition MassTrace.h:42
std::vector< PeakType > trace_peaks_
Actual MassTrace container for doing centroid calculation, peak width estimation etc.
Definition MassTrace.h:347
const_reverse_iterator rbegin() const
Definition MassTrace.h:117
void updateWeightedMeanMZ()
Compute & update centroid m/z as weighted mean of m/z values.
double getMaxIntensity(bool smoothed) const
double computeIntensitySum() const
Sum all peak intensities in the mass trace.
A 2-dimensional raw data point or peak.
Definition Peak2D.h:30
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
Peak2D PeakType
Definition MassTrace.h:21