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

IDSpectrumMapper.h (Maintainer: Nico Pfeifer)

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: Nico Pfeifer $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_ANALYSIS_ID_IDSPECTRUMMAPPER_H
00028 #define OPENMS_ANALYSIS_ID_IDSPECTRUMMAPPER_H
00029 
00030 #include <OpenMS/KERNEL/MSExperiment.h>
00031 #include <OpenMS/METADATA/ProteinIdentification.h>
00032 
00033 #include <vector>
00034 #include <cmath>
00035 
00036 namespace OpenMS 
00037 {
00045   class IDSpectrumMapper
00046   {
00047     public:
00048 
00050       IDSpectrumMapper();
00051       
00060       template <class PeakT>        
00061       UInt annotate(MSExperiment< PeakT >& experiment, const std::vector<PeptideIdentification>& identifications, DoubleReal precision = 0.01f) throw (Exception::MissingInformation)
00062       {
00063         //store mapping of scan RT to index
00064         std::multimap<DoubleReal, UInt> experiment_precursors;
00065         for(UInt i = 0; i < experiment.size(); i++)
00066         {
00067           experiment_precursors.insert(std::make_pair(experiment[i].getRT(), i));
00068         }
00069         
00070         //store mapping of identification RT to index
00071         std::multimap<DoubleReal, UInt> identifications_precursors;
00072         for(UInt i = 0; i < identifications.size(); i++)
00073         {
00074           if (!identifications[i].metaValueExists("RT"))
00075           {
00076             throw Exception::MissingInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__, "IDSpectrumMapper: MetaValue 'RT' missing!"); 
00077           }
00078 
00079           if (!identifications[i].metaValueExists("MZ"))
00080           {
00081             throw Exception::MissingInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__, "IDSpectrumMapper: MetaValue 'MZ' missing!"); 
00082           }
00083           identifications_precursors.insert(std::make_pair(identifications[i].getMetaValue("RT"), i));
00084         }
00085         
00086         //calculate the actual mapping
00087         std::multimap<DoubleReal, UInt>::iterator experiment_iterator = experiment_precursors.begin();
00088         std::multimap<DoubleReal, UInt>::iterator identifications_iterator = identifications_precursors.begin();  
00089         UInt counter = 0;       
00090         while(experiment_iterator != experiment_precursors.end() && identifications_iterator != identifications_precursors.end())
00091         {
00092           while(identifications_iterator != identifications_precursors.end())
00093           {
00094             // testing whether the retention times are within the precision threshold
00095             if (fabs(experiment_iterator->first - identifications_iterator->first) < precision)
00096             {
00097               //std::cout << "RT matching (scan/id) " << experiment_iterator->first << " / " << identifications_iterator->first << std::endl; 
00098               
00099               // testing wheather the m/z fits
00100               if (fabs((DoubleReal)(identifications[identifications_iterator->second].getMetaValue("MZ")) -  (DoubleReal)(experiment[experiment_iterator->second].getPrecursorPeak().getPosition()[0])) < precision)
00101               {
00102                 //std::cout << "MZ matching (scan/id) " << (DoubleReal)(experiment[experiment_iterator->second].getPrecursorPeak().getPosition()[0]) << " / " << (DoubleReal)(identifications[identifications_iterator->second].getMetaValue("MZ")) << std::endl; 
00103                 if (!(identifications[identifications_iterator->second].empty()))
00104                 {
00105                   experiment[experiment_iterator->second].getPeptideIdentifications().push_back(identifications[identifications_iterator->second]);
00106                   counter++;
00107                 }
00108               }
00109             }
00110             ++identifications_iterator;
00111           }
00112           identifications_iterator = identifications_precursors.begin();  
00113           ++experiment_iterator;
00114         }
00115         return counter;       
00116       }
00117     
00118     protected:
00119       
00120   };
00121  
00122 } // namespace OpenMS
00123 
00124 #endif // OPENMS_ANALYSIS_ID_IDSPECTRUMMAPPER_H

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