OpenMS  2.4.0
MassTrace.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2018.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Erhan Kenar, Holger Franken, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/KERNEL/Peak2D.h>
39 
40 
41 #include <vector>
42 #include <list>
43 #include <map>
44 
45 namespace OpenMS
46 {
47  typedef Peak2D PeakType;
48  class string;
49 
61  class OPENMS_DLLAPI MassTrace
62  {
63 public:
64 
65  // must match to names_of_quantmethod[]
67  MT_QUANT_AREA = 0,
69  SIZE_OF_MT_QUANTMETHOD
70  };
71  static const std::string names_of_quantmethod[SIZE_OF_MT_QUANTMETHOD];
72 
74  static MT_QUANTMETHOD getQuantMethod(const String& val);
75 
78 
81  MassTrace();
82 
85  MassTrace(const std::list<PeakType>& trace_peaks);
86 
88  MassTrace(const std::vector<PeakType>& trace_peaks);
89 
91  ~MassTrace();
92 
94  MassTrace(const MassTrace &);
95 
97  MassTrace & operator=(const MassTrace &);
98 
100  PeakType& operator[](const Size & mt_idx);
101  const PeakType& operator[](const Size & mt_idx) const;
103 
107  typedef std::vector<PeakType>::iterator iterator;
109  typedef std::vector<PeakType>::const_iterator const_iterator;
110  typedef std::vector<PeakType>::reverse_iterator reverse_iterator;
111  typedef std::vector<PeakType>::const_reverse_iterator const_reverse_iterator;
112 
114  {
115  return trace_peaks_.begin();
116  }
117 
119  {
120  return trace_peaks_.end();
121  }
122 
124  {
125  return trace_peaks_.begin();
126  }
127 
129  {
130  return trace_peaks_.end();
131  }
132 
134  {
135  return trace_peaks_.rbegin();
136  }
137 
139  {
140  return trace_peaks_.rend();
141  }
142 
144  {
145  return trace_peaks_.rbegin();
146  }
147 
149  {
150  return trace_peaks_.rend();
151  }
153 
157 
160  Size getSize() const
161  {
162  return trace_peaks_.size();
163  }
164 
166  String getLabel() const
167  {
168  return label_;
169  }
170 
172  void setLabel(const String & label)
173  {
174  label_ = label;
175  }
176 
178  double getCentroidMZ() const
179  {
180  return centroid_mz_;
181  }
182 
184  double getCentroidRT() const
185  {
186  return centroid_rt_;
187  }
188 
189  double getCentroidSD() const
190  {
191  return centroid_sd_;
192  }
193 
194  void setCentroidSD(const double & tmp_sd)
195  {
196  centroid_sd_ = tmp_sd;
197  }
198 
199  double getFWHM() const
200  {
201  return fwhm_;
202  }
203 
205  double getTraceLength() const
206  {
207  double length(0.0);
208 
209  if (trace_peaks_.size() > 1)
210  {
211  length = std::fabs(trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT());
212  }
213 
214  return length;
215  }
216 
217  std::pair<Size, Size> getFWHMborders() const
218  {
219  return std::make_pair(fwhm_start_idx_, fwhm_end_idx_);
220  }
221 
223  const std::vector<double>& getSmoothedIntensities() const
224  {
225  return smoothed_intensities_;
226  }
227 
229  void setSmoothedIntensities(const std::vector<double> & db_vec)
230  {
231  if (trace_peaks_.size() != db_vec.size())
232  {
233  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
234  "Number of smoothed intensities deviates from mass trace size! Aborting...", String(db_vec.size()));
235  }
236 
237  smoothed_intensities_ = db_vec;
238  }
239 
241  double getAverageMS1CycleTime() const
242  {
243  if (trace_peaks_.size() <= 1) return 0.0;
244 
245  return (trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT()) / (trace_peaks_.size() - 1);
246  }
248 
251 
254  double computeSmoothedPeakArea() const;
255 
257  double computePeakArea() const;
258 
260  Size findMaxByIntPeak(bool use_smoothed_ints = false) const;
261 
265  double estimateFWHM(bool use_smoothed_ints = false);
266 
268  void setQuantMethod(MT_QUANTMETHOD method);
269 
271  MT_QUANTMETHOD getQuantMethod() const;
272 
274  double computeFwhmAreaSmooth() const;
275  double computeFwhmArea() const;
276  // double computeFwhmAreaSmoothRobust() const;
277  // double computeFwhmAreaRobust() const;
278 
279  double getIntensity(bool smoothed) const;
280  double getMaxIntensity(bool smoothed) const;
281 
283  ConvexHull2D getConvexhull() const;
285 
288 
290  void updateSmoothedMaxRT();
291 
293  void updateWeightedMeanRT();
294 
295  void updateSmoothedWeightedMeanRT();
296 
298  void updateMedianRT();
299 
301  void updateMedianMZ();
302 
304  void updateMeanMZ();
305 
307  void updateWeightedMeanMZ();
308 
314  void updateWeightedMZsd();
316 
318  double fwhm_mz_avg;
319 
320 private:
321 
323  double computeMedianIntensity_() const;
324 
328  double linearInterpolationAtY_(double xA, double xB, double yA, double yB, double y_eval) const;
329 
331  std::vector<PeakType> trace_peaks_;
332 
334  double centroid_mz_;
335 
337  double centroid_sd_;
338 
340  double centroid_rt_;
341 
344 
346  std::vector<double> smoothed_intensities_;
347 
348  double fwhm_;
351 
354 
355  };
356 
357 }
358 
iterator end()
Definition: MassTrace.h:118
A more convenient string class.
Definition: String.h:57
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
void setSmoothedIntensities(const std::vector< double > &db_vec)
Set smoothed intensities (smoothing is done externally, e.g. by LowessSmoothing). ...
Definition: MassTrace.h:229
MT_QUANTMETHOD quant_method_
use area under mass trace or the median of intensities
Definition: MassTrace.h:353
Peak2D PeakType
Definition: MassTrace.h:47
MT_QUANTMETHOD
Definition: MassTrace.h:66
double centroid_sd_
intensity-weighted STD
Definition: MassTrace.h:337
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
reverse_iterator rbegin()
Definition: MassTrace.h:133
A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling...
Definition: ConvexHull2D.h:72
std::vector< PeakType >::const_iterator const_iterator
Definition: MassTrace.h:109
double getTraceLength() const
Returns the length of the trace (as difference in RT)
Definition: MassTrace.h:205
double centroid_rt_
Centroid RT.
Definition: MassTrace.h:340
const_iterator begin() const
Definition: MassTrace.h:123
std::vector< PeakType >::iterator iterator
Definition: MassTrace.h:108
double getCentroidRT() const
Returns the centroid RT.
Definition: MassTrace.h:184
quantify by median of intensities
Definition: MassTrace.h:68
double getCentroidMZ() const
Returns the centroid m/z.
Definition: MassTrace.h:178
double getAverageMS1CycleTime() const
Get average scan time of mass trace.
Definition: MassTrace.h:241
std::vector< PeakType >::reverse_iterator reverse_iterator
Definition: MassTrace.h:110
void setCentroidSD(const double &tmp_sd)
Definition: MassTrace.h:194
iterator begin()
Definition: MassTrace.h:113
double getCentroidSD() const
Definition: MassTrace.h:189
Size fwhm_end_idx_
index into &#39;trace_peaks_&#39; vector (inclusive)
Definition: MassTrace.h:350
const std::vector< double > & getSmoothedIntensities() const
Gets smoothed intensities (empty if no smoothing was explicitly done beforehand!).
Definition: MassTrace.h:223
std::vector< PeakType > trace_peaks_
Actual MassTrace container for doing centroid calculation, peak width estimation etc.
Definition: MassTrace.h:331
double centroid_mz_
Centroid m/z.
Definition: MassTrace.h:334
double fwhm_
FWHM of RT peak.
Definition: MassTrace.h:348
std::vector< PeakType >::const_reverse_iterator const_reverse_iterator
Definition: MassTrace.h:111
Invalid value exception.
Definition: Exception.h:335
std::vector< double > smoothed_intensities_
Container for smoothed intensities. Smoothing must be done externally.
Definition: MassTrace.h:346
double getFWHM() const
Definition: MassTrace.h:199
const_reverse_iterator rbegin() const
Definition: MassTrace.h:143
reverse_iterator rend()
Definition: MassTrace.h:138
Size fwhm_start_idx_
index into &#39;trace_peaks_&#39; vector (inclusive)
Definition: MassTrace.h:349
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
void setLabel(const String &label)
Sets label of mass trace.
Definition: MassTrace.h:172
const_iterator end() const
Definition: MassTrace.h:128
String label_
Trace label.
Definition: MassTrace.h:343
Size getSize() const
Returns the number of peaks contained in the mass trace.
Definition: MassTrace.h:160
double fwhm_mz_avg
Average FWHM of m/z peaks.
Definition: MassTrace.h:318
A container type that gathers peaks similar in m/z and moving along retention time.
Definition: MassTrace.h:61
const_reverse_iterator rend() const
Definition: MassTrace.h:148
std::pair< Size, Size > getFWHMborders() const
Definition: MassTrace.h:217
String getLabel() const
Gets label of mass trace.
Definition: MassTrace.h:166