OpenMS
Loading...
Searching...
No Matches
PosteriorErrorProbabilityModel.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: David Wojnar $
7// --------------------------------------------------------------------------
8
9#pragma once
10
18
19#include <vector>
20#include <map>
21
22namespace OpenMS
23{
24 class String;
25 class TextFile;
26 class PeptideIdentification;
27 class ProteinIdentification;
28 class PeptideHit;
29 class PeptideIdentificationList;
30 namespace Math
31 {
32
33
50 class OPENMS_DLLAPI PosteriorErrorProbabilityModel :
52 {
53public:
54
57
60
72 static std::map<String, std::vector<std::vector<double>>> extractAndTransformScores(
73 const std::vector<ProteinIdentification> & protein_ids,
74 const PeptideIdentificationList & peptide_ids,
75 const bool split_charge,
76 const bool top_hits_only,
77 const bool target_decoy_available,
78 const double fdr_for_targets_smaller);
79
93 static void updateScores(
94 const PosteriorErrorProbabilityModel & PEP_model,
95 const String & search_engine,
96 const Int charge,
97 const bool prob_correct,
98 const bool split_charge,
99 std::vector<ProteinIdentification> & protein_ids,
100 PeptideIdentificationList & peptide_ids,
101 bool & unable_to_fit_data,
102 bool & data_might_not_be_well_fit);
103
113 bool fit(std::vector<double>& search_engine_scores, const String& outlier_handling);
114
124 bool fitGumbelGauss(std::vector<double>& search_engine_scores, const String& outlier_handling);
125
134 bool fit(std::vector<double>& search_engine_scores, std::vector<double>& probabilities, const String& outlier_handling);
135
137 void fillDensities(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
139 void fillLogDensities(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
141 void fillLogDensitiesGumbel(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
143 double computeLogLikelihood(const std::vector<double> & incorrect_density, const std::vector<double> & correct_density) const;
144
152 const std::vector<double>& incorrect_log_density,
153 const std::vector<double>& correct_log_density,
154 std::vector<double>& incorrect_posterior) const;
155
162 std::pair<double, double> pos_neg_mean_weighted_posteriors(const std::vector<double> &x_scores,
163 const std::vector<double> &incorrect_posteriors);
164
172 std::pair<double, double> pos_neg_sigma_weighted_posteriors(const std::vector<double> &x_scores,
173 const std::vector<double> &incorrect_posteriors,
174 const std::pair<double, double>& pos_neg_mean);
175
178 {
179 return correctly_assigned_fit_param_;
180 }
181
184 {
185 return incorrectly_assigned_fit_param_;
186 }
187
190 {
191 return incorrectly_assigned_fit_gumbel_param_;
192 }
193
195 double getNegativePrior() const
196 {
197 return negative_prior_;
198 }
199
201 static double getGumbel_(double x, const GaussFitter::GaussFitResult & params)
202 {
203 double z = exp((params.x0 - x) / params.sigma);
204 return (z * exp(-1 * z)) / params.sigma;
205 }
206
211 double computeProbability(double score) const;
212
214 TextFile initPlots(std::vector<double> & x_scores);
215
218
221
224
226 void plotTargetDecoyEstimation(std::vector<double> & target, std::vector<double> & decoy);
227
229 inline double getSmallestScore() const
230 {
231 return smallest_score_;
232 }
233
235 void tryGnuplot(const String& gp_file);
236
237private:
239 void processOutliers_(std::vector<double>& x_scores, const String& outlier_handling) const;
240
245 static double transformScore_(const String& engine, const PeptideHit& hit, const String& current_score_type);
246
251 static double getScore_(const std::vector<String>& requested_score_types, const PeptideHit & hit, const String& actual_score_type);
252
271 const String (PosteriorErrorProbabilityModel::* getNegativeGnuplotFormula_)(const GaussFitter::GaussFitResult & params) const;
273 const String (PosteriorErrorProbabilityModel::* getPositiveGnuplotFormula_)(const GaussFitter::GaussFitResult & params) const;
274 };
275 }
276}
277
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Implements a fitter for Gaussian functions.
Definition GaussFitter.h:35
Implements a mixture model of the inverse gumbel and the gauss distribution or a gaussian mixture.
Definition PosteriorErrorProbabilityModel.h:52
PosteriorErrorProbabilityModel & operator=(const PosteriorErrorProbabilityModel &rhs)
assignment operator (not implemented)
double computeLLAndIncorrectPosteriorsFromLogDensities(const std::vector< double > &incorrect_log_density, const std::vector< double > &correct_log_density, std::vector< double > &incorrect_posterior) const
static void updateScores(const PosteriorErrorProbabilityModel &PEP_model, const String &search_engine, const Int charge, const bool prob_correct, const bool split_charge, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, bool &unable_to_fit_data, bool &data_might_not_be_well_fit)
update score entries with PEP (or 1-PEP) estimates
const String getBothGnuplotFormula(const GaussFitter::GaussFitResult &incorrect, const GaussFitter::GaussFitResult &correct) const
returns the gnuplot formula of the fitted mixture distribution.
GumbelMaxLikelihoodFitter::GumbelDistributionFitResult incorrectly_assigned_fit_gumbel_param_
Definition PosteriorErrorProbabilityModel.h:259
TextFile initPlots(std::vector< double > &x_scores)
initializes the plots
const String getGaussGnuplotFormula(const GaussFitter::GaussFitResult &params) const
returns the gnuplot formula of the fitted gauss distribution.
void plotTargetDecoyEstimation(std::vector< double > &target, std::vector< double > &decoy)
plots the estimated distribution against target and decoy hits
static double transformScore_(const String &engine, const PeptideHit &hit, const String &current_score_type)
GaussFitter::GaussFitResult incorrectly_assigned_fit_param_
stores parameters for incorrectly assigned sequences. If gumbel fit was used, A can be ignored....
Definition PosteriorErrorProbabilityModel.h:258
double max_correctly_
peak of the gauss distribution (correctly assigned sequences)
Definition PosteriorErrorProbabilityModel.h:267
double computeProbability(double score) const
void fillDensities(const std::vector< double > &x_scores, std::vector< double > &incorrect_density, std::vector< double > &correct_density)
Writes the distributions densities into the two vectors for a set of scores. Incorrect_densities repr...
bool fit(std::vector< double > &search_engine_scores, const String &outlier_handling)
fits the distributions to the data points(search_engine_scores). Estimated parameters for the distrib...
PosteriorErrorProbabilityModel(const PosteriorErrorProbabilityModel &rhs)
Copy constructor (not implemented)
bool fit(std::vector< double > &search_engine_scores, std::vector< double > &probabilities, const String &outlier_handling)
fits the distributions to the data points(search_engine_scores) and writes the computed probabilities...
static double getScore_(const std::vector< String > &requested_score_types, const PeptideHit &hit, const String &actual_score_type)
GaussFitter::GaussFitResult getIncorrectlyAssignedFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition PosteriorErrorProbabilityModel.h:183
double getNegativePrior() const
returns the estimated negative prior probability.
Definition PosteriorErrorProbabilityModel.h:195
const String getGumbelGnuplotFormula(const GaussFitter::GaussFitResult &params) const
returns the gnuplot formula of the fitted gumbel distribution. Only x0 and sigma are used as local pa...
void fillLogDensities(const std::vector< double > &x_scores, std::vector< double > &incorrect_density, std::vector< double > &correct_density)
Writes the log distributions densities into the two vectors for a set of scores. Incorrect_densities ...
double negative_prior_
stores final prior probability for negative peptides
Definition PosteriorErrorProbabilityModel.h:263
void fillLogDensitiesGumbel(const std::vector< double > &x_scores, std::vector< double > &incorrect_density, std::vector< double > &correct_density)
Writes the log distributions of gumbel and gauss densities into the two vectors for a set of scores....
~PosteriorErrorProbabilityModel() override
Destructor.
static std::map< String, std::vector< std::vector< double > > > extractAndTransformScores(const std::vector< ProteinIdentification > &protein_ids, const PeptideIdentificationList &peptide_ids, const bool split_charge, const bool top_hits_only, const bool target_decoy_available, const double fdr_for_targets_smaller)
extract and transform score types to a range and score orientation that the PEP model can handle
void tryGnuplot(const String &gp_file)
try to invoke 'gnuplot' on the file to create PDF automatically
void processOutliers_(std::vector< double > &x_scores, const String &outlier_handling) const
transform different score types to a range and score orientation that the model can handle (engine st...
GaussFitter::GaussFitResult correctly_assigned_fit_param_
stores gauss parameters
Definition PosteriorErrorProbabilityModel.h:261
double max_incorrectly_
peak of the incorrectly assigned sequences distribution
Definition PosteriorErrorProbabilityModel.h:265
PosteriorErrorProbabilityModel()
default constructor
GaussFitter::GaussFitResult getCorrectlyAssignedFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition PosteriorErrorProbabilityModel.h:177
static double getGumbel_(double x, const GaussFitter::GaussFitResult &params)
computes the gumbel density at position x with parameters params.
Definition PosteriorErrorProbabilityModel.h:201
double smallest_score_
smallest score which was used for fitting the model
Definition PosteriorErrorProbabilityModel.h:269
std::pair< double, double > pos_neg_mean_weighted_posteriors(const std::vector< double > &x_scores, const std::vector< double > &incorrect_posteriors)
double getSmallestScore() const
returns the smallest score used in the last fit
Definition PosteriorErrorProbabilityModel.h:229
bool fitGumbelGauss(std::vector< double > &search_engine_scores, const String &outlier_handling)
fits the distributions to the data points(search_engine_scores). Estimated parameters for the distrib...
GumbelMaxLikelihoodFitter::GumbelDistributionFitResult getIncorrectlyAssignedGumbelFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition PosteriorErrorProbabilityModel.h:189
std::pair< double, double > pos_neg_sigma_weighted_posteriors(const std::vector< double > &x_scores, const std::vector< double > &incorrect_posteriors, const std::pair< double, double > &pos_neg_mean)
double computeLogLikelihood(const std::vector< double > &incorrect_density, const std::vector< double > &correct_density) const
computes the Likelihood with a log-likelihood function.
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition PeptideHit.h:52
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
A more convenient string class.
Definition String.h:34
Definition TextFile.h:21
int Int
Signed integer type.
Definition Types.h:72
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
struct of parameters of a Gaussian distribution
Definition GaussFitter.h:40
double sigma
parameter sigma of Gaussian distribution (width)
Definition GaussFitter.h:54
double x0
parameter x0 of Gaussian distribution (center position)
Definition GaussFitter.h:51
struct to represent the parameters of a gumbel distribution
Definition GumbelMaxLikelihoodFitter.h:38