Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
00037 #define OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
00038
00039
00040 #include <OpenMS/KERNEL/MSExperiment.h>
00041 #include <OpenMS/TRANSFORMATIONS/RAW2PEAK/PeakPickerCWT.h>
00042 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00043 #include <OpenMS/CONCEPT/ProgressLogger.h>
00044
00045 #include <iostream>
00046 #include <vector>
00047 #include <map>
00048 #include <gsl/gsl_multifit.h>
00049 #include <gsl/gsl_spline.h>
00050
00051
00052 namespace OpenMS
00053 {
00068 class OPENMS_DLLAPI TOFCalibration :
00069 public DefaultParamHandler,
00070 public ProgressLogger
00071 {
00072 public:
00073
00075 TOFCalibration();
00076
00078 ~TOFCalibration();
00079
00080
00081
00082
00083
00084
00085
00086
00087 template <typename PeakType>
00088 void pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
00089
00090
00091
00092
00093
00094
00095
00096 template <typename PeakType>
00097 void calibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
00098
00100 inline const std::vector<double> & getML1s() const {return ml1s_; }
00102 inline void setML1s(const std::vector<double> & ml1s)
00103 {
00104 ml1s_ = ml1s;
00105 }
00106
00108 inline const std::vector<double> & getML2s() const {return ml2s_; }
00110 inline void setML2s(const std::vector<double> & ml2s)
00111 {
00112 ml2s_ = ml2s;
00113 }
00114
00116 inline const std::vector<double> & getML3s() const {return ml3s_; }
00118 inline void setML3s(const std::vector<double> & ml3s)
00119 {
00120 ml3s_ = ml3s;
00121 }
00122
00123 private:
00125 MSExperiment<> calib_peaks_ft_;
00126
00127
00129 std::vector<double> exp_masses_;
00130
00132 std::map<double, std::vector<double> > errors_;
00133
00135 std::vector<double> error_medians_;
00136
00138 std::vector<double> calib_masses_;
00139
00141 std::vector<double> ml1s_;
00142 std::vector<double> ml2s_;
00143 std::vector<double> ml3s_;
00144
00146 std::vector<double> coeff_quad_fit_;
00147
00149 double a_, b_, c_;
00150
00151
00152 gsl_interp_accel * acc_;
00153
00154 gsl_spline * spline_;
00155
00157 void calculateCalibCoeffs_(MSExperiment<> & calib_peaks_ft);
00158
00159
00161 void getMonoisotopicPeaks_(MSExperiment<> & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks);
00162
00173 void applyTOFConversion_(MSExperiment<> & calib_spectra);
00174
00176 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);
00177
00179 inline double mQ_(double ft, unsigned int spec)
00180 {
00181 return coeff_quad_fit_[3 * spec] + ft * coeff_quad_fit_[3 * spec + 1] + ft * ft * coeff_quad_fit_[3 * spec + 2];
00182 }
00183
00185 inline double mQAv_(double ft)
00186 {
00187 return a_ + ft * b_ + ft * ft * c_;
00188 }
00189
00191 void averageErrors_();
00192
00194 void averageCoefficients_();
00195 };
00196
00197 template <typename PeakType>
00198 void TOFCalibration::pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses)
00199 {
00200 MSExperiment<Peak1D> p_calib_spectra;
00201
00202
00203 PeakPickerCWT pp;
00204 pp.setParameters(param_.copy("PeakPicker:", true));
00205 pp.pickExperiment(calib_spectra, p_calib_spectra);
00206
00207
00208 calibrate(p_calib_spectra, exp, exp_masses);
00209 }
00210
00211 template <typename PeakType>
00212 void TOFCalibration::calibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses)
00213 {
00214 exp_masses_ = exp_masses;
00215 calculateCalibCoeffs_(calib_spectra);
00216 double m;
00217 for (unsigned int spec = 0; spec < exp.size(); ++spec)
00218 {
00219 for (unsigned int peak = 0; peak < exp[spec].size(); ++peak)
00220 {
00221 m = mQAv_(exp[spec][peak].getMZ());
00222 exp[spec][peak].setPos(m - gsl_spline_eval(spline_, m, acc_));
00223 }
00224 }
00225 }
00226
00227 }
00228
00229 #endif // OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H