Repository navigation
[FIX] Picked protein-group FDR: out-of-range read, score direction, double vote, raw FDR, prefix mode, decoy ties - #10489
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is identified; merge after normal checks. Pre-merge checks |
|
jpfeuffer
left a comment
There was a problem hiding this comment.
Yes, clearly an oversight.
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
Branch
claude/core-fdr-picked-protein-pr-20261010(on develop10b0a7af09). The fixes are in picked protein FDR inFalseDiscoveryRateandIDScoreGetterSetter. 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 inFalseDiscoveryRate_testthat fails without it; the failing values are listed below.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 dereferencedlower_bound() == end(): a stack-buffer-overflow atIDScoreGetterSetter.cpp:263. In our builds the group got about 5e-310 or 0, i.e. the best possible q-value. ProSE reaches this withSearch:FDR:protein(develop: 7 ASan reports, all this one, in a 644-test selection of the ProSE TOPP and class tests).no_qvaluesit gets FDR 1: no voting group is accepted at its score, so (0+1)/(0+1) (separate commit).Exception::MissingInformationis thrown. Without groups, this fix changes nothing.>=theirs. For lower-is-better scores, e.g. ProSE withFDR: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 forapplyBasicwith 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).applyBasicandapplyPickedProteinFDRpass both.DECOY_accession first (DECOY_sp|…sorts beforesp|…), so the extra decoy was the common case. It made group q-values too high.XDECOY_was taken as the decoy ofX, and the lookup ofXthrewstd::out_of_range.DECOY_Ahits at 0.9 and a targetCat 0.5,Cgets 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 inapplyBasic; 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 withconservativetrue 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).FDR:protein0.01 on the 20 files of the [BENCHMARK] Reproducible ProSE / ANDES / Sage suite: 20 measurements across six instrument models #10364 benchmark, run once withFDR:PSM0 and once withFDR:PSM0.01:-out_pinare identical.Checks.
IDScoreGetterSetter::setScores_for groups has a new signature (two defaulted arguments). Its only callers are inFalseDiscoveryRate.cpp; it is not wrapped in pyOpenMS.Not changed (pre-existing, separate). The per-charge hit setters used for
ConsensusMapFDR withsplit_charge_variants(IDScoreGetterSetter.h,setScores_(…, charge)andsetScoreAndMoveIfTarget_(…, charge)) look scores up in the direction of the new score and, when decoys are removed, always withlower_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 atIDScoreGetterSetter.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