OpenMS  2.6.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-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: 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::TransitionTSVFile::validateTargetedExperiment
void validateTargetedExperiment(const OpenMS::TargetedExperiment &targeted_exp)
Validate a TargetedExperiment (check that all ids are unique)
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects
Struct for temporary folder structure.
Definition: SiriusAdapterAlgorithm.h:53
OpenMS::TransitionTSVFile
This class supports reading and writing of OpenSWATH transition lists.
Definition: TransitionTSVFile.h:144
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:144
OpenMS::TransitionPQPFile
This class supports reading and writing of PQP files.
Definition: TransitionPQPFile.h:219
OpenMS::Param::copy
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
OpenMS::TargetedExperiment::setCompounds
void setCompounds(const std::vector< Compound > &rhs)
OpenMS::Deisotoper::deisotopeAndSingleCharge
static void deisotopeAndSingleCharge(MSSpectrum &spectrum, double fragment_tolerance, bool fragment_unit_ppm, int min_charge=1, int max_charge=3, bool keep_only_deisotoped=false, unsigned int min_isopeaks=3, unsigned int max_isopeaks=10, bool make_single_charged=true, bool annotate_charge=false, bool annotate_iso_peak_count=false, bool use_decreasing_model=true, unsigned int start_intensity_check=2, bool add_up_intensity=false)
Detect isotopic clusters in a mass spectrum.
TextFile.h
OpenMS::TraMLFile::store
void store(const String &filename, const TargetedExperiment &id) const
Stores a map in a TraML file.
OpenMS::SiriusAdapterAlgorithm::getIsotopePatternIterations
int getIsotopePatternIterations()
TransitionTSVFile.h
OpenMS::MetaboTargetedAssay::extractMetaboTargetedAssay
static std::vector< MetaboTargetedAssay > extractMetaboTargetedAssay(const MSExperiment &spectra, const FeatureMapping::FeatureToMs2Indices &feature_ms2_index, const double &precursor_rt_tol, const double &precursor_mz_distance, const double &cosine_sim_threshold, const double &transition_threshold, const double &min_fragment_mz, const double &max_fragment_mz, const bool &method_consensus_spectrum, const bool &exclude_ms2_precursor, const unsigned int &file_counter)
Extract a vector of MetaboTargetedAssays without using fragment annotation.
OpenMS::SiriusAdapterAlgorithm::getNoMasstraceInfoIsotopePattern
String getNoMasstraceInfoIsotopePattern()
Types.h
OpenMS::SiriusAdapterAlgorithm::preprocessingSirius
static void preprocessingSirius(const String &featureinfo, const MSExperiment &spectra, std::vector< FeatureMap > &v_fp, KDTreeFeatureMaps &fp_map_kd, const SiriusAdapterAlgorithm &sirius_algo, FeatureMapping::FeatureToMs2Indices &feature_mapping)
Preprocessing needed for SIRIUS.
OpenMS::SiriusAdapterAlgorithm
Definition: SiriusAdapterAlgorithm.h:46
OpenMS::SiriusAdapterAlgorithm::callSiriusQProcess
const static std::vector< String > callSiriusQProcess(const String &tmp_ms_file, const String &tmp_out_dir, String &executable, const String &out_csifingerid, const SiriusAdapterAlgorithm &sirius_algo)
Call SIRIUS with QProcess.
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::MetaboTargetedAssay::extractMetaboTargetedAssayFragmentAnnotation
static std::vector< MetaboTargetedAssay > extractMetaboTargetedAssayFragmentAnnotation(const std::vector< CompoundSpectrumPair > &v_cmp_spec, const double &transition_threshold, const double &min_fragment_mz, const double &max_fragment_mz, const bool &use_exact_mass, const bool &exclude_ms2_precursor, const unsigned int &file_counter)
Extract a vector of MetaboTargetedAssays using fragment annotation.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:55
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::BaseFeature
A basic LC-MS feature.
Definition: BaseFeature.h:56
OpenMS::Exception::FileNotFound
File not found exception.
Definition: Exception.h:523
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
FeatureXMLFile.h
OpenMS::Constants::c
const double c
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::TransitionTSVFile::convertTargetedExperimentToTSV
void convertTargetedExperimentToTSV(const char *filename, OpenMS::TargetedExperiment &targeted_exp)
Write out a targeted experiment (TraML structure) into a tsv file.
OpenMS::FeatureMap::getPrimaryMSRunPath
void getPrimaryMSRunPath(StringList &toFill) const
get the file path to the first MS run
OpenMS::PrecursorCorrection::correctToHighestIntensityMS1Peak
static std::set< Size > correctToHighestIntensityMS1Peak(MSExperiment &exp, double mz_tolerance, bool ppm, std::vector< double > &delta_mzs, std::vector< double > &mzs, std::vector< double > &rts)
Selection of the peak with the highest intensity as corrected precursor mass in a given mass range (e...
OpenMS::Math::BasicStatistics::variance_
RealType variance_
Definition: BasicStatistics.h:257
OpenMS::Math::AsymmetricStatistics::variance1_
RealType variance1_
Definition: AsymmetricStatistics.h:144
OPENMS_LOG_WARN
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
OpenMS::SpectrumSettings::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::MSSpectrum::getMSLevel
UInt getMSLevel() const
Returns the MS level.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::TraMLFile
File adapter for HUPO PSI TraML files.
Definition: TraMLFile.h:63
Deisotoper.h
MRMAssay.h
Exception.h
OpenMS::MetaboTargetedAssay::CompoundSpectrumPair::compoundspectrumpair
std::pair< SiriusMSFile::CompoundInfo, MSSpectrum > compoundspectrumpair
Definition: MetaboTargetedAssay.h:76
OpenMS::Math::BasicStatistics::update
void update(ProbabilityIterator probability_begin, ProbabilityIterator const probability_end)
This does the actual calculation.
Definition: BasicStatistics.h:113
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::File::copyDirRecursively
static bool copyDirRecursively(const QString &from_dir, const QString &to_dir, File::CopyOptions option=CopyOptions::OVERWRITE)
OpenMS::MetaboTargetedAssay
This class provides methods for the extraction of targeted assays for metabolomics.
Definition: MetaboTargetedAssay.h:54
OpenMS::Math::AsymmetricStatistics
Internal class for asymmetric distributions.
Definition: AsymmetricStatistics.h:58
OpenMS::SiriusMSFile::store
static void store(const MSExperiment &spectra, const OpenMS::String &msfile, const FeatureMapping::FeatureToMs2Indices &feature_mapping, const bool &feature_only, const int &isotope_pattern_iterations, const bool no_mt_info, std::vector< SiriusMSFile::CompoundInfo > &v_cmpinfo)
Internal structure used in SiriusAdapter that is used for the conversion of a MzMlFile to an internal...
OpenMS::FeatureXMLFile::load
void load(const String &filename, FeatureMap &feature_map)
loads the file with name filename into map and calls updateRanges().
RangeUtils.h
PrecursorCorrection.h
OPENMS_LOG_DEBUG
#define OPENMS_LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:470
OpenMS::SiriusAdapterAlgorithm::checkFeatureSpectraNumber
static void checkFeatureSpectraNumber(const String &featureinfo, const FeatureMapping::FeatureToMs2Indices &feature_mapping, const MSExperiment &spectra, const SiriusAdapterAlgorithm &sirius_algo)
logs number of features and spectra used
OpenMS::SiriusMzTabWriter::extract_scan_index
static int extract_scan_index(const String &path)
Extract scan_index from filepath.
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
SiriusMzTabWriter.h
OpenMS::String::toQString
QString toQString() const
Conversion to Qt QString.
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::MRMAssay::detectingTransitionsCompound
void detectingTransitionsCompound(OpenMS::TargetedExperiment &exp, int min_transitions, int max_transitions)
Filters transitions by intensity, only keeping the top N transitions.
OpenMS::Math::AsymmetricStatistics::Base
BasicStatistics< RealT > Base
The real type and basic statistics specified as template argument.
Definition: AsymmetricStatistics.h:62
SiriusFragmentAnnotation.h
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:97
OpenMS::String::substr
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
OpenMS::SiriusFragmentAnnotation::extractSiriusFragmentAnnotationMapping
static void extractSiriusFragmentAnnotationMapping(const String &path_to_sirius_workspace, MSSpectrum &msspectrum_to_fill, bool use_exact_mass=false)
extractSiriusFragmentAnnotationMapping Extract native id (./spectrum.ms) and fragment annotation (....
OpenMS::FeatureMapping::FeatureToMs2Indices
Definition: FeatureMapping.h:48
OpenMS::FeatureXMLFile
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:68
MetaboTargetedAssay.h
OpenMS::FeatureMapping::FeatureToMs2Indices::assignedMS2
Map< const BaseFeature *, std::vector< size_t > > assignedMS2
Definition: FeatureMapping.h:50
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::TransitionPQPFile::convertTargetedExperimentToPQP
void convertTargetedExperimentToPQP(const char *filename, OpenMS::TargetedExperiment &targeted_exp)
Write out a targeted experiment (TraML structure) into a PQP file.
OpenMS::Math::ppmToMass
T ppmToMass(T ppm, T mz_ref)
Compute the mass diff in [Th], given a ppm value and a reference point.
Definition: MathFunctions.h:263
OpenMS::TargetedExperiment::setTransitions
void setTransitions(const std::vector< ReactionMonitoringTransition > &transitions)
set transition list
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::Map
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:50
OpenMS::Math::AsymmetricStatistics::variance2_
RealType variance2_
Definition: AsymmetricStatistics.h:144
OpenMS::Exception::MissingInformation
Not all required information provided.
Definition: Exception.h:195
OpenMS::TargetedExperiment
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:64
OPENMS_LOG_INFO
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:465
TransitionPQPFile.h
SiriusAdapterAlgorithm.h
OpenMS::MRMAssay
Generate assays from a TargetedExperiment.
Definition: MRMAssay.h:68
OpenMS::Exception::FileEmpty
File is empty.
Definition: Exception.h:594
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::FeatureMap::getDataProcessing
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
TraMLFile.h
OpenMS::Param::insert
void insert(const String &prefix, const Param &param)
StandardTypes.h
OpenMS::KDTreeFeatureMaps
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:49
File.h
TOPPBase.h
OpenMS::MetaboTargetedAssay::CompoundSpectrumPair
CompoundSpectrumPair stores a pair of CompoundInfo and MSSpectrum.
Definition: MetaboTargetedAssay.h:74
OpenMS::Math::AsymmetricStatistics::RealType
Base::RealType RealType
Definition: AsymmetricStatistics.h:63
OpenMS::InIntensityRange
Predicate that determines if a peak lies inside/outside a specific intensity range.
Definition: RangeUtils.h:526
OpenMS::Math::BasicStatistics::RealType
RealT RealType
The real type specified as template argument.
Definition: BasicStatistics.h:74
OpenMS::FeatureMap::getProteinIdentifications
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
OpenMS::SiriusAdapterAlgorithm::getFeatureOnly
String getFeatureOnly()