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

ComplementMarker.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_COMPLEMENTMARKER_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_COMPLEMENTMARKER_H
00029 
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PeakMarker.h>
00031 
00032 #include <map>
00033 #include <cmath>
00034 
00035 namespace OpenMS
00036 {
00044   class ComplementMarker
00045     : public PeakMarker
00046   {
00047   public:
00048 
00049     // @name Constructors and Destructors
00051 
00052     ComplementMarker();
00053 
00055     ComplementMarker(const ComplementMarker& source);
00056 
00058     virtual ~ComplementMarker();
00060 
00061     // @name Operators
00063 
00064     ComplementMarker& operator = (const ComplementMarker& source);
00066 
00067     // @name Accessors
00069 
00070     static PeakMarker* create() { return new ComplementMarker(); }
00071     
00073     template <typename SpectrumType> void apply(std::map<double, bool> marked, SpectrumType& spectrum)
00074     {
00075       if (spectrum.size() < 2)
00076       {
00077         return;
00078       }
00079     
00080       // how often a peak needs to be marked to be returned
00081       double marks = (double)param_.getValue("marks");
00082       double parentmass = spectrum.getPrecursorPeak().getPosition()[0];
00083       double tolerance = (double)param_.getValue("tolerance");
00084       std::map<double, int> matching_b_y_ions;
00085       
00086       spectrum.getContainer().sortByPosition();
00087       
00088       int j = spectrum.size() -1;
00089       for (uint i = 0; i < spectrum.size(); ++i)
00090       {
00091         while (j >= 0 && spectrum.getContainer()[j].getPosition()[0] > (parentmass - spectrum.getContainer()[i].getPosition()[0]) + tolerance)
00092         {
00093           j--;
00094         }
00095         
00096         // just takes the first matching ion; todo take all
00097         if (j >= 0 && std::fabs(spectrum.getContainer()[i].getPosition()[0] + spectrum.getContainer()[j].getPosition()[0] - parentmass) < tolerance)
00098         {
00099           matching_b_y_ions[spectrum.getContainer()[i].getPosition()[0]]++;
00100           matching_b_y_ions[spectrum.getContainer()[j].getPosition()[0]]++;
00101           j--;
00102         }
00103       }
00104 
00105       for (std::map<double, int>::const_iterator cmit = matching_b_y_ions.begin(); cmit != matching_b_y_ions.end(); ++cmit)
00106       {
00107         if (cmit->second >= marks)
00108         {
00109           marked.insert(std::make_pair<double, bool>(cmit->first, true));
00110         }
00111       }
00112     }
00113   
00115     static const String getProductName()
00116     {
00117       return "ComplementMarker";
00118     }
00120     
00121   };
00122 
00123 }
00124 #endif //OPENMS_FILTERING_TRANSFORMERS_COMPLEMENTMARKER_H

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