Skip to content

[FEATURE] Percolator: RESET in rescore() (upstream port reset_algorithm; native PercolatorReset via reset:in_rescore) - #10923

Closed
poshul wants to merge 2 commits into
developfrom
claude/percolator-reset-875848
Closed

poshul wants to merge 2 commits into
developfrom
claude/percolator-reset-875848

Conversation

@poshul

@poshul poshul commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Makes Percolator-RESET available in the in-process OpenMS::Percolator::rescore(RescoreInput), in two opt-in ways. Both are off by default, so the existing interface, behaviour and test references are unchanged:

  1. reset_algorithm: upstream Percolator's RESET, ported from the percolator executable's --reset-algorithm.
  2. reset:in_rescore together with algorithm=reset: OpenMS's native PercolatorReset from [FEATURE] Percolator: exact parallel rescoring, Newton solver, RESET, feature matrix from PSMs #10772. Until now it was available only through rescorePSMs().

Why. Percolator's PSM-level FDR control fails when one peptide produces several spectra, some of which end up in the training folds and some in the test fold (Freestone, Noble, Keich 2024, Re-investigating the correctness of decoy-based FDR control). An entrapment check on NASE RNA data reproduced this: more entrapment hits were accepted than decoys, and they clustered on a few repeated oligos. Percolator-RESET (Freestone, Käll, Noble, Keich, J Proteome Res 2025; bioRxiv 10.1101/2023.10.26.564068; upstream percolator/percolator#378, rel-3-07) is the published fix. It keeps the best PSM of each peptide and splits the winning decoys at random into training decoys and estimating decoys. The estimating decoys count as targets during the training and are used to estimate the FDR. NASE rescoring (OpenMS/OpenMS#10920) will be the first user; this PR does not change NASE.

What was synced, and why the pin stays at eb157f7.

  • RESET's core is already in the vendored files at the pinned commit eb157f7: LabelType::PSEUDO_TARGET, the decoy fraction in Scores::createXvalSetsBySpectrum, the null-target win probability (q-values with a decoy factor of 2), and CrossValidation::postIterationProcessing, which drops the training decoys. The driver (Caller::run --reset-algorithm, CompositionSorter::psmsOnly) is not vendored. Those files read the PSMs' peptide strings, and the wrapper uses those strings for row ids. The wrapper therefore ports the driver of upstream master a90106b (2026-11-13), which includes the November RESET fixes:
    • e9a2b60c: peptides in first-appearance order instead of hash-map order;
    • 68ec0058: no mix-max with RESET;
    • b8e59a02: PEP decoy factor, backported as a patch (see below).
  • Syncing the vendored files to a90106b would bring in 258 commits. They rewrite Scores.cpp (+1337/−291), CrossValidation.cpp, SetHandler.cpp, SanityCheck.cpp and PosteriorEstimator.cpp, and remove ResultHolder, Logger and ScoreHolder.cpp, so all 35 OpenMS patches would have to be redone. Instead, the RESET fixes that touch vendored code are two new patches:
    • patches/36-reset-pep-decoy-factor.patch (b8e59a02): the spline PEP (pep_method nonparametric) applies the decoy factor. The factor is exactly 1 without RESET.
    • patches/37-cv-one-fold.patch (as upstream 6068e7e2): divides by max(1, numFolds - 1). RESET trains on one fold, and there this was a division by zero.
  • UPSTREAM.md documents all of this. sync-from-upstream.sh eb157f7 applies all 37 patches cleanly.

Design of the option (Percolator.cpp: selectResetRepresentatives, resetOutput):

  • Requires RescoreInput::peptide_keys, which already exists. The keys are label-blind, as upstream keys by the peptide string only.
  • Steps, as in the executable:
    • score the rows by the best single feature (SanityCheck::getInitDirection);
    • keep the best row per key;
    • draw one coin per kept decoy with PseudoRandom::lcg_uniform_rand() > 0.5, in the order of the kept rows, so the result is reproducible for a fixed seed and independent of the number of threads;
    • train one fold with 3 nested bins and no pi0.
  • Single-decoy mode only: upstream fixes decoysPerTarget at 1. --composition-match is not ported.
  • subset_max_train, subset_mode and peptide_level do not apply when reset_algorithm is on.
  • RescoreOutput:
    • q_values/peps are set on the ranked rows only (targets and estimating decoys; 1 elsewhere);
    • peptide_q_values/peptide_peps give the RESET values of each row's peptide key;
    • reset_roles is new: 0 target, 1 estimating decoy, 2 training decoy, the same values as PercolatorReset::Role;
    • every row gets the final model's score.
  • rescorePSMs() fills the peptide keys when the option is on.
  • pyOpenMS exposes RescoreOutput.reset_roles.

Native PercolatorReset in rescore() (reset:in_rescore, opt-in). OpenMS's own RESET (algorithm=reset, #10772) supports stems, two-decoy mode, MLP and multiple rounds. It used to run only through rescorePSMs(), because it needs per-PSM inputs that RescoreInput did not carry: a search engine score, the unmodified sequence (stem), the spectrum and, for two-decoy mode, the decoy database.

  • RescoreInput gains the optional fields search_scores, stems and decoy_sets (empty by default; ignored unless the option is on).
  • The competition unit is the row's spectrum: (spec_file_numbers, scan_numbers), else cv_group_keys, else the row itself, the same keys as rescore()'s cross-validation folds (makeRowKeys).
  • With algorithm=reset and reset:in_rescore=true, rescore() runs PercolatorReset::run() with all reset:* parameters.
    • scores/q_values/peps are its PSM-level (heuristic) values.
    • peptide_q_values holds the FDR-controlled stem q-value of each row; peptide_peps stays empty, because the native RESET estimates no stem-level PEP.
    • reset_roles holds the roles, and getResetOutput() returns the full output.
  • Without reset:in_rescore, rescore() uses Percolator as before, also with algorithm=reset (that is the documented behaviour, and the test checks it). reset_algorithm and reset:in_rescore together throw.
  • rescoreReset_ is split into building the input from PeptideIdentifications and a shared runReset_ (options, logging, weights, getResetOutput()). The rescorePSMs() path is unchanged.
  • pyOpenMS exposes RescoreInput.search_scores, stems and decoy_sets.

Tests

  • Percolator_test, new section, on a synthetic set of 1500 peptides with 1–4 PSMs each:
    • one ranked row per peptide;
    • training decoys unranked;
    • about half the decoy peptides are estimating decoys;
    • q-values equal min(1, 2 (D_est + 1) / T), monotonized;
    • false discovery proportion at 5% ≤ 15%;
    • every row's score equals the final model's;
    • bit-identical for a fixed seed with 1 and 4 threads, and another seed draws other estimating decoys;
    • off by default;
    • missing peptide keys throw.
  • Percolator_test, second new section (reset:in_rescore): 900 PSMs are built into a RescoreInput with buildPSMRescoreInput. rescore() with the option matches rescorePSMs() with algorithm=reset bit for bit (scores, PSM q-values and PEPs, stem q-values, roles, salt). With algorithm=reset but without the option, rescore() gives the same result as plain Percolator. Missing or short search_scores/stems, two-decoy mode without decoy_sets, and both RESET options together all throw.
  • Percolator_subprocess_parity_test, new PERCOLATOR_BINARY-gated section, compares with percolator --reset-algorithm on the same PIN. Against a90106b (built locally):
    • the kept rows and the estimating decoys are identical;
    • scores correlate at r = 0.9991 (TRON here, L2-SVM-MFN there);
    • targets at q ≤ 0.01: 206 / 206; at q ≤ 0.05: 273 / 284.
    • Binaries before e9a2b60c draw in hash-map order. For those, the section checks only the kept target rows and loose tolerances. Binaries without --reset-algorithm skip the section.
  • ctest -R Percolator: all 46 tests pass locally (Linux, GCC, Release).

Not verified / known issues

  • The full test suite, the pyOpenMS build (the bindings are plain def_rw fields; pyOpenMS is not configured in my build) and Windows/macOS builds were not run.
  • With PERCOLATOR_BINARY set, the existing section "realistic idXML parity at library layer" of Percolator_subprocess_parity_test fails at max_dpep <= 0.15 (line 1218). It fails the same way on the unmodified code with a locally built eb157f7 binary, so it predates this PR. With the a90106b binary it also fails r >= 0.99.
  • A clean sync-from-upstream.sh eb157f7 no longer reproduces CrossValidation.cpp. The nested-parallel fallback of [FEATURE] Percolator: nested pair loop in the OpenMP 2.0 fallback of trainFoldChains (cl.exe builds, follow-up to #10772) #10792 was committed without a patch. This also predates this PR and is not fixed here.

Checklist

  • New and existing unit tests pass locally with my changes (the Percolator tests, see above)

AI use (see the OpenMS AI Policy)

  • I have read the OpenMS AI Policy, and I understand, have reviewed and tested every change in this PR and can explain it in my own words
  • Substantial AI use in PR (e.g. agentic tools wrote significant parts); commits carry a Co-authored-by: trailer, and the description above explains the design intent and rationale

No need to edit the CHANGELOG file: entries are generated automatically once per week from merged changes.

🤖 Generated with Claude Code

…er reset_algorithm)

Percolator's PSM-level FDR control fails when one peptide produces several
spectra (Freestone, Noble, Keich 2024). Percolator-RESET (Freestone, Käll,
Noble, Keich, J Proteome Res 2025; percolator/percolator#378) controls the
FDR at the peptide level. Its core (pseudo-targets, the decoy fraction, the
null-target win probability, dropping the training decoys) is already in
the vendored tree at eb157f7; its driver lives in upstream's Caller.cpp and
CompositionSorter.cpp, which are not vendored.

- Percolator::rescore(): new parameter reset_algorithm (default false). It
  ports the driver of upstream master a90106b: best-single-feature scores,
  the best row of each RescoreInput::peptide_keys entry (peptides in the
  order of first appearance, upstream e9a2b60c), one coin per kept decoy
  (PseudoRandom, in that order), one fold with 3 nested bins, no mix-max
  (upstream 68ec0058). RescoreOutput gets reset_roles and per-row RESET
  peptide q-values/PEPs; rows outside the final list are scored by the
  final model. rescorePSMs() fills the peptide keys for it.
- Vendored backports: patch 36 (upstream b8e59a02, decoy factor of the
  spline PEP) and patch 37 (one fold: no division by zero, as upstream
  6068e7e2). No change of results without RESET. The pin stays at eb157f7;
  UPSTREAM.md explains why.
- Tests: Percolator_test checks RESET's q-values (2 (D_est + 1) / T),
  roles, reproducibility and thread independence; a binary-gated section
  of Percolator_subprocess_parity_test compares with percolator
  --reset-algorithm (a90106b: same kept rows and estimating decoys,
  score r 0.999).
- pyOpenMS: RescoreOutput.reset_roles.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@poshul poshul mentioned this pull request Nov 16, 2026
6 of 8 tasks

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focused static review of the new reset_algorithm path and vendored Percolator TDC/selection logic. One substantive finding supported by a compiled standalone C++20 reproducer (not a complete OpenMS integration test).

const bool use_pi0 = resolveUsePi0(impl_->use_pi0, impl_->post_processing_tdc, input);
// Percolator-RESET (parameter 'reset_algorithm'): no mix-max, as the executable, whose RESET keeps the best PSM of each
// peptide in a Scores object without pi0 (and is not stopped by its mix-max check, upstream 68ec0058)
const bool reset = impl_->reset_algorithm;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not silently apply spectrum-level TDC to RESET's peptide representatives. post_processing_tdc defaults to true (Percolator.cpp), and the unconditional if (impl_->post_processing_tdc) all_scores.weedOutRedundantTDC() later in rescore() still runs after selectResetRepresentatives() and cv.postIterationProcessing(). RESET has already selected one representative per peptide key, but weedOutRedundantTDC() instead keeps only one score holder per (specFileNr, scan, expMass) regardless of peptide key/label. Thus two different selected peptides from the same spectrum compete again; in particular, an estimating decoy can be removed by a higher-scoring target, changing the decoy counts and peptide-level q-values from the upstream --reset-algorithm semantics. The new parity test assigns a distinct scan to every row and cannot detect this. Please explicitly handle this option for RESET (at minimum avoid silently enabling the extra competition by default, and test multiple peptide keys sharing a scan). Own check: compiled and ran an isolated C++20 reproducer using the exact OrderScanMassCharge / UniqueScanMassCharge comparison rules and the sort+unique sequence from Scores::weedOutRedundantTDC(): three selected peptide representatives (target and estimating decoy at the same scan/mass, plus another peptide) were reduced to two, dropping the estimating decoy. This verifies the TDC pruning mechanism only, not a full OpenMS build or peptide q-value integration test; container has GCC/CMake but cannot access GitHub over DNS for a checkout.

Copy link
Copy Markdown
Contributor

Follow-up review of 9cb5b33. Based on reading the diff, the surrounding rescore() code, the vendored tree and upstream Percolator. Nothing was built or run.

Summary: the patches are current and the port is faithful, but the option is not yet correct for all our input types. It is safe for existing users (off by default, every change gated on reset_algorithm) and sound for one row per spectrum, which is what NASE (#10920) feeds. Multi-hit input and the rescorePSMs path have real problems.

Patches and upstream

  • Upstream master is still a90106b, the commit the driver was ported from. Selection, tie rule, peptide order, coin, one fold and 3 nested bins match Caller::run and CompositionSorter::psmsOnly.
  • Patch 36 matches upstream b8e59a0 (the --irls-pep half; --tdc-pep does not exist at the pin). Patch 37 matches the division fix in 6068e7e.
  • Replaying patches 01–37 on eb157f7 reproduces the vendored tree except about 58 lines in CrossValidation.cpp (the nested-parallel fallback without OpenMP tasks) that no patch carries. This predates the PR, but a re-sync would drop them.
  • Only RESET-related upstream changes were checked, not the other ~250 commits since the pin.

Problems

  1. Multi-hit and chimeric input. The earlier review comment already flags the per-spectrum competition that still runs after RESET has picked its representatives (post_processing_tdc defaults to true). In a toy simulation (single score, no SVM) that step did not bias the FDR when nulls were exchangeable. The order is the problem: only representatives compete, so a runner-up survives when its spectrum's winner is represented by another spectrum. With near-identical target runner-ups, FDP at q ≤ 1% was about 10% (34% with TDC off), against 1% when competing per spectrum first, as algorithm=reset (PercolatorReset) does. Suggested fix: compete per spectrum before the peptide selection, or reject more than one row per spectrum.
  2. Chimeric specifics. ProSE's co-isolated PSMs carry their own precursor m/z, so they do not collide in the (file, scan, expMass) key. Hits sharing scan and precursor m/z collapse to one per spectrum.
  3. rescorePSMs path is untested. The PR wires reset_algorithm into it (peptide keys from toBracketString), but no test covers it. Every PSM except one per peptide, across all files, gets q = 1 as its main score. reset_roles are not written to the hits. Keys are modified sequences, not stems, so localization variants count as separate discoveries.
  4. Score trap. scores come from one model trained on all targets and training decoys. NASE Add optional Percolator rescoring to NASE #10920 currently recomputes its FDR from output.scores; with RESET it must use peptide_q_values and reset_roles instead.
  5. Small data. The lowest possible q is 2/T, so nothing passes 1% with fewer than 200 target peptides.

Smaller items

  • No test with several peptide keys per scan.
  • The parity test is skipped without PERCOLATOR_BINARY.
  • No CHANGELOG entry.

This review was prepared with Claude (AI-assisted).


Generated by Claude Code

…et:in_rescore)

New parameter reset:in_rescore (default false): with algorithm 'reset',
rescore(RescoreInput) runs the native PercolatorReset (as rescorePSMs()
with algorithm 'reset'; all reset:* parameters apply, incl. two-decoy
mode) instead of Percolator. New optional RescoreInput fields
search_scores, stems and decoy_sets; the competition unit is the row's
(spec_file_numbers, scan_numbers) / cv_group_keys as for the CV folds.
Output: PSM-level scores/q/PEP, stem q-values in peptide_q_values, roles
in reset_roles, full output via getResetOutput().

Default behaviour and interface unchanged: without reset:in_rescore,
rescore() uses Percolator as before (also with algorithm 'reset').
rescoreReset_ is split into input building and runReset_ (shared).
Test: rescore() matches rescorePSMs() RESET bit for bit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@poshul poshul changed the title [FEATURE] Percolator: upstream Percolator-RESET in rescore() (parameter reset_algorithm) [FEATURE] Percolator: RESET in rescore() (upstream port reset_algorithm; native PercolatorReset via reset:in_rescore) Nov 17, 2026
@timosachsenberg

Copy link
Copy Markdown
Contributor

There have been quite some changes to percolator. maybe good idea to rebase our internal patch set on it and work from there

@poshul

poshul commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

yeah, I think thats a good idea. This just came up from "your" review of #10920 which flagged the percolator issue.

@timosachsenberg

Copy link
Copy Markdown
Contributor

@poshul what about the native in OpenMS that is already there? Did this not work?

@poshul

poshul commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@poshul what about the native in OpenMS that is already there? Did this not work?

NASE calls rescore(RescoreInput), whereas native RESET was dispatched through rescorePSMs(). I'm gonna close this and try again with the newer Percolator version that is in your open PR

@poshul poshul closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants