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

BernNorm.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_BERNNORM_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
00029 
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PreprocessingFunctor.h>
00031 #include <map>
00032 
00033 namespace OpenMS
00034 {
00046   class BernNorm
00047     : public PreprocessingFunctor
00048   {
00049   public:
00050 
00051     // @name Constructors and Destructors
00053 
00054     BernNorm();
00055 
00057     BernNorm(const BernNorm& source);
00058 
00060     virtual ~BernNorm();
00062   
00063     // @name Operators
00064     // @{
00066     BernNorm& operator=(const BernNorm& source);
00067     // @}
00068 
00069     // @name Accessors
00070     // @{
00072     static PreprocessingFunctor* create() { return new BernNorm(); }
00073 
00075     template <typename SpectrumType> void filterSpectrum(SpectrumType& spectrum)
00076     {
00077       typedef typename SpectrumType::Iterator Iterator;
00078       typedef typename SpectrumType::ConstIterator ConstIterator;
00079     
00080       double c1 = (double)param_.getValue("C1");
00081       double c2 = (double)param_.getValue("C2");
00082       double threshold = (double)param_.getValue("threshold");
00083 
00084       spectrum.getContainer().sortByPosition();
00085 
00086       // find highest peak and ranking
00087       double maxint = 0;
00088       std::map<double, uint> peakranks;
00089       for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00090       {
00091         peakranks[it->getIntensity()] = 0;
00092         if (it->getIntensity() > maxint)
00093         {
00094           maxint = it->getIntensity();
00095         }
00096       }
00097       uint rank = 0;
00098       for (std::map<double, uint>::reverse_iterator mit = peakranks.rbegin(); mit != peakranks.rend(); ++mit)
00099       {
00100         mit->second = ++rank;
00101       }
00102 
00103       // find maxmz i.e. significant (> threshold * maxpeak) peak with highest m/z
00104       double maxmz = 0;
00105       for (int i = spectrum.size() -1 ; i >= 0 ; --i)
00106       {
00107         if (spectrum.getContainer()[i].getIntensity() > maxint * threshold)
00108         {
00109           maxmz = spectrum.getContainer()[i].getMZ();
00110           break;
00111         }
00112       }
00113 
00114       // rank
00115       for (Iterator it = spectrum.begin() ; it != spectrum.end(); )
00116       {
00117         double newint = c1 - (c2 / maxmz) * peakranks[it->getIntensity()];
00118         if (newint < 0)
00119         {
00120           it = spectrum.getContainer().erase(it);
00121         }
00122         else
00123         {
00124           it->setIntensity(newint);
00125           ++it;
00126         }
00127       }
00128       return;
00129     }
00130 
00131     void filterPeakSpectrum(PeakSpectrum& spectrum);
00132 
00133     void filterPeakMap(PeakMap& exp);
00134     
00136     static const String getProductName()
00137     {
00138       return "BernNorm";
00139     }
00140     // @}
00141   
00142   };
00143 
00144 } // namespace OpenMS
00145 
00146 #endif //OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H

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