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
17
18#include <vector>
19#include <map>
20
21namespace OpenMS
22{
23 class TextFile;
24 class PeptideIdentification;
25 class ProteinIdentification;
26 class PeptideHit;
27 class PeptideIdentificationList;
28 namespace Math
29 {
30
31
48 class OPENMS_DLLAPI PosteriorErrorProbabilityModel :
50 {
51public:
52
55
58
72 static std::map<std::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
95 static void updateScores(
96 const PosteriorErrorProbabilityModel & PEP_model,
97 const std::string & search_engine,
98 const Int charge,
99 const bool prob_correct,
100 const bool split_charge,
101 std::vector<ProteinIdentification> & protein_ids,
102 PeptideIdentificationList & peptide_ids,
103 bool & unable_to_fit_data,
104 bool & data_might_not_be_well_fit);
105
115 bool fit(std::vector<double>& search_engine_scores, const std::string& outlier_handling);
116
126 bool fitGumbelGauss(std::vector<double>& search_engine_scores, const std::string& outlier_handling);
127
136 bool fit(std::vector<double>& search_engine_scores, std::vector<double>& probabilities, const std::string& outlier_handling);
137
139 void fillDensities(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
141 void fillLogDensities(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
143 void fillLogDensitiesGumbel(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
145 double computeLogLikelihood(const std::vector<double> & incorrect_density, const std::vector<double> & correct_density) const;
146
154 const std::vector<double>& incorrect_log_density,
155 const std::vector<double>& correct_log_density,
156 std::vector<double>& incorrect_posterior) const;
157
164 std::pair<double, double> pos_neg_mean_weighted_posteriors(const std::vector<double> &x_scores,
165 const std::vector<double> &incorrect_posteriors);
166
174 std::pair<double, double> pos_neg_sigma_weighted_posteriors(const std::vector<double> &x_scores,
175 const std::vector<double> &incorrect_posteriors,
176 const std::pair<double, double>& pos_neg_mean);
177
180 {
181 return correctly_assigned_fit_param_;
182 }
183
186 {
187 return incorrectly_assigned_fit_param_;
188 }
189
192 {
193 return incorrectly_assigned_fit_gumbel_param_;
194 }
195
197 double getNegativePrior() const
198 {
199 return negative_prior_;
200 }
201
203 static double getGumbel_(double x, const GaussFitter::GaussFitResult & params)
204 {
205 double z = exp((params.x0 - x) / params.sigma);
206 return (z * exp(-1 * z)) / params.sigma;
207 }
208
213 double computeProbability(double score) const;
214
216 TextFile initPlots(std::vector<double> & x_scores);
217
219 const std::string getGumbelGnuplotFormula(const GaussFitter::GaussFitResult & params) const;
220
222 const std::string getGaussGnuplotFormula(const GaussFitter::GaussFitResult & params) const;
223
225 const std::string getBothGnuplotFormula(const GaussFitter::GaussFitResult & incorrect, const GaussFitter::GaussFitResult & correct) const;
226
228 void plotTargetDecoyEstimation(std::vector<double> & target, std::vector<double> & decoy);
229
231 inline double getSmallestScore() const
232 {
233 return smallest_score_;
234 }
235
237 void tryGnuplot(const std::string& gp_file);
238
239private:
241 void processOutliers_(std::vector<double>& x_scores, const std::string& outlier_handling) const;
242
247 static double transformScore_(const std::string& engine, const PeptideHit& hit, const std::string& current_score_type);
248
253 static double getScore_(const std::vector<std::string>& requested_score_types, const PeptideHit & hit, const std::string& actual_score_type);
254
273 const std::string (PosteriorErrorProbabilityModel::* getNegativeGnuplotFormula_)(const GaussFitter::GaussFitResult & params) const;
275 const std::string (PosteriorErrorProbabilityModel::* getPositiveGnuplotFormula_)(const GaussFitter::GaussFitResult & params) const;
276 };
277 }
278}
279
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:50
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
bool fitGumbelGauss(std::vector< double > &search_engine_scores, const std::string &outlier_handling)
fits the distributions to the data points(search_engine_scores). Estimated parameters for the distrib...
static std::map< std::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
GumbelMaxLikelihoodFitter::GumbelDistributionFitResult incorrectly_assigned_fit_gumbel_param_
Definition PosteriorErrorProbabilityModel.h:261
TextFile initPlots(std::vector< double > &x_scores)
initializes the plots
void plotTargetDecoyEstimation(std::vector< double > &target, std::vector< double > &decoy)
plots the estimated distribution against target and decoy hits
static double transformScore_(const std::string &engine, const PeptideHit &hit, const std::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:260
bool fit(std::vector< double > &search_engine_scores, const std::string &outlier_handling)
fits the distributions to the data points(search_engine_scores). Estimated parameters for the distrib...
const std::string getBothGnuplotFormula(const GaussFitter::GaussFitResult &incorrect, const GaussFitter::GaussFitResult &correct) const
returns the gnuplot formula of the fitted mixture distribution.
double max_correctly_
peak of the gauss distribution (correctly assigned sequences)
Definition PosteriorErrorProbabilityModel.h:269
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, std::vector< double > &probabilities, const std::string &outlier_handling)
fits the distributions to the data points(search_engine_scores) and writes the computed probabilities...
const std::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...
static void updateScores(const PosteriorErrorProbabilityModel &PEP_model, const std::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
PosteriorErrorProbabilityModel(const PosteriorErrorProbabilityModel &rhs)
Copy constructor (not implemented)
void processOutliers_(std::vector< double > &x_scores, const std::string &outlier_handling) const
transform different score types to a range and score orientation that the model can handle (engine st...
const std::string getGaussGnuplotFormula(const GaussFitter::GaussFitResult &params) const
returns the gnuplot formula of the fitted gauss distribution.
GaussFitter::GaussFitResult getIncorrectlyAssignedFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition PosteriorErrorProbabilityModel.h:185
double getNegativePrior() const
returns the estimated negative prior probability.
Definition PosteriorErrorProbabilityModel.h:197
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:265
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.
GaussFitter::GaussFitResult correctly_assigned_fit_param_
stores gauss parameters
Definition PosteriorErrorProbabilityModel.h:263
double max_incorrectly_
peak of the incorrectly assigned sequences distribution
Definition PosteriorErrorProbabilityModel.h:267
PosteriorErrorProbabilityModel()
default constructor
GaussFitter::GaussFitResult getCorrectlyAssignedFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition PosteriorErrorProbabilityModel.h:179
static double getGumbel_(double x, const GaussFitter::GaussFitResult &params)
computes the gumbel density at position x with parameters params.
Definition PosteriorErrorProbabilityModel.h:203
double smallest_score_
smallest score which was used for fitting the model
Definition PosteriorErrorProbabilityModel.h:271
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:231
static double getScore_(const std::vector< std::string > &requested_score_types, const PeptideHit &hit, const std::string &actual_score_type)
GumbelMaxLikelihoodFitter::GumbelDistributionFitResult getIncorrectlyAssignedGumbelFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition PosteriorErrorProbabilityModel.h:191
void tryGnuplot(const std::string &gp_file)
try to invoke 'gnuplot' on the file to create PDF automatically
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
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