OpenMS
Loading...
Searching...
No Matches
Percolator.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: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
16
17#include <functional>
18#include <memory>
19#include <utility>
20#include <vector>
21
22namespace OpenMS
23{
79 class OPENMS_DLLAPI Percolator : public DefaultParamHandler
80 {
81 public:
83 ~Percolator() override;
84
85 Percolator(const Percolator&) = delete;
86 Percolator& operator=(const Percolator&) = delete;
87
106 void rescore(std::vector<PeptideIdentification>& peptide_ids,
107 const StringList& feature_names = {});
108
138
185 const StringList& feature_set,
186 const std::string& enzyme,
187 int min_charge,
188 int max_charge,
189 const std::string& score_type = "q-value",
190 bool best_hit_only = false);
191
194 using PSMRowLocations = std::vector<std::pair<size_t, size_t>>;
195
221 static void buildPSMRescoreInput(const PeptideIdentificationList& peptide_ids,
222 const StringList& feature_set,
223 const std::string& enzyme,
224 int min_charge,
225 int max_charge,
226 RescoreInput& input,
227 PSMRowLocations& rows,
228 bool calc_mass_feature = false);
229
231 using PSMScorer = std::function<RescoreOutput(const RescoreInput&, const PSMRowLocations&)>;
232
247 const StringList& feature_set,
248 const std::string& enzyme,
249 int min_charge,
250 int max_charge,
251 const std::string& score_type,
252 const PSMScorer& scorer,
253 bool best_hit_only = false);
254
266 const StringList& feature_set,
267 const std::string& enzyme,
268 int min_charge,
269 int max_charge);
270
286 const PercolatorModel& model,
287 PeptideIdentificationList& reference_ids,
288 const StringList& feature_set,
289 const std::string& enzyme,
290 int min_charge,
291 int max_charge,
292 const std::string& score_type = "q-value");
293
316 const std::vector<std::vector<double>>& getSvmWeights() const;
317
339 void storeWeights(const std::string& filename) const;
340
344 {
345 std::vector<int> fold;
346 std::vector<char> sampled;
348 std::vector<std::vector<size_t>> trained_rows;
349 std::vector<int> scorer;
351 // subset_mode 'learning_curve':
352 size_t validation_rows = 0;
353 std::vector<size_t> curve_sizes;
354 std::vector<std::vector<long>> curve_counts;
355 std::vector<std::vector<long>> curve_discordant;
357 std::vector<size_t> chosen_size;
358 };
359
365
382 double getPi0() const;
383
399
419
467 RescoreOutput score(const RescoreInput& input, const PercolatorModel& model);
468
488 RescoreOutput score(const RescoreInput& input, const PercolatorModel& model, const RescoreInput& reference);
489
529 const std::vector<PeptideIdentification>& peptide_ids,
530 bool flatten_hits,
531 RescoreInput& input);
532
552 static void saveModel(const PercolatorModel& model, const std::string& filename);
553
567 static PercolatorModel loadModel(const std::string& filename);
568
577 std::shared_ptr<const PercolatorReset::Output> getResetOutput() const;
578
579 protected:
580 void updateMembers_() override;
581
582 private:
584 const std::vector<std::pair<size_t, size_t>>& hit_locs);
586 struct ReferenceScale_;
589 RescoreOutput score_(const RescoreInput& input, const PercolatorModel& model, ReferenceScale_* scale);
590
591 struct Impl;
592 std::unique_ptr<Impl> impl_;
593 };
594}
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
In-process Percolator: semi-supervised target/decoy rescoring with q-values + PEPs.
Definition Percolator.h:80
bool usedDefaultDirection() const
Whether the last rescore()/train() call replaced the learned model by the default direction.
static PercolatorModel loadModel(const std::string &filename)
Deserialize a PercolatorModel written by saveModel().
RescoreOutput score_(const RescoreInput &input, const PercolatorModel &model, ReferenceScale_ *scale)
void storeWeights(const std::string &filename) const
Writes the models of the last rescore()/train() call as the percolator executable writes them with it...
std::vector< std::vector< long > > curve_counts
per size and fold: validation targets (-1: fold had stopped)
Definition Percolator.h:354
RescoreOutput score(const RescoreInput &input, const PercolatorModel &model, const RescoreInput &reference)
Score feature rows with a pre-trained model on the scale of a reference set (e.g. its training set).
~Percolator() override
Size rescorePSMs(PeptideIdentificationList &peptide_ids, const StringList &feature_set, const std::string &enzyme, int min_charge, int max_charge, const std::string &score_type="q-value", bool best_hit_only=false)
Rescore search engine PSMs in place on the standard Percolator (.pin) feature set.
std::vector< std::vector< size_t > > trained_rows
per fold: the input rows of its model's training set, ascending
Definition Percolator.h:348
std::vector< int > scorer
Definition Percolator.h:349
Percolator & operator=(const Percolator &)=delete
std::function< RescoreOutput(const RescoreInput &, const PSMRowLocations &)> PSMScorer
Scores the feature rows that rescorePSMs() built, in place of rescore(): one score,...
Definition Percolator.h:231
PercolatorModel train(const RescoreInput &input)
Train a Percolator model on feature rows. No scoring.
Size scorePSMs(PeptideIdentificationList &peptide_ids, const PercolatorModel &model, PeptideIdentificationList &reference_ids, const StringList &feature_set, const std::string &enzyme, int min_charge, int max_charge, const std::string &score_type="q-value")
Rescore PSMs with a model trained on other PSMs (trainPSMs()), on the scale of those (reference_ids,...
static void fillPINCompatibleFields(const std::vector< PeptideIdentification > &peptide_ids, bool flatten_hits, RescoreInput &input)
Fill PIN-compatible optional fields on a RescoreInput.
Size rescorePSMsWithScorer(PeptideIdentificationList &peptide_ids, const StringList &feature_set, const std::string &enzyme, int min_charge, int max_charge, const std::string &score_type, const PSMScorer &scorer, bool best_hit_only=false)
As rescorePSMs(), but the feature rows are scored by scorer instead of rescore(input).
const CappedTrainingInfo & getCappedTrainingInfo() const
The folds, sample and training sets of the last rescore() if it trained out-of-fold on a capped sampl...
std::unique_ptr< Impl > impl_
Definition Percolator.h:592
double getPi0() const
Pi0 (null fraction) from the last rescore()/score() call.
static void buildPSMRescoreInput(const PeptideIdentificationList &peptide_ids, const StringList &feature_set, const std::string &enzyme, int min_charge, int max_charge, RescoreInput &input, PSMRowLocations &rows, bool calc_mass_feature=false)
The feature matrix of PSM rescoring: what rescorePSMs() trains and scores on, without rescoring.
std::vector< std::pair< size_t, size_t > > PSMRowLocations
Definition Percolator.h:194
std::vector< std::vector< long > > curve_discordant
Definition Percolator.h:355
RescoreOutput score(const RescoreInput &input, const PercolatorModel &model)
Score feature rows using a pre-trained model. No training.
const std::vector< std::vector< double > > & getSvmWeights() const
SVM weights trained in the last rescore()/train() call.
std::vector< int > fold
per input row: its cross-validation fold, whose model scored it
Definition Percolator.h:345
std::vector< char > sampled
Definition Percolator.h:346
PercolatorModel trainPSMs(PeptideIdentificationList &peptide_ids, const StringList &feature_set, const std::string &enzyme, int min_charge, int max_charge)
Train a model on search engine PSMs (the .pin features of rescorePSMs()), for scorePSMs() on other PS...
std::vector< size_t > curve_sizes
training-sample rows of each trained size, in order
Definition Percolator.h:353
std::vector< size_t > chosen_size
per fold: the sample rows of its kept model
Definition Percolator.h:357
RescoreOutput rescore(const RescoreInput &input)
Rescore a feature matrix domain-agnostically.
std::shared_ptr< const PercolatorReset::Output > getResetOutput() const
Result of the last rescorePSMs() call with parameter 'algorithm' = 'reset' (null otherwise).
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
RescoreOutput rescoreReset_(const PeptideIdentificationList &peptide_ids, RescoreInput &ri, const std::vector< std::pair< size_t, size_t > > &hit_locs)
static void saveModel(const PercolatorModel &model, const std::string &filename)
Serialize a PercolatorModel to a plain-text file.
Percolator(const Percolator &)=delete
void rescore(std::vector< PeptideIdentification > &peptide_ids, const StringList &feature_names={})
Rescore PSMs in place. Domain-specific convenience wrapper over rescore(RescoreInput).
The out-of-fold capped training of the last rescore() (subset_mode 'out_of_fold', 'out_of_fold_avg' o...
Definition Percolator.h:344
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Trained Percolator model: averaged SVM weights in raw feature space.
Definition PercolatorTypes.h:137
Output from Percolator::rescore. Aligned 1:1 with the rows of the RescoreInput (RescoreInput::rowCoun...
Definition PercolatorTypes.h:109
Input to domain-agnostic Percolator::rescore.
Definition PercolatorTypes.h:28