OpenMS  3.0.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-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: 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::Exception::Postcondition
Postcondition failed exception.
Definition: Exception.h:171
OpenMS::TransitionTSVFile::validateTargetedExperiment
void validateTargetedExperiment(const OpenMS::TargetedExperiment &targeted_exp)
Validate a TargetedExperiment (check that all ids are unique)
MetaboTargetedTargetDecoy.h
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:147
OpenMS::TransitionPQPFile
This class supports reading and writing of PQP files.
Definition: TransitionPQPFile.h:215
OpenMS::TargetedExperiment::setCompounds
void setCompounds(const std::vector< Compound > &rhs)
OpenMS::MRMAssay::filterMinMaxTransitionsCompound
void filterMinMaxTransitionsCompound(OpenMS::TargetedExperiment &exp, int min_transitions, int max_transitions)
Filters target and decoy transitions by intensity, only keeping the top N transitions.
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.
OpenMS::TraMLFile::store
void store(const String &filename, const TargetedExperiment &id) const
Stores a map in a TraML file.
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.
Types.h
OpenMS::SiriusAdapterAlgorithm
Definition: SiriusAdapterAlgorithm.h:53
OpenMS::MetaboTargetedTargetDecoy::generateMissingDecoysByMassShift
static void generateMissingDecoysByMassShift(TargetedExperiment &t_exp, std::vector< MetaboTargetedTargetDecoy::MetaboTargetDecoyMassMapping > &mappings, const double &mass_to_add)
Generate a decoy for targets where fragmentation tree re-rooting was not possible,...
OpenMS::Exception::InvalidValue
Invalid value exception.
Definition: Exception.h:327
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::TargetedExperiment::sortTransitionsByName
void sortTransitionsByName()
Lexicographically sorts the transitions by their name.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:57
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::BaseFeature
A basic LC-MS feature.
Definition: BaseFeature.h:58
OpenMS::EmpiricalFormula::getMonoWeight
double getMonoWeight() const
returns the mono isotopic weight of the formula (includes proton charges)
OpenMS::Math::BasicStatistics::sum_
RealType sum_
Definition: BasicStatistics.h:264
MzMLFile.h
BasicStatistics.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::SpectrumSettings::getPrecursors
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
FeatureXMLFile.h
OpenMS::Constants::c
const double c
Definition: Constants.h:209
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:262
OpenMS::MetaboTargetedAssay::extractMetaboTargetedAssayFragmentAnnotation
static std::vector< MetaboTargetedAssay > extractMetaboTargetedAssayFragmentAnnotation(const std::vector< CompoundTargetDecoyPair > &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::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::FeatureMapping::FeatureToMs2Indices
Stores preprocessed feature mapping information.
Definition: FeatureMapping.h:58
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:263
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
OpenMS::Math::BasicStatistics::clear
void clear()
Set sum, mean, and variance to zero.
Definition: BasicStatistics.h:103
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects
Struct for temporary folder structure.
Definition: SiriusAdapterAlgorithm.h:98
OpenMS::SiriusAdapterAlgorithm::updateExistingParameter
void updateExistingParameter(const Param &param)
Updates all parameters that already exist in this DefaultParamHandler with the values provided by the...
OpenMS::MetaboTargetedTargetDecoy::resolveOverlappingTargetDecoyMassesByIndividualMassShift
static void resolveOverlappingTargetDecoyMassesByIndividualMassShift(TargetedExperiment &t_exp, std::vector< MetaboTargetedTargetDecoy::MetaboTargetDecoyMassMapping > &mappings, const double &mass_to_add)
Resolves overlapping target and decoy transition masses by adding a specifiable mass (e....
OpenMS::MSSpectrum::getMSLevel
UInt getMSLevel() const
Returns the MS level.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::TraMLFile
File adapter for HUPO PSI TraML files.
Definition: TraMLFile.h:63
MRMAssay.h
Exception.h
OpenMS::MetaboTargetedAssay::buildAmbiguityGroup
static std::unordered_map< UInt64, std::vector< MetaboTargetedAssay > > buildAmbiguityGroup(const std::vector< MetaboTargetedAssay > &v_mta, const double &ar_mz_tol, const double &ar_rt_tol, const String &ar_mz_tol_unit_res, size_t in_files_size)
Perform feature linking to build ambiguity groups based on the target and decoy position in the vecto...
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::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
OpenMS::SiriusAdapterAlgorithm::logFeatureSpectraNumber
void logFeatureSpectraNumber(const String &featureinfo, const FeatureMapping::FeatureToMs2Indices &feature_mapping, const MSExperiment &spectra) const
logs number of features and spectra used
PrecursorCorrection.h
OpenMS::File::findExecutable
static bool findExecutable(OpenMS::String &exe_filename)
Searches for an executable with the given name (similar to where (Windows) or which (Linux/MacOS)
OPENMS_LOG_DEBUG
#define OPENMS_LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:470
OpenMS::SiriusAdapterAlgorithm::callSiriusQProcess
const vector< String > callSiriusQProcess(const String &tmp_ms_file, const String &tmp_out_dir, String &executable, const String &out_csifingerid, const bool decoy_generation) const
Call SIRIUS with QProcess.
SiriusMzTabWriter.h
OpenMS::DefaultParamHandler::getDefaults
const Param & getDefaults() const
Non-mutable access to the default parameters.
OpenMS::DefaultParamHandler::getParameters
const Param & getParameters() const
Non-mutable access to the parameters.
OpenMS::MRMAssay::filterUnreferencedDecoysCompound
void filterUnreferencedDecoysCompound(OpenMS::TargetedExperiment &exp)
Filters decoy transitions, which do not have respective target transition based on the transitionID.
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
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:71
OpenMS::MetaboTargetedTargetDecoy::constructTargetDecoyMassMapping
static std::vector< MetaboTargetDecoyMassMapping > constructTargetDecoyMassMapping(const TargetedExperiment &t_exp)
Constructs a mass mapping of targets and decoys using the unique m_id identifier.
OpenMS::SiriusAdapterAlgorithm::isNoMasstraceInfoIsotopePattern
bool isNoMasstraceInfoIsotopePattern() const
Definition: SiriusAdapterAlgorithm.h:68
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::SiriusAdapterAlgorithm::getIsotopePatternIterations
int getIsotopePatternIterations() const
Definition: SiriusAdapterAlgorithm.h:69
OpenMS::FeatureMapping::FeatureToMs2Indices::assignedMS2
std::map< const BaseFeature *, std::vector< size_t > > assignedMS2
Definition: FeatureMapping.h:61
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::extractAndResolveSiriusAnnotations
static std::vector< SiriusTargetDecoySpectra > extractAndResolveSiriusAnnotations(const std::vector< String > &sirius_workspace_subdirs, double score_threshold, bool use_exact_mass)
extractAndResolveSiriusAnnotations Extract and resolves SIRIUS target and/or decoy annotation for map...
OpenMS::EmpiricalFormula
Representation of an empirical formula.
Definition: EmpiricalFormula.h:84
OpenMS::FeatureXMLFile
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:62
MetaboTargetedAssay.h
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:291
OpenMS::TargetedExperiment::setTransitions
void setTransitions(const std::vector< ReactionMonitoringTransition > &transitions)
set transition list
Deisotoper.h
OpenMS::Math::AsymmetricStatistics::variance2_
RealType variance2_
Definition: AsymmetricStatistics.h:144
OpenMS::Exception::MissingInformation
Not all required information provided.
Definition: Exception.h:186
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
OpenMS::MetaboTargetedAssay::pairCompoundWithAnnotatedTDSpectraPairs
static std::vector< MetaboTargetedAssay::CompoundTargetDecoyPair > pairCompoundWithAnnotatedTDSpectraPairs(const std::vector< SiriusMSFile::CompoundInfo > &v_cmpinfo, const std::vector< SiriusFragmentAnnotation::SiriusTargetDecoySpectra > &annotated_spectra)
Pair compound information (SiriusMSFile) with the annotated target and decoy spectrum from SIRIUS/Pas...
OpenMS::SiriusAdapterAlgorithm::isFeatureOnly
bool isFeatureOnly() const
Definition: SiriusAdapterAlgorithm.h:63
SiriusAdapterAlgorithm.h
OpenMS::MRMAssay
Generate assays from a TargetedExperiment.
Definition: MRMAssay.h:66
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
TraMLFile.h
OpenMS::MetaboTargetedAssay::resolveAmbiguityGroup
static void resolveAmbiguityGroup(std::unordered_map< UInt64, std::vector< MetaboTargetedAssay > > &map_mta_filter, const double &total_occurrence_filter, size_t in_files_size)
Resolve ambiguity groups based on occurrence in samples (e.g. at least in 20% of the samples) and if ...
StandardTypes.h
File.h
OpenMS::FeatureMapping::FeatureMappingInfo
Stores information required for preprocessing.
Definition: FeatureMapping.h:50
TOPPBase.h
OpenMS::SiriusAdapterAlgorithm::sortSiriusWorkspacePathsByScanIndex
static void sortSiriusWorkspacePathsByScanIndex(std::vector< String > &subdirs)
Sort function using the extracted scan_index from the sirius workspace file path.
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:512
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
OpenMS::SiriusAdapterAlgorithm::preprocessingSirius
void preprocessingSirius(const String &featureinfo, const MSExperiment &spectra, FeatureMapping::FeatureMappingInfo &fm_info, FeatureMapping::FeatureToMs2Indices &feature_mapping) const
Preprocessing needed for SIRIUS.