OpenMS  2.6.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: Chris Bielow, Tom Waschischeck $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
39 
40 #include <ostream>
41 #include <map>
42 
43 namespace OpenMS
44 {
45  class MSExperiment;
46  class ConsensusMap;
47 
54  class OPENMS_DLLAPI QCBase
55  {
56  public:
60  enum class Requires
61  : UInt64 // 64 bit unsigned type for bitwise and/or operations (see below)
62  {
63  NOTHING, //< default, does not require anything
64  RAWMZML, //< mzML file is required
65  POSTFDRFEAT, //< Features with FDR-filtered pepIDs
66  PREFDRFEAT, //< Features with unfiltered pepIDs
67  CONTAMINANTS, //< Contaminant Database
68  TRAFOALIGN, //< transformationXMLs for RT-alignment
69  SIZE_OF_REQUIRES
70  };
72  static const std::string names_of_requires[];
73 
77  class OPENMS_DLLAPI SpectraMap
78  {
79  public:
81  SpectraMap() = default;
82 
84  explicit SpectraMap(const MSExperiment& exp);
85 
87  ~SpectraMap() = default;
88 
90  void calculateMap(const MSExperiment& exp);
91 
94  UInt64 at(const String& identifier) const;
95 
97  void clear();
98 
100  bool empty() const;
101 
103  Size size() const;
104 
105  private:
106  std::map<String, UInt64> nativeid_to_index_; //< nativeID to index
107  };
108 
109 
120  class Status
121  {
122  public:
124  friend std::ostream& operator<<(std::ostream& os, const Status& stat);
125 
127  Status() : value_(0)
128  {}
129 
130  explicit Status(const Requires& req)
131  {
132  value_ = getPow_(req);
133  }
134 
135  Status(const Status& stat)
136  {
137  value_ = stat.value_;
138  }
139 
141  Status& operator=(const Requires& req)
142  {
143  value_ = getPow_(req);
144  return *this;
145  }
146 
148  ~Status() = default;
149 
150  // Equal
151  bool operator==(const Status& stat) const
152  {
153  return (value_ == stat.value_);
154  }
155 
156  Status& operator=(const Status& stat) = default;
157  // Bitwise operators
158 
159  Status operator&(const Requires& req) const
160  {
161  Status s = *this;
162  s.value_ &= getPow_(req);
163  return s;
164  }
165 
166  Status operator&(const Status& stat) const
167  {
168  Status s = *this;
169  s.value_ &= stat.value_;
170  return s;
171  }
172 
174  {
175  value_ &= getPow_(req);
176  return *this;
177  }
178 
179  Status& operator&=(const Status& stat)
180  {
181  value_ &= stat.value_;
182  return *this;
183  }
184 
185  Status operator|(const Requires& req) const
186  {
187  Status s = *this;
188  s.value_ |= getPow_(req);
189  return s;
190  }
191 
192  Status operator|(const Status& stat) const
193  {
194  Status s = *this;
195  s.value_ |= stat.value_;
196  return s;
197  }
198 
200  {
201  value_ |= getPow_(req);
202  return *this;
203  }
204 
205  Status& operator|=(const Status& stat)
206  {
207  value_ |= stat.value_;
208  return *this;
209  }
210 
214  bool isSuperSetOf(const Status& stat) const
215  {
216  return ((value_ & stat.value_) == stat.value_);
217  }
218 
219  private:
221  UInt64 getPow_(const Requires& r) const
222  {
223  return UInt64(1) << UInt64 (r);
224  }
226  };
227 
231  virtual const String& getName() const = 0;
232 
236  virtual Status requires() const = 0;
237 
238 
241  bool isRunnable(const Status& s) const;
242 
244  static bool isLabeledExperiment(const ConsensusMap& cm);
245 
247  template <typename MAP>
248  static bool hasPepID(const MAP& fmap)
249  {
250  if (!fmap.getUnassignedPeptideIdentifications().empty()) return true;
251 
252  for (const auto& features : fmap)
253  {
254  if (!features.getPeptideIdentifications().empty()) return true;
255  }
256  return false;
257  }
258  };
259 
260  inline std::ostream& operator<<(std::ostream& os, const QCBase::Status& stat)
261  {
262  return os << stat.value_;
263  }
264 }
OpenMS::QCBase::Status::operator|
Status operator|(const Requires &req) const
Definition: QCBase.h:185
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:120
OpenMS::QCBase::Status::operator|
Status operator|(const Status &stat) const
Definition: QCBase.h:192
Types.h
OpenMS::String
A more convenient string class.
Definition: String.h:59
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:205
OpenMS::QCBase::Requires
Requires
Enum to encode a file type as a bit.
Definition: QCBase.h:60
OpenMS::QCBase::Status::operator=
Status & operator=(const Requires &req)
Assignment.
Definition: QCBase.h:141
OpenMS::QCBase::Status::operator|=
Status & operator|=(const Requires &req)
Definition: QCBase.h:199
OpenMS::QCBase::SpectraMap
Map to find a spectrum via its NativeID.
Definition: QCBase.h:77
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::QCBase::Status::operator&
Status operator&(const Status &stat) const
Definition: QCBase.h:166
OpenMS::QCBase
This class serves as an abstract base class for all QC classes.
Definition: QCBase.h:54
OpenMS::QCBase::SpectraMap::nativeid_to_index_
std::map< String, UInt64 > nativeid_to_index_
Definition: QCBase.h:106
OpenMS::QCBase::Status::Status
Status(const Requires &req)
Definition: QCBase.h:130
OpenMS::QCBase::Status::operator&=
Status & operator&=(const Status &stat)
Definition: QCBase.h:179
OpenMS::QCBase::Status::Status
Status()
Constructors.
Definition: QCBase.h:127
OpenMS::QCBase::Status::Status
Status(const Status &stat)
Definition: QCBase.h:135
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:80
OpenMS::QCBase::Status::operator&=
Status & operator&=(const Requires &req)
Definition: QCBase.h:173
String.h
OpenMS::QCBase::Status::isSuperSetOf
bool isSuperSetOf(const Status &stat) const
Check if input status fulfills requirement status.
Definition: QCBase.h:214
OpenMS::QCBase::hasPepID
static bool hasPepID(const MAP &fmap)
does the container have a PeptideIdentification in its members or as unassignedPepID ?
Definition: QCBase.h:248
OpenMS::QCBase::Status::operator&
Status operator&(const Requires &req) const
Definition: QCBase.h:159
OpenMS::QCBase::Status::value_
UInt64 value_
Definition: QCBase.h:225
OpenMS::QCBase::Status::getPow_
UInt64 getPow_(const Requires &r) const
computes pow(2, r)
Definition: QCBase.h:221
OpenMS::QCBase::Status::operator==
bool operator==(const Status &stat) const
Definition: QCBase.h:151