OpenMS  2.5.0
QCBase.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-2020.
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: Chris Bielow $
32 // $Authors: Tom Waschischeck $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
39 #include <iostream>
40 #include <map>
41 
42 namespace OpenMS
43 {
44  class MSExperiment;
45 
52  class OPENMS_DLLAPI QCBase
53  {
54  public:
58  enum class Requires
59  : UInt64 // 64 bit unsigned type for bitwise and/or operations (see below)
60  {
61  FAIL, //< default, does not encode for anything
62  RAWMZML, //< mzML file is required
63  POSTFDRFEAT, //< Features with FDR-filtered pepIDs
64  PREFDRFEAT, //< Features with unfiltered pepIDs
65  CONTAMINANTS, //< Contaminant Database
66  TRAFOALIGN, //< transformationXMLs for RT-alignment
67  SIZE_OF_REQUIRES
68  };
70  static const std::string names_of_requires[];
71 
75  class OPENMS_DLLAPI SpectraMap
76  {
77  public:
79  SpectraMap() = default;
80 
82  SpectraMap(const MSExperiment& exp);
83 
85  ~SpectraMap() = default;
86 
88  void calculateMap(const MSExperiment& exp);
89 
92  UInt64 at(const String& identifier) const;
93 
95  void clear();
96 
98  bool empty() const;
99 
101  Size size() const;
102 
103  private:
104  std::map<String, UInt64> nativeid_to_index_; //< nativeID to index
105  };
106 
107 
118  class Status
119  {
120  public:
122  friend std::ostream& operator<<(std::ostream& os, const Status& stat);
123 
125  Status() : value_(0)
126  {}
127 
128  Status(const Requires& req)
129  {
130  value_ = getPow_(req);
131  }
132 
133  Status(const Status& stat)
134  {
135  value_ = stat.value_;
136  }
137 
139  Status& operator=(const Requires& req)
140  {
141  value_ = getPow_(req);
142  return *this;
143  }
144 
146  ~Status() = default;
147 
148  // Equal
149  bool operator==(const Status& stat) const
150  {
151  return (value_ == stat.value_);
152  }
153 
154  Status& operator=(const Status& stat) = default;
155  // Bitwise operators
156 
157  Status operator&(const Requires& req) const
158  {
159  Status s = *this;
160  s.value_ &= getPow_(req);
161  return s;
162  }
163 
164  Status operator&(const Status& stat) const
165  {
166  Status s = *this;
167  s.value_ &= stat.value_;
168  return s;
169  }
170 
172  {
173  value_ &= getPow_(req);
174  return *this;
175  }
176 
177  Status& operator&=(const Status& stat)
178  {
179  value_ &= stat.value_;
180  return *this;
181  }
182 
183  Status operator|(const Requires& req) const
184  {
185  Status s = *this;
186  s.value_ |= getPow_(req);
187  return s;
188  }
189 
190  Status operator|(const Status& stat) const
191  {
192  Status s = *this;
193  s.value_ |= stat.value_;
194  return s;
195  }
196 
198  {
199  value_ |= getPow_(req);
200  return *this;
201  }
202 
203  Status& operator|=(const Status& stat)
204  {
205  value_ |= stat.value_;
206  return *this;
207  }
208 
212  bool isSuperSetOf(const Status& stat) const
213  {
214  return ((value_ & stat.value_) == stat.value_);
215  }
216 
217  private:
219  UInt64 getPow_(const Requires& r) const
220  {
221  return UInt64(1) << UInt64 (r);
222  }
224  };
225 
229  virtual const String& getName() const = 0;
230 
234  virtual Status requires() const = 0;
235 
236 
243  template <typename MAP, typename T>
244  static void iterateFeatureMap(MAP& fmap, T lambda)
245  {
246  for (auto& pep_id : fmap.getUnassignedPeptideIdentifications())
247  {
248  lambda(pep_id);
249  }
250 
251  for (auto& features : fmap)
252  {
253  for (auto& pep_id : features.getPeptideIdentifications())
254  {
255  lambda(pep_id);
256  }
257  }
258  }
259  };
260 
261  inline std::ostream& operator<<(std::ostream& os, const QCBase::Status& stat)
262  {
263  return os << stat.value_;
264  }
265 }
OpenMS::QCBase::Status::operator|
Status operator|(const Requires &req) const
Definition: QCBase.h:183
OpenMS::UInt64
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
OpenMS::QCBase::Status
Storing a status of available/needed inputs (i.e. a set of Requires) as UInt64.
Definition: QCBase.h:118
OpenMS::QCBase::Status::operator|
Status operator|(const Status &stat) const
Definition: QCBase.h:190
Types.h
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::QCBase::Status::operator|=
Status & operator|=(const Status &stat)
Definition: QCBase.h:203
OpenMS::QCBase::Requires
Requires
Enum to encode a file type as a bit.
Definition: QCBase.h:58
OpenMS::QCBase::Status::operator=
Status & operator=(const Requires &req)
Assignment.
Definition: QCBase.h:139
OpenMS::QCBase::Status::operator|=
Status & operator|=(const Requires &req)
Definition: QCBase.h:197
OpenMS::QCBase::SpectraMap
Map to find a spectrum via its NativeID.
Definition: QCBase.h:75
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::QCBase::Status::operator&
Status operator&(const Status &stat) const
Definition: QCBase.h:164
OpenMS::QCBase
This class serves as an abstract base class for all QC classes.
Definition: QCBase.h:52
OpenMS::QCBase::SpectraMap::nativeid_to_index_
std::map< String, UInt64 > nativeid_to_index_
Definition: QCBase.h:104
OpenMS::QCBase::Status::Status
Status(const Requires &req)
Definition: QCBase.h:128
OpenMS::QCBase::Status::operator&=
Status & operator&=(const Status &stat)
Definition: QCBase.h:177
OpenMS::QCBase::Status::Status
Status()
Constructors.
Definition: QCBase.h:125
OpenMS::QCBase::Status::Status
Status(const Status &stat)
Definition: QCBase.h:133
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::QCBase::Status::operator&=
Status & operator&=(const Requires &req)
Definition: QCBase.h:171
String.h
OpenMS::QCBase::Status::isSuperSetOf
bool isSuperSetOf(const Status &stat) const
Check if input status fulfills requirement status.
Definition: QCBase.h:212
OpenMS::QCBase::Status::operator&
Status operator&(const Requires &req) const
Definition: QCBase.h:157
OpenMS::QCBase::Status::value_
UInt64 value_
Definition: QCBase.h:223
OpenMS::QCBase::iterateFeatureMap
static void iterateFeatureMap(MAP &fmap, T lambda)
function, which iterates through all PeptideIdentifications of a given FeatureMap and applies a given...
Definition: QCBase.h:244
OpenMS::QCBase::Status::getPow_
UInt64 getPow_(const Requires &r) const
computes pow(2, r)
Definition: QCBase.h:219
OpenMS::QCBase::Status::operator==
bool operator==(const Status &stat) const
Definition: QCBase.h:149