Repository navigation
[IO,TEST] mzTab: an assay is a (fraction_group, label) unit, not a Sample - #9868
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughChangesConsensus-map mzTab export now separates assays from study variables. It maps assays from fraction groups and labels, emits assay-level protein and peptide abundances, and leaves replicate study-variable aggregates null. Regression coverage validates metadata and abundance placement. Assay-aware mzTab export
Sequence Diagram(s)sequenceDiagram
participant ExperimentalDesign
participant CMMzTabStream
participant ProteinRows
participant PeptideRows
participant MzTabOutput
ExperimentalDesign->>CMMzTabStream: fraction-group and label mappings
CMMzTabStream->>ProteinRows: assay and study-variable mappings
CMMzTabStream->>PeptideRows: assay and study-variable mappings
ProteinRows->>MzTabOutput: assay-level protein abundances
PeptideRows->>MzTabOutput: assay-level peptide abundances
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/openms/source/FORMAT/MzTab.cpp (1)
979-1004: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winSubfeature optional columns can now repeat the same study-variable index in one row.
Before this change each handle resolved to a distinct study variable, so each
opt_global_mass_to_charge_study_variable[i]name appeared at most once per row. Now several handles of the same sample share onestudy_variable. For a sample with two fraction groups, the loop pushesopt_global_mass_to_charge_study_variable[1]andopt_global_retention_time_study_variable[1]twice intorow.opt_. mzTab optional columns are positional against the PEH/PRH header, so duplicated names inside one row break the header-to-row correspondence.Key these columns by
assaywhen the grain is distinct, or restrict them to the single-assay case.🤖 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/MzTab.cpp` around lines 979 - 1004, Update the export_subfeatures handling in the consensus-feature loop to avoid adding duplicate study-variable optional columns when multiple handles share an assay. Key the emitted mass-to-charge and retention-time entries by assay and emit each assay’s values only once, or restrict emission to the single-assay case, while preserving the existing row.opt_ column names and values.
🧹 Nitpick comments (3)
src/openms/source/FORMAT/MzTab.cpp (2)
1784-1790: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider limiting the warning volume and using the return value.
warnAndFallbackemits one warning per protein group. Each message embeds the accession, so log deduplication does not apply. A consensusXML with inconsistent metadata for many groups produces one warning line per group.Two small improvements:
- Aggregate the fallback into a single warning per export, or log the first occurrence and a final count.
- The call site at Lines 3195-3199 discards the returned
bool. If the caller never needs it, change the return type tovoidand keep the early-exit structure.🤖 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/MzTab.cpp` around lines 1784 - 1790, Update the warnAndFallback lambda in the export flow to avoid emitting one accession-specific warning per protein group: aggregate fallback occurrences into a single export-level warning or log the first occurrence with a final count. Also update its call site around the assay-level abundance handling to either consume the returned bool meaningfully or change the lambda to return void while preserving the existing early-exit behavior.
983-983: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse the map-index type instead of
int.
FeatureHandle::getMapIndex()returnsUInt64, whilecm_column_headersis keyed byUInt64. Store the returned value inUInt64or useautobefore callingcm_column_headers.at(...)to avoid narrowing a 64-bit map index.🤖 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/MzTab.cpp` at line 983, Update the local index declaration in the code using FeatureHandle::getMapIndex() to use UInt64 or auto instead of int, preserving the value before passing it to cm_column_headers.at(...).src/tests/class_tests/openms/source/MzTab_test.cpp (1)
240-256: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd cases for the fallback branches and for the 1:1 grain.
The test covers the success path of
applyAssayProteinQuantificationwell, including the reversed key order. Four behaviors introduced by this PR stay untested:
- Mismatched lengths between the three
fraction_group_level_*arrays.- A non-positive
fraction_grouporlabelvalue.- A duplicated
(fraction_group, label)key.- A design where every study variable owns exactly one assay. That path sets
has_distinct_assay_graintofalseand emits no assay columns, and it is the path the unchanged reference mzTab files depend on.Each case needs only a small variation of the existing fixture. The fallback cases should assert that the legacy
abundancesvalue survives in the study-variable column.🤖 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/MzTab_test.cpp` around lines 240 - 256, Extend the tests around applyAssayProteinQuantification with fixtures covering mismatched fraction-group array lengths, non-positive fraction_group or label values, and duplicate (fraction_group, label) keys; assert each fallback preserves the legacy abundances value in the study-variable column. Add a 1:1 study-variable-to-assay fixture and assert has_distinct_assay_grain is false and no assay columns are emitted, preserving the reference mzTab 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.
Inline comments:
In `@src/openms/source/FORMAT/MzTab.cpp`:
- Around line 3047-3053: Replace the unchecked map accesses with diagnostic
checked lookups: in src/openms/source/FORMAT/MzTab.cpp#L3047-L3053, validate
path_label_to_assay_ using c.second.filename and label; in
src/openms/source/FORMAT/MzTab.cpp#L979-L990, validate path_label_to_assay using
ch.filename and label; and in src/openms/source/FORMAT/MzTab.cpp#L3068, validate
path_to_ms_run_index using c.second.filename. Throw
Exception::MissingInformation for missing entries, matching the existing
handling near Lines 2950-2952, and use the resolved iterator values thereafter.
- Around line 1821-1828: The assay-abundance mapping loop silently converts
unmatched keys to null and drops extra entries. Update the logic around
abundance_by_assay_key and assay_keys to warn whenever their key sets differ,
and implement the documented sample-level fallback for missing assay keys; if
null is the intended behavior, retain it but still add the mismatch warning and
align the PR description.
- Around line 955-964: Update has_distinct_assay_grain in the row initialization
logic to derive from study_variable_to_assays rather than comparing n_assays and
n_study_variables. Detect whether any study variable maps to a number of assays
other than one, then use that mapping-based result consistently for assay-column
initialization and the related multi-assay handling around
peptide_abundance_assay.
In `@src/tests/topp/ProteomicsLFQ_1_subset_out.mzTab`:
- Around line 119-130: Regenerate the affected mzTab fixture using the updated
peptide-row generation path, ensuring peptideSectionRowFromConsensusFeature_
copies each single-assay study-variable value directly from the corresponding
assay_abundances entry. Verify the peptide_abundance_assay and
peptide_abundance_study_variable cells are textually identical for the affected
rows, including line 126.
- Around line 49-56: Regenerate the full ProteomicsLFQ mzTab test outputs using
the current exporter logic, including ProteomicsLFQ_1_out.mzTab and
ProteomicsLFQ_2_out.mzTab and all registered TOPP_ProteomicsLFQ_* references
reusing FRACTIONS/BSA* designs. Ensure their assay and study-variable metadata
matches the assay-based, multi-assay schema shown in
ProteomicsLFQ_1_subset_out.mzTab.
---
Outside diff comments:
In `@src/openms/source/FORMAT/MzTab.cpp`:
- Around line 979-1004: Update the export_subfeatures handling in the
consensus-feature loop to avoid adding duplicate study-variable optional columns
when multiple handles share an assay. Key the emitted mass-to-charge and
retention-time entries by assay and emit each assay’s values only once, or
restrict emission to the single-assay case, while preserving the existing
row.opt_ column names and values.
---
Nitpick comments:
In `@src/openms/source/FORMAT/MzTab.cpp`:
- Around line 1784-1790: Update the warnAndFallback lambda in the export flow to
avoid emitting one accession-specific warning per protein group: aggregate
fallback occurrences into a single export-level warning or log the first
occurrence with a final count. Also update its call site around the assay-level
abundance handling to either consume the returned bool meaningfully or change
the lambda to return void while preserving the existing early-exit behavior.
- Line 983: Update the local index declaration in the code using
FeatureHandle::getMapIndex() to use UInt64 or auto instead of int, preserving
the value before passing it to cm_column_headers.at(...).
In `@src/tests/class_tests/openms/source/MzTab_test.cpp`:
- Around line 240-256: Extend the tests around applyAssayProteinQuantification
with fixtures covering mismatched fraction-group array lengths, non-positive
fraction_group or label values, and duplicate (fraction_group, label) keys;
assert each fallback preserves the legacy abundances value in the study-variable
column. Add a 1:1 study-variable-to-assay fixture and assert
has_distinct_assay_grain is false and no assay columns are emitted, preserving
the reference mzTab behavior.
🪄 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: aea093d8-0dfc-4482-b882-0c12cdb46608
📒 Files selected for processing (4)
src/openms/include/OpenMS/FORMAT/MzTab.hsrc/openms/source/FORMAT/MzTab.cppsrc/tests/class_tests/openms/source/MzTab_test.cppsrc/tests/topp/ProteomicsLFQ_1_subset_out.mzTab
| for (Size i = 0; i < assay_keys.size(); ++i) | ||
| { | ||
| const Size assay = i + 1; | ||
| const auto value = abundance_by_assay_key.find(assay_keys[i]); | ||
| protein_row.protein_abundance_assay[assay] = value == abundance_by_assay_key.end() | ||
| ? MzTabDouble() | ||
| : MzTabDouble(value->second); | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Unmatched assay keys are silently written as null.
The PR description states that missing keys fall back to the sample-level values with a warning. This loop instead writes MzTabDouble() for any assay_keys[i] that has no entry in abundance_by_assay_key, without a warning and without falling back. Extra keys present in the arrays but absent from assay_keys are also dropped silently.
If a null value is the intended output for an unmeasured assay, the PR description needs no change here. If not, add the fallback. In either case, warn when the key sets do not match, because that indicates the design and the annotation disagree.
🤖 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/MzTab.cpp` around lines 1821 - 1828, The
assay-abundance mapping loop silently converts unmatched keys to null and drops
extra entries. Update the logic around abundance_by_assay_key and assay_keys to
warn whenever their key sets differ, and implement the documented sample-level
fallback for missing assay keys; if null is the intended behavior, retain it but
still add the mismatch warning and align the PR description.
…mple An mzTab assay was an OpenMS Sample, so a Sample measured in several fraction groups collapsed into one assay and the replicate axis was unrepresentable (OpenMS#9864 §B5). The spec says the opposite: an assay spans the n ms_runs of its fractions, and "multiple assays within the same study variable are taken to be replicates of some kind (biological or technical)". assay <- (fraction_group, label), covering all its fractions study_variable <- Sample, listing its assays as replicates Assay abundances come from the "fraction_group_level_abundance" array and its parallel "_fraction_group"/"_label" key arrays, matched by key rather than by position. When those arrays are absent (older consensusXML, or another producer) the previous sample-grain values are kept, and a mismatched or duplicated key warns and falls back. A study variable holding exactly one assay copies that assay's value -- identity, not an aggregation choice. One holding several stays null: no across-replicate aggregator has been agreed, so none is invented here. stdev/std_error remain null as before. This also resolves OpenMS#9864 §A2. MzTab.cpp:981 assigned instead of accumulating only because a study variable was forced 1:1 with an assay; now that an assay spans its fractions, the handles of one assay are summed, which is what the column means. The positional "abundances" array is still read as the "was quantified" gate, so ConsensusXMLHandler and the study-variable count are unaffected. Only ProteomicsLFQ_1_subset_out.mzTab moves. Its design assigns BSA1's fraction 2 to fraction group 1 and its fraction 3 to fraction group 4, so BSA1 is two assays, not one, and its study variable is null. Every other reference has one assay per sample and is byte-identical. Refs OpenMS#9864 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…iled lookups Three follow-ups from review of the assay-grain change. The "assay and study variable have different grain" flag compared the two counts. That is a proxy for "every study variable owns exactly one assay" and it fails: n_study_variables comes from the sample section while assays come from the MS file section, so a sample owning no assay lets the counts agree while one study variable owns two assays and another owns none. The flag then said "same grain", the assay columns were dropped, and the multi-assay study variable stayed null - so those intensities vanished from the row entirely. It now asks study_variable_to_assays directly. Three lookups resolved a consensus-map column against a precomputed map with std::map::at. When the design and the map disagree on a filename or a label that throws std::out_of_range, which names neither, and which does not derive from Exception::Base so OpenMS error handling never sees it. They are checked lookups now, throwing MissingInformation naming the file and the label. Four peptide_abundance_study_variable cells in ProteomicsLFQ_1_subset_out.mzTab disagreed with the assay cell they are copied from - e.g. 3.0112309375e05 against 3.01123125e05, a difference of 1/32. A study variable owning one assay copies that assay's value, so they cannot differ; the reference had been written before that path was finalized. Verified against fresh output, which agrees on all 42 cells. Only those four cells are corrected: the rest of the file's differences are cross-platform rounding that FuzzyDiff is meant to absorb, and rewriting it here would replace them with this machine's digits. That mismatch survived a full green ctest because FuzzyDiff's tolerance absorbs a 1e-7 relative difference - the same blind spot as OpenMS#9859. Refs OpenMS#9864 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
93149c5 to
3d4c207
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Rebased onto the restructured 3.6.0 changelog (#9881), which moved from a flat "General:" list to per-tool sections. Both entries were therefore re-placed rather than replayed: - ParquetDiff now sits under "TOPP tools: New tools:", alongside the other tools added in 3.6.0. The existing "Build System: Tests:" paragraph only referenced it in passing while announcing the QPX value references; the tool itself was never announced. - The mzTab assay-grain change becomes a new "MzTabExporter:" subsection under "TOPP tools: Changes:", next to the ProteinQuantifier assay-grain entry it mirrors. MzTabExporter had no section at all. Neither #9865 nor #9868 was cited anywhere in the changelog before this. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Y9DY9JfJasCr76qof5n5rx
Rebased onto the restructured 3.6.0 changelog (#9881), which moved from a flat "General:" list to per-tool sections. Both entries were therefore re-placed rather than replayed: - ParquetDiff now sits under "TOPP tools: New tools:", alongside the other tools added in 3.6.0. The existing "Build System: Tests:" paragraph only referenced it in passing while announcing the QPX value references; the tool itself was never announced. - The mzTab assay-grain change becomes a new "MzTabExporter:" subsection under "TOPP tools: Changes:", next to the ProteinQuantifier assay-grain entry it mirrors. MzTabExporter had no section at all. Neither #9865 nor #9868 was cited anywhere in the changelog before this. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Y9DY9JfJasCr76qof5n5rx
* docs(CHANGELOG): add entries for #9865 and #9868 Rebased onto the restructured 3.6.0 changelog (#9881), which moved from a flat "General:" list to per-tool sections. Both entries were therefore re-placed rather than replayed: - ParquetDiff now sits under "TOPP tools: New tools:", alongside the other tools added in 3.6.0. The existing "Build System: Tests:" paragraph only referenced it in passing while announcing the QPX value references; the tool itself was never announced. - The mzTab assay-grain change becomes a new "MzTabExporter:" subsection under "TOPP tools: Changes:", next to the ProteinQuantifier assay-grain entry it mirrors. MzTabExporter had no section at all. Neither #9865 nor #9868 was cited anywhere in the changelog before this. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Y9DY9JfJasCr76qof5n5rx * docs(CHANGELOG): ParquetDiff's exit code also depends on -min_rows ParquetDiff returns EXECUTION_OK only when the comparison or schema check passes and, if -min_rows is set, every input holds at least that many rows (ParquetDiff.cpp:245); otherwise it returns INCOMPATIBLE_INPUT_DATA. Found by CodeRabbit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7 * docs(CHANGELOG): an unmatched MzTabExporter assay key gives null applyAssayProteinQuantification (MzTab.cpp) warns and keeps the previous abundance columns only for missing or unequal-length arrays, keys that are not 1-based, and duplicated keys. An assay whose key the array lacks gets a null abundance, without a warning. The entry said that a mismatched key also warns and falls back. Found by CodeRabbit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7 --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Step 2 of the plan on #9864: report at the assay grain and stop treating the OpenMS
Sampleas a quantification unit. Step 1 is #9867.What changes
An mzTab assay was an OpenMS
Sample(MzTab.cpp:2803n_assays = ed.getNumberOfSamples()), so a Sample measured in several fraction groups collapsed into one assay and the replicate axis had nowhere to live — #9864 §B5. The spec says the opposite:So:
assay(fraction_group, label), covering all its fractionsstudy_variableSample, listing its assays as replicatesThis is what the code's own TODOs at
:2806,:2896and:2905asked for; all three are removed.Assay abundances come from the
fraction_group_level_abundancefloat array and its parallelfraction_group_level_fraction_group/_labelkey arrays thatPeptideAndProteinQuantalready writes, matched by key, not by position. If those arrays are absent (older consensusXML, or a producer other thanPeptideAndProteinQuant) the previous sample-grain values are kept; a mismatched or duplicated key warns and falls back rather than emitting wrong numbers.Study-variable rule: one assay → copy that assay's value (identity, not an aggregation choice). Several assays → null. No across-replicate aggregator has been agreed on #9864, so none is invented here.
stdev/std_errorstay null as before.Also resolves #9864 §A2
MzTab.cpp:981assigned where it had to accumulate, so the highest map index won. That was only ill-defined because a study variable was forced 1:1 with an assay. Now that an assay spans the n ms_runs of its fractions, the handles belonging to one assay are summed — which is whatpeptide_abundance_assay[i]means. The two no-op default-construct statements next to it are gone.Reference movement
One file moves:
ProteomicsLFQ_1_subset_out.mzTab.Its design (
share/OpenMS/examples/FRACTIONS/BSA_design_onetable_nonconsec.tsv) puts sampleBSA1's fraction 2 in fraction group 1 and its fraction 3 in fraction group 4. So BSA1 is genuinely two quantification units, not one:P02769|ALBU_BOVIN:protein_abundance_assay[1] = 1.576e8(FG1) and[4] = 1.547e8(FG4), withstudy_variable[1]null. BSA2 and BSA3 each have one assay, soassay[2] = study_variable[2] = 1.396e8andassay[3] = study_variable[3] = 2.489e7— unchanged from before.Every other mzTab reference is byte-identical, because every other shipped design has exactly one
(fraction_group, label)per sample. That includes all otherProteomicsLFQ_*, everyMzTabExporter_*,QualityControl_1andProteinQuantifier_9_output_mztab.Tests
New section in
MzTab_test.cpp: one sample owning two fraction groups, the first with two measured fractions. Asserts 2 assays with the rightms_run_refsets, 1 study variable referencing both, assay abundances matched through the reversed parallel key arrays (so a positional match would fail), and a null study-variable abundance at both protein and peptide level.Verified it fails without the implementation, for the right reasons:
Not changed
The positional
"abundances"array is still read as the "was quantified" gate, soConsensusXMLHandler(:947,:973-980) and the study-variable count atMzTab.cpp:1300are unaffected.PeptideAndProteinQuant's sample grain,ProteinQuantifier, MSstats/Triqler and the QPX exporters are untouched — those are later steps.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests