| OpenMS 2.5.0

TOFCalibration.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: $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/KERNEL/StandardTypes.h>
38 #include <OpenMS/CONCEPT/ProgressLogger.h>
39 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
40 #include <OpenMS/KERNEL/MSExperiment.h>
41 #include <OpenMS/TRANSFORMATIONS/RAW2PEAK/PeakPickerCWT.h>
42
43 #include <OpenMS/MATH/MISC/MathFunctions.h>
44 #include <OpenMS/MATH/MISC/CubicSpline2d.h>
45
46 #include <vector>
47 #include <map>
48
49 //#define DEBUG_CALIBRATION
50 namespace OpenMS
51 {
66 class OPENMS_DLLAPI TOFCalibration :
67 public DefaultParamHandler,
68 public ProgressLogger
69 {
70 public:
71
73 TOFCalibration();
74
76 ~TOFCalibration() override;
77
78
79 /*
80 @ brief Apply the external calibration using raw calibrant spectra.
81
82 @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
83
84 */
85 void pickAndCalibrate(PeakMap & calib_spectra, PeakMap & exp, std::vector<double> & exp_masses);
86
87 /*
88 @ brief Apply the external calibration using picked calibrant spectra.
89
90 @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
91
92 */
93 void calibrate(PeakMap & calib_spectra, PeakMap & exp, std::vector<double> & exp_masses);
94
96 inline const std::vector<double> & getML1s() const {return ml1s_; }
98 inline void setML1s(const std::vector<double> & ml1s)
99 {
100 ml1s_ = ml1s;
101 }
102
104 inline const std::vector<double> & getML2s() const {return ml2s_; }
106 inline void setML2s(const std::vector<double> & ml2s)
107 {
108 ml2s_ = ml2s;
109 }
110
112 inline const std::vector<double> & getML3s() const {return ml3s_; }
114 inline void setML3s(const std::vector<double> & ml3s)
115 {
116 ml3s_ = ml3s;
117 }
118
119 private:
121 PeakMap calib_peaks_ft_;
122
123
125 std::vector<double> exp_masses_;
126
128 std::map<double, std::vector<double> > errors_;
129
131 std::vector<double> error_medians_;
132
134 std::vector<double> calib_masses_;
135
137 std::vector<double> ml1s_;
138 std::vector<double> ml2s_;
139 std::vector<double> ml3s_;
140
142 std::vector<double> coeff_quad_fit_;
143
145 double a_, b_, c_;
146
147
149 void calculateCalibCoeffs_(PeakMap & calib_peaks_ft);
150
151
153 void getMonoisotopicPeaks_(PeakMap & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks);
154
165 void applyTOFConversion_(PeakMap & calib_spectra);
166
168 void matchMasses_(PeakMap & calib_peaks,
169 std::vector<std::vector<unsigned int> > & monoiso_peaks,
170 std::vector<unsigned int> & obs_masses,
171 std::vector<double> & exp_masses,
172 unsigned int idx);
173
175 inline double mQ_(double ft, unsigned int spec)
176 {
177 return coeff_quad_fit_[3 * spec] + ft * coeff_quad_fit_[3 * spec + 1] + ft * ft * coeff_quad_fit_[3 * spec + 2];
178 }
179
181 inline double mQAv_(double ft)
182 {
183 return a_ + ft * b_ + ft * ft * c_;
184 }
185
187 void averageErrors_();
188
190 void averageCoefficients_();
191 };
192
193 } // namespace OpenMS
194
OpenMS::TOFCalibration::setML1s
void setML1s(const std::vector< double > &ml1s)
mutable access to the first calibration constant
Definition: TOFCalibration.h:98
OpenMS::TOFCalibration::getML2s
const std::vector< double > & getML2s() const
Non-mutable access to the second calibration constant.
Definition: TOFCalibration.h:104
OpenMS::TOFCalibration::setML2s
void setML2s(const std::vector< double > &ml2s)
mutable access to the second calibration constant
Definition: TOFCalibration.h:106
OpenMS::TOFCalibration::mQAv_
double mQAv_(double ft)
Calculate the mass value for a given flight time using the averaged coefficients of the quadratic fit...
Definition: TOFCalibration.h:181
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::TOFCalibration::c_
double c_
Definition: TOFCalibration.h:145
MathFunctions.h
PeakPickerCWT.h
CubicSpline2d.h
OpenMS::TOFCalibration::ml2s_
std::vector< double > ml2s_
Definition: TOFCalibration.h:138
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::TOFCalibration::error_medians_
std::vector< double > error_medians_
median errors
Definition: TOFCalibration.h:131
OpenMS::TOFCalibration::setML3s
void setML3s(const std::vector< double > &ml3s)
mutable access to the third calibration constant
Definition: TOFCalibration.h:114
OpenMS::TOFCalibration::errors_
std::map< double, std::vector< double > > errors_
error in ppm after quadratic fit
Definition: TOFCalibration.h:128
StandardTypes.h
OpenMS::TOFCalibration::ml3s_
std::vector< double > ml3s_
Definition: TOFCalibration.h:139
OpenMS::TOFCalibration::calib_masses_
std::vector< double > calib_masses_
Definition: TOFCalibration.h:134
ProgressLogger.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
MSExperiment.h
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenMS::TOFCalibration::calib_peaks_ft_
PeakMap calib_peaks_ft_
the calibrant spectra still using flight times instead of m/z-values
Definition: TOFCalibration.h:121
DefaultParamHandler.h
OpenMS::TOFCalibration::exp_masses_
std::vector< double > exp_masses_
the expected calibrant masses
Definition: TOFCalibration.h:125
OpenMS::TOFCalibration
This class implements an external calibration for TOF data using external calibrant spectra...
Definition: TOFCalibration.h:66
OpenMS::TOFCalibration::coeff_quad_fit_
std::vector< double > coeff_quad_fit_
all coefficients of the quadratic fit
Definition: TOFCalibration.h:142
OpenMS::TOFCalibration::ml1s_
std::vector< double > ml1s_
calibration constants from the instrument needed for the conversion of the calibrant spectra ...
Definition: TOFCalibration.h:137
OpenMS::TOFCalibration::mQ_
double mQ_(double ft, unsigned int spec)
Calculate the mass value for a given flight time using the coefficients of the quadratic fit in a spe...
Definition: TOFCalibration.h:175
OpenMS::TOFCalibration::getML3s
const std::vector< double > & getML3s() const
Non-mutable access to the third calibration constant.
Definition: TOFCalibration.h:112
OpenMS::TOFCalibration::getML1s
const std::vector< double > & getML1s() const
Non-mutable access to the first calibration constant.
Definition: TOFCalibration.h:96