OpenMS  2.6.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-2020.
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,
70  SIZE_OF_MT_QUANTMETHOD
71  };
72  static const std::string names_of_quantmethod[SIZE_OF_MT_QUANTMETHOD];
73 
75  static MT_QUANTMETHOD getQuantMethod(const String& val);
76 
79 
82  MassTrace();
83 
86  MassTrace(const std::list<PeakType>& trace_peaks);
87 
89  MassTrace(const std::vector<PeakType>& trace_peaks);
90 
92  ~MassTrace();
93 
95  MassTrace(const MassTrace &);
96 
98  MassTrace & operator=(const MassTrace &);
99 
101  PeakType& operator[](const Size & mt_idx);
102  const PeakType& operator[](const Size & mt_idx) const;
104 
108  typedef std::vector<PeakType>::iterator iterator;
110  typedef std::vector<PeakType>::const_iterator const_iterator;
111  typedef std::vector<PeakType>::reverse_iterator reverse_iterator;
112  typedef std::vector<PeakType>::const_reverse_iterator const_reverse_iterator;
113 
115  {
116  return trace_peaks_.begin();
117  }
118 
120  {
121  return trace_peaks_.end();
122  }
123 
125  {
126  return trace_peaks_.begin();
127  }
128 
130  {
131  return trace_peaks_.end();
132  }
133 
135  {
136  return trace_peaks_.rbegin();
137  }
138 
140  {
141  return trace_peaks_.rend();
142  }
143 
145  {
146  return trace_peaks_.rbegin();
147  }
148 
150  {
151  return trace_peaks_.rend();
152  }
154 
158 
161  Size getSize() const
162  {
163  return trace_peaks_.size();
164  }
165 
167  String getLabel() const
168  {
169  return label_;
170  }
171 
173  void setLabel(const String & label)
174  {
175  label_ = label;
176  }
177 
179  double getCentroidMZ() const
180  {
181  return centroid_mz_;
182  }
183 
185  double getCentroidRT() const
186  {
187  return centroid_rt_;
188  }
189 
190  double getCentroidSD() const
191  {
192  return centroid_sd_;
193  }
194 
195  void setCentroidSD(const double & tmp_sd)
196  {
197  centroid_sd_ = tmp_sd;
198  }
199 
200  double getFWHM() const
201  {
202  return fwhm_;
203  }
204 
206  double getTraceLength() const
207  {
208  double length(0.0);
209 
210  if (trace_peaks_.size() > 1)
211  {
212  length = std::fabs(trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT());
213  }
214 
215  return length;
216  }
217 
218  std::pair<Size, Size> getFWHMborders() const
219  {
220  return std::make_pair(fwhm_start_idx_, fwhm_end_idx_);
221  }
222 
224  const std::vector<double>& getSmoothedIntensities() const
225  {
226  return smoothed_intensities_;
227  }
228 
230  void setSmoothedIntensities(const std::vector<double> & db_vec)
231  {
232  if (trace_peaks_.size() != db_vec.size())
233  {
234  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
235  "Number of smoothed intensities deviates from mass trace size! Aborting...", String(db_vec.size()));
236  }
237 
238  smoothed_intensities_ = db_vec;
239  }
240 
242  double getAverageMS1CycleTime() const
243  {
244  if (trace_peaks_.size() <= 1) return 0.0;
245 
246  return (trace_peaks_.rbegin()->getRT() - trace_peaks_.begin()->getRT()) / (trace_peaks_.size() - 1);
247  }
249 
252 
255  double computeSmoothedPeakArea() const;
256 
258  double computePeakArea() const;
259 
261  Size findMaxByIntPeak(bool use_smoothed_ints = false) const;
262 
266  double estimateFWHM(bool use_smoothed_ints = false);
267 
269  void setQuantMethod(MT_QUANTMETHOD method);
270 
272  MT_QUANTMETHOD getQuantMethod() const;
273 
275  double computeFwhmAreaSmooth() const;
276  double computeFwhmArea() const;
277  // double computeFwhmAreaSmoothRobust() const;
278  // double computeFwhmAreaRobust() const;
279 
280  double getIntensity(bool smoothed) const;
281  double getMaxIntensity(bool smoothed) const;
282 
284  ConvexHull2D getConvexhull() const;
286 
289 
291  void updateSmoothedMaxRT();
292 
294  void updateWeightedMeanRT();
295 
296  void updateSmoothedWeightedMeanRT();
297 
299  void updateMedianRT();
300 
302  void updateMedianMZ();
303 
305  void updateMeanMZ();
306 
308  void updateWeightedMeanMZ();
309 
315  void updateWeightedMZsd();
317 
319  double fwhm_mz_avg;
320 
321 private:
322 
324  double computeMedianIntensity_() const;
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_;
336 
338  double centroid_sd_;
339 
341  double centroid_rt_;
342 
345 
347  std::vector<double> smoothed_intensities_;
348 
349  double fwhm_;
352 
355 
356  };
357 
358 }
359 
OpenMS::PeakType
Peak2D PeakType
Definition: MassTrace.h:47
OpenMS::MassTrace::fwhm_end_idx_
Size fwhm_end_idx_
index into 'trace_peaks_' vector (inclusive)
Definition: MassTrace.h:351
OpenMS::MassTrace::rend
reverse_iterator rend()
Definition: MassTrace.h:139
OpenMS::MassTrace::label_
String label_
Trace label.
Definition: MassTrace.h:344
OpenMS::MassTrace::begin
const_iterator begin() const
Definition: MassTrace.h:124
OpenMS::MassTrace::setLabel
void setLabel(const String &label)
Sets label of mass trace.
Definition: MassTrace.h:173
OpenMS::MassTrace::trace_peaks_
std::vector< PeakType > trace_peaks_
Actual MassTrace container for doing centroid calculation, peak width estimation etc.
Definition: MassTrace.h:332
OpenMS::MassTrace::centroid_sd_
double centroid_sd_
intensity-weighted STD
Definition: MassTrace.h:338
OpenMS::MassTrace::const_iterator
std::vector< PeakType >::const_iterator const_iterator
Definition: MassTrace.h:110
OpenMS::MassTrace::iterator
std::vector< PeakType >::iterator iterator
Definition: MassTrace.h:109
OpenMS::MassTrace::rbegin
reverse_iterator rbegin()
Definition: MassTrace.h:134
OpenMS::MassTrace::getSmoothedIntensities
const std::vector< double > & getSmoothedIntensities() const
Gets smoothed intensities (empty if no smoothing was explicitly done beforehand!).
Definition: MassTrace.h:224
OpenMS::Exception::InvalidValue
Invalid value exception.
Definition: Exception.h:335
OpenMS::MassTrace::smoothed_intensities_
std::vector< double > smoothed_intensities_
Container for smoothed intensities. Smoothing must be done externally.
Definition: MassTrace.h:347
OpenMS::Peak2D
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
OpenMS::MassTrace::fwhm_mz_avg
double fwhm_mz_avg
Average FWHM of m/z peaks.
Definition: MassTrace.h:319
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::MassTrace::setSmoothedIntensities
void setSmoothedIntensities(const std::vector< double > &db_vec)
Set smoothed intensities (smoothing is done externally, e.g. by LowessSmoothing).
Definition: MassTrace.h:230
OpenMS::MassTrace
A container type that gathers peaks similar in m/z and moving along retention time.
Definition: MassTrace.h:61
OpenMS::MassTrace::end
const_iterator end() const
Definition: MassTrace.h:129
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::MassTrace::reverse_iterator
std::vector< PeakType >::reverse_iterator reverse_iterator
Definition: MassTrace.h:111
OpenMS::MassTrace::getLabel
String getLabel() const
Gets label of mass trace.
Definition: MassTrace.h:167
OpenMS::MassTrace::fwhm_start_idx_
Size fwhm_start_idx_
index into 'trace_peaks_' vector (inclusive)
Definition: MassTrace.h:350
OpenMS::MassTrace::MT_QUANT_HEIGHT
quantify by peak height
Definition: MassTrace.h:69
OpenMS::MassTrace::MT_QUANT_MEDIAN
quantify by median of intensities
Definition: MassTrace.h:68
OpenMS::MassTrace::end
iterator end()
Definition: MassTrace.h:119
OpenMS::ConvexHull2D
A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling.
Definition: ConvexHull2D.h:72
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::MassTrace::rend
const_reverse_iterator rend() const
Definition: MassTrace.h:149
OpenMS::MassTrace::getSize
Size getSize() const
Returns the number of peaks contained in the mass trace.
Definition: MassTrace.h:161
Peak2D.h
OpenMS::MassTrace::quant_method_
MT_QUANTMETHOD quant_method_
use area under mass trace or the median of intensities
Definition: MassTrace.h:354
FeatureMap.h
OpenMS::MassTrace::centroid_mz_
double centroid_mz_
Centroid m/z.
Definition: MassTrace.h:335
OpenMS::MassTrace::fwhm_
double fwhm_
FWHM of RT peak.
Definition: MassTrace.h:349
OpenMS::MassTrace::const_reverse_iterator
std::vector< PeakType >::const_reverse_iterator const_reverse_iterator
Definition: MassTrace.h:112
OpenMS::MassTrace::getAverageMS1CycleTime
double getAverageMS1CycleTime() const
Get average scan time of mass trace.
Definition: MassTrace.h:242
OpenMS::MassTrace::getCentroidSD
double getCentroidSD() const
Definition: MassTrace.h:190
OpenMS::MassTrace::getFWHMborders
std::pair< Size, Size > getFWHMborders() const
Definition: MassTrace.h:218
OpenMS::MassTrace::begin
iterator begin()
Definition: MassTrace.h:114
OpenMS::MassTrace::getCentroidRT
double getCentroidRT() const
Returns the centroid RT.
Definition: MassTrace.h:185
OpenMS::MassTrace::setCentroidSD
void setCentroidSD(const double &tmp_sd)
Definition: MassTrace.h:195
OpenMS::MassTrace::getCentroidMZ
double getCentroidMZ() const
Returns the centroid m/z.
Definition: MassTrace.h:179
OpenMS::MassTrace::MT_QUANTMETHOD
MT_QUANTMETHOD
Definition: MassTrace.h:66
OpenMS::MassTrace::centroid_rt_
double centroid_rt_
Centroid RT.
Definition: MassTrace.h:341
OpenMS::MassTrace::getTraceLength
double getTraceLength() const
Returns the length of the trace (as difference in RT)
Definition: MassTrace.h:206
OpenMS::MassTrace::getFWHM
double getFWHM() const
Definition: MassTrace.h:200
OpenMS::MassTrace::rbegin
const_reverse_iterator rbegin() const
Definition: MassTrace.h:144