OpenMS  2.6.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 
42 
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 
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:
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 
DefaultParamHandler.h
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:144
OpenMS::TextFile::end
ConstIterator end() const
Gives access to the underlying text buffer.
OpenMS::Param::copy
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
TextFile.h
OpenMS::TOFCalibration::setML2s
void setML2s(const std::vector< double > &ml2s)
mutable access to the second calibration constant
Definition: TOFCalibration.h:106
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::errors_
std::map< double, std::vector< double > > errors_
error in ppm after quadratic fit
Definition: TOFCalibration.h:128
OpenMS::PeakPickerCWT
This class implements a peak picking algorithm using wavelet techniques.
Definition: PeakPickerCWT.h:78
CubicSpline2d.h
OpenMS::TOFCalibration::setML1s
void setML1s(const std::vector< double > &ml1s)
mutable access to the first calibration constant
Definition: TOFCalibration.h:98
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:55
OpenMS::String
A more convenient string class.
Definition: String.h:59
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::TextFile
This class provides some basic file handling methods for text files.
Definition: TextFile.h:46
OpenMS::TOFCalibration::calib_masses_
std::vector< double > calib_masses_
Definition: TOFCalibration.h:134
OpenMS::TOFCalibration::ml3s_
std::vector< double > ml3s_
Definition: TOFCalibration.h:139
OpenMS::MSExperiment::size
Size size() const
Definition: MSExperiment.h:127
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
TOFCalibration.h
OpenMS::TOFCalibration::pickAndCalibrate
void pickAndCalibrate(PeakMap &calib_spectra, PeakMap &exp, std::vector< double > &exp_masses)
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
ProgressLogger.h
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
OpenMS::TOFCalibration::c_
double c_
Definition: TOFCalibration.h:145
MathFunctions.h
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::TOFCalibration::setML3s
void setML3s(const std::vector< double > &ml3s)
mutable access to the third calibration constant
Definition: TOFCalibration.h:114
OpenMS::TOFCalibration::calibrate
void calibrate(PeakMap &calib_spectra, PeakMap &exp, std::vector< double > &exp_masses)
OpenMS::DataProcessing::CALIBRATION
Calibration of m/z positions.
Definition: DataProcessing.h:69
OpenMS::TOFCalibration::coeff_quad_fit_
std::vector< double > coeff_quad_fit_
all coefficients of the quadratic fit
Definition: TOFCalibration.h:142
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
MSExperiment.h
OpenMS::TextFile::begin
ConstIterator begin() const
Gives access to the underlying text buffer.
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
OpenMS::TOFCalibration::getML1s
const std::vector< double > & getML1s() const
Non-mutable access to the first calibration constant.
Definition: TOFCalibration.h:96
OpenMS::TOFCalibration::ml2s_
std::vector< double > ml2s_
Definition: TOFCalibration.h:138
OpenMS::TOFCalibration::error_medians_
std::vector< double > error_medians_
median errors
Definition: TOFCalibration.h:131
PeakPickerCWT.h
OpenMS::TOFCalibration
This class implements an external calibration for TOF data using external calibrant spectra.
Definition: TOFCalibration.h:66
OpenMS::TOFCalibration::exp_masses_
std::vector< double > exp_masses_
the expected calibrant masses
Definition: TOFCalibration.h:125
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
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::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::getML3s
const std::vector< double > & getML3s() const
Non-mutable access to the third calibration constant.
Definition: TOFCalibration.h:112
OpenMS::TOFCalibration::getML2s
const std::vector< double > & getML2s() const
Non-mutable access to the second calibration constant.
Definition: TOFCalibration.h:104
OpenMS::TextFile::ConstIterator
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: TextFile.h:56
OpenMS::Param::insert
void insert(const String &prefix, const Param &param)
OpenMS::TextFile::load
void load(const String &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false)
Loads data from a text file.
StandardTypes.h
OpenMS::ProgressLogger::setLogType
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
TOPPBase.h