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-2015.
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 
46 
47 #include <vector>
48 #include <map>
49 
50 //#define DEBUG_CALIBRATION
51 namespace OpenMS
52 {
67  class OPENMS_DLLAPI TOFCalibration :
68  public DefaultParamHandler,
69  public ProgressLogger
70  {
71 public:
72 
75 
77  ~TOFCalibration();
78 
79 
80  /*
81  @ brief Apply the external calibration using raw calibrant spectra.
82 
83  @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
84 
85  */
86  template <typename PeakType>
87  void pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
88 
89  /*
90  @ brief Apply the external calibration using picked calibrant spectra.
91 
92  @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
93 
94  */
95  template <typename PeakType>
96  void calibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
97 
99  inline const std::vector<double> & getML1s() const {return ml1s_; }
101  inline void setML1s(const std::vector<double> & ml1s)
102  {
103  ml1s_ = ml1s;
104  }
105 
107  inline const std::vector<double> & getML2s() const {return ml2s_; }
109  inline void setML2s(const std::vector<double> & ml2s)
110  {
111  ml2s_ = ml2s;
112  }
113 
115  inline const std::vector<double> & getML3s() const {return ml3s_; }
117  inline void setML3s(const std::vector<double> & ml3s)
118  {
119  ml3s_ = ml3s;
120  }
121 
122 private:
125 
126 
128  std::vector<double> exp_masses_;
129 
131  std::map<double, std::vector<double> > errors_;
132 
134  std::vector<double> error_medians_;
135 
137  std::vector<double> calib_masses_;
138 
140  std::vector<double> ml1s_;
141  std::vector<double> ml2s_;
142  std::vector<double> ml3s_;
143 
145  std::vector<double> coeff_quad_fit_;
146 
148  double a_, b_, c_;
149 
150 
152  void calculateCalibCoeffs_(MSExperiment<> & calib_peaks_ft);
153 
154 
156  void getMonoisotopicPeaks_(MSExperiment<> & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks);
157 
168  void applyTOFConversion_(MSExperiment<> & calib_spectra);
169 
171  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);
172 
174  inline double mQ_(double ft, unsigned int spec)
175  {
176  return coeff_quad_fit_[3 * spec] + ft * coeff_quad_fit_[3 * spec + 1] + ft * ft * coeff_quad_fit_[3 * spec + 2];
177  }
178 
180  inline double mQAv_(double ft)
181  {
182  return a_ + ft * b_ + ft * ft * c_;
183  }
184 
186  void averageErrors_();
187 
189  void averageCoefficients_();
190  };
191 
192  template <typename PeakType>
193  void TOFCalibration::pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses)
194  {
195  MSExperiment<Peak1D> p_calib_spectra;
196 
197  // pick peaks
198  PeakPickerCWT pp;
199  pp.setParameters(param_.copy("PeakPicker:", true));
200  pp.pickExperiment(calib_spectra, p_calib_spectra);
201 
202  //calibrate
203  calibrate(p_calib_spectra, exp, exp_masses);
204  }
205 
206  template <typename PeakType>
207  void TOFCalibration::calibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses)
208  {
209  exp_masses_ = exp_masses;
210  calculateCalibCoeffs_(calib_spectra);
211 
213 
214 #ifdef DEBUG_CALIBRATION
215  std::cout << "fehler nach spline fitting" << std::endl;
216 
217  for (unsigned int spec = 0; spec < calib_peaks_ft_.size(); ++spec)
218  {
219 
220  std::vector<double> exp_masses;
221  std::vector<unsigned int> monoiso;
222  matchMasses_(calib_spectra, monoiso_peaks, monoiso, exp_masses, spec);
223  for (unsigned int p = 0; p < monoiso.size(); ++p)
224  {
225  double xi = mQ_(calib_peaks_ft_[spec][monoiso[p]].getMZ(), spec);
226  if (xi > calib_masses[error_medians_.size() - 1])
227  continue;
228  if (xi < calib_masses[0])
229  continue;
230  std::cout << exp_masses[p] << "\t"
231  << (xi - exp_masses[p] - spline(xi)) / exp_masses[p] * 1e6
232  << std::endl;
233 
234  }
235 
236  }
237 
238 
239  double xi, yi;
240  std::cout << "interpolation \n\n";
241  for (xi = calib_masses[0]; xi < calib_masses[error_medians_.size() - 1]; xi += 0.01)
242  {
243  yi = spline(xi);
244  std::cout << xi << "\t" << yi << std::endl;
245  }
246  std::cout << "--------------\nend interpolation \n\n";
247 #endif
248 
249 // delete[] calib_masses;
250 // delete[] error_medians;
251 
252  double m;
253  for (unsigned int spec = 0; spec < exp.size(); ++spec)
254  {
255  for (unsigned int peak = 0; peak < exp[spec].size(); ++peak)
256  {
257  m = mQAv_(exp[spec][peak].getMZ());
258  exp[spec][peak].setPos(m - spline.eval(m));
259  }
260  }
261  }
262 
263 } // namespace OpenMS
264 
265 #endif // OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
void setML3s(const std::vector< double > &ml3s)
mutable access to the third calibration constant
Definition: TOFCalibration.h:117
This class implements an external calibration for TOF data using external calibrant spectra...
Definition: TOFCalibration.h:67
std::vector< double > coeff_quad_fit_
all coefficients of the quadratic fit
Definition: TOFCalibration.h:145
Wrapper for Spline interpolation.
Definition: Spline2d.h:52
const std::vector< double > & getML2s() const
Non-mutable access to the second calibration constant.
Definition: TOFCalibration.h:107
Size size() const
Definition: MSExperiment.h:117
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:150
std::vector< double > error_medians_
median errors
Definition: TOFCalibration.h:134
This class implements a peak picking algorithm using wavelet techniques.
Definition: PeakPickerCWT.h:78
std::vector< double > ml3s_
Definition: TOFCalibration.h:142
std::vector< double > ml2s_
Definition: TOFCalibration.h:141
void setML1s(const std::vector< double > &ml1s)
mutable access to the first calibration constant
Definition: TOFCalibration.h:101
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setParameters(const Param &param)
Sets the parameters.
std::vector< double > exp_masses_
the expected calibrant masses
Definition: TOFCalibration.h:128
std::vector< double > ml1s_
calibration constants from the instrument needed for the conversion of the calibrant spectra ...
Definition: TOFCalibration.h:140
ValType eval(ValType x) const
Definition: Spline2d.h:103
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:148
const std::vector< double > & getML3s() const
Non-mutable access to the third calibration constant.
Definition: TOFCalibration.h:115
const std::vector< double > & getML1s() const
Non-mutable access to the first calibration constant.
Definition: TOFCalibration.h:99
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:124
void pickAndCalibrate(MSExperiment< Peak1D > &calib_spectra, MSExperiment< PeakType > &exp, std::vector< double > &exp_masses)
Definition: TOFCalibration.h:193
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:131
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:174
std::vector< double > calib_masses_
Definition: TOFCalibration.h:137
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
void calibrate(MSExperiment< Peak1D > &calib_spectra, MSExperiment< PeakType > &exp, std::vector< double > &exp_masses)
Definition: TOFCalibration.h:207
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)
determine the monoisotopic masses that have matching expected masses
double mQAv_(double ft)
Calculate the mass value for a given flight time using the averaged coefficients of the quadratic fit...
Definition: TOFCalibration.h:180
void setML2s(const std::vector< double > &ml2s)
mutable access to the second calibration constant
Definition: TOFCalibration.h:109

OpenMS / TOPP release 2.0.0 Documentation generated on Thu Aug 20 2015 01:44:29 using doxygen 1.8.9.1