OpenMS
Loading...
Searching...
No Matches
PeptDeepRescoring Class Reference

Annotates PSMs with rescoring features derived from PeptDeep predictions. More...

#include <OpenMS/ANALYSIS/ID/PeptDeepRescoring.h>

Inheritance diagram for PeptDeepRescoring:
DefaultParamHandler ProgressLogger

Classes

struct  Row
 Row of the flat PSM work list built by annotate(). More...
 

Public Member Functions

 PeptDeepRescoring ()
 Constructor. Sets the default parameters; the model paths start empty and must be set.
 
 ~PeptDeepRescoring () override
 Destructor.
 
void annotate (const PeakMap &spectra, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids)
 Annotates peptide_ids in place and registers the features for rescoring.
 
double getUsedNCE () const
 
double getRTCalibrationError () const
 
Size getNumPSMs () const
 Number of PSMs (peptide hits) seen by the last annotate() call.
 
Size getNumPredictedPSMs () const
 
- Public Member Functions inherited from DefaultParamHandler
 DefaultParamHandler (const std::string &name)
 Constructor with name that is displayed in error messages.
 
 DefaultParamHandler (const DefaultParamHandler &rhs)
 Copy constructor.
 
virtual ~DefaultParamHandler ()
 Destructor.
 
DefaultParamHandler & operator= (const DefaultParamHandler &rhs)
 Assignment operator.
 
virtual bool operator== (const DefaultParamHandler &rhs) const
 Equality operator.
 
void setParameters (const Param &param)
 Sets the parameters.
 
const Param & getParameters () const
 Non-mutable access to the parameters.
 
const Param & getDefaults () const
 Non-mutable access to the default parameters.
 
const std::string & getName () const
 Non-mutable access to the name.
 
void setName (const std::string &name)
 Mutable access to the name.
 
const std::vector< std::string > & getSubsections () const
 Non-mutable access to the registered subsections.
 
- Public Member Functions inherited from ProgressLogger
 ProgressLogger ()
 Constructor.
 
virtual ~ProgressLogger ()
 Destructor.
 
 ProgressLogger (const ProgressLogger &other)
 Copy constructor.
 
ProgressLogger & operator= (const ProgressLogger &other)
 Assignment Operator.
 
void setLogType (LogType type) const
 Sets the progress log that should be used. The default type is NONE!
 
LogType getLogType () const
 Returns the type of progress log being used.
 
void setLogger (ProgressLoggerImpl *logger)
 Sets the logger to be used for progress logging.
 
void startProgress (SignedSize begin, SignedSize end, const std::string &label) const
 Initializes the progress display.
 
void setProgress (SignedSize value) const
 Sets the current progress.
 
void endProgress (UInt64 bytes_processed=0) const
 
void nextProgress () const
 increment progress by 1 (according to range begin-end)
 

Static Public Member Functions

static StringList featureNames ()
 Names of the features this class adds to each PSM, in a stable order.
 
- Static Public Member Functions inherited from DefaultParamHandler
static void writeParametersToMetaValues (const Param &write_this, MetaInfoInterface &write_here, const std::string &key_prefix="")
 Writes all parameters to meta values.
 

Protected Member Functions

void updateMembers_ () override
 This method is used to update extra member variables at the end of the setParameters() method.
 
void annotateRun_ (const std::string &run_id, const std::map< std::string, double > &collision_energies, PeptideIdentificationList &peptide_ids, const std::vector< Row > &rows, const std::vector< Size > &run_rows, const std::vector< std::string > &uniq_seq, const std::vector< float > &uniq_charge, bool higher_score_better, PeptDeepMS2Inference &ms2_inference, PeptDeepRTInference &rt_inference)
 
- Protected Member Functions inherited from DefaultParamHandler
void defaultsToParam_ ()
 Updates the parameters after the defaults have been set in the constructor.
 

Protected Attributes

std::string ms2_model_
 
std::string rt_model_
 
double nce_ {-1.0}
 
double nce_grid_halfwidth_ {6.0}
 
double nce_grid_step_ {2.0}
 
double nce_fallback_ {30.0}
 
Size nce_sample_size_ {2000}
 
std::string instrument_
 
double calibration_quantile_ {0.5}
 
std::string rt_model_type_ {"b_spline"}
 
Size rt_num_nodes_ {5}
 
int ms2_min_ordinal_ {1}
 
double ms2_strong_fraction_ {0.05}
 
Size batch_size_ {500}
 
Int threads_ {4}
 
double used_nce_ {-1.0}
 
double rt_calibration_error_ {-1.0}
 
Size num_psms_ {0}
 
Size num_predicted_psms_ {0}
 
- Protected Attributes inherited from DefaultParamHandler
Param param_
 Container for current parameters.
 
Param defaults_
 Container for default parameters. This member should be filled in the constructor of derived classes!
 
std::vector< std::string > subsections_
 Container for registered subsections. This member should be filled in the constructor of derived classes!
 
std::string error_name_
 Name that is displayed in error messages during the parameter checking.
 
bool check_defaults_
 If this member is set to false no checking if parameters in done;.
 
bool warn_empty_defaults_
 If this member is set to false no warning is emitted when defaults are empty;.
 
- Protected Attributes inherited from ProgressLogger
LogType type_
 
time_t last_invoke_
 
ProgressLoggerImpl * current_logger_
 

Additional Inherited Members

- Public Types inherited from ProgressLogger
enum  LogType { CMD , GUI , NONE }
 Possible log types. More...
 
- Static Protected Attributes inherited from ProgressLogger
static int recursion_depth_
 

Detailed Description

Annotates PSMs with rescoring features derived from PeptDeep predictions.

Compares every PSM against an AlphaPeptDeep prediction of the same peptide and stores the agreement as per-hit features, which are then registered in the search parameters' extra_features list so that PercolatorAdapter picks them up:

  • ms2_cosine, ms2_spectral_angle, ms2_pearson, ms2_frac_pred_found – predicted versus observed fragment intensities
  • rt_abs_error – observed retention time versus a per-run calibration of the predicted retention time

Observed intensities are taken from the PSM's own peak annotations, so no second pass over the spectra is needed; the search engine must have been run with fragment annotation enabled (ProSE's annotate:PSM default of ALL does this). Predicted ions that were not matched contribute zero on the observed side, which is what makes a wrong peptide score badly rather than simply score on fewer ions.

Two per-run quantities are calibrated from the data rather than being asked of the user, because both are properties of the run and neither has a safe global default:

  • Normalised collision energy. The model's NCE scale does not coincide with the number the instrument reports, so the mzML value is used only as the centre of a small search grid. Each candidate is scored on a sample of confident PSMs and the one with the highest median cosine wins. With nce set to a positive value the scan is skipped and that value is used directly.
  • Retention time. Predicted RT is in the model's own iRT-like units, so it is mapped onto the run's observed gradient by fitting a TransformationModel on confident PSMs before the residual is taken.

Confident PSMs are selected by search score rather than by spectral similarity: using similarity here would tie the RT feature to the MS2 features and let one feature's errors propagate into the other. Only the best-scoring hit of each spectrum, and only if it is not a decoy, is a candidate, so the calibration does not depend on how many hits per spectrum the search reports: with ten, lower-ranked candidates and decoys would otherwise make up most of the better-scoring half.

Parameters are not pulled into the generated documentation with @htmlinclude: that requires the class to be registered in DefaultParamHandlerDocumenter, which cannot instantiate a type that only exists in ONNX-enabled builds. ProSEAlgorithm omits it for the same reason.


Class Documentation

◆ OpenMS::PeptDeepRescoring::Row

struct OpenMS::PeptDeepRescoring::Row

Row of the flat PSM work list built by annotate().

Class Members
bool calibration_candidate best hit of its spectrum and not a decoy
Size hit index into that identification's hits
Size key index into the de-duplicated (sequence, charge) list
Size len peptide length
Size pi index into the PeptideIdentificationList
double score search score, used to pick the calibration set

Constructor & Destructor Documentation

◆ PeptDeepRescoring()

Constructor. Sets the default parameters; the model paths start empty and must be set.

◆ ~PeptDeepRescoring()

~PeptDeepRescoring ( )
override

Destructor.

Member Function Documentation

◆ annotate()

void annotate ( const PeakMap &  spectra,
std::vector< ProteinIdentification > &  protein_ids,
PeptideIdentificationList &  peptide_ids 
)

Annotates peptide_ids in place and registers the features for rescoring.

Parameters
[in]spectraSpectra the identifications were made on; supplies retention time and, for the NCE scan, the instrument's reported collision energy.
[in,out]protein_idsSearch metadata; the feature names are appended to the first run's extra_features.
[in,out]peptide_idsPSMs to annotate. Every hit receives every feature, so that no run ends up with a feature present on only some of its PSMs.

Multiple runs in one call are fine: PSMs are partitioned by PeptideIdentification::getIdentifier() and each run gets its own NCE scan and its own RT calibration.

Note
That partition is only as good as the run identifiers, so call this before any step that collapses several runs into one – ProSE's out_merged and IDMergerAlgorithm, which remap every identifier onto a single merged run, or IDMerger with merge_proteins_add_PSMs (its default appends runs and is therefore safe). Both calibrated quantities genuinely differ between runs: six files of one HLA ligand atlas dataset (PXD019643) calibrated to median RT residuals between 98 s and 625 s. On already-collapsed input this silently fits one NCE and one RT curve across all of them, and nothing here can detect it after the fact – the merged input is indistinguishable from a genuine single run.
Exceptions
Exception::FileNotFoundif a configured model file does not exist.
Exception::MissingInformationif no PSM carries peak annotations, since every MS2 feature would otherwise be silently zero.

◆ annotateRun_()

void annotateRun_ ( const std::string &  run_id,
const std::map< std::string, double > &  collision_energies,
PeptideIdentificationList &  peptide_ids,
const std::vector< Row > &  rows,
const std::vector< Size > &  run_rows,
const std::vector< std::string > &  uniq_seq,
const std::vector< float > &  uniq_charge,
bool  higher_score_better,
PeptDeepMS2Inference &  ms2_inference,
PeptDeepRTInference &  rt_inference 
)
protected

Annotates the PSMs of a single identification run. Each run gets its own collision energy and its own retention-time calibration, since neither transfers across runs with different gradients or acquisition settings.

◆ featureNames()

static StringList featureNames ( )
static

Names of the features this class adds to each PSM, in a stable order.

◆ getNumPredictedPSMs()

Size getNumPredictedPSMs ( ) const

Number of PSMs of the last annotate() call that received a model prediction and carry peak annotations, i.e. whose MS2 features are computed rather than zero-filled. 0 if annotate() returned early or predicted nothing.

◆ getNumPSMs()

Size getNumPSMs ( ) const

Number of PSMs (peptide hits) seen by the last annotate() call.

◆ getRTCalibrationError()

double getRTCalibrationError ( ) const

Median absolute RT residual over the calibration set of the run annotated last. -1 if annotate() has not run, or could not calibrate.

◆ getUsedNCE()

double getUsedNCE ( ) const

Normalised collision energy used for the run annotated last (after any scan). -1 if annotate() has not run, or returned before selecting one.

◆ updateMembers_()

void updateMembers_ ( )
overrideprotectedvirtual

This method is used to update extra member variables at the end of the setParameters() method.

Also call it at the end of the derived classes' copy constructor and assignment operator.

The default implementation is empty.

Reimplemented from DefaultParamHandler.

Member Data Documentation

◆ batch_size_

Size batch_size_ {500}
protected

◆ calibration_quantile_

double calibration_quantile_ {0.5}
protected

◆ instrument_

std::string instrument_
protected

◆ ms2_min_ordinal_

int ms2_min_ordinal_ {1}
protected

◆ ms2_model_

std::string ms2_model_
protected

◆ ms2_strong_fraction_

double ms2_strong_fraction_ {0.05}
protected

◆ nce_

double nce_ {-1.0}
protected

◆ nce_fallback_

double nce_fallback_ {30.0}
protected

◆ nce_grid_halfwidth_

double nce_grid_halfwidth_ {6.0}
protected

◆ nce_grid_step_

double nce_grid_step_ {2.0}
protected

◆ nce_sample_size_

Size nce_sample_size_ {2000}
protected

◆ num_predicted_psms_

Size num_predicted_psms_ {0}
protected

◆ num_psms_

Size num_psms_ {0}
protected

◆ rt_calibration_error_

double rt_calibration_error_ {-1.0}
protected

◆ rt_model_

std::string rt_model_
protected

◆ rt_model_type_

std::string rt_model_type_ {"b_spline"}
protected

◆ rt_num_nodes_

Size rt_num_nodes_ {5}
protected

◆ threads_

Int threads_ {4}
protected

◆ used_nce_

double used_nce_ {-1.0}
protected