![]() |
OpenMS
|
Per-run likelihood model of fragment ion presence, intensity rank and mass error, learned from confident PSMs. More...
#include <OpenMS/ANALYSIS/ID/FragmentIonLikelihoodModel.h>
Classes | |
| struct | Features |
| Features of one PSM. More... | |
| struct | Ion |
| One theoretical ion after matching. More... | |
| class | PeakLists |
| Compact peak lists of the spectra of one run: per peak only its m/z and its intensity-rank bin. More... | |
Public Types | |
| enum class | ContextSet { BASIC , RICH } |
| Ion contexts and outcomes the model distinguishes. More... | |
Public Member Functions | |
| FragmentIonLikelihoodModel (ContextSet context_set=ContextSet::RICH, double pseudo_count=20.0) | |
| Untrained model. | |
| ContextSet | contextSet () const |
| The context set of this model. | |
| Size | contexts () const |
| Number of ion contexts. | |
| Size | outcomes () const |
| Number of outcomes, absence included. | |
| Size | absentOutcome () const |
| Outcome of an unmatched ion. | |
| void | matchIons (const PeakLists &peaks, Size index, const MSSpectrum &theoretical, const AASequence &peptide, int precursor_charge, double tolerance, bool ppm, std::vector< Ion > &ions) const |
Match the named ions of a theoretical spectrum against peak list index: one Ion per recognised ion. | |
| void | matchIons (const PeakLists &peaks, Size index, const MSSpectrum &theoretical, const std::vector< Residue::ResidueType > &ion_types, const std::vector< UInt > &ion_ordinals, const std::vector< Int > &ion_charges, const AASequence &peptide, int precursor_charge, double tolerance, bool ppm, std::vector< Ion > &ions) const |
matchIons() with the ions given as codes instead of names: per peak of theoretical its ion type, ordinal and charge, as TheoreticalSpectrumGenerator::getIonSeriesSpectrum() writes them. The same ions as matchIons() on the spectrum of getSpectrum() with the names. | |
| void | addObservations (const std::vector< Ion > &ions, bool noise) |
Add the matched ions of one PSM to the signal (noise false) or noise counts. | |
| void | finalize () |
| Turn the counts into smoothed log-probabilities. Required before scoring; observations added later need another call. | |
| bool | isTrained () const |
| Whether finalize() was called after the last observation. | |
| Size | signalPsms () const |
| Number of confident PSMs added. | |
| Size | noisePsms () const |
| Number of reversed PSMs added. | |
| double | pseudoCount () const |
| Pseudo-count of the back-off smoothing. | |
| double | logLikelihoodRatio (Size context, Size outcome) const |
| ln P(outcome | signal, context) - ln P(outcome | noise, context) | |
| double | presenceProbability (Size context) const |
| Probability that an ion of this context is present in the spectrum of its peptide. | |
| Features | score (const std::vector< Ion > &ions, Size top_k=6) const |
Features of one PSM from its matched ions (see matchIons()); top_k bounds top_predicted_observed. | |
Static Public Member Functions | |
| static Size | rankBin (Size rank) |
| Rank bin (0 .. RANK_BINS - 1) of a matched peak with the given 1-based intensity rank. | |
| static Size | errorBin (double relative_error) |
| Error bin (0 .. ERROR_BINS - 1) of a match with the given |mass error| / tolerance (at most 1) | |
| static bool | parseIonName (const std::string &name, bool &prefix, Size &ordinal) |
| Terminus and ordinal of an ion name as written by TheoreticalSpectrumGenerator, e.g. "b5+", "y3++", "z.4+". | |
| static bool | parseIonSeries (const std::string &name, Size &series, Size &ordinal) |
| parseIonName() that returns the ion series (see SERIES) instead of the terminus, e.g. 2 for "c7+" and 3 for "z.4+". | |
| static Size | seriesOf (Residue::ResidueType type) |
| Ion series (see SERIES) of an ion type (Residue::AIon ... Residue::Zp2Ion); SERIES for any other type. | |
Static Public Attributes | |
| static constexpr Size | SERIES = 4 |
| static constexpr Size | PRECURSOR_BUCKETS = 3 |
| precursor charge 1-2, 3, at least 4 | |
| static constexpr Size | FRAGMENT_CHARGES = 2 |
| fragment charge 1, at least 2 | |
| static constexpr Size | POSITION_BINS = 10 |
| fragment length / peptide length | |
| static constexpr Size | CLEAVAGE_SITES = 3 |
| RICH: bond before P, bond after D or E, any other bond. | |
| static constexpr Size | COMPLEMENT_STATES = 2 |
| RICH: complementary singly charged ion not matched / matched. | |
| static constexpr Size | RANK_BINS = 7 |
| matched peak intensity rank bins | |
| static constexpr Size | ERROR_BINS = 3 |
| RICH: |mass error| / tolerance below 0.25, below 0.5, up to 1. | |
Private Member Functions | |
| template<typename IonOf , typename ChargeOf > | |
| void | matchIons_ (const PeakLists &peaks, Size index, const MSSpectrum &theoretical, IonOf &&ion_of, ChargeOf &&charge_of, const AASequence &peptide, int precursor_charge, double tolerance, bool ppm, std::vector< Ion > &ions) const |
| matchIons() for ion(i, series, ordinal) (false: not an ion of a series) and charge(i) of the peaks | |
| Size | level1Context_ (Size context) const |
| Contexts of the coarser back-off levels: level 1 is the coarsest above the flat prior. | |
| Size | level2Context_ (Size context) const |
| std::vector< double > | smooth_ (const std::vector< double > &counts) const |
| Smoothed log-probabilities of one count table, backing off over the context hierarchy. | |
| void | requireTrained_ () const |
| Throws unless finalize() was called after the last observation. | |
Private Attributes | |
| ContextSet | context_set_ |
| Size | sites_ |
| cleavage-site classes of the context set (1 for BASIC) | |
| Size | complement_ |
| complement states of the context set (1 for BASIC) | |
| Size | errors_ |
| error bins of the context set (1 for BASIC) | |
| Size | contexts_ |
| Size | outcomes_ |
| std::vector< double > | signal_counts_ |
| contexts_ * outcomes_ counts of confident ions | |
| std::vector< double > | noise_counts_ |
| contexts_ * outcomes_ counts of reversed ions | |
| std::vector< double > | signal_logp_ |
| smoothed ln P(outcome | signal, context) | |
| std::vector< double > | noise_logp_ |
| smoothed ln P(outcome | noise, context) | |
| Size | signal_psms_ = 0 |
| Size | noise_psms_ = 0 |
| double | pseudo_count_ = 20.0 |
| bool | finalized_ = false |
Per-run likelihood model of fragment ion presence, intensity rank and mass error, learned from confident PSMs.
Every theoretical ion of a peptide-spectrum match is placed in a context and gets an outcome. Two context sets are available (see ContextSet):
The c and z ions of electron-based activation (ETD, ECD, EThcD, ETciD) are series of their own, apart from the b and y ions: their presence and intensity differ from those of b and y ions, also in the same spectrum (EThcD), and depend on the cleavage site in other ways (the N-Calpha bond of proline does not break, so c and z ions at a bond X|P are missing where b and y ions are often enhanced). Spectra with b and y ions only use the a/b and x/y series, whose contexts are the same whether or not other spectra of the run have c and z ions.
Two sets of counts are kept: the ions of confident peptides ("signal") and the ions of their reversed sequences matched against the same spectra ("noise"). finalize() turns both into smoothed probabilities with pseudo-count back-off over a context hierarchy (BASIC: full context -> series, precursor and fragment charge -> series -> flat prior; RICH: full context -> series, precursor and fragment charge, cleavage site, complement -> series and fragment charge -> flat prior), so that a few thousand PSMs suffice and unseen contexts stay finite.
A scored PSM yields three additive features: the summed log-likelihood ratio of its outcomes (present ions are credited, absent ions debited by what the run has taught about them), the fraction of the predicted ion presence that was observed, and the fraction of the ions most likely to be present that were observed. The model carries no pre-trained tables; it is meant to be trained on the run it scores, with the PSMs it scores held out from its training data (see ProSEAlgorithm, annotate:self_trained_ion_priors, which trains one model per half of the spectra and scores each half with the model of the other half).
The peaks are read from PeakLists, a compact copy of the spectra (m/z and intensity-rank bin per peak). Matching is closest-peak within the tolerance, as in HyperScore.
| struct OpenMS::FragmentIonLikelihoodModel::Features |
Features of one PSM.
| Class Members | ||
|---|---|---|
| double | explained_presence = 0.0 | sum of P(present) over matched ions / sum of P(present) over all ions |
| double | log_likelihood_ratio = 0.0 | sum over all theoretical ions of ln P(outcome | signal) / P(outcome | noise) |
| Size | matched_ions = 0 | theoretical ions with a peak within tolerance |
| Size | theoretical_ions = 0 | theoretical ions with a recognised ion name |
| double | top_predicted_observed = 0.0 | fraction of the top_k ions with the highest P(present) that matched |
| struct OpenMS::FragmentIonLikelihoodModel::Ion |
One theoretical ion after matching.
| Class Members | ||
|---|---|---|
| UInt32 | context | flat context index, below contexts() |
| UInt32 | outcome | outcome index, below outcomes(); absentOutcome() if unmatched |
|
strong |
Ion contexts and outcomes the model distinguishes.
|
explicit |
Untrained model.
| context_set | Contexts and outcomes to distinguish. |
| pseudo_count | Pseudo-count of the back-off smoothing (must be finite and positive). |
| Exception::InvalidParameter | if the pseudo-count is not finite and positive |
|
inline |
Outcome of an unmatched ion.
| void addObservations | ( | const std::vector< Ion > & | ions, |
| bool | noise | ||
| ) |
Add the matched ions of one PSM to the signal (noise false) or noise counts.
|
inline |
Number of ion contexts.
|
inline |
The context set of this model.
|
static |
Error bin (0 .. ERROR_BINS - 1) of a match with the given |mass error| / tolerance (at most 1)
| void finalize | ( | ) |
Turn the counts into smoothed log-probabilities. Required before scoring; observations added later need another call.
|
inline |
Whether finalize() was called after the last observation.
Contexts of the coarser back-off levels: level 1 is the coarsest above the flat prior.
ln P(outcome | signal, context) - ln P(outcome | noise, context)
| Exception::Precondition | if the model is not finalized. |
Referenced by NuXLIonLikelihood::score().
| void matchIons | ( | const PeakLists & | peaks, |
| Size | index, | ||
| const MSSpectrum & | theoretical, | ||
| const AASequence & | peptide, | ||
| int | precursor_charge, | ||
| double | tolerance, | ||
| bool | ppm, | ||
| std::vector< Ion > & | ions | ||
| ) | const |
Match the named ions of a theoretical spectrum against peak list index: one Ion per recognised ion.
| peaks | Peak lists of the run. | |
| index | Peak list of the PSM's spectrum. | |
| theoretical | Sorted theoretical spectrum with ion names (first StringDataArray) and charges (first IntegerDataArray), as TheoreticalSpectrumGenerator writes them with add_metainfo. Without charges every ion counts as singly charged. | |
| peptide | The peptide of the theoretical spectrum (length; residues at the cleavage sites for RICH). | |
| precursor_charge | Precursor charge of the PSM. | |
| tolerance | Positive finite matching tolerance. | |
| ppm | Whether the tolerance is in ppm rather than Da. | |
| [out] | ions | The matched ions, in the order of the theoretical spectrum. |
| Exception::InvalidValue | if the theoretical spectrum lacks ion names |
| Exception::InvalidParameter | if the tolerance is not finite and positive |
Referenced by NuXLIonLikelihood::matchHypothesis_().
| void matchIons | ( | const PeakLists & | peaks, |
| Size | index, | ||
| const MSSpectrum & | theoretical, | ||
| const std::vector< Residue::ResidueType > & | ion_types, | ||
| const std::vector< UInt > & | ion_ordinals, | ||
| const std::vector< Int > & | ion_charges, | ||
| const AASequence & | peptide, | ||
| int | precursor_charge, | ||
| double | tolerance, | ||
| bool | ppm, | ||
| std::vector< Ion > & | ions | ||
| ) | const |
matchIons() with the ions given as codes instead of names: per peak of theoretical its ion type, ordinal and charge, as TheoreticalSpectrumGenerator::getIonSeriesSpectrum() writes them. The same ions as matchIons() on the spectrum of getSpectrum() with the names.
| Exception::InvalidValue | if the codes do not have one entry per peak |
| Exception::InvalidParameter | if the tolerance is not finite and positive |
|
private |
matchIons() for ion(i, series, ordinal) (false: not an ion of a series) and charge(i) of the peaks
|
inline |
Number of reversed PSMs added.
|
inline |
Number of outcomes, absence included.
|
static |
Terminus and ordinal of an ion name as written by TheoreticalSpectrumGenerator, e.g. "b5+", "y3++", "z.4+".
Names carrying the ion type after a '$' (cross-link annotations) are supported. Returns false for names without a terminal series letter or ordinal.
Referenced by NuXLIonLikelihood::matchHypothesis_().
parseIonName() that returns the ion series (see SERIES) instead of the terminus, e.g. 2 for "c7+" and 3 for "z.4+".
| double presenceProbability | ( | Size | context | ) | const |
Probability that an ion of this context is present in the spectrum of its peptide.
| Exception::Precondition | if the model is not finalized. |
Referenced by NuXLIonLikelihood::score().
|
inline |
Pseudo-count of the back-off smoothing.
Rank bin (0 .. RANK_BINS - 1) of a matched peak with the given 1-based intensity rank.
|
private |
Throws unless finalize() was called after the last observation.
Features of one PSM from its matched ions (see matchIons()); top_k bounds top_predicted_observed.
| Exception::Precondition | if the model is not finalized. |
|
static |
Ion series (see SERIES) of an ion type (Residue::AIon ... Residue::Zp2Ion); SERIES for any other type.
|
inline |
Number of confident PSMs added.
|
private |
Smoothed log-probabilities of one count table, backing off over the context hierarchy.
|
staticconstexpr |
RICH: bond before P, bond after D or E, any other bond.
|
private |
complement states of the context set (1 for BASIC)
|
staticconstexpr |
RICH: complementary singly charged ion not matched / matched.
Referenced by NuXLIonLikelihood::matchHypothesis_().
|
private |
|
private |
|
staticconstexpr |
RICH: |mass error| / tolerance below 0.25, below 0.5, up to 1.
|
private |
error bins of the context set (1 for BASIC)
|
private |
|
staticconstexpr |
fragment charge 1, at least 2
|
private |
contexts_ * outcomes_ counts of reversed ions
|
private |
smoothed ln P(outcome | noise, context)
|
private |
|
private |
|
staticconstexpr |
fragment length / peptide length
|
staticconstexpr |
precursor charge 1-2, 3, at least 4
|
private |
|
staticconstexpr |
matched peak intensity rank bins
|
staticconstexpr |
Ion series: a/b (0), x/y (1), c (2), and z, z+1, z+2 (3). Even series are N-terminal (prefix) ions, odd series C-terminal (suffix) ions; series s and s ^ 1 are complementary (b and y, c and z).
|
private |
contexts_ * outcomes_ counts of confident ions
|
private |
smoothed ln P(outcome | signal, context)
|
private |
|
private |
cleavage-site classes of the context set (1 for BASIC)