Repository navigation
[FIX] QPX export: three columns that were silently wrong - #9834
Conversation
Found by an adversarial review after #9832. All three predate that PR. 1. gg_accessions/gg_names lost positional alignment with pg_accessions. pg_accessions appends one entry per group member unconditionally and pg_names appends "" on a lookup miss, but the gene lists appended only inside `if (hit found)` AND `if (has_ga || has_gn)`. An unannotated member contributed nothing, so the lists came out short and every later gene shifted onto the wrong protein -- a partially gene-annotated FASTA is all it takes. The comment claimed the lists were "symmetric so they can be zipped"; they were symmetric with each other, which is not the symmetry a consumer needs. The identification-only overload already did this right. 2. peptide_counts.total_sequences counted features. It was `group_features.size()`, character-identical to the feature_counts expression two lines below, so total_sequences always equalled total_features -- while peptides[] in the same row was built from distinct sequences. Now accumulated from the same per-member seqs.size() that peptides[] emits, so the two agree by construction. This is the sibling field of the unique_sequences divergence fixed in #9832, which corrected one half of the struct and left the other. 3. The psm view wrote an empty run_file_name with no log output. QPX makes it a non-nullable primary-key component and the key psm is joined to feature and pg on; an empty string satisfies Arrow while violating the spec. Protein-inference output triggers it with no malformed metadata, since inference commonly drops spectra_data -- and the pg exporter warns loudly on the same input while the psm exporter said nothing. The row is still written: a PSM is a primary record and dropping it would discard an identification, unlike a protein group, which is a per-run aggregate that cannot exist without a run. Only the diagnostic was missing. buildQPXPSMTableRange runs inside an OpenMP region, so the count is an out-parameter written through a per-worker slot and summed by the caller after the region; both the streaming and single-shot paths report once per export. Each defect was invisible for a specific reason: no fixture had a partially gene-annotated group, every fixture had exactly one feature per sequence (the one case where the two count meanings coincide), and the empty-key path wrote a valid file silently. The two new sections target those gaps and were both confirmed to fail against the previous code -- reverting gives "GENE_OF_B" at index 0 and total_sequences 2 instead of 1. 153/153 TOPP tests; Arrow/QPX class tests green; no reference-file churn. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DF2YUewPQTC5tJWqn23pUm
📝 WalkthroughWalkthroughChangesProtein-group export corrections
QPX origin reporting
Sequence Diagram(s)sequenceDiagram
participant QPXExporter
participant buildQPXPSMTableRange
participant QPXWriter
QPXExporter->>buildQPXPSMTableRange: Build PSM range and update unresolved-origin counter
buildQPXPSMTableRange->>QPXWriter: Provide PSM rows with run-file stems
QPXWriter-->>QPXExporter: Close writer and output stream
QPXExporter->>QPXExporter: Report accumulated unresolved-origin count
Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 1
🧹 Nitpick comments (3)
src/openms/source/FORMAT/QPXFile.cpp (3)
1273-1273: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPlace braces on separate aligned lines.
Line 1273 and Line 1708 put the braces and statements on one line. Expand both blocks to match the required C++ format.
As per coding guidelines,
**/*.{h,hpp,cpp,cc,cxx}requires braces on their own aligned lines.Proposed formatting fix
- if (run_stem.empty()) { ++unattributable_psms; } + if (run_stem.empty()) + { + ++unattributable_psms; + } - for (int t = 0; t < W; ++t) { unattributable_total += unattr[t]; } + for (int t = 0; t < W; ++t) + { + unattributable_total += unattr[t]; + }Also applies to: 1708-1708
🤖 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/QPXFile.cpp` at line 1273, The if statement checking run_stem.empty() at line 1273 has its opening brace and body statement on the same line as the condition. Expand this block to place the opening brace on a new line, the statement body (incrementing unattributable_psms) on the next line, and the closing brace on its own aligned line. Apply the same multi-line formatting fix to the identical block at line 1708.Source: Coding guidelines
1496-1496: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
\ninstead ofstd::endlin the new warnings.
std::endlflushes the log stream. Replace it with'\n'in both warning statements.As per coding guidelines,
src/**/*.cpp: Prefer\noverstd::endl.Proposed logging fix
- "ProteinIdentification::setPrimaryMSRunPath() before exporting." << std::endl; + "ProteinIdentification::setPrimaryMSRunPath() before exporting." << '\n';Also applies to: 1778-1778
🤖 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/QPXFile.cpp` at line 1496, In the QPXFile.cpp file, locate the two warning statements that currently use std::endl at the end of their messages (one related to ProteinIdentification::setPrimaryMSRunPath() and another similar warning). Replace std::endl with a newline character '\n' in both warning statements to eliminate unnecessary stream flushing and align with the coding guidelines that prefer '\n' over std::endl for log output.Source: Coding guidelines
1267-1274: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression coverage for unresolved QPX origins.
QPXFile_test.cppexercises the normal export paths, but the new unresolved-origin behavior still needs coverage. Add a test forexportPSMsToQPXArrowand multithreadedexportToParquetStreaming(multiple batches/workers) that intentionally includes PSMs without a primary MS run path, asserts the PSM row is retained with an emptyrun_file_name, and checks the returned count aggregates across workers. Register the class test insrc/tests/class_tests/openms/srcs.cmakewithNEW_TMP_FILEfor output files.🤖 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/QPXFile.cpp` around lines 1267 - 1274, Add regression tests covering unresolved-origin PSMs in exportPSMsToQPXArrow and multithreaded exportToParquetStreaming, using multiple batches/workers. Assert the PSM row remains present with an empty run_file_name and that the returned unattributable count aggregates across workers; register the test class in srcs.cmake with NEW_TMP_FILE for generated outputs.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.
Inline comments:
In `@src/tests/class_tests/openms/source/ProteinGroupArrowExport_test.cpp`:
- Around line 393-435: The test currently verifies only the length of the
gg_accessions list but does not validate the actual accession values, which
leaves a regression undetected if an accession is emitted incorrectly. Set a
distinct gene_accession metadata value on the PROT_B ProteinHit (similar to how
gene_name is already set), then add assertions after the gg_accessions length
check to retrieve and verify the accession values from the gg_accessions array
using value_offset and GetString, checking for an empty string at member 0
(PROT_A) and the assigned gene_accession at member 1 (PROT_B).
---
Nitpick comments:
In `@src/openms/source/FORMAT/QPXFile.cpp`:
- Line 1273: The if statement checking run_stem.empty() at line 1273 has its
opening brace and body statement on the same line as the condition. Expand this
block to place the opening brace on a new line, the statement body (incrementing
unattributable_psms) on the next line, and the closing brace on its own aligned
line. Apply the same multi-line formatting fix to the identical block at line
1708.
- Line 1496: In the QPXFile.cpp file, locate the two warning statements that
currently use std::endl at the end of their messages (one related to
ProteinIdentification::setPrimaryMSRunPath() and another similar warning).
Replace std::endl with a newline character '\n' in both warning statements to
eliminate unnecessary stream flushing and align with the coding guidelines that
prefer '\n' over std::endl for log output.
- Around line 1267-1274: Add regression tests covering unresolved-origin PSMs in
exportPSMsToQPXArrow and multithreaded exportToParquetStreaming, using multiple
batches/workers. Assert the PSM row remains present with an empty run_file_name
and that the returned unattributable count aggregates across workers; register
the test class in srcs.cmake with NEW_TMP_FILE for generated outputs.
🪄 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 Plus
Run ID: 38970f35-45dc-4671-a156-27918b5370f6
📒 Files selected for processing (3)
src/openms/source/FORMAT/ProteinGroupArrowExport.cppsrc/openms/source/FORMAT/QPXFile.cppsrc/tests/class_tests/openms/source/ProteinGroupArrowExport_test.cpp
| ProteinHit pa; pa.setAccession("PROT_A"); // no gene annotation | ||
| ProteinHit pb; pb.setAccession("PROT_B"); | ||
| pb.setMetaValue("gene_name", "GENE_OF_B"); | ||
| prot.setHits({pa, pb}); | ||
| ProteinIdentification::ProteinGroup g; | ||
| g.accessions = {"PROT_A", "PROT_B"}; | ||
| g.probability = 0.01; | ||
| prot.insertIndistinguishableProteins(g); | ||
| cmap.setProteinIdentifications({prot}); | ||
|
|
||
| PeptideIdentification pid; | ||
| pid.setIdentifier("run"); | ||
| pid.setScoreType("q-value"); | ||
| pid.setHigherScoreBetter(false); | ||
| PeptideHit hit; | ||
| hit.setSequence(AASequence::fromString("PEPTIDEK")); | ||
| hit.setCharge(2); | ||
| PeptideEvidence ev; ev.setProteinAccession("PROT_A"); | ||
| hit.setPeptideEvidences({ev}); | ||
| pid.setHits({hit}); | ||
|
|
||
| ConsensusFeature cf; | ||
| cf.setMZ(500.0); cf.setRT(100.0); cf.setCharge(2); | ||
| BaseFeature bf; bf.setIntensity(10.0f); bf.setMZ(500.0); bf.setRT(100.0); bf.setCharge(2); | ||
| cf.insert(0, bf); | ||
| cf.setPeptideIdentifications({pid}); | ||
| cmap.push_back(cf); | ||
|
|
||
| auto t = ProteinGroupArrowExport::exportToArrow(cmap); | ||
| TEST_NOT_EQUAL(t, nullptr) | ||
| TEST_EQUAL(t->num_rows(), 1) | ||
|
|
||
| auto pg_acc = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("pg_accessions")->chunk(0)); | ||
| auto gg_acc = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("gg_accessions")->chunk(0)); | ||
| auto gg_nam = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("gg_names")->chunk(0)); | ||
| TEST_EQUAL(gg_acc->value_length(0), pg_acc->value_length(0)) | ||
| TEST_EQUAL(gg_nam->value_length(0), pg_acc->value_length(0)) | ||
|
|
||
| // The gene belongs to PROT_B, which is member 1 -- not member 0. | ||
| auto names = std::static_pointer_cast<arrow::StringArray>(gg_nam->values()); | ||
| const int64_t off = gg_nam->value_offset(0); | ||
| TEST_STRING_EQUAL(names->GetString(off), "") | ||
| TEST_STRING_EQUAL(names->GetString(off + 1), "GENE_OF_B") |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert gg_accessions values.
Lines 425-429 verify only the gg_accessions list length. The fixture does not assign gene_accession to PROT_B. A regression that emits an empty or wrong accession for the annotated member will pass.
Set a distinct gene_accession on PROT_B. Assert an empty value at member 0 and that accession at member 1.
Proposed test update
ProteinHit pb; pb.setAccession("PROT_B");
+pb.setMetaValue("gene_accession", "GENE_ACC_OF_B");
pb.setMetaValue("gene_name", "GENE_OF_B");
@@
auto names = std::static_pointer_cast<arrow::StringArray>(gg_nam->values());
+auto accessions = std::static_pointer_cast<arrow::StringArray>(gg_acc->values());
const int64_t off = gg_nam->value_offset(0);
+const int64_t acc_off = gg_acc->value_offset(0);
+TEST_STRING_EQUAL(accessions->GetString(acc_off), "")
+TEST_STRING_EQUAL(accessions->GetString(acc_off + 1), "GENE_ACC_OF_B")
TEST_STRING_EQUAL(names->GetString(off), "")
TEST_STRING_EQUAL(names->GetString(off + 1), "GENE_OF_B")📝 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.
| ProteinHit pa; pa.setAccession("PROT_A"); // no gene annotation | |
| ProteinHit pb; pb.setAccession("PROT_B"); | |
| pb.setMetaValue("gene_name", "GENE_OF_B"); | |
| prot.setHits({pa, pb}); | |
| ProteinIdentification::ProteinGroup g; | |
| g.accessions = {"PROT_A", "PROT_B"}; | |
| g.probability = 0.01; | |
| prot.insertIndistinguishableProteins(g); | |
| cmap.setProteinIdentifications({prot}); | |
| PeptideIdentification pid; | |
| pid.setIdentifier("run"); | |
| pid.setScoreType("q-value"); | |
| pid.setHigherScoreBetter(false); | |
| PeptideHit hit; | |
| hit.setSequence(AASequence::fromString("PEPTIDEK")); | |
| hit.setCharge(2); | |
| PeptideEvidence ev; ev.setProteinAccession("PROT_A"); | |
| hit.setPeptideEvidences({ev}); | |
| pid.setHits({hit}); | |
| ConsensusFeature cf; | |
| cf.setMZ(500.0); cf.setRT(100.0); cf.setCharge(2); | |
| BaseFeature bf; bf.setIntensity(10.0f); bf.setMZ(500.0); bf.setRT(100.0); bf.setCharge(2); | |
| cf.insert(0, bf); | |
| cf.setPeptideIdentifications({pid}); | |
| cmap.push_back(cf); | |
| auto t = ProteinGroupArrowExport::exportToArrow(cmap); | |
| TEST_NOT_EQUAL(t, nullptr) | |
| TEST_EQUAL(t->num_rows(), 1) | |
| auto pg_acc = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("pg_accessions")->chunk(0)); | |
| auto gg_acc = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("gg_accessions")->chunk(0)); | |
| auto gg_nam = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("gg_names")->chunk(0)); | |
| TEST_EQUAL(gg_acc->value_length(0), pg_acc->value_length(0)) | |
| TEST_EQUAL(gg_nam->value_length(0), pg_acc->value_length(0)) | |
| // The gene belongs to PROT_B, which is member 1 -- not member 0. | |
| auto names = std::static_pointer_cast<arrow::StringArray>(gg_nam->values()); | |
| const int64_t off = gg_nam->value_offset(0); | |
| TEST_STRING_EQUAL(names->GetString(off), "") | |
| TEST_STRING_EQUAL(names->GetString(off + 1), "GENE_OF_B") | |
| ProteinHit pa; pa.setAccession("PROT_A"); // no gene annotation | |
| ProteinHit pb; pb.setAccession("PROT_B"); | |
| pb.setMetaValue("gene_accession", "GENE_ACC_OF_B"); | |
| pb.setMetaValue("gene_name", "GENE_OF_B"); | |
| prot.setHits({pa, pb}); | |
| ProteinIdentification::ProteinGroup g; | |
| g.accessions = {"PROT_A", "PROT_B"}; | |
| g.probability = 0.01; | |
| prot.insertIndistinguishableProteins(g); | |
| cmap.setProteinIdentifications({prot}); | |
| PeptideIdentification pid; | |
| pid.setIdentifier("run"); | |
| pid.setScoreType("q-value"); | |
| pid.setHigherScoreBetter(false); | |
| PeptideHit hit; | |
| hit.setSequence(AASequence::fromString("PEPTIDEK")); | |
| hit.setCharge(2); | |
| PeptideEvidence ev; ev.setProteinAccession("PROT_A"); | |
| hit.setPeptideEvidences({ev}); | |
| pid.setHits({hit}); | |
| ConsensusFeature cf; | |
| cf.setMZ(500.0); cf.setRT(100.0); cf.setCharge(2); | |
| BaseFeature bf; bf.setIntensity(10.0f); bf.setMZ(500.0); bf.setRT(100.0); bf.setCharge(2); | |
| cf.insert(0, bf); | |
| cf.setPeptideIdentifications({pid}); | |
| cmap.push_back(cf); | |
| auto t = ProteinGroupArrowExport::exportToArrow(cmap); | |
| TEST_NOT_EQUAL(t, nullptr) | |
| TEST_EQUAL(t->num_rows(), 1) | |
| auto pg_acc = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("pg_accessions")->chunk(0)); | |
| auto gg_acc = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("gg_accessions")->chunk(0)); | |
| auto gg_nam = std::static_pointer_cast<arrow::ListArray>(t->GetColumnByName("gg_names")->chunk(0)); | |
| TEST_EQUAL(gg_acc->value_length(0), pg_acc->value_length(0)) | |
| TEST_EQUAL(gg_nam->value_length(0), pg_acc->value_length(0)) | |
| // The gene belongs to PROT_B, which is member 1 -- not member 0. | |
| auto names = std::static_pointer_cast<arrow::StringArray>(gg_nam->values()); | |
| auto accessions = std::static_pointer_cast<arrow::StringArray>(gg_acc->values()); | |
| const int64_t off = gg_nam->value_offset(0); | |
| const int64_t acc_off = gg_acc->value_offset(0); | |
| TEST_STRING_EQUAL(accessions->GetString(acc_off), "") | |
| TEST_STRING_EQUAL(accessions->GetString(acc_off + 1), "GENE_ACC_OF_B") | |
| TEST_STRING_EQUAL(names->GetString(off), "") | |
| TEST_STRING_EQUAL(names->GetString(off + 1), "GENE_OF_B") |
🤖 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/tests/class_tests/openms/source/ProteinGroupArrowExport_test.cpp` around
lines 393 - 435, The test currently verifies only the length of the
gg_accessions list but does not validate the actual accession values, which
leaves a regression undetected if an accession is emitted incorrectly. Set a
distinct gene_accession metadata value on the PROT_B ProteinHit (similar to how
gene_name is already set), then add assertions after the gg_accessions length
check to retrieve and verify the accession values from the gg_accessions array
using value_offset and GetString, checking for an empty string at member 0
(PROT_A) and the assigned gene_accession at member 1 (PROT_B).
Source: Coding guidelines
…9835, #9836 (#9841) Backfills the QPX export spec-conformance series, the macOS PKG notarization fix, and the Windows GUI DLL export fix that merged into develop without changelog entries. #9805 and #9821 were intentionally skipped (test-only / comment-only, no user-visible behavior change), and #9818 was already documented. Claude-Session: https://claude.ai/code/session_0118Yt3TZEMzhMhH6FwZPDVt Co-authored-by: Claude <[email protected]>
Three defects in the QPX export columns, found by an adversarial review after #9832. All three are in already-merged code, none came from that PR, and each produces plausible-looking wrong data with no diagnostic — which is why the test suite never saw them.
1. Gene lists lose positional alignment with
pg_accessionsProteinGroupArrowExport.cpp(ConsensusMap overload).pg_accessionsgets one entry per group member unconditionally, andpg_namesappends""on a lookup miss — butgg_accessions/gg_namesappended only insideif (it != hit_lookup.end())andif (has_ga || has_gn). A member with noProteinHit, or with a hit but no gene metavalue, contributed nothing.So the gene lists come out shorter than
pg_accessionsand every subsequent gene shifts down one index, silently attributed to the wrong protein. A partially gene-annotated FASTA is all it takes — group{PROT_A, PROT_B}with a gene onPROT_Bonly yieldsgg_names = ["GENE_OF_B"], which a consumer zips ontoPROT_A.The comment claimed "keep lists symmetric so they can be zipped". The two gene lists were symmetric with each other, which is not the symmetry a consumer needs. The identification-only overload of the same view already did this correctly; this aligns the ConsensusMap one to it.
2.
peptide_counts.total_sequencescounted features, not sequencesSame file, two lines apart:
Character-identical expressions, so
total_sequenceswas always equal tototal_features— while thepeptides[]list in the same row was built from distinct sequences. One row assertingpeptides = [{PROT_A, 1}]next tototal_sequences = 2is self-contradictory, and distinguishing peptidoform and charge is whatfeature_countsexists for.total_sequencesis now accumulated from the same per-memberseqs.size()thatpeptides[]emits, so the two agree by construction.This is the sibling field of the
unique_sequencesdivergence fixed in #9832 — that PR corrected one half of the struct and left the other, so the two overloads still disagreed.3. The psm view wrote an empty primary key with no log output
QPXFile.cppappendedFile::stemName(run_file)unguarded. When neither the hit metavalue nor the mapper resolves anything, that is""— and QPX makesrun_file_namea non-nullable primary-key component, and the key the psm view is joined to feature and pg on. An empty string satisfies Arrow while violating the spec.Protein-inference output triggers it with no malformed metadata and no exception: inference commonly drops
spectra_dataentirely. The same input through the pg exporter emits a full warning naming the remedy; the psm exporter said nothing at all.The row is still written. A PSM is a primary record and dropping it would discard an identification — unlike a protein group, which is a per-run aggregate that cannot exist without a run. Only the diagnostic was missing, so only the diagnostic is added: a count of unattributable PSMs and one aggregated warning naming
setPrimaryMSRunPath().buildQPXPSMTableRangeruns inside an OpenMP region, so the counter is an out-parameter written through a per-worker slot and summed by the caller after the region — the serial counter idiom used elsewhere would have been a data race. Both the streaming and single-shot paths report once per export.Why no test caught these
Each was invisible for a specific, checkable reason:
The new sections target exactly those gaps: a two-member group with one gene, and one sequence at two charge states. Both were confirmed to fail against the previous code before being kept.
Verification
ProteomicsLFQ/ProSE/ProteinQuantifier/IsobaricAnalyzerTOPP suite🤖 Generated with Claude Code
https://claude.ai/code/session_01DF2YUewPQTC5tJWqn23pUm
Summary by CodeRabbit
Bug Fixes
Tests