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

Normalizer.h (Maintainer: Andreas Bertsch)

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: Andreas Bertsch $
00025 // --------------------------------------------------------------------------
00026 //
00027 #ifndef OPENMS_FILTERING_TRANSFORMERS_NORMALIZER_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_NORMALIZER_H
00029 
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PreprocessingFunctor.h>
00031 #include <vector>
00032 
00033 namespace OpenMS
00034 {
00042   class Normalizer
00043     : public PreprocessingFunctor
00044   {
00045   public:
00046 
00047     // @name Constructors and Destructors
00048     // @{
00050     Normalizer();
00051 
00053     Normalizer(const Normalizer& source);
00054 
00056     virtual ~Normalizer();
00057     // @}
00058 
00059     // @name Operators
00060     // @{
00062     Normalizer& operator = (const Normalizer& source);
00063     // @}
00064 
00065     // @name Accessors
00066     // @{
00068     static PreprocessingFunctor* create() { return new Normalizer();}
00069 
00071     static const String getProductName()
00072     {
00073       return "Normalizer";
00074     }
00075 
00077     template <typename SpectrumType> void filterSpectrum(SpectrumType& spectrum)
00078     {
00079       typedef typename SpectrumType::Iterator Iterator;
00080       typedef typename SpectrumType::ConstIterator ConstIterator;
00081   
00082       String method = param_.getValue("method");
00083       
00084       // normalizes the max peak to 1 and the rest of the peaks to values relative to max
00085       if (method == "to_one")
00086       {
00087         double max(0);
00088         for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00089         {
00090           if (max < it->getIntensity())
00091           {
00092             max = it->getIntensity();
00093           }
00094         }
00095         for (Iterator it = spectrum.begin(); it != spectrum.end(); ++it)
00096         {
00097           it->setIntensity(it->getIntensity() / max);
00098         }
00099         return;
00100       }
00101 
00102       // normalizes the peak intensities to the TIC
00103       if (method == "to_TIC")
00104       {
00105         double sum(0);
00106         for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00107         {
00108           sum += it->getIntensity();
00109         }
00110 
00111         for (Iterator it = spectrum.begin(); it != spectrum.end(); ++it)
00112         {
00113           it->setIntensity(it->getIntensity() / sum);
00114         }
00115         return;
00116       }
00117       
00118       // method unknown
00119       throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Method not known", method);
00120       return;
00121       
00122     }
00123 
00125     void filterPeakSpectrum(PeakSpectrum& spectrum);
00126 
00128     void filterPeakMap(PeakMap& exp);
00129     // @}
00130 
00131   };
00132 
00133 
00134 }
00135 #endif //OPENMS_FILTERING_TRANSFORMERS_NORMALIZER_H

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