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

WindowMower.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_WINDOWMOWER_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H
00029 
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PreprocessingFunctor.h>
00031 #include <set>
00032 
00033 namespace OpenMS
00034 {
00035 
00043   class WindowMower
00044      : public PreprocessingFunctor
00045   {
00046   public:
00047 
00048     // @name Constructors and Destructors
00049     // @{
00051     WindowMower();
00052 
00054     WindowMower(const WindowMower& source);
00055 
00057     virtual ~WindowMower();
00058     // @}
00059 
00060     // @name Operators
00061     // @{
00063     WindowMower& operator = (const WindowMower& source);
00064     // @}
00065 
00066     // @name Accessors
00067     // @{
00069     static PreprocessingFunctor* create() { return new WindowMower(); }
00070     
00072     template <typename SpectrumType> void filterSpectrum(SpectrumType& spectrum)
00073     {
00074       typedef typename SpectrumType::Iterator Iterator;
00075       typedef typename SpectrumType::ConstIterator ConstIterator;
00076       typedef typename SpectrumType::ContainerType ContainerType;
00077       
00078       double windowsize = (double)param_.getValue("windowsize");
00079       UInt peakcount = (int)param_.getValue("peakcount");
00080 
00081       std::set<double> positions; // store the indices that are the most intense ones in an interval
00082       
00083       spectrum.getContainer().sortByPosition();
00084       
00085       // slide the window over spectrum and store peakcount most intense peaks (if available) of every window position
00086       bool end(false);
00087       for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00088       {
00089         ContainerType container;
00090         for (ConstIterator it2 = it; (it2->getPosition() - it->getPosition() < windowsize); )
00091         {
00092           container.push_back(*it2);
00093           if (++it2 == spectrum.end())
00094           {
00095             end = true;
00096             break;
00097           }
00098         }
00099 
00100         container.sortByIntensity(true);
00101         
00102         for (UInt i = 0; i < peakcount; ++i)
00103         {
00104           if (container.size() > i)
00105           {
00106             positions.insert(container[i].getMZ());
00107           }
00108         }
00109 
00110         if (end)
00111         {
00112           break;
00113         }
00114       }
00115 
00116       // add the found peaks to a new container
00117       ContainerType container;
00118       for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00119       {
00120         if (positions.find(it->getMZ()) != positions.end())
00121         {
00122           container.push_back(*it);
00123         }
00124       }
00125       
00126       // overwrite the spectrum with the new container
00127       spectrum.setContainer(container);
00128     }
00129 
00130     void filterPeakSpectrum(PeakSpectrum& spectrum);
00131 
00132     void filterPeakMap(PeakMap& exp);
00133   
00135     static const String getProductName()
00136     {
00137       return "WindowMower";
00138     }
00139     // @}
00140     
00141   };
00142 
00143 }
00144 
00145 #endif //OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H

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