OpenMS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AnnotatedMSRun.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg$
6 // $Authors: David Voigt, Timo Sachsenberg $
7 // -------------------------------------------------------------------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/OpenMSConfig.h>
13 #include <boost/range/combine.hpp>
14 
15 #include <vector>
16 
17 namespace OpenMS
18 {
19  class PeptideIdentification;
20 
21  class MSSpectrum;
22 
33  class OPENMS_DLLAPI AnnotatedMSRun
34  {
35  public:
36  using SpectrumIdRef = std::pair<MSSpectrum&, PeptideIdentification&>;
37  using ConstSpectrumIdRef = std::pair<const MSSpectrum&, const PeptideIdentification&>;
40 
41 
43  AnnotatedMSRun() = default;
44 
49  explicit AnnotatedMSRun(MSExperiment&& experiment) : data(std::move(experiment))
50  {};
51 
54 
56  AnnotatedMSRun(const AnnotatedMSRun&) = default;
59 
61  ~AnnotatedMSRun() = default;
62 
67  std::vector<ProteinIdentification>& getProteinIdentifications()
68  {
69  return protein_ids_;
70  }
71 
76  const std::vector<ProteinIdentification>& getProteinIdentifications() const
77  {
78  return protein_ids_;
79  }
80 
85  std::vector<PeptideIdentification>& getPeptideIdentifications();
86 
91  const std::vector<PeptideIdentification>& getPeptideIdentifications() const;
92 
97  void setPeptideIdentifications(std::vector<PeptideIdentification>&& ids);
98 
103  void setPeptideIdentifications(const std::vector<PeptideIdentification>& ids);
104 
110 
116 
121  void setMSExperiment(MSExperiment&& experiment);
122 
127  void setMSExperiment(const MSExperiment& experiment);
128 
133  inline auto cbegin() const
134  {
135  checkPeptideIdSize_(OPENMS_PRETTY_FUNCTION);
136  return PairIterator(data.getSpectra().cbegin(), peptide_ids_.cbegin());
137  }
138 
143  inline auto begin()
144  {
145  checkPeptideIdSize_(OPENMS_PRETTY_FUNCTION);
146  return PairIterator(data.getSpectra().begin(), peptide_ids_.begin());
147  }
148 
153  inline auto begin() const
154  {
155  checkPeptideIdSize_(OPENMS_PRETTY_FUNCTION);
156  return PairIterator(data.getSpectra().cbegin(), peptide_ids_.cbegin());
157  }
158 
163  inline auto end()
164  {
165  return PairIterator(data.getSpectra().end(), peptide_ids_.end());
166  }
167 
172  inline auto end() const
173  {
174  return PairIterator(data.getSpectra().end(), peptide_ids_.end());
175  }
176 
181  inline auto cend() const
182  {
183  return PairIterator(data.getSpectra().cend(), peptide_ids_.cend());
184  }
185 
191  inline SpectrumIdRef operator[](size_t idx)
192  {
193  if (idx >= peptide_ids_.size())
194  {
195  throw Exception::IndexOverflow(__FILE__, __LINE__,
196  OPENMS_PRETTY_FUNCTION,
197  idx, peptide_ids_.size());
198  }
199  if (idx >= data.getSpectra().size())
200  {
201  throw Exception::IndexOverflow(__FILE__, __LINE__,
202  OPENMS_PRETTY_FUNCTION,
203  idx, data.getSpectra().size());
204  }
205  return {data.getSpectra()[idx], peptide_ids_[idx]};
206  }
207 
213  inline ConstSpectrumIdRef operator[](size_t idx) const
214  {
215  if (idx >= peptide_ids_.size())
216  {
217  throw Exception::IndexOverflow(__FILE__, __LINE__,
218  OPENMS_PRETTY_FUNCTION,
219  idx, peptide_ids_.size());
220  }
221  if (idx >= data.getSpectra().size())
222  {
223  throw Exception::IndexOverflow(__FILE__, __LINE__,
224  OPENMS_PRETTY_FUNCTION,
225  idx, data.getSpectra().size());
226  }
227  return {data.getSpectra()[idx], peptide_ids_[idx]};
228  }
229 
236  template<typename T1, typename T2>
238  {
239  using iterator_category = std::forward_iterator_tag;
240  using difference_type = std::ptrdiff_t;
241 
247  PairIterator(T1 ptr1, T2 ptr2) : m_ptr1(ptr1), m_ptr2(ptr2)
248  {}
249 
255  {
256  ++m_ptr1;
257  ++m_ptr2;
258  return *this;
259  }
260 
266  {
267  auto tmp(*this);
268  ++(*this);
269  return tmp;
270  }
271 
276  auto operator*()
277  {
278  return std::make_pair(std::ref(*m_ptr1), std::ref(*m_ptr2));
279  }
280 
287  inline friend bool operator==(const PairIterator& a, const PairIterator& b)
288  {
289  return a.m_ptr1 == b.m_ptr1 && a.m_ptr2 == b.m_ptr2;
290  }
291 
298  inline friend bool operator!=(const PairIterator& a, const PairIterator& b)
299  {
300  return !(a == b);
301  }
302 
303  private:
304  T1 m_ptr1;
305  T2 m_ptr2;
306  };
307 
308  typedef AnnotatedMSRun::PairIterator<std::vector<MSSpectrum>::iterator, std::vector<PeptideIdentification>::iterator> Iterator;
309  typedef AnnotatedMSRun::PairIterator<std::vector<MSSpectrum>::const_iterator, std::vector<PeptideIdentification>::const_iterator> ConstIterator;
310 
311  private:
312 
313  // Helper to enforce invariant
314  void checkPeptideIdSize_(const char* function_name) const;
315 
316  std::vector<PeptideIdentification> peptide_ids_;
317  std::vector<ProteinIdentification> protein_ids_;
319  };
320 }
Class for storing MS run data with peptide and protein identifications.
Definition: AnnotatedMSRun.h:34
AnnotatedMSRun::PairIterator< std::vector< MSSpectrum >::iterator, std::vector< PeptideIdentification >::iterator > Iterator
Definition: AnnotatedMSRun.h:308
std::vector< ProteinIdentification > protein_ids_
Definition: AnnotatedMSRun.h:317
~AnnotatedMSRun()=default
Destructor.
AnnotatedMSRun(MSExperiment &&experiment)
Move constructor for efficiently loading a MSExperiment without a deep copy.
Definition: AnnotatedMSRun.h:49
SpectrumIdRef operator[](size_t idx)
Access a spectrum and its associated peptide identification.
Definition: AnnotatedMSRun.h:191
MSExperiment & getMSExperiment()
Get the MSExperiment.
std::vector< PeptideIdentification > peptide_ids_
Definition: AnnotatedMSRun.h:316
AnnotatedMSRun()=default
Default constructor.
std::vector< ProteinIdentification > & getProteinIdentifications()
Get the protein identification.
Definition: AnnotatedMSRun.h:67
AnnotatedMSRun & operator=(const AnnotatedMSRun &)=default
AnnotatedMSRun(const AnnotatedMSRun &)=default
Copy constructor.
std::vector< PeptideIdentification > & getPeptideIdentifications()
Get all peptide identifications for all spectra.
auto end()
Get an iterator to the end of the data.
Definition: AnnotatedMSRun.h:163
void checkPeptideIdSize_(const char *function_name) const
void setMSExperiment(const MSExperiment &experiment)
Set the MSExperiment.
void setPeptideIdentifications(std::vector< PeptideIdentification > &&ids)
Set all peptide identifications for all spectra.
MSExperiment data
Definition: AnnotatedMSRun.h:318
const std::vector< PeptideIdentification > & getPeptideIdentifications() const
Get all peptide identifications for all spectra (const version)
void setMSExperiment(MSExperiment &&experiment)
Set the MSExperiment.
auto cbegin() const
Get a const iterator to the beginning of the data.
Definition: AnnotatedMSRun.h:133
const std::vector< ProteinIdentification > & getProteinIdentifications() const
Get the protein identification (const version)
Definition: AnnotatedMSRun.h:76
AnnotatedMSRun::PairIterator< std::vector< MSSpectrum >::const_iterator, std::vector< PeptideIdentification >::const_iterator > ConstIterator
Definition: AnnotatedMSRun.h:309
AnnotatedMSRun(AnnotatedMSRun &&)=default
Move constructor.
ConstSpectrumIdRef operator[](size_t idx) const
Access a spectrum and its associated peptide identification (const version)
Definition: AnnotatedMSRun.h:213
const MSExperiment & getMSExperiment() const
Get the MSExperiment (const version)
auto begin() const
Get a const iterator to the beginning of the data.
Definition: AnnotatedMSRun.h:153
auto begin()
Get an iterator to the beginning of the data.
Definition: AnnotatedMSRun.h:143
void setPeptideIdentifications(const std::vector< PeptideIdentification > &ids)
Set all peptide identifications for all spectra.
auto end() const
Get a const iterator to the end of the data.
Definition: AnnotatedMSRun.h:172
std::pair< MSSpectrum &, PeptideIdentification & > SpectrumIdRef
Definition: AnnotatedMSRun.h:36
AnnotatedMSRun & operator=(AnnotatedMSRun &&)=default
auto cend() const
Get a const iterator to the end of the data.
Definition: AnnotatedMSRun.h:181
std::pair< const MSSpectrum &, const PeptideIdentification & > ConstSpectrumIdRef
Definition: AnnotatedMSRun.h:37
Int overflow exception.
Definition: Exception.h:211
The representation of a chromatogram.
Definition: MSChromatogram.h:30
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:49
MSChromatogram ChromatogramType
Chromatogram type.
Definition: MSExperiment.h:76
MSSpectrum SpectrumType
Spectrum Type.
Definition: MSExperiment.h:74
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Iterator for pairs of spectra and peptide identifications.
Definition: AnnotatedMSRun.h:238
friend bool operator!=(const PairIterator &a, const PairIterator &b)
Inequality operator.
Definition: AnnotatedMSRun.h:298
PairIterator & operator++()
Pre-increment operator.
Definition: AnnotatedMSRun.h:254
PairIterator operator++(int)
Post-increment operator.
Definition: AnnotatedMSRun.h:265
std::forward_iterator_tag iterator_category
Definition: AnnotatedMSRun.h:239
auto operator*()
Dereference operator.
Definition: AnnotatedMSRun.h:276
friend bool operator==(const PairIterator &a, const PairIterator &b)
Equality operator.
Definition: AnnotatedMSRun.h:287
PairIterator(T1 ptr1, T2 ptr2)
Constructor.
Definition: AnnotatedMSRun.h:247
T1 m_ptr1
Definition: AnnotatedMSRun.h:304
std::ptrdiff_t difference_type
Definition: AnnotatedMSRun.h:240
T2 m_ptr2
Definition: AnnotatedMSRun.h:305