00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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
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
00095 if (fabs(experiment_iterator->first - identifications_iterator->first) < precision)
00096 {
00097
00098
00099
00100 if (fabs((DoubleReal)(identifications[identifications_iterator->second].getMetaValue("MZ")) - (DoubleReal)(experiment[experiment_iterator->second].getPrecursorPeak().getPosition()[0])) < precision)
00101 {
00102
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 }
00123
00124 #endif // OPENMS_ANALYSIS_ID_IDSPECTRUMMAPPER_H