Skip to content

Native rescorer: Percolator's algorithm with target-decoy competition (calibrated q-values) - #220

Merged
ypriverol merged 5 commits into
mainfrom
fix/native-rescorer-calibration
Oct 21, 2026
Merged

ypriverol merged 5 commits into
mainfrom
fix/native-rescorer-calibration

Conversation

@ypriverol

@ypriverol ypriverol commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

--rescore-native reported q-values that were far too optimistic. On UPS1, at q ≤ 0.01 its entrapment FDP was 15.6–16.9% where Percolator -Y on the same PIN gives 2.4%; at q ≤ 0.05 it was 31% (Percolator 5.9%). This PR replaces it with Percolator's algorithm run in process. On the same PINs it now matches Percolator's calibration on UPS1, Astral and phospho, with about the same number of PSMs.

Root cause

There were two defects:

  1. No target-decoy competition. Every PIN row entered a single q-value walk: up to 10 ranks per spectrum, at every charge. On UPS1, 1,327 scans had more than one row accepted at q ≤ 0.01, and those extra rows had a 73% FDP.
  2. Every target trained as a positive. The GBDT learned target vs decoy over all rows, so about half of its positives were false targets. A model trained that way learns what separates false targets from decoys and ranks them above decoys, which breaks the assumption that decoys model false targets. A linear model trained on the same labels fails the same way (UPS1: 3.6% at q 0.01, 14% at q 0.05), so the labels are the cause, not the model class.

The Astral and phospho benchmarks did not show this because their entrapment sequences are shuffled and look like decoys to every feature. UPS1's entrapment is a natural proteome, so a model that prefers natural false targets to decoys is caught there. Real searches also have natural false targets.

I tested one variable at a time on UPS1, with a stand-in for the same pipeline:

Change FDP at q 0.01 / 0.05
GBDT on all rows (main) 14.5% / 30.8%
+ competition per scan and ExpMass 12.0% / 24.6%
drop the mass features, fold by peptide, or train on a decoy split 9.9–12.1% / 21.8–24.8%
train on rank-1 rows only 4.7% / 16.9%
semi-supervised (positives: targets at q ≤ 0.01) 2.6% / 6.3%
Percolator -Y 2.4% / 5.9%

A semi-supervised GBDT is also calibrated, but it finds 26% fewer PSMs. A semi-supervised linear model keeps Percolator-level PSMs on all three datasets, so that is the one in this PR.

Change

crates/andes/src/rescore.rs now does the following:

  • Competition: rows with the same ScanNr and ExpMass text form one group, as with Percolator -Y and the QPX join. Each group reports its best row, target or decoy, and q-values come from these winners.
  • Folds: 3-fold cross-validation by spectrum (includes the fold-by-spectrum commit from Rescue the pre-release fixes from #188 #214, so the two merge cleanly).
  • Training: each training split starts from the single best feature. Then 10 rounds of L2 logistic regression, with target winners at q ≤ 0.01 as positives and all decoy winners as negatives.
  • Scores: each fold's scores are normalised so the folds can be pooled (q = 0.01 threshold → 0, median decoy → −1).
  • PEP: an isotonic fit of decoys/targets among the winners. Before, PEP was 1 − P(target) from a classifier trained on false targets.
  • Features: ExpMass and CalcMass are no longer features, as in Percolator.
  • Untrained folds: a fold with too few confident targets keeps the single-feature score, and andes prints a warning. Before, its rows were silently scored 0.

search.rs passes the winning decoys to the QPX join. Target rows that lost competition are left out of the bundle, as with Percolator -Y. The CLI help, DOCS and README describe the method.

The review finding "--rescore runs Percolator without -Y" was already fixed on main by #210. Nothing changes there.

Measured

Same PINs (origin/main search), entrapment FDP with docs/benchmarks/entrap_common.py and (1 + T/E) scaling (UPS1 2.351, Astral 0.964, phospho 0.971). Each cell lists PSMs and FDP for seeds 42 / 1 / 2.

Dataset Rescorer q ≤ 0.01 q ≤ 0.05
UPS1 Percolator -Y 16,442–16,463 / 2.36–2.42% 18,514–18,613 / 5.70–5.94%
UPS1 native, main 17,716–17,944 / 15.6–16.9% 23,409–23,774 / 30.8–31.6%
UPS1 native, this PR 16,381–16,436 / 2.54–2.69% 18,703–18,744 / 6.19–6.42%
Astral Percolator -Y 46,463–46,528 / 0.80–0.83% 54,631–54,728 / 4.63–4.87%
Astral native, main 46,331–46,555 / 0.82–0.86% 56,836–57,045 / 4.58–4.63%
Astral native, this PR 47,086–47,134 / 0.82–0.84% 54,800–54,840 / 4.73–4.78%
Phospho Percolator -Y 38,753–38,792 / 1.03–1.09% 42,406–42,424 / 5.23–5.24%
Phospho native, main 39,205–39,368 / 0.84–0.95% 44,018–44,328 / 5.31–5.52%
Phospho native, this PR 38,901–39,038 / 0.96–1.07% 42,477–42,599 / 5.16–5.34%
  • UPS1: neither rescorer reaches nominal FDP, because UPS1's entrapment null is not valid: the entrapment is E. coli for an E. coli-expressed standard, and the UPS1 sequences are not in the target database. The native rescorer now matches Percolator there within noise (124–132 vs 116–119 entrapment hits at q 0.01).
  • Astral and phospho: FDP is at or below nominal at q 0.01 and q 0.05, with 1.4% (Astral) and 0.5% (phospho) more PSMs than Percolator at q 0.01.
  • Speed: rescoring takes 3–7 s on these PINs, against 84–239 s for the GBDT.

Tests

New tests check:

  • one PSM per scan/ExpMass group;
  • false targets that differ from decoys on one feature are not rewarded (FDP ≤ 2q; a model trained on every target gives about 30% here);
  • the same scores at 1 and 4 threads;
  • ExpMass/CalcMass are not features;
  • the logistic solver.

Gate

  • cargo clippy --workspace --all-targets -- -D warnings is clean.
  • cargo test --release --workspace --locked: 1741 passed, 0 failed, 9 ignored.
  • The ignored out-of-core PIN goldens pass (4/4). No golden changed; the PIN is not touched.

Summary by CodeRabbit

  • New Features

    • Native rescoring now uses a cross-validated semi-supervised linear model with target-decoy competition.
    • Results include q-values and PEP estimates, retain only winning entries per competition group, and report competed-away rows.
    • Rescoring warns when folds lack sufficient training data and rejects malformed or invalid input values.
  • Documentation

    • Updated command-line help, README, and QPX documentation to describe the revised native rescoring behavior and competition handling.

The 3-fold CV assigned folds by ScanNr. With ScanNr 0 on every row, all rows
fell into one fold, that fold had no training data, and --rescore-native
returned almost no PSMs without a warning. Rows are now folded and grouped
by their spectrum: the SpecId without its scan, rank and row suffix.
…tition

The native rescorer trained a GBDT on every target PSM as a positive and
computed q-values over every PIN row. On UPS1 its entrapment FDP at q 0.01
was 15.6% (Percolator -Y on the same PIN: 2.4%).

Two causes:
- No target-decoy competition: every rank of a spectrum entered the q-value
  walk, and several rows of one scan and precursor mass could be accepted.
- Training every target as a positive (half of them false) teaches the model
  what separates false targets from decoys, so false targets outscore decoys
  and the target-decoy estimate undercounts them.

The rescorer now runs Percolator's algorithm in process: competition groups
of ScanNr and ExpMass (as -Y), 3-fold CV by spectrum, an initial best single
feature, then 10 rounds of an L2 logistic regression trained on target
winners at q <= 0.01 against all decoy winners, per-fold score normalisation,
q-values over the winners and PEP from an isotonic fit of the decoy share.
ExpMass and CalcMass are not features, as in Percolator. The QPX join gets
the winning decoys, so targets that lost competition are left out as with
Percolator -Y.
…the QPX section

Partial sums of the Newton step are taken over fixed row chunks and added in
chunk order, so the scores do not depend on the thread count.
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9cbf0b11-2c72-4cce-ad88-2e14b8e406ef
📥 Commits

Reviewing files that changed from the base of the PR and between cab36f6 and e3ed603.

📒 Files selected for processing: 5
  • DOCS.md
  • README.md
  • crates/andes/src/bin/andes/cli.rs
  • crates/andes/src/bin/andes/search.rs
  • crates/andes/src/rescore.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The native rescorer replaces its GBDT fallback with a 3-fold, semi-supervised linear model. It groups rows for target-decoy competition, calculates q-values and PEPs for winners, and reports competition and training diagnostics.

Changes: Native rescoring

Layer / File(s) Summary
PIN parsing and competition
crates/andes/src/rescore.rs
PIN parsing excludes precursor mass columns from model features. Spectrum keys determine folds, and competition groups use scan and precursor mass when available. The rescorer selects group winners for q-value calculation.
Fold training and scoring
crates/andes/src/rescore.rs
The rescorer trains regularized logistic models with semi-supervised examples, scores held-out folds, normalizes scores, and estimates winner PEPs. Tests cover model fitting, PEP behavior, and determinism.
Rescorer outputs and reporting
crates/andes/src/rescore.rs, crates/andes/src/bin/andes/search.rs, crates/andes/src/bin/andes/cli.rs, README.md, DOCS.md
The result includes winning targets and decoys, competed-away row counts, and untrained-fold counts. CLI help and documentation describe the algorithm and its competition behavior.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Search
  participant NativeRescore as native_rescore_pin_all
  participant FoldModels as Fold models
  Search->>NativeRescore: Submit PIN text and seed
  NativeRescore->>FoldModels: Train fold models and score held-out rows
  FoldModels-->>NativeRescore: Return normalized scores and untrained-fold count
  NativeRescore->>NativeRescore: Select competition winners and calculate q-values and PEPs
  NativeRescore-->>Search: Return winner maps and competition diagnostics
Loading

Suggested reviewers: claude

Merge Risk: ⚪ Minimal · up to e3ed6

The native rescorer is replaced with a target-decoy competition workflow, and no concrete merge-blocking issue was found. Normal checks apply.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: replacing the native rescorer with a Percolator-style algorithm using target-decoy competition and calibrated q-values.
Docstring Coverage Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 3 files. (2 skipped: 2 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 3 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ypriverol
ypriverol merged commit 3fceefb into main Oct 21, 2026
5 checks passed
@ypriverol
ypriverol deleted the fix/native-rescorer-calibration branch November 4, 2026 07:38
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.

1 participant