Skip to content

fix(ProSE): per-file output isolation + dangling decoy refs (#9197 items 1a/1b) - #9205

Merged
timosachsenberg merged 4 commits into
developfrom
feat/prose-9197-fixes-1a-1b
Apr 22, 2026
Merged

timosachsenberg merged 4 commits into
developfrom
feat/prose-9197-fixes-1a-1b

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes items 1a and 1b of #9197. Items 3 + 4 (FDR:PSM deferral, valid .pin) were already handled by #9195.

Summary

  • Item 1a — write-order isolation: -out_merged write failure no longer discards per-file outputs. Per-file -out_idxml/-out_pin/-out_qpx/-out_parquet writes complete first; the merged write moved AFTER the per-file loop and is wrapped in try/catch so its failure becomes a logged error (with a reference to the per-file output errors logged above) rather than a terminal exception.
  • Item 1b — dangling decoy PeptideEvidence: merged idXML write no longer crashes with Invalid protein reference 'DECOY_...' when target+decoy shared peptides are present and FDR:protein > 0. Root cause: applyPickedProteinFDR deletes decoy ProteinHits while removeDecoyHits keeps target+decoy PSMs (whose target_decoy meta is target+decoy, not decoy). Those kept PSMs retain PeptideEvidence entries pointing at deleted decoy proteins. Fix: one call to IDFilter::removeDanglingProteinReferences after the existing decoy/protein cleanup.

Test Plan

  • All 18 TOPP_ProSE_* topp tests pass on the rebased branch (no fixture exercises target+decoy + FDR:protein > 0, so existing tests are no-op for the new code paths)
  • Manual repro from the issue: multi-file MHC-I run with Percolator, FDR:protein > 0, decoys present, shared target+decoy peptides — verify (a) per-file outputs land on disk regardless of merged-write outcome and (b) merged write succeeds (no dangling-ref crash)

Notes

This PR supersedes #9201 (closed). #9201 originally bundled a 4-item fix including FDR:PSM deferral and an -out_pin BREAKING change; #9195 has since merged with a different (better) approach for those, leaving only items 1a + 1b in scope here.

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Per-file outputs are now preserved when generating merged results in multi-file runs.
  • Fixed crashes caused by invalid protein references when target and decoy share peptides with protein FDR enabled.
  • Merged output failures no longer discard previously written results.

timosachsenberg and others added 4 commits April 22, 2026 07:29
Fixes 'Invalid protein reference DECOY_...' crash when merged path runs
applyPickedProteinFDR (deletes decoy ProteinHits) and target+decoy PSMs
remain (kept by removeDecoyHits's exact-match check on target_decoy=='decoy').

Refs OpenMS#9197 item 1b.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…catch

Fixes data loss on merged-write failure: previously a merged-write exception
aborted main_ and discarded per-file outputs even when per-file PSMs were
already complete in memory. Per-file writes now complete first and the merged
write is wrapped in try/catch so its failure becomes a logged error rather
than a terminal exception.

Refs OpenMS#9197 item 1a.
Don't claim per-file outputs were 'written successfully' — input_failed
may be true for one or more files. Direct user to check per-file errors
above.
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

CHANGELOG is updated with two ProSE output fixes. ProSE.cpp is refactored to wrap merged-IDXML writing in exception handling and reorder operations to ensure per-file outputs are written before merged output, plus add a cleanup pass to remove dangling protein references after decoy/protein cleanup.

Changes

Cohort / File(s) Summary
CHANGELOG
CHANGELOG
Added two ProSE fixes: per-file output protection during merged-write failures and invalid protein reference handling in merged idXML.
ProSE Output Handling
src/topp/ProSE.cpp
Restructured merged-IDXML write logic to wrap generation and storage in try/catch for error resilience, added IDFilter::removeDanglingProteinReferences cleanup pass after decoy/FDR processing, and ensured per-file writes complete before merged operations.

Possibly related issues

Possibly related PRs

Poem

🐰 Per-file outputs safe, no more lost treasure,
Wrapped in try-catch's gentle measure!
Dangling proteins vanish with a sweep,
While merged idXML writes run deep.
ProSE hops forward, bugs now gone! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 accurately reflects the primary changes in the PR: per-file output isolation (item 1a) and fixing dangling decoy protein references (item 1b), with a direct issue reference.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/prose-9197-fixes-1a-1b

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 and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/topp/ProSE.cpp (1)

665-667: Use \n for new log messages.

These new log statements use endl, which flushes unnecessarily.

♻️ Proposed cleanup
-                            << user_protein_fdr * 100 << "% FDR" << endl;
+                            << user_protein_fdr * 100 << "% FDR\n";
...
-        OPENMS_LOG_WARN << "-out_merged is only useful with multiple -in files. Skipping merged output." << endl;
+        OPENMS_LOG_WARN << "-out_merged is only useful with multiple -in files. Skipping merged output.\n";

As per coding guidelines, **/*.{cpp,cxx,cc}: Avoid std::endl for performance; prefer \n.

Also applies to: 696-698

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/ProSE.cpp` around lines 665 - 667, Replace usages of std::endl in
the ProSE logging lines with '\n' to avoid unnecessary flushes: update the
OPENMS_LOG_INFO statements that print merged protein/FDR messages (e.g., the
line building "[ProSE] Merged protein inference + FDR: " using
merged_protein_ids[0].getHits().size() and user_protein_fdr) and the similar
logging block at the later occurrence (around the other OPENMS_LOG_INFO that
spans lines ~696-698) to use '\n' instead of endl.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/topp/ProSE.cpp`:
- Around line 686-694: Detect and record the merged idXML write failure by
setting a boolean failure flag (e.g., bool merged_write_failed = true) inside
the catch block that handles Exception::BaseException for
FileHandler().storeIdentifications(out_merged, ...), and ensure the routine that
computes the final exit status checks this flag so it returns INTERNAL_ERROR
instead of EXECUTION_OK when merged_write_failed is true; also update the final
merged-output message logic to reflect that the merged file was not created when
the flag is set.

---

Nitpick comments:
In `@src/topp/ProSE.cpp`:
- Around line 665-667: Replace usages of std::endl in the ProSE logging lines
with '\n' to avoid unnecessary flushes: update the OPENMS_LOG_INFO statements
that print merged protein/FDR messages (e.g., the line building "[ProSE] Merged
protein inference + FDR: " using merged_protein_ids[0].getHits().size() and
user_protein_fdr) and the similar logging block at the later occurrence (around
the other OPENMS_LOG_INFO that spans lines ~696-698) to use '\n' instead of
endl.
🪄 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: e30f28c8-04bb-4dba-9af4-3094b07ac402

📥 Commits

Reviewing files that changed from the base of the PR and between c162f2d and ecf3eb3.

📒 Files selected for processing (2)
  • CHANGELOG
  • src/topp/ProSE.cpp

Comment thread src/topp/ProSE.cpp
Comment on lines +686 to +694
FileHandler().storeIdentifications(out_merged, merged_protein_ids, merged_peptides, {FileTypes::IDXML});
}
catch (const Exception::BaseException& e)
{
OPENMS_LOG_ERROR << "Failed to write merged idXML output -> " << out_merged
<< ": " << e.what()
<< ". Per-file outputs were written (check above for any per-file errors)." << endl;
// Do NOT propagate; per-file outputs are already on disk.
}

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.

⚠️ Potential issue | 🟠 Major

Mark merged idXML failure in the final exit status.

The catch preserves per-file outputs, but it also lets ProSE return EXECUTION_OK when the requested -out_merged file was not generated. Set a failure flag here and let the existing final status handling return INTERNAL_ERROR.

🐛 Proposed fix
-          FileHandler().storeIdentifications(out_merged, merged_protein_ids, merged_peptides, {FileTypes::IDXML});
+          FileHandler().storeIdentifications(out_merged, merged_protein_ids, merged_peptides, {FileTypes::IDXML});
         }
         catch (const Exception::BaseException& e)
         {
-          OPENMS_LOG_ERROR << "Failed to write merged idXML output -> " << out_merged
+          merged_ok = false;
+          OPENMS_LOG_ERROR << "Failed to generate/write merged idXML output -> " << out_merged
                            << ": " << e.what()
-                           << ". Per-file outputs were written (check above for any per-file errors)." << endl;
+                           << ". Per-file output attempts have already completed; check above for any per-file errors.\n";
           // Do NOT propagate; per-file outputs are already on disk.
         }

Also update the final merged-output message:

-        OPENMS_LOG_ERROR << "ProSE failed to write one or more merged Parquet files." << endl;
+        OPENMS_LOG_ERROR << "ProSE failed to write one or more merged output files.\n";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/ProSE.cpp` around lines 686 - 694, Detect and record the merged
idXML write failure by setting a boolean failure flag (e.g., bool
merged_write_failed = true) inside the catch block that handles
Exception::BaseException for FileHandler().storeIdentifications(out_merged,
...), and ensure the routine that computes the final exit status checks this
flag so it returns INTERNAL_ERROR instead of EXECUTION_OK when
merged_write_failed is true; also update the final merged-output message logic
to reflect that the merged file was not created when the flag is set.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@jpfeuffer can you take a quick look at 1b

@jpfeuffer

Copy link
Copy Markdown
Contributor

Yes. Same as always. You could filter pre merging then you have 50% less to merge.

@jpfeuffer

Copy link
Copy Markdown
Contributor

Ah but not if you do FDR on the merge

@timosachsenberg
timosachsenberg merged commit 9a7f816 into develop Apr 22, 2026
45 checks passed
@timosachsenberg
timosachsenberg deleted the feat/prose-9197-fixes-1a-1b branch April 22, 2026 08:21
timosachsenberg pushed a commit that referenced this pull request Apr 23, 2026
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]>
@timosachsenberg timosachsenberg mentioned this pull request Jun 8, 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