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 class string;
23
35 class OPENMS_DLLAPI MassTrace
36 {
37public:
38
39 // must match to names_of_quantmethod[]
41 MT_QUANT_AREA = 0,
44 SIZE_OF_MT_QUANTMETHOD
45 };
46 static const std::string names_of_quantmethod[SIZE_OF_MT_QUANTMETHOD];
47
50
54
56 MassTrace() = default;
57
60 MassTrace(const std::list<PeakType>& trace_peaks);
61
63 MassTrace(const std::vector<PeakType>& trace_peaks);
64
66 ~MassTrace() = default;
67
69 MassTrace(const MassTrace &) = default;
70
72 MassTrace & operator=(const MassTrace &) = default;
73
75 PeakType& operator[](const Size & mt_idx);
76 const PeakType& operator[](const Size & mt_idx) const;
78
83 typedef std::vector<PeakType>::iterator iterator;
84 typedef std::vector<PeakType>::const_iterator const_iterator;
85 typedef std::vector<PeakType>::reverse_iterator reverse_iterator;
86 typedef std::vector<PeakType>::const_reverse_iterator const_reverse_iterator;
87
89 {
90 return trace_peaks_.begin();
91 }
92
94 {
95 return trace_peaks_.end();
96 }
97
99 {
100 return trace_peaks_.begin();
101 }
102
104 {
105 return trace_peaks_.end();
106 }
107
109 {
110 return trace_peaks_.rbegin();
111 }
112
114 {
115 return trace_peaks_.rend();
116 }
117
119 {
120 return trace_peaks_.rbegin();
121 }
122
124 {
125 return trace_peaks_.rend();
126 }
128
133
135 Size getSize() const
136 {
137 return trace_peaks_.size();
138 }
139
142 {
143 return label_;
144 }
145
147 void setLabel(const String & label)
148 {
149 label_ = label;
150 }
151
153 double getCentroidMZ() const
154 {
155 return centroid_mz_;
156 }
157
159 bool containsIMData() const
160 {
161 return has_centroid_im_;
162 }
163
165 double getCentroidIM() const
166 {
167 return centroid_im_;
168 }
169
171 double getCentroidRT() const
172 {
173 return centroid_rt_;
174 }
175
176 double getCentroidSD() const
177 {
178 return centroid_sd_;
179 }
180
181 void setCentroidSD(const double & tmp_sd)
182 {
183 centroid_sd_ = tmp_sd;
184 }
185
186 void setCentroidIM(const double & im)
187 {
188 centroid_im_ = im;
189 has_centroid_im_ = true;
190 }
191
192 double getFWHM() const
193 {
194 return fwhm_;
195 }
196
198 double getTraceLength() const
199 {
200 double length(0.0);
201
202 if (trace_peaks_.size() > 1)
203 {
204 length = std::fabs(trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT());
205 }
206
207 return length;
208 }
209
210 std::pair<Size, Size> getFWHMborders() const
211 {
212 return std::make_pair(fwhm_start_idx_, fwhm_end_idx_);
213 }
214
216 const std::vector<double>& getSmoothedIntensities() const
217 {
218 return smoothed_intensities_;
219 }
220
222 void setSmoothedIntensities(const std::vector<double> & db_vec)
223 {
224 if (trace_peaks_.size() != db_vec.size())
225 {
226 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
227 "Number of smoothed intensities deviates from mass trace size! Aborting...", String(db_vec.size()));
228 }
229
230 smoothed_intensities_ = db_vec;
231 }
232
235 {
236 if (trace_peaks_.size() <= 1) return 0.0;
237
238 return (trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT()) / (trace_peaks_.size() - 1);
239 }
241
245
248
250 double computePeakArea() const;
251
253 double computeIntensitySum() const;
254
256 Size findMaxByIntPeak(bool use_smoothed_ints = false) const;
257
261 double estimateFWHM(bool use_smoothed_ints = false);
262
265
268
270 double computeFwhmAreaSmooth() const;
271 double computeFwhmArea() const;
272 // double computeFwhmAreaSmoothRobust() const;
273 // double computeFwhmAreaRobust() const;
274
275 double getIntensity(bool smoothed) const;
276 double getMaxIntensity(bool smoothed) const;
277
281
285
287
290
292
295
298
301
304
312
315 double fwhm_mz_avg = 0;
316
319 double fwhm_im_avg = 0;
320
321private:
322
325
329 double linearInterpolationAtY_(double xA, double xB, double yA, double yB, double y_eval) const;
330
332 std::vector<PeakType> trace_peaks_;
333
335 double centroid_mz_ = 0.0;
336
338 double centroid_im_ = 0.0;
339
341 bool has_centroid_im_ = false;
342
344 double centroid_sd_ = 0.0;
345
347 double centroid_rt_ = 0.0;
348
351
353 std::vector<double> smoothed_intensities_;
354
355 double fwhm_ = 0.0;
356 Size fwhm_start_idx_ = 0;
357 Size fwhm_end_idx_ = 0;
358
360 MT_QUANTMETHOD quant_method_ = MT_QUANT_AREA;
361
362 };
363
364}
365
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:36
void setSmoothedIntensities(const std::vector< double > &db_vec)
Set smoothed intensities (smoothing is done externally, e.g. by LowessSmoothing).
Definition MassTrace.h:222
double computePeakArea() const
Compute area of peaks in the mass trace.
void updateMedianMZ()
Compute & update centroid m/z as median of m/z values.
String getLabel() const
Gets label of mass trace.
Definition MassTrace.h:141
const_reverse_iterator rend() const
Definition MassTrace.h:123
void updateMedianRT()
Compute & update centroid RT as median position of intensities.
double getCentroidMZ() const
Returns the centroid m/z.
Definition MassTrace.h:153
void setLabel(const String &label)
Sets label of mass trace.
Definition MassTrace.h:147
std::vector< PeakType >::const_reverse_iterator const_reverse_iterator
Definition MassTrace.h:86
const_iterator begin() const
Definition MassTrace.h:98
void setQuantMethod(MT_QUANTMETHOD method)
determine if area or median is used for quantification
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:135
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:198
double getFWHM() const
Definition MassTrace.h:192
double estimateFWHM(bool use_smoothed_ints=false)
bool containsIMData() const
Returns true if this mass trace contains ion mobility data.
Definition MassTrace.h:159
MassTrace & operator=(const MassTrace &)=default
Assignment operator.
static MT_QUANTMETHOD getQuantMethod(const String &val)
converts a string to enum value; returns 'SIZE_OF_MT_QUANTMETHOD' upon error
void setCentroidIM(const double &im)
Definition MassTrace.h:186
double computeMedianIntensity_() const
median of trace intensities
MassTrace()=default
Default constructor.
std::vector< PeakType >::const_iterator const_iterator
Definition MassTrace.h:84
double getIntensity(bool smoothed) const
reverse_iterator rend()
Definition MassTrace.h:113
std::pair< Size, Size > getFWHMborders() const
Definition MassTrace.h:210
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:85
MassTrace(const MassTrace &)=default
Copy constructor.
std::vector< double > smoothed_intensities_
Container for smoothed intensities. Smoothing must be done externally.
Definition MassTrace.h:353
double computeSmoothedPeakArea() const
Sum all non-negative (smoothed!) intensities in the mass trace.
String label_
Trace label.
Definition MassTrace.h:350
const PeakType & operator[](const Size &mt_idx) const
double getCentroidRT() const
Returns the centroid RT.
Definition MassTrace.h:171
double getCentroidSD() const
Definition MassTrace.h:176
void updateSmoothedWeightedMeanRT()
double computeFwhmArea() const
void updateMeanMZ()
Compute & update centroid m/z as mean of m/z values.
void updateSmoothedMaxRT()
std::vector< PeakType >::iterator iterator
Definition MassTrace.h:83
double getCentroidIM() const
Returns the centroid ion mobility.
Definition MassTrace.h:165
~MassTrace()=default
Destructor.
double getAverageMS1CycleTime() const
Get average scan time of mass trace.
Definition MassTrace.h:234
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:93
const_iterator end() const
Definition MassTrace.h:103
reverse_iterator rbegin()
Definition MassTrace.h:108
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:181
iterator begin()
Definition MassTrace.h:88
const std::vector< double > & getSmoothedIntensities() const
Gets smoothed intensities (empty if no smoothing was explicitly done beforehand!).
Definition MassTrace.h:216
MT_QUANTMETHOD
Definition MassTrace.h:40
@ MT_QUANT_MEDIAN
quantify by median of intensities
Definition MassTrace.h:42
@ MT_QUANT_HEIGHT
quantify by peak height
Definition MassTrace.h:43
std::vector< PeakType > trace_peaks_
Actual MassTrace container for doing centroid calculation, peak width estimation etc.
Definition MassTrace.h:332
const_reverse_iterator rbegin() const
Definition MassTrace.h:118
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
A more convenient string class.
Definition String.h:34
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