Repository navigation
fix(ProSE): defer PSM FDR when Percolator enabled and emit valid .pin - #9195
Conversation
Two related ProSE bugs around Percolator rescoring:
1. FDR:PSM was applied inside the algorithm on raw HyperScore q-values
before Percolator ran, which also stripped decoys via the
fdr_protein_==0 branch (protein FDR is already deferred). Percolator
then saw a target-only input and aborted with "No decoys found".
Fix: defer FDR:PSM alongside FDR:protein when -percolator_executable
is set. Post-rescoring, apply PSM FDR on Percolator q-values
directly (scores are already q-values via -score_type q-value).
Files that fell back to HyperScores (Percolator skipped/failed)
compute q-values via FalseDiscoveryRate first. Decoys are only
removed when protein FDR is disabled, matching the algorithm's
existing semantics.
2. -out_pin emitted a .pin header missing the mandatory SpecId / Label
/ ScanNr columns and the standard mass/charge/enzyme features
(ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt,
dm, absdm) that PercolatorInfile::preparePin_ already sets on every
hit. The output was not consumable by the percolator CLI.
Fix: factor the canonical column list into a new
PercolatorInfile::getStandardFeatureSet() helper. Both
PercolatorAdapter (previously hardcoded) and ProSE -out_pin now
build their feature_set from this helper, so the two tools emit
consistent, standards-compliant .pin files.
Verified: all 18 ProSE tests, PercolatorInfile_test, and
PercolatorAdapter INI/CTD tests pass. Smoke-tested ProSE -out_pin on
SimpleSearchEngine_1.mzML: header now begins with SpecId / Label /
ScanNr and ends with Peptide / Proteins.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR defers PSM and protein FDR filtering in ProSE until after Percolator rescoring completes, preventing premature decoy removal. It also centralizes Changes
Sequence Diagram(s)sequenceDiagram
actor Input as Input Data<br/>(with HyperScores)
participant ProSE
participant Perc as Percolator
participant FDR as Filtering
actor Output as Filtered PSMs<br/>(by q-value FDR)
Input->>ProSE: PSM candidates
Note over ProSE: Defer FDR:PSM & FDR:protein<br/>Set both to 0.0
ProSE->>Perc: .pin file with all decoys
alt Percolator succeeds
Perc-->>ProSE: Rescored PSMs<br/>(q-values computed)
ProSE->>FDR: Apply PSM FDR threshold<br/>on q-values directly
else Percolator fails/skipped
ProSE->>FDR: Compute q-values via<br/>FalseDiscoveryRate
FDR-->>ProSE: q-values
ProSE->>FDR: Apply PSM FDR threshold
end
FDR-->>Output: Filtered results
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/openms/include/OpenMS/FORMAT/PercolatorInfile.h (1)
85-85: Use OpenMSIntfor the new public API.
min_chargeandmax_chargeare OpenMS numeric values; preferIntin the declaration and mirror it in the.cppdefinition/loop variable.♻️ Proposed API polish
- static StringList getStandardFeatureSet(int min_charge, int max_charge); + static StringList getStandardFeatureSet(Int min_charge, Int max_charge);As per coding guidelines,
src/openms/**/*.{cpp,h,hpp}: Use OpenMS primitive types fromOpenMS/CONCEPT/Types.hinstead of standard C++ types.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/include/OpenMS/FORMAT/PercolatorInfile.h` at line 85, Change the public API of getStandardFeatureSet to use the OpenMS primitive type Int for both parameters instead of raw int: update the declaration of static StringList getStandardFeatureSet(int min_charge, int max_charge); to use Int, and mirror the change in the corresponding .cpp definition and any loop/index variables inside (e.g., any for-loops over min_charge/max_charge) so they use OpenMS::Int/Int from OpenMS/CONCEPT/Types.h; ensure the header includes the appropriate Types.h import if not already present.src/openms/source/FORMAT/PercolatorInfile.cpp (1)
36-48: Guard invalid charge ranges before emitting the header.If
min_charge > max_charge, the helper silently emits nochargeNcolumns while still returning a.pinheader. A fail-fast precondition would make upstream range bugs easier to diagnose.🛡️ Proposed guard
StringList PercolatorInfile::getStandardFeatureSet(int min_charge, int max_charge) { + OPENMS_PRECONDITION(min_charge <= max_charge, "min_charge must be less than or equal to max_charge") StringList fs = { "SpecId", "Label", "ScanNr", "ExpMass", "CalcMass", "mass", "peplen"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/FORMAT/PercolatorInfile.cpp` around lines 36 - 48, In PercolatorInfile::getStandardFeatureSet, add a fail-fast guard for the charge range: if min_charge > max_charge, throw an informative exception (e.g., InvalidParameter/InvalidValue) before building fs so callers immediately see the bad input rather than returning a header missing chargeN columns; reference the function name PercolatorInfile::getStandardFeatureSet and the local fs variable in your change and include the offending values in the exception message.src/topp/ProSE.cpp (2)
526-541: Centralized feature-set construction LGTM; behavior diverges from PercolatorAdapter.Using
PercolatorInfile::getStandardFeatureSet(min_charge, max_charge)here fixes the missingSpecId/Label/ScanNrheader and keeps ProSE's-out_pinconsumable by the Percolator CLI.Minor note on the
scorehandling: PercolatorAdapter usesif (extra_features) { ... } else if (generic_feature_set) push "score"; else error;(i.e.scoreis only appended in the generic fallback), whereas ProSE here unconditionally ensuresscoreis appended when absent. For ProSE this is fine because it always emits a HyperScore under thescorecolumn, but the two code paths are no longer symmetric despite the PR goal of aligning them — worth a comment in code or an explicit acknowledgement that ProSE intentionally always injectsscore.🧹 Optional clarifying comment
StringList feature_set = PercolatorInfile::getStandardFeatureSet(min_charge, max_charge); if (sp.metaValueExists("extra_features")) { StringList extra = ListUtils::create<String>(sp.getMetaValue("extra_features").toString()); feature_set.insert(feature_set.end(), extra.begin(), extra.end()); } + // ProSE always exports a HyperScore under the "score" column; unlike + // PercolatorAdapter (which gates this behind -generic_feature_set), + // we unconditionally ensure the column is present. if (std::find(feature_set.begin(), feature_set.end(), "score") == feature_set.end()) { feature_set.push_back("score"); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/topp/ProSE.cpp` around lines 526 - 541, The feature-set construction in ProSE.cpp now uses PercolatorInfile::getStandardFeatureSet(min_charge, max_charge) but then unconditionally appends "score" when missing, diverging from PercolatorAdapter's conditional logic; add a concise inline comment near the block that builds feature_set (referencing feature_set and the extra_features handling) stating that ProSE intentionally always emits a HyperScore into the "score" column so appending "score" is deliberate and not a bug, or alternatively add an explicit assertion/acknowledgement variable (e.g., bool prose_always_injects_score) and comment it to make the divergence clear to future readers.
353-398: Deferred PSM-FDR application logic looks correct.A couple of observations worth confirming rather than fixing:
- This whole block is (correctly) nested inside
if (!percolator_executable.empty()), keeping behavior symmetric with the non-percolator path whereProSEAlgorithmapplies FDR internally.- The
percolator_succeeded[i] == falsebranch (fallback) correctly covers all three "no Percolator q-values available" cases: (a) globalhas_decoys_for_percolator == false→ whole rescoring loop skipped; (b) per-file<100 PSMsskip; (c) per-fileperc_ec != EXECUTION_OK. In each, we re-check per-file decoys before runningFalseDiscoveryRateand skip with a warning if absent. Good.- Note that after rescoring we call
IDFilter::keepNBestHits(result.peptide_ids, 1)(Line 344), but fallback/non-rescored files don't get the same collapse before FDR. ProSEAlgorithm'spostProcessHits_()truncates results to a configurablereport_top_hitsparameter (default 1), so with default settings both paths operate on single hits per spectrum. However, if a user configuresreport:top_hits > 1, the fallback path could compute q-values on multiple hits per spectrum while the rescored path is reduced to 1 first—potentially affecting filtering behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/topp/ProSE.cpp` around lines 353 - 398, Fallback files (percolator_succeeded[i] == false) compute FDR on all hits but rescored files are collapsed via IDFilter::keepNBestHits earlier, which can cause different filtering when report_top_hits > 1; before calling FalseDiscoveryRate::apply(result.peptide_ids) in the non-rescored branch, collapse to the same number of top hits as the rescored path (use IDFilter::keepNBestHits(result.peptide_ids, report_top_hits) or the literal used elsewhere, e.g., keepNBestHits(..., 1)) so both paths operate on the same hits; reference percolator_succeeded, FalseDiscoveryRate::apply, IDFilter::keepNBestHits, and ProSEAlgorithm::postProcessHits_/report_top_hits.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG`:
- Around line 107-108: Update the two changelog bullets by appending the PR
reference " (`#9195`)" to each relevant line: the bullet starting "Fix: FDR:PSM is
now deferred (alongside FDR:protein)..." and the bullet starting "Fix: -out_pin
output is now a valid, percolator-CLI-consumable .pin file..."; ensure the exact
text of those bullets remains unchanged aside from adding the " (`#9195`)" suffix
so they match surrounding entries for traceability.
---
Nitpick comments:
In `@src/openms/include/OpenMS/FORMAT/PercolatorInfile.h`:
- Line 85: Change the public API of getStandardFeatureSet to use the OpenMS
primitive type Int for both parameters instead of raw int: update the
declaration of static StringList getStandardFeatureSet(int min_charge, int
max_charge); to use Int, and mirror the change in the corresponding .cpp
definition and any loop/index variables inside (e.g., any for-loops over
min_charge/max_charge) so they use OpenMS::Int/Int from OpenMS/CONCEPT/Types.h;
ensure the header includes the appropriate Types.h import if not already
present.
In `@src/openms/source/FORMAT/PercolatorInfile.cpp`:
- Around line 36-48: In PercolatorInfile::getStandardFeatureSet, add a fail-fast
guard for the charge range: if min_charge > max_charge, throw an informative
exception (e.g., InvalidParameter/InvalidValue) before building fs so callers
immediately see the bad input rather than returning a header missing chargeN
columns; reference the function name PercolatorInfile::getStandardFeatureSet and
the local fs variable in your change and include the offending values in the
exception message.
In `@src/topp/ProSE.cpp`:
- Around line 526-541: The feature-set construction in ProSE.cpp now uses
PercolatorInfile::getStandardFeatureSet(min_charge, max_charge) but then
unconditionally appends "score" when missing, diverging from PercolatorAdapter's
conditional logic; add a concise inline comment near the block that builds
feature_set (referencing feature_set and the extra_features handling) stating
that ProSE intentionally always emits a HyperScore into the "score" column so
appending "score" is deliberate and not a bug, or alternatively add an explicit
assertion/acknowledgement variable (e.g., bool prose_always_injects_score) and
comment it to make the divergence clear to future readers.
- Around line 353-398: Fallback files (percolator_succeeded[i] == false) compute
FDR on all hits but rescored files are collapsed via IDFilter::keepNBestHits
earlier, which can cause different filtering when report_top_hits > 1; before
calling FalseDiscoveryRate::apply(result.peptide_ids) in the non-rescored
branch, collapse to the same number of top hits as the rescored path (use
IDFilter::keepNBestHits(result.peptide_ids, report_top_hits) or the literal used
elsewhere, e.g., keepNBestHits(..., 1)) so both paths operate on the same hits;
reference percolator_succeeded, FalseDiscoveryRate::apply,
IDFilter::keepNBestHits, and ProSEAlgorithm::postProcessHits_/report_top_hits.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5b85ab20-7ad7-492d-b82d-ce09fb72f440
📒 Files selected for processing (5)
CHANGELOGsrc/openms/include/OpenMS/FORMAT/PercolatorInfile.hsrc/openms/source/FORMAT/PercolatorInfile.cppsrc/topp/PercolatorAdapter.cppsrc/topp/ProSE.cpp
| - Fix: FDR:PSM is now deferred (alongside FDR:protein) when -percolator_executable is set, and applied post-rescoring on Percolator q-values. Previously FDR:PSM=0.01 filtered raw HyperScore q-values before Percolator ran and also stripped decoys, causing "No decoys found" and skipping Percolator entirely; fallback files (Percolator skipped/failed) still apply PSM FDR on HyperScore q-values via FalseDiscoveryRate | ||
| - Fix: -out_pin output is now a valid, percolator-CLI-consumable .pin file. Previously the header was missing the mandatory SpecId/Label/ScanNr columns and the standard mass/charge/enzyme feature columns (ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt, dm, absdm), which are populated on hits by PercolatorInfile::preparePin_ but were not declared in the feature list. Both ProSE -out_pin and PercolatorAdapter now build their feature set from the new PercolatorInfile::getStandardFeatureSet() helper so the two emit consistent .pin files |
There was a problem hiding this comment.
Add the PR reference for changelog traceability.
These two new bullets should include (#9195) like the surrounding entries.
📝 Proposed changelog tweak
- - Fix: FDR:PSM is now deferred (alongside FDR:protein) when -percolator_executable is set, and applied post-rescoring on Percolator q-values. Previously FDR:PSM=0.01 filtered raw HyperScore q-values before Percolator ran and also stripped decoys, causing "No decoys found" and skipping Percolator entirely; fallback files (Percolator skipped/failed) still apply PSM FDR on HyperScore q-values via FalseDiscoveryRate
- - Fix: -out_pin output is now a valid, percolator-CLI-consumable .pin file. Previously the header was missing the mandatory SpecId/Label/ScanNr columns and the standard mass/charge/enzyme feature columns (ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt, dm, absdm), which are populated on hits by PercolatorInfile::preparePin_ but were not declared in the feature list. Both ProSE -out_pin and PercolatorAdapter now build their feature set from the new PercolatorInfile::getStandardFeatureSet() helper so the two emit consistent .pin files
+ - Fix: FDR:PSM is now deferred (alongside FDR:protein) when -percolator_executable is set, and applied post-rescoring on Percolator q-values. Previously FDR:PSM=0.01 filtered raw HyperScore q-values before Percolator ran and also stripped decoys, causing "No decoys found" and skipping Percolator entirely; fallback files (Percolator skipped/failed) still apply PSM FDR on HyperScore q-values via FalseDiscoveryRate (`#9195`)
+ - Fix: -out_pin output is now a valid, percolator-CLI-consumable .pin file. Previously the header was missing the mandatory SpecId/Label/ScanNr columns and the standard mass/charge/enzyme feature columns (ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt, dm, absdm), which are populated on hits by PercolatorInfile::preparePin_ but were not declared in the feature list. Both ProSE -out_pin and PercolatorAdapter now build their feature set from the new PercolatorInfile::getStandardFeatureSet() helper so the two emit consistent .pin files (`#9195`)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - Fix: FDR:PSM is now deferred (alongside FDR:protein) when -percolator_executable is set, and applied post-rescoring on Percolator q-values. Previously FDR:PSM=0.01 filtered raw HyperScore q-values before Percolator ran and also stripped decoys, causing "No decoys found" and skipping Percolator entirely; fallback files (Percolator skipped/failed) still apply PSM FDR on HyperScore q-values via FalseDiscoveryRate | |
| - Fix: -out_pin output is now a valid, percolator-CLI-consumable .pin file. Previously the header was missing the mandatory SpecId/Label/ScanNr columns and the standard mass/charge/enzyme feature columns (ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt, dm, absdm), which are populated on hits by PercolatorInfile::preparePin_ but were not declared in the feature list. Both ProSE -out_pin and PercolatorAdapter now build their feature set from the new PercolatorInfile::getStandardFeatureSet() helper so the two emit consistent .pin files | |
| - Fix: FDR:PSM is now deferred (alongside FDR:protein) when -percolator_executable is set, and applied post-rescoring on Percolator q-values. Previously FDR:PSM=0.01 filtered raw HyperScore q-values before Percolator ran and also stripped decoys, causing "No decoys found" and skipping Percolator entirely; fallback files (Percolator skipped/failed) still apply PSM FDR on HyperScore q-values via FalseDiscoveryRate (`#9195`) | |
| - Fix: -out_pin output is now a valid, percolator-CLI-consumable .pin file. Previously the header was missing the mandatory SpecId/Label/ScanNr columns and the standard mass/charge/enzyme feature columns (ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt, dm, absdm), which are populated on hits by PercolatorInfile::preparePin_ but were not declared in the feature list. Both ProSE -out_pin and PercolatorAdapter now build their feature set from the new PercolatorInfile::getStandardFeatureSet() helper so the two emit consistent .pin files (`#9195`) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@CHANGELOG` around lines 107 - 108, Update the two changelog bullets by
appending the PR reference " (`#9195`)" to each relevant line: the bullet starting
"Fix: FDR:PSM is now deferred (alongside FDR:protein)..." and the bullet
starting "Fix: -out_pin output is now a valid, percolator-CLI-consumable .pin
file..."; ensure the exact text of those bullets remains unchanged aside from
adding the " (`#9195`)" suffix so they match surrounding entries for traceability.
Restore ProSE/FragmentIndex/File entries dropped by the FeatureFinderCentroided reorganization commit (#9159) and add new entries for commits merged after the last sync: - #9188: ProSE BREAKING: default isotope error range changed to [0,+2] - #9191: ProSE SNES mother-peptide indexing for non-specific searches - #9195: ProSE fix: defer PSM FDR when Percolator enabled; valid .pin output - #9203: FragmentIndex: fixed bucket_size 4096 for tighter candidate lists - #9204: ProSE: resolve PercolatorAdapter via findSiblingTOPPExecutable - #9205: ProSE: per-file output isolation + dangling decoy ref crash fix - #9207: File::rename: cross-device fallback (copy+remove on EXDEV) Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
… columns (#9460) (#9536) PercolatorInfile_test only covered load(); the .pin feature-set / header writer (getStandardFeatureSet, used to assemble the Percolator input header) was untested. Adds a section asserting the exact ordered feature set: - the three mandatory columns SpecId, Label, ScanNr - mass/length features (ExpMass, CalcMass, mass, peplen) - one "charge<c>" column per charge state in [min,max] (verified for 2..4 and the single-state 3..3 case) - enzyme / mass-delta features (enzN, enzC, enzInt, dm, absdm) and that the assembled header (features + Peptide + Proteins) begins with SpecId and ends with Peptide, Proteins -- the exact shape Percolator parses (#9195). Verified: builds clean and the test runs PASSED. Co-authored-by: Claude Opus 4.8 <[email protected]>
Summary
Fixes two related ProSE bugs around Percolator rescoring:
FDR:PSM stripped decoys before Percolator ran. Only
FDR:proteinwas deferred when-percolator_executableis set;FDR:PSMstill ran inside the algorithm on raw HyperScore q-values and — because protein FDR had been zeroed — also removed decoys via thefdr_protein_==0branch. Percolator then saw a target-only input and aborted with "No decoys found". Now both FDRs are deferred; PSM FDR is applied post-rescoring on Percolator q-values (fallback files that didn't get rescored runFalseDiscoveryRate::applyfirst).-out_pinemitted a malformed.pin. The header was missing the mandatorySpecId / Label / ScanNrcolumns plus the standard mass/charge/enzyme feature columns (ExpMass, CalcMass, mass, peplen, charge{N}, enzN, enzC, enzInt, dm, absdm) thatPercolatorInfile::preparePin_already computes on every hit. The file was not consumable by thepercolatorCLI. Factored the canonical column list into a newPercolatorInfile::getStandardFeatureSet()helper; bothPercolatorAdapter(previously hardcoded) and ProSE's-out_pinnow use it, so the two tools emit consistent, standards-compliant.pinfiles.Changes
src/topp/ProSE.cpp— deferFDR:PSMwhen Percolator is enabled; apply post-rescoring; usegetStandardFeatureSet()for-out_pin.src/openms/include/OpenMS/FORMAT/PercolatorInfile.h+.cpp— newgetStandardFeatureSet(min_charge, max_charge)helper.src/topp/PercolatorAdapter.cpp— use the helper instead of a hardcoded 22-line feature-set construction. Same columns, same output.CHANGELOG— entries under ProSE.Test plan
cmake --build OpenMS-build --target OpenMS ProSE PercolatorAdapter PercolatorInfile_test— clean build.ctest -R "TOPP_ProSE|PercolatorInfile|PercolatorAdapter"— 23/23 pass locally.ProSE -out_pinonSimpleSearchEngine_1.mzML: header begins withSpecId, Label, ScanNrand ends withPeptide, Proteins.developbase.-out_pinoutput (no external test harness currently exists;TOPP_PercolatorAdapter_missingis the only percolator-binary-dependent test in tree and it's skipped when percolator isn't installed).Notes
-percolator_executablein any ProSE test insrc/tests/topp/CMakeLists.txt). Consider adding a percolator-conditional test similar to howTOPP_PercolatorAdapter_missingis guarded — happy to do in a follow-up if desired..pincolumn order changes slightly whendescription_of_correct != 0:retentiontime, deltamassnow appear at the end instead of right afterScanNr. Column order in the middle of a Percolator.pinis not significant to thepercolatorbinary, and the tool's final idXML output is unaffected.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Improvements