OpenMS  3.0.0
LayerStatistics.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-2022.
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 $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
40 #include <OpenMS/CONCEPT/Types.h>
44 
45 #include <array>
46 #include <map>
47 #include <string>
48 #include <variant>
49 
50 namespace OpenMS
51 {
52  class MetaInfoInterface;
53  class ConsensusMap;
54  class FeatureMap;
55 
61  template <typename VALUE_TYPE>
62  struct RangeStats
63  {
64  public:
65  void addDataPoint(VALUE_TYPE v)
66  {
67  ++count_;
68  sum_ += v;
69  min_ = std::min(min_, v);
70  max_ = std::max(max_, v);
71  }
72 
73  VALUE_TYPE getMin() const
74  {
75  return min_;
76  }
77 
78  VALUE_TYPE getMax() const
79  {
80  return max_;
81  }
82 
83  size_t getCount() const
84  {
85  return count_;
86  }
87 
89  double getAvg() const
90  {
91  return count_ == 0 ? 0 : double(sum_) / count_;
92  }
93 
94  protected:
95  size_t count_{0};
96  VALUE_TYPE min_{std::numeric_limits<VALUE_TYPE>::max()}; // init with very high value
97  VALUE_TYPE max_{std::numeric_limits<VALUE_TYPE>::lowest()}; // init with lowest (=negative) value possible
98  VALUE_TYPE sum_{0};
99  };
100 
103  using RangeStatsVariant = std::variant<RangeStatsInt, RangeStatsDouble>;
104 
107  {
108  size_t counter{0};
109  };
110 
112  enum class RangeStatsSource
113  {
114  CORE,
115  METAINFO,
116  ARRAYINFO,
118  };
119 
121  static const std::array<const char*, (size_t)RangeStatsSource::SIZE_OF_STATSSOURCE> StatsSourceNames = {"core statistics", "meta values", "data arrays"};
122 
125  {
127  std::string name;
128 
129  bool operator<(const RangeStatsType& rhs) const
130  {
131  return std::tie(src, name) < std::tie(rhs.src, rhs.name);
132  }
133 
134  bool operator==(const RangeStatsType& rhs) const
135  {
136  return src == rhs.src && name == rhs.name;
137  }
138  };
139 
141  using StatsMap = std::map<RangeStatsType, RangeStatsVariant>;
143  using StatsCounterMap = std::map<std::string, StatsCounter>;
144 
148  class OPENMS_GUI_DLLAPI LayerStatistics
149  {
150  public:
153  {
154  return overview_range_data_;
155  }
156 
159  {
160  return overview_count_data_;
161  }
162 
170  virtual Math::Histogram<> getDistribution(const RangeStatsType& which, const UInt number_of_bins = 500) const = 0;
171 
172 
173  protected:
175  virtual void computeStatistics_() = 0;
177  void bringInMetaStats_(const MetaInfoInterface* meta_interface);
178 
181  };
182 
186  class OPENMS_GUI_DLLAPI LayerStatisticsPeakMap
187  : public LayerStatistics
188  {
189  public:
190  LayerStatisticsPeakMap(const PeakMap& pm);
191 
192  Math::Histogram<> getDistribution(const RangeStatsType& which, const UInt number_of_bins) const override;
193 
194  private:
195  void computeStatistics_() override;
196  const PeakMap* pm_;
197  };
199 
203  class OPENMS_GUI_DLLAPI LayerStatisticsFeatureMap : public LayerStatistics
204  {
205  public:
207 
208  Math::Histogram<> getDistribution(const RangeStatsType& which,
209  const UInt number_of_bins) const override;
210 
211  private:
212  void computeStatistics_() override;
213  const FeatureMap* fm_;
214  };
216 
220  class OPENMS_GUI_DLLAPI LayerStatisticsConsensusMap : public LayerStatistics
221  {
222  public:
224 
225  Math::Histogram<> getDistribution(const RangeStatsType& which,
226  const UInt number_of_bins) const override;
227 
228  private:
229  void computeStatistics_() override;
230  const ConsensusMap* cm_;
231  };
233 
237  class OPENMS_GUI_DLLAPI LayerStatisticsIdent : public LayerStatistics
238  {
239  public:
241 
242  Math::Histogram<> getDistribution(const RangeStatsType& which,
243  const UInt number_of_bins) const override;
244 
245  private:
246  void computeStatistics_() override;
248  };
250 
251 } // namespace OpenMS
OpenMS::RangeStatsType::operator==
bool operator==(const RangeStatsType &rhs) const
Definition: LayerStatistics.h:134
OpenMS::RangeStatsType::name
std::string name
Definition: LayerStatistics.h:127
OpenMS::LayerStatisticsFeatureMap::fm_
const FeatureMap * fm_
Definition: LayerStatistics.h:213
OpenMS::LayerStatisticsPeakMap::pm_
const PeakMap * pm_
Definition: LayerStatistics.h:196
double
OpenMS::LayerStatistics::overview_count_data_
StatsCounterMap overview_count_data_
count data on non-numerical values computed during getOverviewStatistics
Definition: LayerStatistics.h:180
Types.h
OpenMS::StatsCounter
a simple counting struct, for non-numerical occurrences of meta-values
Definition: LayerStatistics.h:106
OpenMS::RangeStats::addDataPoint
void addDataPoint(VALUE_TYPE v)
Definition: LayerStatistics.h:65
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::RangeStatsType::operator<
bool operator<(const RangeStatsType &rhs) const
Definition: LayerStatistics.h:129
OpenMS::LayerStatisticsIdent
Computes statistics and distributions for a vector<PeptideIdentifications>
Definition: LayerStatistics.h:237
OpenMS::LayerStatistics::getRangeStatistics
const StatsMap & getRangeStatistics() const
get all range statistics, any of which can then be plugged into getDistribution()
Definition: LayerStatistics.h:152
OpenMS::LayerStatisticsFeatureMap
Computes statistics and distributions for a PeakMap.
Definition: LayerStatistics.h:203
OpenMS::RangeStatsSource::ARRAYINFO
statistic was obtained from Float/IntegerArrays of the container elements, e.g. "IonMobility" for Pea...
OpenMS::LayerStatisticsConsensusMap
Computes statistics and distributions for a PeakMap.
Definition: LayerStatistics.h:220
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::Math::Histogram
Representation of a histogram.
Definition: Histogram.h:63
OpenMS::RangeStats::getMax
VALUE_TYPE getMax() const
Definition: LayerStatistics.h:78
OpenMS::LayerStatistics
Compute summary statistics (count/min/max/avg) about a container, e.g. intensity, charge,...
Definition: LayerStatistics.h:148
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
OpenMS::LayerStatisticsIdent::ids_
const IPeptideIds::PepIds * ids_
Definition: LayerStatistics.h:247
OpenMS::RangeStatsVariant
std::variant< RangeStatsInt, RangeStatsDouble > RangeStatsVariant
Definition: LayerStatistics.h:103
OpenMS::RangeStats::getAvg
double getAvg() const
get the average value from all calls to addDataPoint()
Definition: LayerStatistics.h:89
OpenMS::RangeStatsSource::SIZE_OF_STATSSOURCE
OpenMS::RangeStats::min_
VALUE_TYPE min_
Definition: LayerStatistics.h:96
OpenMS::StatsMap
std::map< RangeStatsType, RangeStatsVariant > StatsMap
collection of Min/Max/Avg statistics from different sources. Note: must be sorted,...
Definition: LayerStatistics.h:141
OpenMS::RangeStatsSource::METAINFO
statistic was obtained from MetaInfoInterface of container elements, e.g. "FWHM" for FeatureMaps
OpenMS::StatsSourceNames
static const std::array< const char *,(size_t) RangeStatsSource::SIZE_OF_STATSSOURCE > StatsSourceNames
Names corresponding to elements of enum RangeStatsSource.
Definition: LayerStatistics.h:121
OpenMS::RangeStats::count_
size_t count_
Definition: LayerStatistics.h:95
OpenMS::RangeStatsSource::CORE
statistic was obtained from a core data structure of the container, e.g. intensity
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:82
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::LayerStatistics::getCountStatistics
const StatsCounterMap & getCountStatistics() const
obtain count statistics for all meta values which are not numerical
Definition: LayerStatistics.h:158
OpenMS::RangeStatsType
Origin and name of a statistic.
Definition: LayerStatistics.h:124
OpenMS::StatsCounter::counter
size_t counter
Definition: LayerStatistics.h:108
OpenMS::IPeptideIds::PepIds
std::vector< PeptideIdentification > PepIds
Definition: IPeptideIds.h:51
Histogram.h
OpenMS::LayerStatistics::overview_range_data_
StatsMap overview_range_data_
data on numerical values computed during getOverviewStatistics
Definition: LayerStatistics.h:179
OpenMS::RangeStatsType::src
RangeStatsSource src
Definition: LayerStatistics.h:126
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::RangeStats::getCount
size_t getCount() const
Definition: LayerStatistics.h:83
OpenMS::RangeStats::sum_
VALUE_TYPE sum_
Definition: LayerStatistics.h:98
OpenMS::StatsCounterMap
std::map< std::string, StatsCounter > StatsCounterMap
collection of MetaValues which are not numeric (counts only the number of occurrences per metavalue)
Definition: LayerStatistics.h:143
OpenMS::RangeStatsSource
RangeStatsSource
Where did a statistic come from? Useful for display to user, and for internal dispatch when user requ...
Definition: LayerStatistics.h:112
OpenMS::LayerStatisticsConsensusMap::cm_
const ConsensusMap * cm_
Definition: LayerStatistics.h:230
IPeptideIds.h
OpenMS::RangeStats::getMin
VALUE_TYPE getMin() const
Definition: LayerStatistics.h:73
OpenMS::RangeStats::max_
VALUE_TYPE max_
Definition: LayerStatistics.h:97
StandardTypes.h
OpenMS::RangeStats
Struct representing the statistics about a set of values.
Definition: LayerStatistics.h:62
OpenMS::LayerStatisticsPeakMap
Computes statistics and distributions for a PeakMap.
Definition: LayerStatistics.h:186