Skip to content

[FIX,TEST] QPX: separate unmapped features by observed_mz, never leave a partial collection - #9849

Merged
timosachsenberg merged 7 commits into
developfrom
fix/qpx-feature-key-and-atomic-export
Aug 4, 2026
Merged

timosachsenberg merged 7 commits into
developfrom
fix/qpx-feature-key-and-atomic-export

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Three defects in the QPX export contract added by #9846/#9843, found while reviewing #9847. Tightening the contract is right where the producers can satisfy it — these are the cases where they cannot, or where the enforcement is not clean.

1. The feature primary key refused maps OpenMS itself produces

The key is (peptidoform, charge, run_file_name, rt). QPX permits unmapped features and ConsensusMapArrowExport writes them with an empty peptidoform, so for those rows the key collapses to (charge, run_file_name, rt) — and rt is narrowed to float32 on write, one ULP being 244 µs at a retention time of 3000 s. Two co-eluting unmapped features of the same charge in one run then share a key although they are plainly different features, and the whole table is refused: both exportToParquet() and exportToParquetStreaming() return false and -out_qpx aborts with UnableToCreateFile.

Reproduced with two unmapped features at m/z 400 and 500, RT 3000.0000 and 3000.0001:

ConsensusMapArrowExport: refusing invalid QPX feature table: row 10 repeats the
QPX feature primary key (peptidoform, charge, run_file_name, rt)
Error: Unable to write file ...          (exit 5, nothing written)

This is the normal shape for the tools that write QPX, not a corner case. BSA_plusSeeds_plusTransfer — ProteomicsLFQ with seeds — is 156 of 198 consensus features (79 %) with no identification at all, largest single (run, charge) bucket 25 rows. A real run carries tens of thousands, where the birthday bound over the ~2.2e7 representable float32 retention times makes a collision the expected outcome:

same-charge unmapped features in one run expected colliding pairs
5,000 0.6
20,000 9.2
100,000 230

Nothing exercised it because the only ProteomicsLFQ QPX test uses the unseeded configuration, whose features are all identified.

observed_mz — written one column over and previously excluded — is now part of the key. Genuine duplicates (agreeing on run, charge, rt and m/z) are still refused.

2. A refused collection left its earlier files behind

requireExportable() catches everything decidable from the input, but a view can still refuse a row it only sees while building its table, and a write can fail on I/O. By then quantms.feature.parquet is on disk, and a directory holding it without a PSM file is indistinguishable from a complete export of a smaller dataset. The class header already flagged this as a known gap.

$ ProteinQuantifier ... -out_qpx dir/      # one PSM without spectrum_reference
ArrowIOHelpers: refusing invalid QPX psm_file table: row 0 has an empty 'scan' primary-key value
$ ls dir/
quantms.feature.parquet    (17833 bytes)

New QPXCollectionExport::Transaction scope guard: constructed before the first write, committed after the last, and on any other exit — a view returning false, a writer throwing, an early return — it removes the collection files this export created. Used by ProteinQuantifier, ProteomicsLFQ and IsobaricWorkflow. Guarding the scope rather than enumerating the failure sites means the next refusal mode is covered without anyone having to remember it.

Files that were already in the directory are never removed: re-running a pipeline into the same -out_qpx directory is normal, and a failed re-run must not destroy the previous result. Such a run does leave the directory mixing two exports — views that ran before the failure overwrote their files in place — so the destructor names the surviving files in a warning instead of letting the directory look coherent. (Raised by CodeRabbit; the first version of this guard deleted them, and the test encoded that. Both are fixed, and the new assertion fails without it.)

QPXFile and ConsensusMapArrowExport additionally leave a zero-byte .parquet behind when parquet::arrow::FileWriter::Open fails — FileOutputStream::Open has already created and truncated the file, and that early return happens before the close-and-remove block covering every later failure. Both now close and remove it.

3. The streaming PSM writer left a truncated file

One validator spans all batches so it can fail on a late one, and the writer and sink are closed regardless, so the footer is written and the result reads as a valid, merely smaller, PSM table. It is now removed — matching what ConsensusMapArrowExport's streaming writer already did for the identical situation.

Plus: the contract, written down once

The four requirements a foreign consensus map can miss (a scan per identification, a resolvable origin file, uniqueness per (peptidoform, charge, run, scan), a channel label from the QPX vocabulary) were only discoverable by reading the validator. They are now stated on OpenMS::QPXValueValidation — the code that enforces them, so they cannot drift — and nowhere else; ProteinQuantifier's -out_qpx parameter and doc page point there rather than restating it.

QPXValueValidation also had no test file although every sibling QPX class has one. QPXValueValidation_test covers all three views, the documented cross-batch statefulness and reset(), the schema-mismatch path, multi-chunk columns, and null/0-row tables. Its invalid inputs are built through the exporters rather than by patching columns, so each section exercises a shape a producer really emits.

Verification

before after
two co-eluting unmapped features exit 5, nothing written exit 0, all three parquet files
PSM refusal after feature.parquet exit 5, quantms.feature.parquet left behind exit 5, directory empty
genuine duplicate (same run/charge/rt/mz) refused still refused

Each fix ships with a test confirmed to fail without it — the feature-key section at validate() on the two co-eluting features, the streaming section at TEST_FALSE(File::exists(duplicate_file)) — both green again once restored.

94 QPX/Arrow/ProteinQuantifier/IsobaricWorkflow/ProSE tests pass, 66 ProteomicsLFQ tests pass, doxygen clean. No reference files change.

Known limitation, not addressed here

QPXValueValidation retains one heap key per row for the whole output file and never clears it (~130–150 B/row, several GB on a very large export), which sits badly with the reason exportToParquetStreaming exists. Adding observed_mz adds ~13 B/row on top. That is a pre-existing issue and worth fixing separately — by hashing the key rather than retaining the string, or scoping the set per batch and accepting the loss of cross-batch detection.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

Summary by CodeRabbit

  • Bug Fixes

    • Prevented QPX feature-key collisions by incorporating observed m/z values.
    • Rejected invalid or non-finite feature coordinates with clearer validation.
    • Removed incomplete Parquet files after failed streaming, writing, or closing operations.
  • Reliability

    • Added transactional QPX exports that clean up partial files after failures while preserving completed collections and existing outputs.
  • Documentation

    • Clarified QPX validation rules, supported inputs, key uniqueness, and output behavior.

Merge order

These four PRs are all descendants of the same review of #9847. Test-merged locally in this order; only one conflict exists and it is trivial.

# branch base depends on
1. #9847 codex/fix-best-charge-and-fraction develop —
2. #9852 fix/file-channel-zeros-not-detected #9847 #9847 (rewrites the function it patches)
3. #9851 fix/zero-abundances-not-evidence develop — (conflicts with #9852, see below)
4. #9849 fix/qpx-feature-key-and-atomic-export develop —

Verified locally: all four merged together, conflicts resolved as above, 63/63 PeptideAndProteinQuant_test / TOPP_ProteinQuantifier_* / TOPP_IsobaricWorkflow_* / QPX / Arrow tests pass, and the two isobaric abundance arrays agree exactly.

timosachsenberg and others added 2 commits August 4, 2026 13:56
…lection

Three defects in the QPX export contract added by #9846/#9843, found reviewing
#9847. Tightening the contract is fine where the producers can satisfy it; these
are cases where they cannot, or where the enforcement is not clean.

1. Feature primary key refused maps OpenMS itself produces.
   The key is (peptidoform, charge, run_file_name, rt). QPX permits unmapped
   features and ConsensusMapArrowExport writes them with an empty peptidoform, so
   for those rows the key collapses to (charge, run_file_name, rt) - and 'rt' is
   narrowed to float32 on write, one ULP being 244 us at 3000 s. Two co-eluting
   unmapped features of the same charge in one run then share a key although they
   are plainly different features, and the whole table is refused.
   Not a corner case for the tools that write QPX: ProteomicsLFQ with seeds
   leaves 79 % of the ProteomicsLFQ_3 fixture's consensus features unidentified,
   and a real run carries tens of thousands, where the birthday bound over the
   ~2.2e7 representable float32 retention times makes a collision expected. The
   only ProteomicsLFQ QPX test uses the unseeded configuration, whose features are
   all identified, so nothing exercised it.
   'observed_mz' - written one column over, previously excluded - joins the key.
   Genuine duplicates (same run, charge, rt AND m/z) are still refused.

2. A refused collection left its earlier files behind.
   requireExportable() catches everything decidable from the input, but a view can
   still refuse a row it only sees while building its table, and a write can fail
   on I/O; by then quantms.feature.parquet is on disk, and a directory holding it
   without a PSM file is indistinguishable from a complete export of a smaller
   dataset. New QPXCollectionExport::Transaction scope guard: constructed before
   the first write, committed after the last, and on any other exit - a view
   returning false, a writer throwing, an early return - it removes every
   collection file present. Used by ProteinQuantifier, ProteomicsLFQ and
   IsobaricWorkflow. Guarding the scope rather than enumerating the failure sites
   covers the next refusal mode without anyone having to remember it.

3. QPXFile::exportToParquetStreaming() left a truncated PSM file.
   One validator spans all batches so it can fail on a late one, and the writer
   and sink are closed regardless, so the footer is written and the file reads as
   a valid, merely smaller, PSM table. It is now removed, matching what
   ConsensusMapArrowExport's streaming writer already did for the same situation.

Each fix ships with a test that was confirmed to fail without it: the feature-key
section fails at the validate() of two co-eluting unmapped features, and the
streaming section at TEST_FALSE(File::exists(duplicate_file)).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
…r directly

Documentation and tests only; no behaviour change.

The QPX input contract was not written down anywhere a user could find it: the
tools that offer -out_qpx just fail with UnableToCreateFile, and the four
requirements a foreign consensus map can miss (a scan per identification, a
resolvable origin file, uniqueness per (peptidoform, charge, run, scan), and a
channel label from the QPX vocabulary) were only discoverable by reading
QPXValueValidation. It is now stated on that class - the code that enforces it,
so it cannot drift - and nowhere else. ProteinQuantifier's -out_qpx parameter and
its documentation page point there rather than restating it, naming ProteomicsLFQ
and IsobaricWorkflow as the producers that satisfy the contract by construction.

QPXValueValidation had no test file of its own although every sibling QPX class
has one, and it is a 600-line OPENMS_DLLAPI class that decides whether an export
happens at all. QPXValueValidation_test covers all three views: the psm view's
empty-scan, empty/blank run_file_name and duplicate-key refusals, the feature
view's separation of unmapped rows by observed_mz and its non-finite coordinate
refusals, the documented statefulness (a validator spans batches so a key
repeated after a batch boundary is caught; a rejected batch does not advance the
key state; reset() starts a new file), the schema-mismatch path, multi-chunk
columns, null and 0-row tables, and Result::toString().

The invalid inputs are built through the exporters rather than by patching
columns, so each section exercises a shape a producer really emits - an
identification without a spectrum reference, or the one-MS2-on-two-features
duplication IDMapper creates.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9496f7cd-0029-43a6-8684-1f84cadb91be

📥 Commits

Reviewing files that changed from the base of the PR and between 92ac9ee and 771325b.

📒 Files selected for processing (3)
  • CHANGELOG
  • src/tests/topp/CMakeLists.txt
  • src/topp/ProteinQuantifier.cpp
🔥 Files not summarized due to errors (1)
  • src/tests/topp/CMakeLists.txt: Server error: no LLM provider could handle the message

📝 Walkthrough

Walkthrough

QPX feature keys now include observed_mz. Collection exports use transaction cleanup. Failed one-shot and streaming Parquet exports close and remove incomplete files. Tests cover validation, rollback, and failure cleanup.

Changes

QPX export integrity

Layer / File(s) Summary
Feature key validation
src/openms/include/OpenMS/FORMAT/QPXValueValidation.h, src/openms/source/FORMAT/QPXValueValidation.cpp, src/tests/class_tests/openms/source/QPXValueValidation_test.cpp, src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp, src/tests/class_tests/openms/executables.cmake, CHANGELOG
Feature keys include nullable rt and observed_mz values. Validation rejects non-finite coordinates and covers stateful and multi-chunk validation.
Collection transaction cleanup
src/openms/include/OpenMS/FORMAT/QPXCollectionExport.h, src/openms/source/FORMAT/QPXCollectionExport.cpp, src/tests/class_tests/openms/source/QPXCollectionExport_test.cpp, src/topp/IsobaricWorkflow.cpp, src/topp/ProteinQuantifier.cpp, src/topp/ProteomicsLFQ.cpp, CHANGELOG
QPXCollectionExport::Transaction preserves pre-existing files and removes incomplete collection files unless all three Parquet exports succeed and call commit().
Parquet failure cleanup
src/openms/source/FORMAT/ArrowIOHelpers.cpp, src/openms/source/FORMAT/ConsensusMapArrowExport.cpp, src/openms/source/FORMAT/QPXFile.cpp, src/tests/class_tests/openms/source/ArrowIOHelpers_test.cpp, src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp, src/tests/class_tests/openms/source/QPXFile_test.cpp, CHANGELOG
One-shot and streaming exports close failed outputs and remove incomplete Parquet files. Close failures are reported as export failures.

Sequence Diagram(s)

sequenceDiagram
  participant Workflow as QPX workflow
  participant Transaction as QPXCollectionExport::Transaction
  participant Exporters as Parquet exporters
  participant Output as QPX output files
  Workflow->>Transaction: Start transaction
  Workflow->>Exporters: Export feature, PSM, and protein-group views
  Exporters->>Output: Write Parquet files
  Workflow->>Transaction: Commit after successful exports
  Transaction->>Output: Remove new files if uncommitted
Loading

Possibly related issues

Possibly related PRs

  • OpenMS/OpenMS#9698 — Modifies the streaming export path updated by this PR.
  • OpenMS/OpenMS#9846 — Introduces the QPX validation framework extended by this PR.
  • OpenMS/OpenMS#9843 — Adds related QPX validation and error-handling infrastructure used by this cleanup work.

Suggested reviewers: singjc

Poem

Poem

A rabbit checks each m/z key,
Three Parquet files export cleanly.
Failed outputs disappear,
Committed files remain clear.
QPX hops safely through the stream.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.58% 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 clearly summarizes the main changes: observed_mz-based feature separation and prevention of partial QPX collections.
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.
✨ 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 fix/qpx-feature-key-and-atomic-export

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.

@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: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openms/include/OpenMS/FORMAT/QPXCollectionExport.h`:
- Around line 102-109: Update the Doxygen comments for Transaction’s
constructor, destructor, and commit() to use /** */ blocks with `@brief`
descriptions; add `@param`[in] directory to the constructor documentation while
preserving the existing semantics.

In `@src/openms/source/FORMAT/QPXCollectionExport.cpp`:
- Around line 161-179: Reformat the cleanup logic in QPXCollectionExport’s
destructor or cleanup method by placing the committed_ and File::remove
conditional opening braces on their own aligned lines and replacing both
std::endl log terminators with '\n'. Also update the while block in
src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp at line 300
so its opening brace is on a separate aligned line.
- Around line 166-180: Update QPXCollectionExport’s failure cleanup so it cannot
delete collection files that predate the current export: either stage writes
under transaction-owned paths and publish only after every writer succeeds, or
reject non-empty output directories before opening writers. Document the
selected staging or empty-directory contract in QPXCollectionExport’s public
documentation. In QPXCollectionExport_test, create partial files only after the
guard begins and add coverage verifying that a failed export preserves an
existing complete collection.

In `@src/openms/source/FORMAT/QPXFile.cpp`:
- Around line 1822-1829: Update the QPXFile writer-opening path so a failed
parquet::arrow::FileWriter::Open closes the already-open outfile and removes
filename before returning. Ensure the existing !ok cleanup remains effective for
later failures without duplicating unsafe cleanup.

In `@src/topp/ProteinQuantifier.cpp`:
- Around line 1049-1053: Refactor the QPX export flow in all three files to
write each QPX view to temporary files first, then atomically replace the entire
collection only after all views complete successfully. In
src/topp/ProteinQuantifier.cpp (lines 1049-1053), src/topp/IsobaricWorkflow.cpp
(lines 997-1002), and src/topp/ProteomicsLFQ.cpp (lines 1919-1922), move the
QPXCollectionExport::Transaction guard to wrap the final atomic replacement step
instead of the initial view writes, so that partial failures do not corrupt or
delete an existing valid collection in out_qpx. This ensures that if any view
export fails, the prior output collection remains intact.
🪄 Autofix

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 Plus

Run ID: 2c488cf0-a4ec-4157-9ae8-540dc7c73535

📥 Commits

Reviewing files that changed from the base of the PR and between 39c4fe6 and 9cf6d23.

📒 Files selected for processing (14)
  • CHANGELOG
  • src/openms/include/OpenMS/FORMAT/QPXCollectionExport.h
  • src/openms/include/OpenMS/FORMAT/QPXValueValidation.h
  • src/openms/source/FORMAT/QPXCollectionExport.cpp
  • src/openms/source/FORMAT/QPXFile.cpp
  • src/openms/source/FORMAT/QPXValueValidation.cpp
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
  • src/tests/class_tests/openms/source/QPXCollectionExport_test.cpp
  • src/tests/class_tests/openms/source/QPXFile_test.cpp
  • src/tests/class_tests/openms/source/QPXValueValidation_test.cpp
  • src/topp/IsobaricWorkflow.cpp
  • src/topp/ProteinQuantifier.cpp
  • src/topp/ProteomicsLFQ.cpp

Comment thread src/openms/source/FORMAT/QPXFile.cpp Resolved
Comment thread src/topp/ProteinQuantifier.cpp Resolved
Addresses the CodeRabbit review on #9849.

The scope guard removed every collection file in the output directory on a failed
export, including files that were already there. Re-running a pipeline into the
same -out_qpx directory is the normal case, so a failed re-run destroyed the
previous, complete result. The test encoded that behaviour by creating its stub
files before constructing the guard.

The guard now records which of the three files exist at construction and removes
only the ones this export created. A run that fails after overwriting a
pre-existing file still leaves the directory mixing two exports - that cannot be
undone without staging - so the destructor names the surviving files in a warning
instead of letting the directory look coherent. The test creates its files inside
the guard's lifetime, as an export does, and gains coverage that a failed export
preserves a complete previous collection; that assertion fails without the fix.

Also from the same review:
- QPXFile and ConsensusMapArrowExport left a zero-byte .parquet behind when
  parquet::arrow::FileWriter::Open failed: arrow::io::FileOutputStream::Open had
  already created and truncated the file, and this early return happens before
  the close-and-remove block that covers every later failure. Both now close and
  remove it. (ConsensusMapArrowExport is not otherwise part of this PR's changes,
  but the two writers are deliberately symmetric here.)
- Doxygen: the Transaction constructor, destructor and commit() use /** */ with
  @brief, and the constructor documents @PARAM[in] directory.
- Style: braces on their own aligned lines, and '\n' instead of std::endl in the
  new logging.

Verified end to end: a failed export into a fresh directory still leaves it
empty, and a failed export into a directory holding a previous collection leaves
all three of its files in place with the warning.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
timosachsenberg added a commit that referenced this pull request Aug 4, 2026
Addresses the CodeRabbit nitpick on #9851. The repository's own .clang-format
permits the compact form (AllowShortBlocksOnASingleLine: true), and the file
already contains several instances of it, so this is cosmetic rather than a
correctness or guideline fix - applied for consistency with the same change made
on #9849.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

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

🧹 Nitpick comments (1)
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (1)

1477-1486: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Cleanup logic is correct; minor inconsistency in error handling.

The close-then-remove sequence for the truncated file is correct and matches the PR objective. Line 1479 discards the status of outfile->Close(). The later cleanup path in this same function, at Lines 1580-1586, checks outfile_close.ok() and logs a failure. Apply the same check here for consistency, even though the file is removed immediately after.

Proposed consistency fix
-    (void)outfile->Close();
+    auto close_status = outfile->Close();
+    if (!close_status.ok())
+    {
+      OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close output stream for "
+                       << filename << ": " << close_status.ToString() << std::endl;
+    }
     if (!File::remove(filename))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/ConsensusMapArrowExport.cpp` around lines 1477 -
1486, Update the cleanup block in the ConsensusMapArrowExport function to retain
and check the status returned by outfile->Close(), matching the later
outfile_close.ok() handling in the same function; log a close failure before
attempting to remove the incomplete file, while preserving the existing removal
and return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/openms/source/FORMAT/ConsensusMapArrowExport.cpp`:
- Around line 1477-1486: Update the cleanup block in the ConsensusMapArrowExport
function to retain and check the status returned by outfile->Close(), matching
the later outfile_close.ok() handling in the same function; log a close failure
before attempting to remove the incomplete file, while preserving the existing
removal and return behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c5112eb-acba-4b36-b156-182c59824d99

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf6d23 and e5d0755.

📒 Files selected for processing (6)
  • src/openms/include/OpenMS/FORMAT/QPXCollectionExport.h
  • src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
  • src/openms/source/FORMAT/QPXCollectionExport.cpp
  • src/openms/source/FORMAT/QPXFile.cpp
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
  • src/tests/class_tests/openms/source/QPXCollectionExport_test.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
  • src/openms/source/FORMAT/QPXFile.cpp
  • src/tests/class_tests/openms/source/QPXCollectionExport_test.cpp

timosachsenberg and others added 3 commits August 4, 2026 17:08
Fixes the windows-2025/cl.exe build failure on this branch: 37 LNK2019s, all
unresolved __declspec(dllimport) arrow:: symbols, on
QPXValueValidation_test.exe.

The test was added to executables.cmake without the matching
target_link_libraries(... ${OPENMS_ARROW_TARGET} ${OPENMS_PARQUET_TARGET}) that
every other Arrow-using class test carries. It builds its invalid inputs with
arrow::FloatBuilder and ArrayData::Make rather than through the exporters -
deliberately, so each section exercises a shape a producer really emits - so it
needs Arrow itself, not just what OpenMS re-exports. On Linux/macOS libOpenMS
statically links Arrow and re-exports its symbols, so the link happens to
succeed; on Windows they are dllimport and nothing satisfies them.

QPXCollectionExport_test, added alongside it, uses no Arrow type and correctly
stays unlinked.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
This PR taught both streaming writers to clean up after themselves, but the
one-shot writers next to them still leak. arrow::io::FileOutputStream::Open
creates and truncates the file before the table is written, so a write that
fails afterwards leaves a fragment carrying little more than the Parquet magic
bytes - no footer, so a reader reports it as corrupt rather than as the smaller
table it looks like.

Two sites, both now closing the stream and removing the file on any failure
after the open:

- ConsensusMapArrowExport::exportToParquet, directly above the streaming
  function this PR already fixed.
- ArrowIOHelpers::writeTableToParquet, the shared path behind the psm, pg,
  OpenSwath and MSExperiment exports.

ConsensusMapArrowExport::exportToParquet additionally closes explicitly instead
of leaving it to the stream's destructor, which discards the error: the final
flush is where a full disk surfaces, and that used to be reported as success
with a truncated file on disk.

Inside the three tools this was contained by QPXCollectionExport::Transaction,
which is why it did not show up as a bug; it was not contained for pyOpenMS and
library callers, or for ProSE, whose -out_qpx layout the guard cannot cover.

Each fix ships with a test confirmed to fail without it - both at the
TEST_FALSE(File::exists(...)) line, with the write failing for the intended
reason. A row group size of 0 is refused by Parquet for a non-empty table, which
reaches a post-open write failure deterministically on every platform.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
The feature-key defect this PR fixes reached develop because the only
ProteomicsLFQ QPX test runs -targeted_only true, whose consensus features are
all identified: 0 of its 60 feature rows are unmapped, so nothing ever exported
the shape the key could not distinguish. The class test added here reproduces
that shape synthetically, but nothing asserts that the tool still produces it.

New TOPP_ProteomicsLFQ_qpx_seeds runs TOPP_ProteomicsLFQ_3's seeded
configuration with -out_qpx: 210 of 298 feature rows are unmapped, and all three
collection files must exist afterwards. Kept as a separate run rather than
folded into TOPP_ProteomicsLFQ_3 so no reference file is touched.

What it guards is that the shape reaches the exporter and clears it end to end.
It is not a reproducer for the float32-rt collision itself - measured on the
produced table, the pre-fix key happens not to collide at this fixture's size -
and the comment says so rather than implying more; ConsensusMapArrowExport_test
covers that directly.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

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

🧹 Nitpick comments (1)
src/openms/source/FORMAT/ArrowIOHelpers.cpp (1)

535-543: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use \n in the new log statements.

Replace std::endl in the changed logging statements.

  • src/openms/source/FORMAT/ArrowIOHelpers.cpp#L535-L543: replace std::endl in abandon.
  • src/openms/source/FORMAT/ConsensusMapArrowExport.cpp#L1407-L1415: replace std::endl in the one-shot abandon lambda.
  • src/openms/source/FORMAT/ConsensusMapArrowExport.cpp#L1503-L1507: replace std::endl in the streaming cleanup error log.

As per coding guidelines, prefer \n over std::endl.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/ArrowIOHelpers.cpp` around lines 535 - 543, Replace
std::endl with \n in the logging statements within abandon in
src/openms/source/FORMAT/ArrowIOHelpers.cpp (535-543), the one-shot abandon
lambda in src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (1407-1415), and
the streaming cleanup error log in
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (1503-1507); make no other
changes.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/openms/source/FORMAT/ArrowIOHelpers.cpp`:
- Around line 535-543: Replace std::endl with \n in the logging statements
within abandon in src/openms/source/FORMAT/ArrowIOHelpers.cpp (535-543), the
one-shot abandon lambda in src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
(1407-1415), and the streaming cleanup error log in
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (1503-1507); make no other
changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c8bd58c-3302-44e1-a12e-d9b8dfb34bf6

📥 Commits

Reviewing files that changed from the base of the PR and between e5d0755 and 92ac9ee.

📒 Files selected for processing (7)
  • CHANGELOG
  • src/openms/source/FORMAT/ArrowIOHelpers.cpp
  • src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
  • src/tests/class_tests/openms/CMakeLists.txt
  • src/tests/class_tests/openms/source/ArrowIOHelpers_test.cpp
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
  • src/tests/topp/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
  • CHANGELOG

@timosachsenberg
timosachsenberg merged commit 4af0cde into develop Aug 4, 2026
7 checks passed
@timosachsenberg
timosachsenberg deleted the fix/qpx-feature-key-and-atomic-export branch August 4, 2026 15:59
timosachsenberg added a commit that referenced this pull request Aug 4, 2026
…ptide (#9851)

* [FIX,TEST] fix_peptides: a stored zero is not a sample the peptide occurs in

'consensus:fix_peptides' ranks peptides by the size() of their sample->abundance
map. That map has an entry wherever quantifyFeature_ saw a feature handle, and
IsobaricChannelExtractor writes a reporter it could not find - or one below
'min_reporter_intensity' - as an explicit 0.0, so every peptide of an isobaric
run reported the full channel count:

  - with 'top:N' 0, "all peptides that occur in every sample" admitted every
    peptide seen anywhere; the filter stopped filtering.
  - with 'top:N' > 0, all peptides tied at the channel count, so the tie-break by
    total abundance decided alone and a peptide with a large signal in 2 of 10
    channels took the slot from one genuinely measured in 6.

Both now count only the samples with a positive abundance, via one helper. This
is the rule the class already applies elsewhere and the inconsistency is the
actual defect: normalizePeptides_() excludes zeros from its medians, with a
comment explaining that a zero means "not detected" rather than "no protein",
and the charge-prevalence count in 'best_charge_and_fraction' does the same.

Scoped deliberately to the counting. total_abundances is untouched, so peptide
and protein abundances, mzTab and QPX values do not move; only which peptides are
selected changes, and only when 'consensus:fix_peptides' is enabled - off by
default and set by no OpenMS tool. The five in-tree fix_peptides tests
(TOPP_ProteinQuantifier_7/8/9/12/13) use a fixture with no zero intensities, so
no reference file changes.

Two class-test sections cover the two branches on an isobaric fixture, which
nothing had before. Both were confirmed to fail without the fix, reporting 600
instead of 100 (the undetected peptide admitted) and 1000 instead of 100 (the
taller peptide taking the top:N slot).

Reported as finding 13 of the #9847 review.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

* [FIX,TEST] protein aggregation: a stored zero is not a detected peptide

Third and most consequential site of the same defect: calculateProteinAbundances_
aggregated peptides that were never detected, so an isobaric protein could be
reported as absent from a sample it was measured in.

quantifyFeature_ records every feature handle, and IsobaricChannelExtractor
writes a reporter it could not find - or one below 'min_reporter_intensity' - as
an explicit 0.0 and inserts the handle regardless
(IsobaricChannelExtractor.cpp:620/658/663). Every peptide of an isobaric run
therefore carries an entry for every channel. Those entries were pushed into the
per-sample list, where they both counted towards the "enough peptides in this
sample" gate and fed the aggregate: with the default median, a channel in which
most of a protein's peptides went undetected got a median of exactly 0; with mean
it was diluted towards 0.

That is the artefact normalizePeptides_() already excludes zeros to avoid, and
the opposite of what the tool documents - "(intensity weighted) mean and median
ignore missing cases, averaging only present values", with only 'sum' documented
as treating missing values as zero.

Only detected (positive) abundances are aggregated and counted now. 'sum' is
numerically unaffected, since summing zeros changes nothing. Samples are tracked
separately from their values, so a sample in which nothing was detected keeps its
zero entry under 'top:include_all' rather than disappearing from the output.

Unlike the two earlier sites this is not opt-in: IsobaricWorkflow sets
'top:include_all', otherwise takes the defaults, and passes no aggregation
override - and so does quantms, whose ISOBARIC_WORKFLOW module supplies no
-ProteinQuantification:* arguments and has no ext.args.

The IsobaricWorkflow_1 reference shows it on real data. Its only changed line is
the protein-abundance array of group 1 (PROTB, two peptides): MYFINGERK has no
reporter in channels 1, 3, 6, 7, 9 and 10, which are exactly the six channels
whose value doubles - the old median of (GIRAFFERK, 0) reported the protein at
half its single measurement. The four channels where both peptides were detected
are byte-identical.

Label-free data is unaffected: a feature that was not found has no entry at all,
rather than an entry of zero. All 97 ProteomicsLFQ/MzTab tests are unchanged.

Both new class-test sections were confirmed to fail without the fix, reporting 0
(median) and 333.33 (mean) where the protein was measured at 1000.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

* [STYLE] expand a short if-block per review

Addresses the CodeRabbit nitpick on #9851. The repository's own .clang-format
permits the compact form (AllowShortBlocksOnASingleLine: true), and the file
already contains several instances of it, so this is cosmetic rather than a
correctness or guideline fix - applied for consistency with the same change made
on #9849.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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