Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
ChromatogramTools.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Andreas Bertsch $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_CHROMATOGRAMTOOLS_H
36 #define OPENMS_KERNEL_CHROMATOGRAMTOOLS_H
37 
39 #include <OpenMS/CONCEPT/Types.h>
44 
45 namespace OpenMS
46 {
56  {
57 public:
59 
62  {}
63 
66  {}
67 
70  {}
71 
73 
75 
76 
85  template <typename ExperimentType>
86  void convertChromatogramsToSpectra(ExperimentType & exp)
87  {
88  for (std::vector<MSChromatogram >::const_iterator it = exp.getChromatograms().begin(); it != exp.getChromatograms().end(); ++it)
89  {
90  // for each peak add a new spectrum
91  for (typename ExperimentType::ChromatogramType::const_iterator pit = it->begin(); pit != it->end(); ++pit)
92  {
93  typename ExperimentType::SpectrumType spec;
94 
95  // add precursor and product peaks to spectrum settings
96  spec.getPrecursors().push_back(it->getPrecursor());
97  spec.getProducts().push_back(it->getProduct());
98  spec.setRT(pit->getRT());
99  spec.setMSLevel(2);
100  spec.setInstrumentSettings(it->getInstrumentSettings());
101  spec.setAcquisitionInfo(it->getAcquisitionInfo());
102  spec.setSourceFile(it->getSourceFile());
103 
104  // TODO implement others
106  {
107  spec.getInstrumentSettings().setScanMode(InstrumentSettings::SRM);
108  }
109  if (it->getChromatogramType() == ChromatogramSettings::SELECTED_ION_MONITORING_CHROMATOGRAM)
110  {
111  spec.getInstrumentSettings().setScanMode(InstrumentSettings::SIM);
112  }
113 
114  // new spec contains one peak, with product m/z and intensity
115  typename ExperimentType::PeakType peak;
116  peak.setMZ(it->getMZ());
117  peak.setIntensity(pit->getIntensity());
118  spec.push_back(peak);
119  exp.addSpectrum(spec);
120  }
121  }
122 
123  exp.setChromatograms(std::vector<MSChromatogram >());
124  }
125 
137  template <typename ExperimentType>
138  void convertSpectraToChromatograms(ExperimentType & exp, bool remove_spectra = false)
139  {
142  for (typename ExperimentType::ConstIterator it = exp.begin(); it != exp.end(); ++it)
143  {
144  // TODO other types
145  if (it->getInstrumentSettings().getScanMode() == InstrumentSettings::SRM)
146  {
147  // exactly one precursor and one product ion
148  if (it->getPrecursors().size() == 1 && it->size() == 1)
149  {
150  chroms[it->getPrecursors().begin()->getMZ()][it->begin()->getMZ()].push_back(*it);
151  }
152  // Exactly one precursor and more than one product ion.
153  // This is how some converters (e.g. ReAdW 4.0.2) store SRM data,
154  // collecting all information from one precursor in a single
155  // pseudo-spectrum
156  else if (it->getPrecursors().size() == 1 && it->size() > 0)
157  {
158  for (Size peak_idx = 0; peak_idx < it->size(); peak_idx++)
159  {
160  // copy spectrum and delete all data, but keep metadata, then add single peak
161  SpectrumType dummy = *it;
162  dummy.clear(false);
163  dummy.push_back((*it)[peak_idx]);
164  chroms[it->getPrecursors().begin()->getMZ()][(*it)[peak_idx].getMZ()].push_back(dummy);
165  }
166  }
167  else
168  {
169  LOG_WARN << "ChromatogramTools: need exactly one precursor (given " << it->getPrecursors().size() <<
170  ") and one or more product ions (" << it->size() << "), skipping conversion of this spectrum to chromatogram." << std::endl;
171  }
172  }
173  else
174  {
175  // This does not makes sense to warn here, because it would also warn on simple mass spectra...
176  // TODO think what to to here
177  //LOG_WARN << "ChromatogramTools: cannot convert other chromatogram spectra types than 'Selected Reaction Monitoring', skipping conversion." << std::endl;
178  //
179  }
180  }
181 
182  typename Map<double, Map<double, std::vector<SpectrumType> > >::const_iterator it1 = chroms.begin();
183  for (; it1 != chroms.end(); ++it1)
184  {
185  typename Map<double, std::vector<SpectrumType> >::const_iterator it2 = it1->second.begin();
186  for (; it2 != it1->second.end(); ++it2)
187  {
188  typename ExperimentType::ChromatogramType chrom;
189  chrom.setPrecursor(*it2->second.begin()->getPrecursors().begin());
190  Product prod;
191  prod.setMZ(it2->first);
192  chrom.setProduct(prod);
193  chrom.setInstrumentSettings(it2->second.begin()->getInstrumentSettings());
194  chrom.setAcquisitionInfo(it2->second.begin()->getAcquisitionInfo());
195  chrom.setSourceFile(it2->second.begin()->getSourceFile());
196 
197  typename std::vector<SpectrumType>::const_iterator it3 = it2->second.begin();
198  for (; it3 != it2->second.end(); ++it3)
199  {
201  p.setRT(it3->getRT());
202  p.setIntensity(it3->begin()->getIntensity());
203  chrom.push_back(p);
204  }
205 
206  chrom.setNativeID("chromatogram=" + it2->second.begin()->getNativeID()); // TODO native id?
208  exp.addChromatogram(chrom);
209  }
210  }
211 
212  if (remove_spectra)
213  {
214  exp.getSpectra().erase(remove_if(exp.begin(), exp.end(), HasScanMode<SpectrumType>(InstrumentSettings::SRM)), exp.end());
215  }
216  }
217 
219  };
220 } // namespace OpenMS
221 
222 #endif // OPENMS_KERNEL_CHROMATOGRAMTOOLS_H
virtual ~ChromatogramTools()
destructor
Definition: ChromatogramTools.h:69
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:203
Product meta information.
Definition: Product.h:49
void convertChromatogramsToSpectra(ExperimentType &exp)
converts the chromatogram to a list of spectra with instrument settings SRM
Definition: ChromatogramTools.h:86
Predicate that determines if a spectrum has a certain scan mode.
Definition: RangeUtils.h:207
Peak2D PeakType
Definition: MassTrace.h:48
void setMZ(double mz)
sets the target m/z
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
MSChromatogram ChromatogramType
Definition: MzDataHandler.h:63
Selected reaction monitoring scan Synonyms: &#39;Multiple reaction monitoring scan&#39;, &#39;SRM scan&#39;, &#39;MRM scan&#39;.
Definition: InstrumentSettings.h:60
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged...
Definition: LogStream.h:451
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:215
void convertSpectraToChromatograms(ExperimentType &exp, bool remove_spectra=false)
converts e.g. SRM spectra to chromatograms
Definition: ChromatogramTools.h:138
Selected ion monitoring scan Synonyms: &#39;Multiple ion monitoring scan&#39;, &#39;SIM scan&#39;, &#39;MIM scan&#39;.
Definition: InstrumentSettings.h:59
void clear(bool clear_meta_data)
Clears all data and meta data.
ChromatogramTools(const ChromatogramTools &)
copy constructor
Definition: ChromatogramTools.h:65
ChromatogramTools()
default constructor
Definition: ChromatogramTools.h:61
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Conversion class to convert chromatograms.
Definition: ChromatogramTools.h:55
void setPrecursor(const Precursor &precursor)
sets the precursors
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:51
MSSpectrum SpectrumType
Definition: MzDataHandler.h:62

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13