Skip to content

[FIX] Picked protein-group FDR: out-of-range read, score direction, double vote, raw FDR, prefix mode, decoy ties - #10489

Merged
jpfeuffer merged 9 commits into
OpenMS:developfrom
okohlbacher:claude/core-fdr-picked-protein-pr-20261010
Oct 10, 2026
Merged

jpfeuffer merged 9 commits into
OpenMS:developfrom
okohlbacher:claude/core-fdr-picked-protein-pr-20261010

Conversation

@okohlbacher

@okohlbacher okohlbacher commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Branch claude/core-fdr-picked-protein-pr-20261010 (on develop 10b0a7af09). The fixes are in picked protein FDR in FalseDiscoveryRate and IDScoreGetterSetter. Fixes 1 to 4 concern protein groups only; fix 5 also changes the q-values of protein hits. Each fix has its own commit and a hand-computed case in FalseDiscoveryRate_test that fails without it; the failing values are listed below.

  1. Out-of-range read (ASan). In applyPickedProteinFDR, a group whose members all lost their target/decoy pairs does not vote, so its score can lie beyond every calibrated group score. setScores_ then dereferenced lower_bound() == end(): a stack-buffer-overflow at IDScoreGetterSetter.cpp:263. In our builds the group got about 5e-310 or 0, i.e. the best possible q-value. ProSE reaches this with Search:FDR:protein (develop: 7 ASan reports, all this one, in a 644-test selection of the ProSE TOPP and class tests).
    • A group score worse than every calibrated score gets the q-value (or FDR) of the worst calibrated score, i.e. of accepting every group.
    • A group score better than every calibrated score gets the best q-value. With no_qvalues it gets FDR 1: no voting group is accepted at its score, so (0+1)/(0+1) (separate commit).
    • If there are groups but none takes part in the competition, Exception::MissingInformation is thrown. Without groups, this fix changes nothing.
  2. Score direction. Groups always took the first calibrated score that is >= theirs. For lower-is-better scores, e.g. ProSE with FDR:PSM, where protein scores are PSM q-values, that is the next worse score. Groups now get the closest equal-or-better calibrated score, also for scores within the 1e-12 tie tolerance of a calibrated one (relevant for applyBasic with groups).
    • setScores_ for groups takes the direction of the group scores and whether the map holds q-values as new arguments (defaults: higher is better, q-values). applyBasic and applyPickedProteinFDR pass both.
  3. One vote per group. A group counted as both decoy and target when a member whose decoy won its pair came before a member whose target won its pair. It now counts once, as target, as the documentation already says.
    • Mixed groups usually list the DECOY_ accession first (DECOY_sp|… sorts before sp|…), so the extra decoy was the common case. It made group q-values too high.
  4. Prefix mode. Picked group FDR also removed the decoy string from the end of an accession in prefix mode, so a target such as XDECOY_ was taken as the decoy of X, and the lookup of X threw std::out_of_range.
  5. Decoy ties. A tie between two hits of the same pair made the pair's winner a target even when both hits were decoys (duplicate decoy accessions). A tie now prefers a target only if one of the tied hits is a target. The protein hits use the same picked scores, so this also changes hit q-values: with two DECOY_A hits at 0.9 and a target C at 0.5, C gets q = 1 instead of 1/3.

Tests (new section of FalseDiscoveryRate_test, values hand-computed before the code ran). Values before each fix: fix 1, denormals of about 5e-310 or 0 instead of 2/3 and 1/2, and no exception; fix 2, 1/2 instead of 1/3 (picked groups) and 1/2 instead of 1/3 for a near-tied group in applyBasic; fix 3, 1/2 instead of 1/4; raw FDR, 1/2 instead of 1; prefix mode, std::out_of_range; decoy ties, 1/2 instead of 1 for the groups and 1/3 instead of 1 for the protein hit. The raw-FDR case runs with conservative true and false; a non-voting group with a NaN score gets the worst calibrated q-value in both directions (develop: the best one for lower-is-better scores).

Behaviour change. In the runs we compared, only commit 3 changed saved outputs.

  • TOPP_ProteinInference_3 (picked FDR, suffix _rev): the group {sp|P16109|LYAM3_HUMAN_rev, sp|Q14315|FLNC_HUMAN} voted twice. All 49 group q-values go down, e.g. 0.04 to 0.02. Only these 49 values of the reference change (in the one-vote commit).
    • An independent Python re-implementation, run on the same data without protein FDR, gives the old reference values under the old vote and the new values under one vote per group (49/49 each).
  • ProSE with FDR:protein 0.01 on the 20 files of the [BENCHMARK] Reproducible ProSE / ANDES / Sage suite: 20 measurements across six instrument models #10364 benchmark, run once with FDR:PSM 0 and once with FDR:PSM 0.01:
    • PSMs, protein hits and -out_pin are identical.
    • Group q-values change in 2 and 3 files, always downwards. Example: one double vote at the best score doubled the q-value of 1451 groups (2/1452 instead of 1/1452).
    • The other fixes change nothing in these runs (40/40 identical between the state after fix 3 and the branch head).
  • Other test outputs: among the 481 TOPP test outputs we compared as text and the 102 Parquet files we compared by column, the other differences are timings, dates, paths and run-to-run variation. Epifany's posteriors differ by up to about 1e-7 between two runs of the same binary, even at one thread. Binary outputs other than Parquet were not compared.

Checks.

  • ctest selection of 730 tests (FalseDiscoveryRate, ProteinInference, Epifany, IDFilter, ProSE, ProteomicsLFQ, IsobaricWorkflow, MS1LabeledWorkflow, IDBoostGraph, and the ID/IO areas) in Release, Debug and ASan+UBSan builds (GCC 14.4): 730/730 each.
  • ASan/UBSan: 0 reports on the 730 tests; 0 reports in 40 ProSE runs with protein FDR.
  • No compiler warnings in the rebuilt files.
  • IDScoreGetterSetter::setScores_ for groups has a new signature (two defaulted arguments). Its only callers are in FalseDiscoveryRate.cpp; it is not wrapped in pyOpenMS.

Not changed (pre-existing, separate). The per-charge hit setters used for ConsensusMap FDR with split_charge_variants (IDScoreGetterSetter.h, setScores_(…, charge) and setScoreAndMoveIfTarget_(…, charge)) look scores up in the direction of the new score and, when decoys are removed, always with lower_bound, which can run past the end for scores that were not calibrated. A probe with ASan confirms both: wrong q-values, and a stack-buffer-overflow at IDScoreGetterSetter.h:548. That is a different code path and is left for its own PR.

Related: #10486 (opened today) skips protein-group FDR when a run has no indistinguishable-protein groups, in the same functions. The two changes complement each other and merge without code conflicts (only CHANGELOG).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved false-discovery-rate assignment for protein groups, including scores outside the calibrated range and groups with tied or mixed target and decoy hits.
    • Corrected picked protein-group counting and decoy matching when using accession prefixes.
    • Fixed handling of empty groups and missing calibration data.

okohlbacher and others added 9 commits October 9, 2026 19:44
…of its score map

IDScoreGetterSetter::setScores_ for protein groups looked every group score up
with std::map::lower_bound() and dereferenced the result unchecked. In
FalseDiscoveryRate::applyPickedProteinFDR, a group whose members all lost their
target/decoy pairs does not vote, so its score can lie beyond every calibrated
group score. lower_bound() then returns end(), and the group got whatever lay
next to the map on the stack: ASan reports a stack-buffer-overflow at
IDScoreGetterSetter.cpp:263, from applyPickedProteinFDR. In our builds the value
was a denormal close to 0, i.e. the best possible q-value. ProSE reaches this
with protein FDR on (Search:FDR:protein; 7 reports in the ProSE TOPP and class
tests).

A score beyond the last calibrated score now gets that score's value. For
q-values this is the q-value such a score has: a higher-is-better score above
every calibrated one gets the best calibrated q-value, and a lower-is-better
score worse than every calibrated one gets the q-value of the whole set. If
there are groups but no calibrated score (no group took part in the
competition), Exception::MissingInformation is thrown.

The new FalseDiscoveryRate_test section has hand-computed q-values for both
score directions and the no-vote case; before the fix it read 5.4e-310 or 0 for
the out-of-range groups (Release, Debug, ASan builds).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… of the group scores

IDScoreGetterSetter::setScores_ for protein groups always took the first
calibrated score >= the group score (std::map::lower_bound). That is the closest
equal or better score only if higher scores are better. For lower-is-better
scores, e.g. ProSE with Search:FDR:PSM, whose protein scores are PSM q-values,
a group got the q-value of the next worse calibrated score. Protein hits
already use the score direction (setScore_ / setScoreHigherWorse_).

Groups store no score direction, so applyBasic and applyPickedProteinFDR pass
it as a new last argument, old_higher_better (default true, the former lookup).
Outside the calibrated range a group gets the value of the nearest end.

Only groups whose score is not itself a calibrated score are affected: in
picked protein FDR the groups that take no part in the competition, in
applyBasic scores within the 1e-12 tie tolerance of a calibrated score. The new
test case, a hand-computed lower-is-better fixture and its negated
higher-is-better mirror, got 1/2 instead of 1/3 for such a group before; the
mirror passed before and after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-group FDR

IDScoreGetterSetter::getPickedProteinGroupScores_ is documented to count a
group as target if a member's target won its target/decoy pair, else as decoy
if a member's decoy won it. When a member whose decoy had won was listed
before the first member whose target had won, the loop set decoy_picked, then
added the target vote and left the loop, and the decoy vote was added after it:
two votes. With the target member first, the group voted once. Mixed groups
list the DECOY_ accession first (e.g. "DECOY_sp|..." < "sp|..."), so the extra
decoys are the common case, and they raise the group q-values.

The target vote now clears decoy_picked. The new test case (hand-computed, both
member orders) got q = 1/2 instead of 1/4 for the decoy-first order before.

ProSE with protein FDR (Search:FDR:protein 0.01) on the 20 files of the OpenMS#10364
benchmark: such groups occur in 10 files with FDR:PSM 0 and 4 with FDR:PSM 0.01.
Group q-values change in 2 and 3 of them, always downwards (e.g. 2/1452 ->
1/1452 for 1451 groups, after one double vote at the best score); protein hits,
PSMs and the PIN files are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n every calibrated one is 1

With no_qvalues, a protein group whose score is better than every calibrated
group score (in picked protein FDR: a group that takes no part in the
competition) got the FDR of the best calibrated score. No voting group is
accepted at its score, so its FDR is (0+1)/(0+1) = 1; only for q-values is
the best calibrated value right (the minimum over all thresholds).
IDScoreGetterSetter::setScores_ for protein groups gets whether the map holds
q-values (default: true); both callers pass it. Test (6) covers raw FDR in
both score directions and with conservative true and false.
The CHANGELOG entries now say when MissingInformation is thrown (groups
present, none takes part) and no longer compare with protein hits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-tied lower-is-better scores

Two cases of the score-direction fix had no test:
- applyBasic with protein groups: a lower-is-better group score within 1e-12
  of a better one gets that score's q-value (on develop: the next worse one);
- picked protein FDR: a group with a NaN score that takes no part in the
  competition gets the worst calibrated q-value in both score directions (on
  develop: the best one for lower-is-better scores).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oved the decoy string as suffix

removeDecoyStringIfPresent_ also removed the decoy string from the end of an
accession in prefix mode, so a target such as "XDECOY_" was taken as the decoy
of "X", and the lookup of "X" threw std::out_of_range from
applyPickedProteinFDR. The suffix is now removed in suffix mode only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts made a target winner

A tie between two hits of the same pair set the winner to target even when
both hits were decoys (duplicate decoy accessions). The pair then counted as
target, and its decoy group did not vote. A tie now prefers a target only if
one of the tied hits is a target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wo decoy hits in picked protein FDR

The tie fix also changes the q-values of protein hits, which use the same
picked scores, not only those of the groups. With two DECOY_A hits at 0.9 and
a target C at 0.5, C now gets q = 1; before the fix DECOY_A counted as a
target winner and C got 1/3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…missing protein hit

TEST_EQUAL does not stop the test, so a regression that leaves no protein
hit would have read run.getHits()[0] out of range. Use ABORT_IF instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c9ba9475-93e7-481f-9e76-b2e5f49b962f

📥 Commits

Reviewing files that changed from the base of the PR and between 6e3e4fa and 66f94d0.


📒 Files selected for processing (6)
  • CHANGELOG
  • src/openms/include/OpenMS/ANALYSIS/ID/IDScoreGetterSetter.h
  • src/openms/source/ANALYSIS/ID/FalseDiscoveryRate.cpp
  • src/openms/source/ANALYSIS/ID/IDScoreGetterSetter.cpp
  • src/tests/class_tests/openms/source/FalseDiscoveryRate_test.cpp
  • src/tests/topp/ProteinInference_3_output.consensusXML

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



📝 Walkthrough

Walkthrough

Protein-group FDR assignment now accounts for score direction and whether mapped values are q-values or raw FDRs. Picked-protein group voting and decoy-hit handling are updated. Regression tests and changelog entries cover the changes.

Changes

Protein-group FDR

Layer / File(s) Summary
Protein-group score assignment
src/openms/include/OpenMS/ANALYSIS/ID/IDScoreGetterSetter.h, src/openms/source/ANALYSIS/ID/IDScoreGetterSetter.cpp, src/openms/source/ANALYSIS/ID/FalseDiscoveryRate.cpp, src/tests/class_tests/openms/source/FalseDiscoveryRate_test.cpp, src/tests/topp/ProteinInference_3_output.consensusXML, CHANGELOG
The protein-group score setter accepts score direction and q-value status. Its callers pass those settings. The setter handles empty groups, empty calibration maps, and scores outside the calibrated range. Tests cover score boundaries and updated protein-inference output.
Picked-group voting and decoy matching
src/openms/source/ANALYSIS/ID/IDScoreGetterSetter.cpp, src/tests/class_tests/openms/source/FalseDiscoveryRate_test.cpp, CHANGELOG
A protein group with target and decoy wins is counted as a target. Prefix-mode decoy removal applies only at the configured accession end. Tied decoy hits do not replace the target label. Tests cover these cases.

Suggested reviewers: timosachsenberg


Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 66f94

No actionable merge-blocking issue is identified; merge after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
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 scope: picked protein-group FDR fixes for score-range handling, score direction, voting, raw FDR, prefix mode, and decoy ties. It is specific and related to the c…
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 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (2 skipped: 2 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • 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

A rabbit checks the scores at dawn
It hops where calibrated values run
A target wins; the group counts once
The decoy suffix stays at its end
The tests spring up, then thump along
The changelog joins the burrow song

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

@jpfeuffer jpfeuffer 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.

Yes, clearly an oversight.

@jpfeuffer
jpfeuffer merged commit a5720bb into OpenMS:develop Oct 10, 2026
32 checks passed
timosachsenberg pushed a commit that referenced this pull request Oct 10, 2026
Resolves the CHANGELOG conflict with the FalseDiscoveryRate fixes of #10489
by keeping both sets of entries. The empty-group guards auto-merged and
still apply: setScores_ for protein groups returns early for no groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014NvhGkqMF7GrDzTDyfS9rS
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