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

TOFCalibration.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Alexandra Zerck $
00032 // $Authors: $
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 //#define DEBUG_CALIBRATION
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         @ brief Apply the external calibration using raw calibrant spectra.
00083 
00084         @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
00085 
00086     */
00087     template <typename PeakType>
00088     void pickAndCalibrate(MSExperiment<Peak1D> & calib_spectra, MSExperiment<PeakType> & exp, std::vector<double> & exp_masses);
00089 
00090     /*
00091         @ brief Apply the external calibration using picked calibrant spectra.
00092 
00093         @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
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     // pick peaks
00203     PeakPickerCWT pp;
00204     pp.setParameters(param_.copy("PeakPicker:", true));
00205     pp.pickExperiment(calib_spectra, p_calib_spectra);
00206 
00207     //calibrate
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 } // namespace OpenMS
00228 
00229 #endif // OPENMS_FILTERING_CALIBRATION_TOFCALIBRATION_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:45 using doxygen 1.7.1