Repository navigation
[FIX,TEST] QPX: separate unmapped features by observed_mz, never leave a partial collection - #9849
Conversation
…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
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🔥 Files not summarized due to errors (1)
📝 WalkthroughWalkthroughQPX feature keys now include ChangesQPX export integrity
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
Possibly related issues
Possibly related PRs
Suggested reviewers: Poem Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 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
📒 Files selected for processing (14)
CHANGELOGsrc/openms/include/OpenMS/FORMAT/QPXCollectionExport.hsrc/openms/include/OpenMS/FORMAT/QPXValueValidation.hsrc/openms/source/FORMAT/QPXCollectionExport.cppsrc/openms/source/FORMAT/QPXFile.cppsrc/openms/source/FORMAT/QPXValueValidation.cppsrc/tests/class_tests/openms/executables.cmakesrc/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cppsrc/tests/class_tests/openms/source/QPXCollectionExport_test.cppsrc/tests/class_tests/openms/source/QPXFile_test.cppsrc/tests/class_tests/openms/source/QPXValueValidation_test.cppsrc/topp/IsobaricWorkflow.cppsrc/topp/ProteinQuantifier.cppsrc/topp/ProteomicsLFQ.cpp
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
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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (1)
1477-1486: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCleanup 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, checksoutfile_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
📒 Files selected for processing (6)
src/openms/include/OpenMS/FORMAT/QPXCollectionExport.hsrc/openms/source/FORMAT/ConsensusMapArrowExport.cppsrc/openms/source/FORMAT/QPXCollectionExport.cppsrc/openms/source/FORMAT/QPXFile.cppsrc/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cppsrc/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
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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/openms/source/FORMAT/ArrowIOHelpers.cpp (1)
535-543: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
\nin the new log statements.Replace
std::endlin the changed logging statements.
src/openms/source/FORMAT/ArrowIOHelpers.cpp#L535-L543: replacestd::endlinabandon.src/openms/source/FORMAT/ConsensusMapArrowExport.cpp#L1407-L1415: replacestd::endlin the one-shotabandonlambda.src/openms/source/FORMAT/ConsensusMapArrowExport.cpp#L1503-L1507: replacestd::endlin the streaming cleanup error log.As per coding guidelines, prefer
\noverstd::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
📒 Files selected for processing (7)
CHANGELOGsrc/openms/source/FORMAT/ArrowIOHelpers.cppsrc/openms/source/FORMAT/ConsensusMapArrowExport.cppsrc/tests/class_tests/openms/CMakeLists.txtsrc/tests/class_tests/openms/source/ArrowIOHelpers_test.cppsrc/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cppsrc/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
…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]>
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 andConsensusMapArrowExportwrites them with an empty peptidoform, so for those rows the key collapses to(charge, run_file_name, rt)— andrtis 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: bothexportToParquet()andexportToParquetStreaming()return false and-out_qpxaborts withUnableToCreateFile.Reproduced with two unmapped features at m/z 400 and 500, RT 3000.0000 and 3000.0001:
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: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 thenquantms.feature.parquetis 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.New
QPXCollectionExport::Transactionscope 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_qpxdirectory 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.)QPXFileandConsensusMapArrowExportadditionally leave a zero-byte.parquetbehind whenparquet::arrow::FileWriter::Openfails —FileOutputStream::Openhas 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 onOpenMS::QPXValueValidation— the code that enforces them, so they cannot drift — and nowhere else; ProteinQuantifier's-out_qpxparameter and doc page point there rather than restating it.QPXValueValidationalso had no test file although every sibling QPX class has one.QPXValueValidation_testcovers all three views, the documented cross-batch statefulness andreset(), 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
quantms.feature.parquetleft behindEach 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 atTEST_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
QPXValueValidationretains 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 reasonexportToParquetStreamingexists. Addingobserved_mzadds ~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
Reliability
Documentation
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.
codex/fix-best-charge-and-fractionfix/file-channel-zeros-not-detectedfix/zero-abundances-not-evidencefix/qpx-feature-key-and-atomic-exportsrc/tests/topp/IsobaricWorkflow_1_out.consensusXML, on adjacent lines — [FIX,TEST] PeptideAndProteinQuant: a stored zero is not a detected peptide #9851 the sample-levelindistinguishable_proteins_1_abundances, [FIX,TEST] file+channel level: a stored zero is not a detected peptide #9852 the..._file_channel_level_abundance. Resolution: take both. They are the two halves of one fix, and afterwards the two arrays are byte-identical, which is the invariant to check (one file × N channels means a cell is a sample).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.