OpenMS
LayerStatistics.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 // OpenMS_GUI config
12 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
13 
14 #include <OpenMS/CONCEPT/Types.h>
18 
19 #include <array>
20 #include <map>
21 #include <string>
22 #include <variant>
23 
24 namespace OpenMS
25 {
26  class MetaInfoInterface;
27  class ConsensusMap;
28  class FeatureMap;
29 
35  template <typename VALUE_TYPE>
36  struct RangeStats
37  {
38  public:
39  void addDataPoint(VALUE_TYPE v)
40  {
41  ++count_;
42  sum_ += v;
43  min_ = std::min(min_, v);
44  max_ = std::max(max_, v);
45  }
46 
47  VALUE_TYPE getMin() const
48  {
49  return min_;
50  }
51 
52  VALUE_TYPE getMax() const
53  {
54  return max_;
55  }
56 
57  size_t getCount() const
58  {
59  return count_;
60  }
61 
63  double getAvg() const
64  {
65  return count_ == 0 ? 0 : double(sum_) / count_;
66  }
67 
68  protected:
69  size_t count_{0};
70  VALUE_TYPE min_{std::numeric_limits<VALUE_TYPE>::max()}; // init with very high value
71  VALUE_TYPE max_{std::numeric_limits<VALUE_TYPE>::lowest()}; // init with lowest (=negative) value possible
72  VALUE_TYPE sum_{0};
73  };
74 
77  using RangeStatsVariant = std::variant<RangeStatsInt, RangeStatsDouble>;
78 
80  struct StatsCounter
81  {
82  size_t counter{0};
83  };
84 
86  enum class RangeStatsSource
87  {
88  CORE,
89  METAINFO,
90  ARRAYINFO,
92  };
93 
95  static const std::array<const char*, (size_t)RangeStatsSource::SIZE_OF_STATSSOURCE> StatsSourceNames = {"core statistics", "meta values", "data arrays"};
96 
99  {
101  std::string name;
102 
103  bool operator<(const RangeStatsType& rhs) const
104  {
105  return std::tie(src, name) < std::tie(rhs.src, rhs.name);
106  }
107 
108  bool operator==(const RangeStatsType& rhs) const
109  {
110  return src == rhs.src && name == rhs.name;
111  }
112  };
113 
115  using StatsMap = std::map<RangeStatsType, RangeStatsVariant>;
117  using StatsCounterMap = std::map<std::string, StatsCounter>;
118 
122  class OPENMS_GUI_DLLAPI LayerStatistics
123  {
124  public:
125 
127  virtual ~LayerStatistics() = default;
128 
131  {
132  return overview_range_data_;
133  }
134 
137  {
138  return overview_count_data_;
139  }
140 
148  virtual Math::Histogram<> getDistribution(const RangeStatsType& which, const UInt number_of_bins = 500) const = 0;
149 
150 
151  protected:
153  virtual void computeStatistics_() = 0;
155  void bringInMetaStats_(const MetaInfoInterface* meta_interface);
156 
159  };
160 
164  class OPENMS_GUI_DLLAPI LayerStatisticsPeakMap
165  : public LayerStatistics
166  {
167  public:
169 
170  Math::Histogram<> getDistribution(const RangeStatsType& which, const UInt number_of_bins) const override;
171 
172  private:
173  void computeStatistics_() override;
174  const PeakMap* pm_;
176  };
177 
181  class OPENMS_GUI_DLLAPI LayerStatisticsFeatureMap : public LayerStatistics
182  {
183  public:
185 
187  const UInt number_of_bins) const override;
188 
189  private:
190  void computeStatistics_() override;
191  const FeatureMap* fm_;
193  };
194 
198  class OPENMS_GUI_DLLAPI LayerStatisticsConsensusMap : public LayerStatistics
199  {
200  public:
202 
204  const UInt number_of_bins) const override;
205 
206  private:
207  void computeStatistics_() override;
208  const ConsensusMap* cm_;
210  };
211 
215  class OPENMS_GUI_DLLAPI LayerStatisticsIdent : public LayerStatistics
216  {
217  public:
219 
221  const UInt number_of_bins) const override;
222 
223  private:
224  void computeStatistics_() override;
227  };
228 
229 } // namespace OpenMS
A container for consensus elements.
Definition: ConsensusMap.h:66
A container for features.
Definition: FeatureMap.h:80
std::vector< PeptideIdentification > PepIds
Definition: IPeptideIds.h:25
Computes statistics and distributions for a PeakMap.
Definition: LayerStatistics.h:199
const ConsensusMap * cm_
Definition: LayerStatistics.h:208
void computeStatistics_() override
compute the range and count statistics. Call this method in the Ctor of derived classes.
Math::Histogram getDistribution(const RangeStatsType &which, const UInt number_of_bins) const override
After computing the overview statistic, you can query a concrete distribution by giving the name of t...
LayerStatisticsConsensusMap(const ConsensusMap &cm)
Computes statistics and distributions for a PeakMap.
Definition: LayerStatistics.h:182
const FeatureMap * fm_
Definition: LayerStatistics.h:191
void computeStatistics_() override
compute the range and count statistics. Call this method in the Ctor of derived classes.
LayerStatisticsFeatureMap(const FeatureMap &fm)
Math::Histogram getDistribution(const RangeStatsType &which, const UInt number_of_bins) const override
After computing the overview statistic, you can query a concrete distribution by giving the name of t...
Computes statistics and distributions for a vector<PeptideIdentifications>
Definition: LayerStatistics.h:216
void computeStatistics_() override
compute the range and count statistics. Call this method in the Ctor of derived classes.
LayerStatisticsIdent(const IPeptideIds::PepIds &cm)
Math::Histogram getDistribution(const RangeStatsType &which, const UInt number_of_bins) const override
After computing the overview statistic, you can query a concrete distribution by giving the name of t...
const IPeptideIds::PepIds * ids_
Definition: LayerStatistics.h:225
Computes statistics and distributions for a PeakMap
Definition: LayerStatistics.h:166
void computeStatistics_() override
compute the range and count statistics. Call this method in the Ctor of derived classes.
const PeakMap * pm_
Definition: LayerStatistics.h:174
LayerStatisticsPeakMap(const PeakMap &pm)
Math::Histogram getDistribution(const RangeStatsType &which, const UInt number_of_bins) const override
After computing the overview statistic, you can query a concrete distribution by giving the name of t...
Compute summary statistics (count/min/max/avg) about a container, e.g. intensity, charge,...
Definition: LayerStatistics.h:123
void bringInMetaStats_(const MetaInfoInterface *meta_interface)
Brings the meta values of one meta_interface (a peak or feature) into the statistics.
virtual void computeStatistics_()=0
compute the range and count statistics. Call this method in the Ctor of derived classes.
virtual ~LayerStatistics()=default
Make D'tor virtual for correct destruction from pointers to base.
StatsMap overview_range_data_
data on numerical values computed during getOverviewStatistics
Definition: LayerStatistics.h:157
const StatsCounterMap & getCountStatistics() const
obtain count statistics for all meta values which are not numerical
Definition: LayerStatistics.h:136
const StatsMap & getRangeStatistics() const
get all range statistics, any of which can then be plugged into getDistribution()
Definition: LayerStatistics.h:130
StatsCounterMap overview_count_data_
count data on non-numerical values computed during getOverviewStatistics
Definition: LayerStatistics.h:158
virtual Math::Histogram getDistribution(const RangeStatsType &which, const UInt number_of_bins=500) const =0
After computing the overview statistic, you can query a concrete distribution by giving the name of t...
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Representation of a histogram.
Definition: Histogram.h:38
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:35
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
static const std::array< const char *,(size_t) RangeStatsSource::SIZE_OF_STATSSOURCE > StatsSourceNames
Names corresponding to elements of enum RangeStatsSource.
Definition: LayerStatistics.h:95
RangeStatsSource
Where did a statistic come from? Useful for display to user, and for internal dispatch when user requ...
Definition: LayerStatistics.h:87
@ METAINFO
statistic was obtained from MetaInfoInterface of container elements, e.g. "FWHM" for FeatureMaps
@ CORE
statistic was obtained from a core data structure of the container, e.g. intensity
@ ARRAYINFO
statistic was obtained from Float/IntegerArrays of the container elements, e.g. "IonMobility" for Pea...
size_t counter
Definition: LayerStatistics.h:82
std::map< std::string, StatsCounter > StatsCounterMap
collection of MetaValues which are not numeric (counts only the number of occurrences per metavalue)
Definition: LayerStatistics.h:117
std::map< RangeStatsType, RangeStatsVariant > StatsMap
collection of Min/Max/Avg statistics from different sources. Note: must be sorted,...
Definition: LayerStatistics.h:115
std::variant< RangeStatsInt, RangeStatsDouble > RangeStatsVariant
Definition: LayerStatistics.h:77
a simple counting struct, for non-numerical occurrences of meta-values
Definition: LayerStatistics.h:81
Origin and name of a statistic.
Definition: LayerStatistics.h:99
RangeStatsSource src
Definition: LayerStatistics.h:100
bool operator==(const RangeStatsType &rhs) const
Definition: LayerStatistics.h:108
std::string name
Definition: LayerStatistics.h:101
bool operator<(const RangeStatsType &rhs) const
Definition: LayerStatistics.h:103
Struct representing the statistics about a set of values.
Definition: LayerStatistics.h:37
VALUE_TYPE getMin() const
Definition: LayerStatistics.h:47
VALUE_TYPE min_
Definition: LayerStatistics.h:70
size_t getCount() const
Definition: LayerStatistics.h:57
size_t count_
Definition: LayerStatistics.h:69
double getAvg() const
get the average value from all calls to addDataPoint()
Definition: LayerStatistics.h:63
VALUE_TYPE sum_
Definition: LayerStatistics.h:72
void addDataPoint(VALUE_TYPE v)
Definition: LayerStatistics.h:39
VALUE_TYPE max_
Definition: LayerStatistics.h:71
VALUE_TYPE getMax() const
Definition: LayerStatistics.h:52