OpenMS
PosteriorErrorProbabilityModel.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- 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 
21 namespace OpenMS
22 {
23  class String;
24  class TextFile;
25  class PeptideIdentification;
26  class ProteinIdentification;
27  class PeptideHit;
28  namespace Math
29  {
30 
31 
48  class OPENMS_DLLAPI PosteriorErrorProbabilityModel :
49  public DefaultParamHandler
50  {
51 public:
52 
55 
58 
70  static std::map<String, std::vector<std::vector<double>>> extractAndTransformScores(
71  const std::vector<ProteinIdentification> & protein_ids,
72  const std::vector<PeptideIdentification> & peptide_ids,
73  const bool split_charge,
74  const bool top_hits_only,
75  const bool target_decoy_available,
76  const double fdr_for_targets_smaller);
77 
91  static void updateScores(
92  const PosteriorErrorProbabilityModel & PEP_model,
93  const String & search_engine,
94  const Int charge,
95  const bool prob_correct,
96  const bool split_charge,
97  std::vector<ProteinIdentification> & protein_ids,
98  std::vector<PeptideIdentification> & peptide_ids,
99  bool & unable_to_fit_data,
100  bool & data_might_not_be_well_fit);
101 
111  bool fit(std::vector<double>& search_engine_scores, const String& outlier_handling);
112 
122  bool fitGumbelGauss(std::vector<double>& search_engine_scores, const String& outlier_handling);
123 
132  bool fit(std::vector<double>& search_engine_scores, std::vector<double>& probabilities, const String& outlier_handling);
133 
135  void fillDensities(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
137  void fillLogDensities(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
139  void fillLogDensitiesGumbel(const std::vector<double> & x_scores, std::vector<double> & incorrect_density, std::vector<double> & correct_density);
141  double computeLogLikelihood(const std::vector<double> & incorrect_density, const std::vector<double> & correct_density) const;
142 
150  const std::vector<double>& incorrect_log_density,
151  const std::vector<double>& correct_log_density,
152  std::vector<double>& incorrect_posterior) const;
153 
160  std::pair<double, double> pos_neg_mean_weighted_posteriors(const std::vector<double> &x_scores,
161  const std::vector<double> &incorrect_posteriors);
162 
170  std::pair<double, double> pos_neg_sigma_weighted_posteriors(const std::vector<double> &x_scores,
171  const std::vector<double> &incorrect_posteriors,
172  const std::pair<double, double>& pos_neg_mean);
173 
176  {
177  return correctly_assigned_fit_param_;
178  }
179 
182  {
183  return incorrectly_assigned_fit_param_;
184  }
185 
188  {
189  return incorrectly_assigned_fit_gumbel_param_;
190  }
191 
193  double getNegativePrior() const
194  {
195  return negative_prior_;
196  }
197 
199  static double getGumbel_(double x, const GaussFitter::GaussFitResult & params)
200  {
201  double z = exp((params.x0 - x) / params.sigma);
202  return (z * exp(-1 * z)) / params.sigma;
203  }
204 
209  double computeProbability(double score) const;
210 
212  TextFile initPlots(std::vector<double> & x_scores);
213 
216 
219 
222 
224  void plotTargetDecoyEstimation(std::vector<double> & target, std::vector<double> & decoy);
225 
227  inline double getSmallestScore() const
228  {
229  return smallest_score_;
230  }
231 
233  void tryGnuplot(const String& gp_file);
234 
235 private:
237  void processOutliers_(std::vector<double>& x_scores, const String& outlier_handling) const;
238 
243  static double transformScore_(const String& engine, const PeptideHit& hit, const String& current_score_type);
244 
249  static double getScore_(const std::vector<String>& requested_score_types, const PeptideHit & hit, const String& actual_score_type);
250 
269  const String (PosteriorErrorProbabilityModel::* getNegativeGnuplotFormula_)(const GaussFitter::GaussFitResult & params) const;
271  const String (PosteriorErrorProbabilityModel::* getPositiveGnuplotFormula_)(const GaussFitter::GaussFitResult & params) const;
272  };
273  }
274 }
275 
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Implements a mixture model of the inverse gumbel and the gauss distribution or a gaussian mixture.
Definition: PosteriorErrorProbabilityModel.h:50
std::pair< double, double > pos_neg_mean_weighted_posteriors(const std::vector< double > &x_scores, const std::vector< double > &incorrect_posteriors)
double computeLLAndIncorrectPosteriorsFromLogDensities(const std::vector< double > &incorrect_log_density, const std::vector< double > &correct_log_density, std::vector< double > &incorrect_posterior) const
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:257
PosteriorErrorProbabilityModel & operator=(const PosteriorErrorProbabilityModel &rhs)
assignment operator (not implemented)
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:256
double max_correctly_
peak of the gauss distribution (correctly assigned sequences)
Definition: PosteriorErrorProbabilityModel.h:265
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...
static std::map< String, std::vector< std::vector< double > > > extractAndTransformScores(const std::vector< ProteinIdentification > &protein_ids, const std::vector< PeptideIdentification > &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
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:181
double getNegativePrior() const
returns the estimated negative prior probability.
Definition: PosteriorErrorProbabilityModel.h:193
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:261
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.
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:259
double max_incorrectly_
peak of the incorrectly assigned sequences distribution
Definition: PosteriorErrorProbabilityModel.h:263
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, std::vector< PeptideIdentification > &peptide_ids, bool &unable_to_fit_data, bool &data_might_not_be_well_fit)
update score entries with PEP (or 1-PEP) estimates
PosteriorErrorProbabilityModel()
default constructor
GaussFitter::GaussFitResult getCorrectlyAssignedFitResult() const
returns estimated parameters for correctly assigned sequences. Fit should be used before.
Definition: PosteriorErrorProbabilityModel.h:175
static double getGumbel_(double x, const GaussFitter::GaussFitResult &params)
computes the gumbel density at position x with parameters params.
Definition: PosteriorErrorProbabilityModel.h:199
double smallest_score_
smallest score which was used for fitting the model
Definition: PosteriorErrorProbabilityModel.h:267
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 getSmallestScore() const
returns the smallest score used in the last fit
Definition: PosteriorErrorProbabilityModel.h:227
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:187
double computeLogLikelihood(const std::vector< double > &incorrect_density, const std::vector< double > &correct_density) const
computes the Likelihood with a log-likelihood function.
Representation of a peptide hit.
Definition: PeptideHit.h:31
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