Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2013.
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: Alexandra Zerck $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 
36 #ifndef OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
37 #define OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
38 
39 
44 
45 #include <iostream>
46 #include <vector>
47 #include <map>
48 #include <gsl/gsl_multifit.h>
49 #include <gsl/gsl_spline.h>
50 
51 //#define DEBUG_CALIBRATION
52 namespace OpenMS
53 {
68  class OPENMS_DLLAPI TOFCalibration :
69  public DefaultParamHandler,
70  public ProgressLogger
71  {
72 public:
73 
76 
78  ~TOFCalibration();
79 
80 
81  /*
82  @ brief Apply the external calibration using raw calibrant spectra.
83 
84  @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
85 
86  */
87  template <typename PeakType>
88  void pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
89 
90  /*
91  @ brief Apply the external calibration using picked calibrant spectra.
92 
93  @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
94 
95  */
96  template <typename PeakType>
97  void calibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
98 
100  inline const std::vector<double> & getML1s() const {return ml1s_; }
102  inline void setML1s(const std::vector<double> & ml1s)
103  {
104  ml1s_ = ml1s;
105  }
106 
108  inline const std::vector<double> & getML2s() const {return ml2s_; }
110  inline void setML2s(const std::vector<double> & ml2s)
111  {
112  ml2s_ = ml2s;
113  }
114 
116  inline const std::vector<double> & getML3s() const {return ml3s_; }
118  inline void setML3s(const std::vector<double> & ml3s)
119  {
120  ml3s_ = ml3s;
121  }
122 
123 private:
126 
127 
129  std::vector<double> exp_masses_;
130 
132  std::map<double, std::vector<double> > errors_;
133 
135  std::vector<double> error_medians_;
136 
138  std::vector<double> calib_masses_;
139 
141  std::vector<double> ml1s_;
142  std::vector<double> ml2s_;
143  std::vector<double> ml3s_;
144 
146  std::vector<double> coeff_quad_fit_;
147 
149  double a_, b_, c_;
150 
151 
152  gsl_interp_accel * acc_;
153 
154  gsl_spline * spline_;
155 
157  void calculateCalibCoeffs_(MSExperiment<> & calib_peaks_ft);
158 
159 
161  void getMonoisotopicPeaks_(MSExperiment<> & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks);
162 
173  void applyTOFConversion_(MSExperiment<> & calib_spectra);
174 
176  void matchMasses_(MSExperiment<> & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks, std::vector<unsigned int> & obs_masses, std::vector<double> & exp_masses, unsigned int idx);
177 
179  inline double mQ_(double ft, unsigned int spec)
180  {
181  return coeff_quad_fit_[3 * spec] + ft * coeff_quad_fit_[3 * spec + 1] + ft * ft * coeff_quad_fit_[3 * spec + 2];
182  }
183 
185  inline double mQAv_(double ft)
186  {
187  return a_ + ft * b_ + ft * ft * c_;
188  }
189 
191  void averageErrors_();
192 
194  void averageCoefficients_();
195  };
196 
197  template <typename PeakType>
198  void TOFCalibration::pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses)
199  {
200  MSExperiment<Peak1D> p_calib_spectra;
201 
202  // pick peaks
203  PeakPickerCWT pp;
204  pp.setParameters(param_.copy("PeakPicker:", true));
205  pp.pickExperiment(calib_spectra, p_calib_spectra);
206 
207  //calibrate
208  calibrate(p_calib_spectra, exp, exp_masses);
209  }
210 
211  template <typename PeakType>
212  void TOFCalibration::calibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses)
213  {
214  exp_masses_ = exp_masses;
215  calculateCalibCoeffs_(calib_spectra);
216  double m;
217  for (unsigned int spec = 0; spec < exp.size(); ++spec)
218  {
219  for (unsigned int peak = 0; peak < exp[spec].size(); ++peak)
220  {
221  m = mQAv_(exp[spec][peak].getMZ());
222  exp[spec][peak].setPos(m - gsl_spline_eval(spline_, m, acc_));
223  }
224  }
225  }
226 
227 } // namespace OpenMS
228 
229 #endif // OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
void setML3s(const std::vector< double > &ml3s)
mutable access to the third calibration constant
Definition: TOFCalibration.h:118
This class implements an external calibration for TOF data using external calibrant spectra...
Definition: TOFCalibration.h:68
gsl_interp_accel * acc_
Definition: TOFCalibration.h:152
std::vector< double > coeff_quad_fit_
all coefficients of the quadratic fit
Definition: TOFCalibration.h:146
const std::vector< double > & getML2s() const
Non-mutable access to the second calibration constant.
Definition: TOFCalibration.h:108
Size size() const
Definition: MSExperiment.h:117
gsl_spline * spline_
Definition: TOFCalibration.h:154
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:148
std::vector< double > error_medians_
median errors
Definition: TOFCalibration.h:135
This class implements a peak picking algorithm using wavelet techniques.
Definition: PeakPickerCWT.h:77
std::vector< double > ml3s_
Definition: TOFCalibration.h:143
std::vector< double > ml2s_
Definition: TOFCalibration.h:142
void setML1s(const std::vector< double > &ml1s)
mutable access to the first calibration constant
Definition: TOFCalibration.h:102
void setParameters(const Param &param)
Sets the parameters.
std::vector< double > exp_masses_
the expected calibrant masses
Definition: TOFCalibration.h:129
std::vector< double > ml1s_
calibration constants from the instrument needed for the conversion of the calibrant spectra ...
Definition: TOFCalibration.h:141
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
double c_
Definition: TOFCalibration.h:149
const std::vector< double > & getML3s() const
Non-mutable access to the third calibration constant.
Definition: TOFCalibration.h:116
const std::vector< double > & getML1s() const
Non-mutable access to the first calibration constant.
Definition: TOFCalibration.h:100
void pickExperiment(const MSExperiment<> &input, MSExperiment<> &output)
Picks the peaks in an MSExperiment.
MSExperiment calib_peaks_ft_
the calibrant spectra still using flight times instead of m/z-values
Definition: TOFCalibration.h:125
void pickAndCalibrate(MSExperiment< Peak1D > &calib_spectra, MSExperiment< PeakType > &exp, std::vector< double > &exp_masses)
Definition: TOFCalibration.h:198
void calculateCalibCoeffs_(MSExperiment<> &calib_peaks_ft)
Calculates the coefficients of the quadratic fit used for external calibration.
std::map< double, std::vector< double > > errors_
error in ppm after quadratic fit
Definition: TOFCalibration.h:132
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:179
std::vector< double > calib_masses_
Definition: TOFCalibration.h:138
Base class for all classes that want to report their progess.
Definition: ProgressLogger.h:56
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:90
void calibrate(MSExperiment< Peak1D > &calib_spectra, MSExperiment< PeakType > &exp, std::vector< double > &exp_masses)
Definition: TOFCalibration.h:212
double mQAv_(double ft)
Calculate the mass value for a given flight time using the averaged coefficients of the quadratic fit...
Definition: TOFCalibration.h:185
void setML2s(const std::vector< double > &ml2s)
mutable access to the second calibration constant
Definition: TOFCalibration.h:110

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:22 using doxygen 1.8.5