OpenMS
MapUtilities.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Julianus Pfeuffer$
6 // $Authors: Julianus Pfeuffer $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/config.h>
13 #include <vector>
14 
15 namespace OpenMS
16 {
22  template <class MapType>
24  {
25  public:
27  template <class T>
28  void applyFunctionOnPeptideHits(T&& f, bool include_unassigned = true)
29  {
30  for (auto& feat : static_cast<MapType&>(*this))
31  {
32  applyFunctionOnPeptideHits_(feat.getPeptideIdentifications(), f);
33  }
34  if (include_unassigned)
35  {
36  applyFunctionOnPeptideHits_(static_cast<MapType&>(*this).getUnassignedPeptideIdentifications(), f);
37  }
38  }
39 
41  template <class T>
42  void applyFunctionOnPeptideIDs(T&& f, bool include_unassigned = true)
43  {
44  for (auto& feat : static_cast<MapType&>(*this))
45  {
46  applyFunctionOnPeptideIDs_(feat.getPeptideIdentifications(), f);
47  }
48  if (include_unassigned)
49  {
50  applyFunctionOnPeptideIDs_(static_cast<MapType&>(*this).getUnassignedPeptideIdentifications(), f);
51  }
52  }
53 
55  template <class T>
56  void applyFunctionOnPeptideHits(T&& f, bool include_unassigned = true) const
57  {
58  for (const auto& feat : static_cast<MapType const&>(*this))
59  {
60  applyFunctionOnPeptideHits_(feat.getPeptideIdentifications(), f);
61  }
62  if (include_unassigned)
63  {
64  applyFunctionOnPeptideHits_(static_cast<MapType const&>(*this).getUnassignedPeptideIdentifications(), f);
65  }
66  }
67 
69  template <class T>
70  void applyFunctionOnPeptideIDs(T&& f, bool include_unassigned = true) const
71  {
72  for (const auto& feat : static_cast<MapType const&>(*this))
73  {
74  applyFunctionOnPeptideIDs_(feat.getPeptideIdentifications(), f);
75  }
76  if (include_unassigned)
77  {
78  applyFunctionOnPeptideIDs_(static_cast<MapType const&>(*this).getUnassignedPeptideIdentifications(), f);
79  }
80  }
81 
82  private:
83  template <class T>
84  void applyFunctionOnPeptideIDs_(std::vector<PeptideIdentification>& idvec, T&& f)
85  {
86  for (auto& id : idvec)
87  {
88  f(id);
89  }
90  }
91 
92  template <class T>
93  void applyFunctionOnPeptideHits_(std::vector<PeptideIdentification>& idvec, T&& f)
94  {
95  for (auto& id : idvec)
96  {
97  for (auto& hit : id.getHits())
98  {
99  f(hit);
100  }
101  }
102  }
103 
104  template <class T>
105  void applyFunctionOnPeptideIDs_(const std::vector<PeptideIdentification>& idvec, T&& f) const
106  {
107  for (const auto& id : idvec)
108  {
109  f(id);
110  }
111  }
112 
113  template <class T>
114  void applyFunctionOnPeptideHits_(const std::vector<PeptideIdentification>& idvec, T&& f) const
115  {
116  for (const auto& id : idvec)
117  {
118  for (const auto& hit : id.getHits())
119  {
120  f(hit);
121  }
122  }
123  }
124  };
125 
126 } // namespace OpenMS
127 
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Utilities for Feature and ConsensusMap.
Definition: MapUtilities.h:24
void applyFunctionOnPeptideIDs(T &&f, bool include_unassigned=true) const
applies a const function on all PeptideIDs or only assigned ones
Definition: MapUtilities.h:70
void applyFunctionOnPeptideHits_(const std::vector< PeptideIdentification > &idvec, T &&f) const
Definition: MapUtilities.h:114
void applyFunctionOnPeptideIDs_(const std::vector< PeptideIdentification > &idvec, T &&f) const
Definition: MapUtilities.h:105
void applyFunctionOnPeptideHits(T &&f, bool include_unassigned=true)
applies a function on all PeptideHits or only assigned ones
Definition: MapUtilities.h:28
void applyFunctionOnPeptideIDs(T &&f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
Definition: MapUtilities.h:42
void applyFunctionOnPeptideIDs_(std::vector< PeptideIdentification > &idvec, T &&f)
Definition: MapUtilities.h:84
void applyFunctionOnPeptideHits_(std::vector< PeptideIdentification > &idvec, T &&f)
Definition: MapUtilities.h:93
void applyFunctionOnPeptideHits(T &&f, bool include_unassigned=true) const
applies a const function on all PeptideHits or only assigned ones
Definition: MapUtilities.h:56
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22