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

NeutralLossMarker.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_NEUTRALLOSSMARKER_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_NEUTRALLOSSMARKER_H
00029 
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PeakMarker.h>
00031 
00032 #include <map>
00033 #include <cmath>
00034 
00035 namespace OpenMS
00036 {
00044   class NeutralLossMarker
00045     : public PeakMarker
00046   {
00047   public:
00048 
00049     // @name Constructors and Destructors
00050     // @{
00052     NeutralLossMarker();
00053 
00055     NeutralLossMarker(const NeutralLossMarker& source);
00056 
00058     virtual ~NeutralLossMarker();
00059     // @}
00060 
00061     // @name Operators
00062     // @{
00064     NeutralLossMarker& operator = (const NeutralLossMarker& source);
00065     // @}
00066 
00067     // @name Accessors
00068     // @{
00070     static PeakMarker* create() { return new NeutralLossMarker(); }
00071 
00073     template <typename SpectrumType> void apply(std::map<double, bool>& marked, SpectrumType& spectrum)
00074     {
00075       // how often a peak needs to be marked to be returned
00076       double marks = (double)param_.getValue("marks");
00077       double tolerance = (double)param_.getValue("tolerance");
00078       std::map<double, int> ions_w_neutrallosses;
00079       spectrum.getContainer().sortByPosition();
00080       for (uint i = 0; i < spectrum.size(); ++i)
00081       {
00082         double mz = spectrum.getContainer()[i].getPosition()[0];
00083         double intensity = spectrum.getContainer()[i].getIntensity();
00084         int j = i - 1;
00085         while (j >= 0)
00086         {
00087           double curmz = spectrum.getContainer()[j].getPosition()[0];
00088           double curIntensity = spectrum.getContainer()[j].getIntensity();
00089 
00090           // check for peak thats a a water or ammonia away
00091           if (std::fabs(mz - curmz - 17) < tolerance || std::fabs(mz - curmz - 18) < tolerance)
00092           {
00093             // neutral loss peak should be smaller
00094             if (curIntensity < intensity)
00095             {
00096               ions_w_neutrallosses[mz]++;
00097               // neutral loss peak not marked
00098               //ions_w_neutrallosses[curmz]++;
00099             }
00100           }
00101           else 
00102           {
00103             if (mz - curmz > 18.3)
00104             {
00105               break;
00106             }
00107           }
00108           --j;
00109         }
00110       }
00111       
00112       for (std::map<double, int>::const_iterator cmit = ions_w_neutrallosses.begin(); cmit != ions_w_neutrallosses.end(); ++cmit)
00113       {
00114         if (cmit->second >= marks)
00115         {
00116           marked.insert(std::make_pair<double, bool>(cmit->first, true));
00117         }
00118       }
00119       return;
00120     }
00121 
00123     static const String getProductName()
00124     {
00125       return "NeutralLossMarker";
00126     }
00127     // @}
00128 
00129   };
00130 
00131 }
00132 #endif //OPENMS_FILTERING_TRANSFORMERS_NEUTRALLOSSMARKER_H

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