OpenMS  2.4.0
AsymmetricStatistics.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-2018.
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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
39 
40 #include <vector>
41 #include <ostream>
42 #include <cmath>
43 
44 namespace OpenMS
45 {
46  namespace Math
47  {
48 
57  template <typename RealT = double>
59  public BasicStatistics<RealT>
60  {
63  typedef typename Base::RealType RealType;
64 
65  using Base::clear;
66  using Base::sum_;
67  using Base::mean_;
68  using Base::variance_;
69 
70 public:
71 
74  BasicStatistics<>(),
75  variance1_(0),
76  variance2_(0)
77  {}
78 
81  {
82  return variance1_;
83  }
84 
87  {
88  return variance2_;
89  }
90 
92  template <typename ProbabilityIterator, typename CoordinateIterator>
93  void update(ProbabilityIterator const probability_begin,
94  ProbabilityIterator const probability_end,
95  CoordinateIterator const coordinate_begin)
96  {
97  // reuse...
98  Base::update(probability_begin, probability_end, coordinate_begin);
99 
100  const RealType stdev = std::sqrt(variance_);
101 
102  RealType sum1 = 0;
103  RealType sum2 = 0;
104  variance1_ = 0;
105  variance2_ = 0;
106  ProbabilityIterator prob_iter = probability_begin;
107  CoordinateIterator coord_iter = coordinate_begin;
108  for (; prob_iter != probability_end; ++prob_iter, ++coord_iter)
109  {
110  RealType diff = *coord_iter - mean_;
111  RealType diff_squared = diff * diff;
112 
113  if (diff_squared > variance_)
114  {
115  if (*coord_iter < mean_)
116  {
117  variance1_ += (*prob_iter * diff_squared);
118  sum1 += *prob_iter;
119  }
120  else // ( *coord_iter > mean_ )
121  {
122  variance2_ += (*prob_iter * diff_squared);
123  sum2 += *prob_iter;
124  }
125  }
126  else
127  {
128  RealType frac = (diff / stdev + 1.) / 2.;
129  RealType prob_frac = frac * *prob_iter;
130  variance2_ += prob_frac * diff_squared;
131  sum2 += prob_frac;
132  prob_frac = *prob_iter * (1. - frac);
133  variance1_ += prob_frac * diff_squared;
134  sum1 += prob_frac;
135  }
136  }
137  variance1_ /= sum1;
138  variance2_ /= sum2;
139  return;
140  }
141 
142 protected:
145  };
146 
147  } // namespace Math
148 
149 } // namespace OpenMS
150 
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:150
OpenMS::TextFile::addLine
void addLine(const StringType &line)
Definition: TextFile.h:112
TextFile.h
BinnedSpectralContrastAngle.h
OpenMS::BinnedSpectrum::DEFAULT_BIN_WIDTH_HIRES
static constexpr const float DEFAULT_BIN_WIDTH_HIRES
Definition: BinnedSpectrum.h:99
Types.h
Int
OpenMS::SpectraMerger
Merges blocks of MS or MS2 spectra.
Definition: SpectraMerger.h:63
OpenMS::BinnedSpectrum
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:75
OpenMS::MSExperiment::sortSpectra
void sortSpectra(bool sort_mz=true)
Sorts the data points by retention time.
OpenMS::Math::AsymmetricStatistics::variance1
RealType variance1() const
"variance to the left hand side"
Definition: AsymmetricStatistics.h:80
KDTreeFeatureMaps.h
OpenMS::Param::setValue
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:55
OpenMS::String
A more convenient string class.
Definition: String.h:57
OpenMS::MSExperiment::begin
Iterator begin()
Definition: MSExperiment.h:157
OpenMS::BaseFeature
A basic LC-MS feature.
Definition: BaseFeature.h:55
OpenMS::Exception::Precondition
Precondition failed exception.
Definition: Exception.h:166
OpenMS::String::trim
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
OpenMS::Math::BasicStatistics::sum_
RealType sum_
Definition: BasicStatistics.h:258
MzMLFile.h
BasicStatistics.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::SpectrumSettings::getPrecursors
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
OpenMS::TextFile
This class provides some basic file handling methods for text files.
Definition: TextFile.h:46
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
SpectraMerger.h
FeatureXMLFile.h
OpenMS::Math::AsymmetricStatistics::variance2
RealType variance2() const
"variance to the right hand side"
Definition: AsymmetricStatistics.h:86
OpenMS::Math::BasicStatistics::mean_
RealType mean_
Definition: BasicStatistics.h:256
OpenMS::String::prefix
String prefix(SizeType length) const
returns the prefix of length length
OpenMS::Math::BasicStatistics::variance_
RealType variance_
Definition: BasicStatistics.h:257
OpenMS::Math::getTolWindow
static std::pair< double, double > getTolWindow(double val, double tol, bool ppm)
Return tolerance window around val given tolerance tol.
Definition: MathFunctions.h:296
OpenMS::Math::AsymmetricStatistics::variance1_
RealType variance1_
Definition: AsymmetricStatistics.h:144
OpenMS::KDTreeFeatureMaps::feature
const BaseFeature * feature(Size i) const
Return pointer to feature i.
BinnedSpectrum.h
OpenMS::SpectrumSettings::PROFILE
@ PROFILE
profile data
Definition: SpectrumSettings.h:74
OpenMS::BaseFeature::getPeptideIdentifications
const std::vector< PeptideIdentification > & getPeptideIdentifications() const
returns a const reference to the PeptideIdentification vector
OpenMS::Math::BasicStatistics::clear
void clear()
Set sum, mean, and variance to zero.
Definition: BasicStatistics.h:103
OpenMS::MSExperiment::size
Size size() const
Definition: MSExperiment.h:127
OpenMS::MSExperiment::getPrecursorSpectrum
ConstIterator getPrecursorSpectrum(ConstIterator iterator) const
Returns the precursor spectrum of the scan pointed to by iterator.
OpenMS::Exception::InvalidParameter
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:347
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::MSExperiment::Iterator
std::vector< SpectrumType >::iterator Iterator
Mutable iterator.
Definition: MSExperiment.h:111
OpenMS::MSExperiment::addSpectrum
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
OpenMS::KDTreeFeatureMaps::addMaps
void addMaps(const std::vector< MapType > &maps)
Add maps and balance kd-tree.
Definition: KDTreeFeatureMaps.h:81
LOG_WARN
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:450
OpenMS::Math::BasicStatistics::update
void update(ProbabilityIterator probability_begin, ProbabilityIterator const probability_end)
This does the actual calculation.
Definition: BasicStatistics.h:113
OpenMS::KDTreeFeatureMaps::mz
double mz(Size i) const
m/z
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
OpenMS::SpectrumSettings::SpectrumType
SpectrumType
Spectrum peak type.
Definition: SpectrumSettings.h:70
OpenMS::Math::BasicStatistics
Calculates some basic statistical parameters of a distribution: sum, mean, variance,...
Definition: BasicStatistics.h:67
OpenMS::Math::AsymmetricStatistics
Internal class for asymmetric distributions.
Definition: AsymmetricStatistics.h:58
OpenMS::FeatureXMLFile::load
void load(const String &filename, FeatureMap &feature_map)
loads the file with name filename into map and calls updateRanges().
MathFunctions.h
OpenMS::Peak1D::getMZ
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:113
OpenMS::Peak1D::IntensityLess
Definition: Peak1D.h:188
OpenMS::MSSpectrum::MZBegin
Iterator MZBegin(CoordinateType mz)
Binary search for peak range begin.
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::SpectraMerger::mergeSpectraPrecursors
void mergeSpectraPrecursors(MapType &exp)
merges spectra with similar precursors (must have MS2 level)
Definition: SpectraMerger.h:209
OpenMS::Peak1D
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
OpenMS::Peak2D::getRT
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:208
OpenMS::Math::AsymmetricStatistics::Base
BasicStatistics< RealT > Base
The real type and basic statistics specified as template argument.
Definition: AsymmetricStatistics.h:62
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
MSExperiment.h
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:93
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::MSExperiment::end
Iterator end()
Definition: MSExperiment.h:167
OpenMS::MSExperiment::getSpectra
const std::vector< MSSpectrum > & getSpectra() const
returns the spectrum list
OpenMS::FeatureXMLFile
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:68
OpenMS::Math::AsymmetricStatistics::AsymmetricStatistics
AsymmetricStatistics()
Default constructor.
Definition: AsymmetricStatistics.h:73
OpenMS::Math::AsymmetricStatistics::update
void update(ProbabilityIterator const probability_begin, ProbabilityIterator const probability_end, CoordinateIterator const coordinate_begin)
You can call this as often as you like, using different input vectors.
Definition: AsymmetricStatistics.h:93
OpenMS::TextFile::store
void store(const String &filename)
Writes the data to a file.
OpenMS::KDTreeFeatureMaps::queryRegion
void queryRegion(double rt_low, double rt_high, double mz_low, double mz_high, std::vector< Size > &result_indices, Size ignored_map_index=std::numeric_limits< Size >::max()) const
Fill result with indices of all features within the specified boundaries.
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:74
OpenMS::MSExperiment::ConstIterator
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:113
OpenMS::Math::AsymmetricStatistics::variance2_
RealType variance2_
Definition: AsymmetricStatistics.h:144
OpenMS::BinnedSpectralContrastAngle
Compare functor scoring the spectral contrast angle for similarity measurement.
Definition: BinnedSpectralContrastAngle.h:57
OpenMS::MSSpectrum::ConstIterator
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:103
OpenMS::Exception::FileEmpty
File is empty.
Definition: Exception.h:594
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
OpenMS::FeatureMap::getDataProcessing
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
OpenMS::String::suffix
String suffix(SizeType length) const
returns the suffix of length length
OpenMS::Peak1D::getIntensity
IntensityType getIntensity() const
Definition: Peak1D.h:108
OpenMS::KDTreeFeatureMaps
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:49
TOPPBase.h
OpenMS::Math::AsymmetricStatistics::RealType
Base::RealType RealType
Definition: AsymmetricStatistics.h:63
OpenMS::Math::BasicStatistics::RealType
RealT RealType
The real type specified as template argument.
Definition: BasicStatistics.h:74
OpenMS::BinnedSpectrum::DEFAULT_BIN_OFFSET_HIRES
static constexpr const float DEFAULT_BIN_OFFSET_HIRES
default bin offset for high-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
Definition: BinnedSpectrum.h:102
MSSpectrum.h
OpenMS::FeatureMap::getProteinIdentifications
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications