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
17
18#include <functional>
19#include <memory>
20#include <utility>
21#include <vector>
22
23namespace OpenMS
24{
80 class OPENMS_DLLAPI Percolator : public DefaultParamHandler
81 {
82 public:
84 ~Percolator() override;
85
86 Percolator(const Percolator&) = delete;
87 Percolator& operator=(const Percolator&) = delete;
88
107 void rescore(std::vector<PeptideIdentification>& peptide_ids,
108 const StringList& feature_names = {});
109
139
186 const StringList& feature_set,
187 const std::string& enzyme,
188 int min_charge,
189 int max_charge,
190 const std::string& score_type = "q-value",
191 bool best_hit_only = false);
192
195 using PSMRowLocations = std::vector<std::pair<size_t, size_t>>;
196
222 static void buildPSMRescoreInput(const PeptideIdentificationList& peptide_ids,
223 const StringList& feature_set,
224 const std::string& enzyme,
225 int min_charge,
226 int max_charge,
227 RescoreInput& input,
228 PSMRowLocations& rows,
229 bool calc_mass_feature = false);
230
232 using PSMScorer = std::function<RescoreOutput(const RescoreInput&, const PSMRowLocations&)>;
233
248 const StringList& feature_set,
249 const std::string& enzyme,
250 int min_charge,
251 int max_charge,
252 const std::string& score_type,
253 const PSMScorer& scorer,
254 bool best_hit_only = false);
255
267 const StringList& feature_set,
268 const std::string& enzyme,
269 int min_charge,
270 int max_charge);
271
287 const PercolatorModel& model,
288 PeptideIdentificationList& reference_ids,
289 const StringList& feature_set,
290 const std::string& enzyme,
291 int min_charge,
292 int max_charge,
293 const std::string& score_type = "q-value");
294
317 const std::vector<std::vector<double>>& getSvmWeights() const;
318
340 void storeWeights(const std::string& filename) const;
341
343 static constexpr const char* VENDORED_VERSION = "3.08-vendored";
344
359 static void markRescoredRuns(std::vector<ProteinIdentification>& runs,
360 const std::string& tool,
361 const std::vector<std::pair<std::string, DataValue>>& settings,
362 const std::string& version = VENDORED_VERSION);
363
367 {
368 std::vector<int> fold;
369 std::vector<char> sampled;
371 std::vector<std::vector<size_t>> trained_rows;
372 std::vector<int> scorer;
374 // subset_mode 'learning_curve':
375 size_t validation_rows = 0;
376 std::vector<size_t> curve_sizes;
377 std::vector<std::vector<long>> curve_counts;
378 std::vector<std::vector<long>> curve_discordant;
380 std::vector<size_t> chosen_size;
381 };
382
388
405 double getPi0() const;
406
422
442
490 RescoreOutput score(const RescoreInput& input, const PercolatorModel& model);
491
511 RescoreOutput score(const RescoreInput& input, const PercolatorModel& model, const RescoreInput& reference);
512
552 const std::vector<PeptideIdentification>& peptide_ids,
553 bool flatten_hits,
554 RescoreInput& input);
555
575 static void saveModel(const PercolatorModel& model, const std::string& filename);
576
590 static PercolatorModel loadModel(const std::string& filename);
591
600 std::shared_ptr<const PercolatorReset::Output> getResetOutput() const;
601
602 protected:
603 void updateMembers_() override;
604
605 private:
607 const std::vector<std::pair<size_t, size_t>>& hit_locs);
609 struct ReferenceScale_;
612 RescoreOutput score_(const RescoreInput& input, const PercolatorModel& model, ReferenceScale_* scale);
613
614 struct Impl;
615 std::unique_ptr<Impl> impl_;
616 };
617}
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:81
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:377
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:371
std::vector< int > scorer
Definition Percolator.h:372
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:232
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:615
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:195
std::vector< std::vector< long > > curve_discordant
Definition Percolator.h:378
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:368
std::vector< char > sampled
Definition Percolator.h:369
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:376
std::vector< size_t > chosen_size
per fold: the sample rows of its kept model
Definition Percolator.h:380
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.
static void markRescoredRuns(std::vector< ProteinIdentification > &runs, const std::string &tool, const std::vector< std::pair< std::string, DataValue > > &settings, const std::string &version=VENDORED_VERSION)
Marks search runs as post-processed by Percolator, so that downstream tools see that their PSMs were ...
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:367
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