Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

TOFCalibration.h (Maintainer: Alexandra Zerck)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Alexandra Zerck $
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 //#define DEBUG_CALIBRATION
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     // pick peaks
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 } // namespace OpenMS
00229 
00230 #endif // OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H
00231 

Generated Tue Apr 1 15:36:38 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1