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 #ifndef OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
00029 #define OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
00030
00031
00032 #include <OpenMS/KERNEL/MSExperiment.h>
00033 #include <OpenMS/KERNEL/RawDataPoint1D.h>
00034 #include <OpenMS/TRANSFORMATIONS/RAW2PEAK/PeakPickerCWT.h>
00035 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00036 #include <OpenMS/CONCEPT/ProgressLogger.h>
00037
00038 #include <iostream>
00039 #include <vector>
00040 #include <map>
00041 #include <gsl/gsl_multifit.h>
00042 #include <gsl/gsl_spline.h>
00043
00044
00045 namespace OpenMS
00046 {
00057 class TOFCalibration : public DefaultParamHandler,public ProgressLogger
00058 {
00059 public:
00065 class UnableToCalibrate
00066 : public Exception::Base
00067 {
00068 public:
00069 UnableToCalibrate(const char* file, int line, const char* function, const std::string& name , const std::string& message) throw();
00070 virtual ~UnableToCalibrate() throw();
00071 };
00072
00074 typedef RawDataPoint1D RawDataPointType;
00075
00077 typedef PickedPeak1D PickedPeakType;
00078
00080 TOFCalibration();
00081
00083 ~TOFCalibration();
00084
00086 template<typename PeakType>
00087 void calibrate(MSExperiment<RawDataPointType>& calib_spectra,MSExperiment<PeakType >& exp,
00088 std::vector<double>& exp_masses);
00089
00091 template<typename PeakType>
00092 void calibrate(MSExperiment<PickedPeakType>& calib_spectra,MSExperiment<PeakType >& exp,
00093 std::vector<double>& exp_masses);
00094
00096 inline const std::vector<double>& getML1s() const {return ml1s_;}
00098 inline void setML1s(const std::vector<double>& ml1s)
00099 {
00100 ml1s_ = ml1s;
00101 }
00102
00104 inline const std::vector<double>& getML2s() const {return ml2s_;}
00106 inline void setML2s(const std::vector<double>& ml2s)
00107 {
00108 ml2s_ = ml2s;
00109 }
00110
00112 inline const std::vector<double>& getML3s() const {return ml3s_;}
00114 inline void setML3s(const std::vector<double>& ml3s)
00115 {
00116 ml3s_ = ml3s;
00117 }
00118
00119 private:
00121 MSExperiment<PickedPeakType> calib_peaks_ft_;
00122
00123
00125 std::vector<double> exp_masses_;
00126
00128 std::map<double,std::vector<double> > errors_;
00129
00131 std::vector<double> error_medians_;
00132
00134 std::vector<double> calib_masses_;
00135
00137 std::vector<double> ml1s_;
00138 std::vector<double> ml2s_;
00139 std::vector<double> ml3s_;
00140
00142 std::vector<double> coeff_quad_fit_;
00143
00145 double a_,b_,c_;
00146
00147
00148 gsl_interp_accel* acc_;
00149
00150 gsl_spline* spline_;
00151
00153 void calculateCalibCoeffs_(MSExperiment<PickedPeakType >& calib_peaks_ft) throw (UnableToCalibrate);
00154
00155
00157 void getMonoisotopicPeaks_(MSExperiment<PickedPeakType >& calib_peaks,
00158 std::vector<std::vector<unsigned int> >& monoiso_peaks);
00159
00170 void applyTOFConversion_(MSExperiment<PickedPeakType>& calib_spectra);
00171
00173 void matchMasses_(MSExperiment<PickedPeakType>& calib_peaks,std::vector<std::vector<unsigned int> >& monoiso_peaks,
00174 std::vector<unsigned int>& obs_masses,std::vector<double>& exp_masses,unsigned int idx);
00175
00177 inline double mQ_(double ft, unsigned int spec)
00178 {
00179 return coeff_quad_fit_[3*spec] + ft*coeff_quad_fit_[3*spec+1] + ft*ft*coeff_quad_fit_[3*spec+2];
00180 }
00181
00183 inline double mQAv_(double ft)
00184 {
00185 return a_ + ft*b_ + ft*ft*c_;
00186 }
00187
00189 void averageErrors_();
00190
00192 void averageCoefficients_();
00193 };
00194
00195 template<typename PeakType>
00196 void TOFCalibration::calibrate(MSExperiment<RawDataPointType>& calib_spectra,MSExperiment<PeakType >& exp,
00197 std::vector<double>& exp_masses)
00198 {
00199 MSExperiment<PickedPeakType> p_calib_spectra;
00200
00201
00202 PeakPickerCWT pp;
00203 pp.setParameters(param_.copy("PeakPicker:",true));
00204 pp.pickExperiment(calib_spectra,p_calib_spectra);
00205 calibrate(p_calib_spectra,exp,exp_masses);
00206 }
00207
00208 template<typename PeakType>
00209 void TOFCalibration::calibrate(MSExperiment<PickedPeakType>& calib_spectra,MSExperiment<PeakType >& exp,
00210 std::vector<double>& exp_masses)
00211 {
00212 exp_masses_ = exp_masses;
00213 calculateCalibCoeffs_(calib_spectra);
00214 double m;
00215 for(unsigned int spec=0;spec < exp.size(); ++spec)
00216 {
00217 for(unsigned int peak=0;peak < exp[spec].size(); ++peak)
00218 {
00219 m = mQAv_(exp[spec][peak].getMZ());
00220 exp[spec][peak].setPos(m - gsl_spline_eval(spline_,m,acc_));
00221
00222 }
00223 }
00224 }
00225
00226
00227
00228 }
00229
00230 #endif // OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
00231