Go to the documentation of this file.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
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_KERNEL_CHROMATOGRAMTOOLS_H
00036 #define OPENMS_KERNEL_CHROMATOGRAMTOOLS_H
00037
00038 #include <OpenMS/DATASTRUCTURES/Map.h>
00039 #include <OpenMS/CONCEPT/Types.h>
00040 #include <OpenMS/KERNEL/MSChromatogram.h>
00041 #include <OpenMS/KERNEL/MSExperiment.h>
00042 #include <OpenMS/KERNEL/RangeUtils.h>
00043 #include <OpenMS/CONCEPT/LogStream.h>
00044
00045 namespace OpenMS
00046 {
00055 class ChromatogramTools
00056 {
00057 public:
00059
00060
00061 ChromatogramTools()
00062 {}
00063
00065 ChromatogramTools(const ChromatogramTools & )
00066 {}
00067
00069 virtual ~ChromatogramTools()
00070 {}
00071
00073
00075
00076
00085 template <typename ExperimentType>
00086 void convertChromatogramsToSpectra(ExperimentType & exp)
00087 {
00088 for (std::vector<MSChromatogram<> >::const_iterator it = exp.getChromatograms().begin(); it != exp.getChromatograms().end(); ++it)
00089 {
00090
00091 for (typename ExperimentType::ChromatogramType::const_iterator pit = it->begin(); pit != it->end(); ++pit)
00092 {
00093 typename ExperimentType::SpectrumType spec;
00094
00095
00096 spec.getPrecursors().push_back(it->getPrecursor());
00097 spec.getProducts().push_back(it->getProduct());
00098 spec.setRT(pit->getRT());
00099 spec.setMSLevel(2);
00100 spec.setInstrumentSettings(it->getInstrumentSettings());
00101 spec.setAcquisitionInfo(it->getAcquisitionInfo());
00102 spec.setSourceFile(it->getSourceFile());
00103
00104
00105 if (it->getChromatogramType() == ChromatogramSettings::SELECTED_REACTION_MONITORING_CHROMATOGRAM)
00106 {
00107 spec.getInstrumentSettings().setScanMode(InstrumentSettings::SRM);
00108 }
00109 if (it->getChromatogramType() == ChromatogramSettings::SELECTED_ION_MONITORING_CHROMATOGRAM)
00110 {
00111 spec.getInstrumentSettings().setScanMode(InstrumentSettings::SIM);
00112 }
00113
00114
00115 typename ExperimentType::PeakType peak;
00116 peak.setMZ(it->getMZ());
00117 peak.setIntensity(pit->getIntensity());
00118 spec.push_back(peak);
00119 exp.push_back(spec);
00120 }
00121 }
00122
00123 exp.setChromatograms(std::vector<MSChromatogram<> >());
00124 }
00125
00137 template <typename ExperimentType>
00138 void convertSpectraToChromatograms(ExperimentType & exp, bool remove_spectra = false)
00139 {
00140 typedef typename ExperimentType::SpectrumType SpectrumType;
00141 Map<DoubleReal, Map<DoubleReal, std::vector<SpectrumType> > > chroms;
00142 for (typename ExperimentType::ConstIterator it = exp.begin(); it != exp.end(); ++it)
00143 {
00144
00145 if (it->getInstrumentSettings().getScanMode() == InstrumentSettings::SRM)
00146 {
00147
00148 if (it->getPrecursors().size() == 1 && it->size() == 1)
00149 {
00150 chroms[it->getPrecursors().begin()->getMZ()][it->begin()->getMZ()].push_back(*it);
00151 }
00152
00153
00154
00155
00156 else if (it->getPrecursors().size() == 1 && it->size() > 0)
00157 {
00158 for (Size peak_idx = 0; peak_idx < it->size(); peak_idx++)
00159 {
00160
00161 SpectrumType dummy = *it;
00162 dummy.clear(false);
00163 dummy.push_back((*it)[peak_idx]);
00164 chroms[it->getPrecursors().begin()->getMZ()][(*it)[peak_idx].getMZ()].push_back(dummy);
00165 }
00166 }
00167 else
00168 {
00169 LOG_WARN << "ChromatogramTools: need exactly one precursor (given " << it->getPrecursors().size() <<
00170 ") and one or more product ions (" << it->size() << "), skipping conversion of this spectrum to chromatogram." << std::endl;
00171 }
00172 }
00173 else
00174 {
00175
00176
00177
00178
00179 }
00180 }
00181
00182 typename Map<DoubleReal, Map<DoubleReal, std::vector<SpectrumType> > >::const_iterator it1 = chroms.begin();
00183 for (; it1 != chroms.end(); ++it1)
00184 {
00185 typename Map<DoubleReal, std::vector<SpectrumType> >::const_iterator it2 = it1->second.begin();
00186 for (; it2 != it1->second.end(); ++it2)
00187 {
00188 typename ExperimentType::ChromatogramType chrom;
00189 chrom.setPrecursor(*it2->second.begin()->getPrecursors().begin());
00190 Product prod;
00191 prod.setMZ(it2->first);
00192 chrom.setProduct(prod);
00193 chrom.setInstrumentSettings(it2->second.begin()->getInstrumentSettings());
00194 chrom.setAcquisitionInfo(it2->second.begin()->getAcquisitionInfo());
00195 chrom.setSourceFile(it2->second.begin()->getSourceFile());
00196
00197 typename std::vector<SpectrumType>::const_iterator it3 = it2->second.begin();
00198 for (; it3 != it2->second.end(); ++it3)
00199 {
00200 typename ExperimentType::ChromatogramType::PeakType p;
00201 p.setRT(it3->getRT());
00202 p.setIntensity(it3->begin()->getIntensity());
00203 chrom.push_back(p);
00204 }
00205
00206 chrom.setNativeID("chromatogram=" + it2->second.begin()->getNativeID());
00207 chrom.setChromatogramType(ChromatogramSettings::SELECTED_REACTION_MONITORING_CHROMATOGRAM);
00208 exp.addChromatogram(chrom);
00209 }
00210 }
00211
00212 if (remove_spectra)
00213 {
00214 exp.erase(remove_if(exp.begin(), exp.end(), HasScanMode<SpectrumType>(InstrumentSettings::SRM)), exp.end());
00215 }
00216 }
00217
00219 };
00220 }
00221
00222 #endif // OPENMS_KERNEL_CHROMATOGRAMTOOLS_H