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>
15 #include <boost/range/combine.hpp>
16 
17 #include <vector>
18 
19 namespace OpenMS
20 {
21  class PeptideIdentification;
22 
23  class MSSpectrum;
24 
35  class OPENMS_DLLAPI AnnotatedMSRun
36  {
37  public:
38  using SpectrumIdRef = std::pair<MSSpectrum&, PeptideIdentification&>;
39  using ConstSpectrumIdRef = std::pair<const MSSpectrum&, const PeptideIdentification&>;
42 
43 
45  AnnotatedMSRun() = default;
46 
51  explicit AnnotatedMSRun(MSExperiment&& experiment) : data(std::move(experiment))
52  {};
53 
56 
58  AnnotatedMSRun(const AnnotatedMSRun&) = default;
61 
63  ~AnnotatedMSRun() = default;
64 
69  std::vector<ProteinIdentification>& getProteinIdentifications()
70  {
71  return protein_ids_;
72  }
73 
78  const std::vector<ProteinIdentification>& getProteinIdentifications() const
79  {
80  return protein_ids_;
81  }
82 
87  void setProteinIdentifications(const std::vector<ProteinIdentification>& ids)
88  {
89  protein_ids_ = ids;
90  }
91 
96  void setProteinIdentifications(std::vector<ProteinIdentification>&& ids)
97  {
98  protein_ids_ = std::move(ids);
99  }
100 
106 
112 
118 
124 
130 
136 
141  void setMSExperiment(MSExperiment&& experiment);
142 
147  void setMSExperiment(const MSExperiment& experiment);
148 
153  inline auto cbegin() const
154  {
155  checkPeptideIdSize_(OPENMS_PRETTY_FUNCTION);
156  return PairIterator(data.getSpectra().cbegin(), peptide_ids_.cbegin());
157  }
158 
163  inline auto begin()
164  {
165  checkPeptideIdSize_(OPENMS_PRETTY_FUNCTION);
166  return PairIterator(data.getSpectra().begin(), peptide_ids_.begin());
167  }
168 
173  inline auto begin() const
174  {
175  checkPeptideIdSize_(OPENMS_PRETTY_FUNCTION);
176  return PairIterator(data.getSpectra().cbegin(), peptide_ids_.cbegin());
177  }
178 
183  inline auto end()
184  {
185  return PairIterator(data.getSpectra().end(), peptide_ids_.end());
186  }
187 
192  inline auto end() const
193  {
194  return PairIterator(data.getSpectra().end(), peptide_ids_.end());
195  }
196 
201  inline auto cend() const
202  {
203  return PairIterator(data.getSpectra().cend(), peptide_ids_.cend());
204  }
205 
211  inline SpectrumIdRef operator[](size_t idx)
212  {
213  if (idx >= peptide_ids_.size())
214  {
215  throw Exception::IndexOverflow(__FILE__, __LINE__,
216  OPENMS_PRETTY_FUNCTION,
217  idx, peptide_ids_.size());
218  }
219  if (idx >= data.getSpectra().size())
220  {
221  throw Exception::IndexOverflow(__FILE__, __LINE__,
222  OPENMS_PRETTY_FUNCTION,
223  idx, data.getSpectra().size());
224  }
225  return {data.getSpectra()[idx], peptide_ids_[idx]};
226  }
227 
233  inline ConstSpectrumIdRef operator[](size_t idx) const
234  {
235  if (idx >= peptide_ids_.size())
236  {
237  throw Exception::IndexOverflow(__FILE__, __LINE__,
238  OPENMS_PRETTY_FUNCTION,
239  idx, peptide_ids_.size());
240  }
241  if (idx >= data.getSpectra().size())
242  {
243  throw Exception::IndexOverflow(__FILE__, __LINE__,
244  OPENMS_PRETTY_FUNCTION,
245  idx, data.getSpectra().size());
246  }
247  return {data.getSpectra()[idx], peptide_ids_[idx]};
248  }
249 
256  template<typename T1, typename T2>
258  {
259  using iterator_category = std::forward_iterator_tag;
260  using difference_type = std::ptrdiff_t;
261 
267  PairIterator(T1 ptr1, T2 ptr2) : m_ptr1(ptr1), m_ptr2(ptr2)
268  {}
269 
275  {
276  ++m_ptr1;
277  ++m_ptr2;
278  return *this;
279  }
280 
286  {
287  auto tmp(*this);
288  ++(*this);
289  return tmp;
290  }
291 
296  auto operator*()
297  {
298  return std::make_pair(std::ref(*m_ptr1), std::ref(*m_ptr2));
299  }
300 
307  inline friend bool operator==(const PairIterator& a, const PairIterator& b)
308  {
309  return a.m_ptr1 == b.m_ptr1 && a.m_ptr2 == b.m_ptr2;
310  }
311 
318  inline friend bool operator!=(const PairIterator& a, const PairIterator& b)
319  {
320  return !(a == b);
321  }
322 
323  private:
324  T1 m_ptr1;
325  T2 m_ptr2;
326  };
327 
330 
331  private:
332 
333  // Helper to enforce invariant
334  void checkPeptideIdSize_(const char* function_name) const;
335 
337  std::vector<ProteinIdentification> protein_ids_;
339  };
340 }
Class for storing MS run data with peptide and protein identifications.
Definition: AnnotatedMSRun.h:36
std::vector< ProteinIdentification > protein_ids_
Definition: AnnotatedMSRun.h:337
~AnnotatedMSRun()=default
Destructor.
void setProteinIdentifications(const std::vector< ProteinIdentification > &ids)
set the protein identifications
Definition: AnnotatedMSRun.h:87
AnnotatedMSRun(MSExperiment &&experiment)
Move constructor for efficiently loading a MSExperiment without a deep copy.
Definition: AnnotatedMSRun.h:51
AnnotatedMSRun::PairIterator< std::vector< MSSpectrum >::const_iterator, PeptideIdentificationList::const_iterator > ConstIterator
Definition: AnnotatedMSRun.h:329
SpectrumIdRef operator[](size_t idx)
Access a spectrum and its associated peptide identification.
Definition: AnnotatedMSRun.h:211
MSExperiment & getMSExperiment()
Get the MSExperiment.
PeptideIdentificationList & getPeptideIdentifications()
Get all peptide identifications for all spectra.
void setProteinIdentifications(std::vector< ProteinIdentification > &&ids)
Set the protein identifications (move version)
Definition: AnnotatedMSRun.h:96
AnnotatedMSRun()=default
Default constructor.
std::vector< ProteinIdentification > & getProteinIdentifications()
Get the protein identification.
Definition: AnnotatedMSRun.h:69
AnnotatedMSRun & operator=(const AnnotatedMSRun &)=default
AnnotatedMSRun(const AnnotatedMSRun &)=default
Copy constructor.
auto end()
Get an iterator to the end of the data.
Definition: AnnotatedMSRun.h:183
void checkPeptideIdSize_(const char *function_name) const
void setPeptideIdentifications(PeptideIdentificationList &&ids)
Set all peptide identifications for all spectra (move version)
void setMSExperiment(const MSExperiment &experiment)
Set the MSExperiment.
AnnotatedMSRun::PairIterator< std::vector< MSSpectrum >::iterator, PeptideIdentificationList::iterator > Iterator
Definition: AnnotatedMSRun.h:328
MSExperiment data
Definition: AnnotatedMSRun.h:338
void setMSExperiment(MSExperiment &&experiment)
Set the MSExperiment.
auto cbegin() const
Get a const iterator to the beginning of the data.
Definition: AnnotatedMSRun.h:153
const std::vector< ProteinIdentification > & getProteinIdentifications() const
Get the protein identification (const version)
Definition: AnnotatedMSRun.h:78
AnnotatedMSRun(AnnotatedMSRun &&)=default
Move constructor.
PeptideIdentificationList peptide_ids_
Definition: AnnotatedMSRun.h:336
ConstSpectrumIdRef operator[](size_t idx) const
Access a spectrum and its associated peptide identification (const version)
Definition: AnnotatedMSRun.h:233
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:173
auto begin()
Get an iterator to the beginning of the data.
Definition: AnnotatedMSRun.h:163
auto end() const
Get a const iterator to the end of the data.
Definition: AnnotatedMSRun.h:192
std::pair< MSSpectrum &, PeptideIdentification & > SpectrumIdRef
Definition: AnnotatedMSRun.h:38
void setPeptideIdentifications(const PeptideIdentificationList &ids)
Set all peptide identifications for all spectra.
AnnotatedMSRun & operator=(AnnotatedMSRun &&)=default
auto cend() const
Get a const iterator to the end of the data.
Definition: AnnotatedMSRun.h:201
std::pair< const MSSpectrum &, const PeptideIdentification & > ConstSpectrumIdRef
Definition: AnnotatedMSRun.h:39
const PeptideIdentificationList & getPeptideIdentifications() const
Get all peptide identifications for all spectra (const version)
Int overflow exception.
Definition: Exception.h:211
typename VecMember::iterator iterator
Definition: ExposedVector.h:68
typename VecMember::const_iterator const_iterator
Definition: ExposedVector.h:69
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
Container for peptide identifications from multiple spectra.
Definition: PeptideIdentificationList.h:66
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Iterator for pairs of spectra and peptide identifications.
Definition: AnnotatedMSRun.h:258
friend bool operator!=(const PairIterator &a, const PairIterator &b)
Inequality operator.
Definition: AnnotatedMSRun.h:318
PairIterator & operator++()
Pre-increment operator.
Definition: AnnotatedMSRun.h:274
PairIterator operator++(int)
Post-increment operator.
Definition: AnnotatedMSRun.h:285
std::forward_iterator_tag iterator_category
Definition: AnnotatedMSRun.h:259
auto operator*()
Dereference operator.
Definition: AnnotatedMSRun.h:296
friend bool operator==(const PairIterator &a, const PairIterator &b)
Equality operator.
Definition: AnnotatedMSRun.h:307
PairIterator(T1 ptr1, T2 ptr2)
Constructor.
Definition: AnnotatedMSRun.h:267
T1 m_ptr1
Definition: AnnotatedMSRun.h:324
std::ptrdiff_t difference_type
Definition: AnnotatedMSRun.h:260
T2 m_ptr2
Definition: AnnotatedMSRun.h:325