Skip to content

[FIX,TEST] PeptideAndProteinQuant: a stored zero is not a detected peptide - #9851

Merged
timosachsenberg merged 4 commits into
developfrom
fix/zero-abundances-not-evidence
Aug 4, 2026
Merged

timosachsenberg merged 4 commits into
developfrom
fix/zero-abundances-not-evidence

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

One defect — an abundance stored as 0.0 is "not detected", not a measured absence — at three sites in PeptideAndProteinQuant. Findings 13 of the #9847 review, plus a larger instance found while verifying it.

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). So every peptide of an isobaric run carries an entry for every channel, and three places read those entries as observations.

The class had already ruled the other way, twice: normalizePeptides_() excludes zeros from its medians — with a comment citing MSstatsTMT, isobar and scp — and the charge-prevalence count in best_charge_and_fraction skips <= 0.0. The inconsistency is the defect.

1. Protein aggregation — not opt-in, and the serious one

calculateProteinAbundances_ pushed every entry into the per-sample list, where it both counted towards the "enough peptides in this sample" gate and fed the aggregate. With the default top:aggregate median, a channel in which most of a protein's peptides went undetected got a median of exactly 0 — the protein reported absent from a sample it was measured in. With mean it was diluted toward 0.

This contradicts the tool's own documentation:

(intensity weighted) mean and median ignore missing cases, averaging only present values. … sum implicitly treats missing values as zero

Only detected abundances are aggregated and counted now. sum is numerically unaffected. Samples are tracked separately from their values, so a sample where nothing was detected keeps its zero entry under top:include_all instead of disappearing.

This is the shipped isobaric path. 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.

2 & 3. consensus:fix_peptides selection and ranking

Both branches ranked by the size() of the sample→abundance map, so every peptide of an isobaric run reported the full channel count. top:N 0 — "all peptides that occur in every sample" — admitted every peptide seen anywhere, i.e. stopped filtering; top:N > 0 tied them all and let the abundance tie-break decide alone, so a peptide with a large signal in 2 of 10 channels took the slot from one genuinely measured in 6. Both now count samples with a positive abundance.

These two are opt-in: consensus:fix_peptides is off by default and set by no OpenMS tool.

The reference change is the proof

IsobaricWorkflow_1_out.consensusXML — one changed line, the protein-abundance array of group 1 (PROTB, two peptides):

MYFINGERK          0    3091       0    2050    2127       0       0    2188       0       0
GIRAFFERK      17301   11810    8584   10510   16390   13120   10740    7489   15770   11930
                  ↑             ↑                       ↑       ↑               ↑       ↑
channels where one peptide has no reporter: 1, 3, 6, 7, 9, 10
channels whose abundance doubles:           1, 3, 6, 7, 9, 10   (ratio exactly 2.000000)

The old median(x, 0) = x/2 reported the protein at exactly half its single measurement in those six channels. The four channels where both peptides were detected are byte-identical.

Verification

  • Both aggregation sections confirmed to fail without the fix: 0 (median) and 333.33 (mean) where the protein was measured at 1000. The two fix_peptides sections likewise: 600 instead of 100, and 1000 instead of 100.
  • 51/51 PeptideAndProteinQuant_test + TOPP_ProteinQuantifier_* + TOPP_IsobaricWorkflow_*; 63/63 including the QPX/Arrow tests.
  • Label-free is unaffected — a feature that was not found has no entry at all, rather than an entry of zero. All 97 TOPP_ProteomicsLFQ_*/MzTab tests unchanged.
  • The five in-tree fix_peptides tests use a fixture with no zero intensities, so they do not move.

Two things worth knowing

ProteinQuantifier's TSV writer prints 0.0 for a sample with no entry, so at strict defaults (top:N 3, no include_all) a sample that is now correctly unquantified still shows as 0.0. The internal state is right; the writer cannot distinguish absent from zero. Pre-existing, unchanged here.

The same pattern exists in calculateFileAndChannelLevelProteinAbundances_, which feeds the abundance|<file>|ch<N> columns and the QPX pg view. #9847 rewrites that function, so fixing it here would conflict; it is a follow-up on top of that PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

Summary by CodeRabbit

  • Bug Fixes

    • Improved isobaric protein quantification by treating only positive abundances as detected samples.
    • Prevented missing reporter channels from distorting median and mean protein abundance calculations.
    • Improved peptide selection and ranking based on genuinely quantified samples.
    • Preserved explicit zero-valued entries when using top:include_all.
  • Tests

    • Added regression coverage for zero-valued reporters, aggregation methods, ranking, and undetected samples.
  • Documentation

    • Clarified how zero abundances are interpreted in consensus:fix_peptides.

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.

…curs 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
@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: 14975247-00dc-48cd-98aa-82b858fc7281

📥 Commits

Reviewing files that changed from the base of the PR and between 0a45ef1 and c27e370.

📒 Files selected for processing (4)
  • CHANGELOG
  • src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h
  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
  • src/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cpp

📝 Walkthrough

Walkthrough

The change counts only positive peptide and protein abundances during filtering, ranking, and aggregation. Zero abundance represents non-detection. Regression tests and fixtures cover the updated behavior.

Changes

Positive abundance quantification

Layer / File(s) Summary
Positive-abundance helper and peptide selection
src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h, src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp, CHANGELOG
Added countQuantifiedSamples_. Peptide filtering and ranking now count positive abundances. Documentation defines zero abundance as non-detection.
Protein abundance aggregation
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
Protein aggregation excludes zero abundances from validation, top-N selection, and median or mean aggregation. It retains zero results for undetected samples when include_all is enabled.
Regression coverage and fixtures
src/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cpp, src/tests/topp/IsobaricWorkflow_1_out.consensusXML, src/tests/topp/THIRDPARTY/*
Added regression tests for detection counts, ranking, aggregation, and enough-peptides behavior. Updated expected workflow and binary fixture data.

Sequence Diagram(s)

sequenceDiagram
  participant ConsensusFeatures
  participant PeptideAndProteinQuant
  participant ProteinAggregation
  ConsensusFeatures->>PeptideAndProteinQuant: provide reporter abundances
  PeptideAndProteinQuant->>PeptideAndProteinQuant: count positive detections
  PeptideAndProteinQuant->>ProteinAggregation: select detected peptide abundances
  ProteinAggregation-->>PeptideAndProteinQuant: aggregated protein abundances
Loading

Possibly related PRs

  • OpenMS/OpenMS#9793: Modifies protein abundance aggregation and detection handling in PeptideAndProteinQuant.
  • OpenMS/OpenMS#9847: Modifies quantification ranking to count positive abundances.
  • OpenMS/OpenMS#9852: Modifies related zero-abundance handling in protein aggregation and peptide selection.

Poem

A rabbit counts the signals bright,
And leaves zero out of sight.
Peptides rank by detections true,
Proteins keep the zeros due.
Tests record each measured light. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix that stored zero abundances do not represent detected peptides and indicates related tests.
✨ 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/zero-abundances-not-evidence

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.

🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp (1)

1301-1309: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Put the if braces on aligned lines.

Line 1306 puts both braces on the condition line. Put each brace on its own aligned line.

Proposed fix
-      if (sample_abundance.second > 0.0) { ++n_quantified; }
+      if (sample_abundance.second > 0.0)
+      {
+        ++n_quantified;
+      }

As per coding guidelines, “braces on their own aligned lines; always use braces for blocks.”

🤖 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/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp` around
lines 1301 - 1309, Update the conditional block in
PeptideAndProteinQuant::countQuantifiedSamples_ so its opening and closing
braces are each on separate, vertically aligned lines, while preserving the
existing increment behavior.

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/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp`:
- Around line 1301-1309: Update the conditional block in
PeptideAndProteinQuant::countQuantifiedSamples_ so its opening and closing
braces are each on separate, vertically aligned lines, while preserving the
existing increment behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c11d848-f5e7-47d6-8a43-d526ac0f7ac7

📥 Commits

Reviewing files that changed from the base of the PR and between 4aece61 and 55a68ee.

📒 Files selected for processing (4)
  • CHANGELOG
  • src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h
  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
  • src/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cpp

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
@timosachsenberg timosachsenberg changed the title [FIX,TEST] fix_peptides: a stored zero is not a sample the peptide occurs in [FIX,TEST] PeptideAndProteinQuant: a stored zero is not a detected peptide 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
timosachsenberg added a commit that referenced this pull request Aug 4, 2026
Same defect as at the sample level, in the array that feeds the
abundance|<file>|ch<N> columns and the QPX pg view. Stacked on #9847, which
rewrites this function.

calculateFileAndChannelLevelProteinAbundances_ contributed one value per selected
peptide and (fraction, file, channel) cell whether or not that peptide had a
reporter there. IsobaricChannelExtractor writes a reporter it could not find - or
one below 'min_reporter_intensity' - as an explicit 0.0 and inserts the handle
regardless, so undetected peptides both satisfied the per-file "at least N
peptides" gate and entered the aggregate. With the default median, a cell in
which most of a protein's peptides went undetected was reported as 0: absent from
a channel the protein was measured in.

Only detected (positive) abundances are collected and counted now. 'sum' is
numerically unaffected. A cell whose peptides were all undetected still keeps its
zero entry, so it does not drop out of the parallel (filename, channel,
abundance) arrays - the previous 'if (all_abundances.empty()) continue' guard was
unreachable, since the key was only ever created by a push, and is now the case
that must NOT be skipped.

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

Note the reference is internally inconsistent until #9851 lands: the sample-level
'abundances' array in the same file still carries the halved values, because that
is the other half of this fix and is independent of #9847. The two agree once
both are merged.

Label-free data is unaffected: a feature that was not found has no entry at all.
129/129 PeptideAndProteinQuant/ProteinQuantifier/IsobaricWorkflow/ProteomicsLFQ
tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
@timosachsenberg
timosachsenberg merged commit 6024dce into develop Aug 4, 2026
7 checks passed
@timosachsenberg
timosachsenberg deleted the fix/zero-abundances-not-evidence branch August 4, 2026 17:42
timosachsenberg added a commit that referenced this pull request Aug 4, 2026
Same defect as at the sample level, in the array that feeds the
abundance|<file>|ch<N> columns and the QPX pg view. Stacked on #9847, which
rewrites this function.

calculateFileAndChannelLevelProteinAbundances_ contributed one value per selected
peptide and (fraction, file, channel) cell whether or not that peptide had a
reporter there. IsobaricChannelExtractor writes a reporter it could not find - or
one below 'min_reporter_intensity' - as an explicit 0.0 and inserts the handle
regardless, so undetected peptides both satisfied the per-file "at least N
peptides" gate and entered the aggregate. With the default median, a cell in
which most of a protein's peptides went undetected was reported as 0: absent from
a channel the protein was measured in.

Only detected (positive) abundances are collected and counted now. 'sum' is
numerically unaffected. A cell whose peptides were all undetected still keeps its
zero entry, so it does not drop out of the parallel (filename, channel,
abundance) arrays - the previous 'if (all_abundances.empty()) continue' guard was
unreachable, since the key was only ever created by a push, and is now the case
that must NOT be skipped.

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

Note the reference is internally inconsistent until #9851 lands: the sample-level
'abundances' array in the same file still carries the halved values, because that
is the other half of this fix and is independent of #9847. The two agree once
both are merged.

Label-free data is unaffected: a feature that was not found has no entry at all.
129/129 PeptideAndProteinQuant/ProteinQuantifier/IsobaricWorkflow/ProteomicsLFQ
tests pass.

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
The third and last copy of this aggregation. calculateFractionGroupLevelProteinAbundances_
pushed every stored abundance into its per-(fraction group, label) cell, zeros
included, so undetected peptides both satisfied its 'top_n' gate and dragged the
cell's median or mean towards zero - exactly what the sample level (#9851) and
the file+channel level (the commit before this one) already fix.

It now contributes only positive abundances while still touching every cell the
selected peptides reach, so a cell whose peptides all went undetected reports
zero rather than dropping out. Same idiom as its two siblings.

This is not a theoretical third site. The three levels describe one measurement
at different granularities and must agree where the granularities coincide, and
they did not: IsobaricWorkflow_1 is one file x 10 channels, so a cell IS a
sample, yet its fraction-group array sat at exactly half the sample-level values
in the six channels where a peptide went undetected - the signature of
mean(x, 0). All three arrays are now byte-identical there, which is the
invariant, and that one line of IsobaricWorkflow_1_out.consensusXML is the only
reference value that moves. The array feeds ProteinData::fraction_group_abundances,
which is what the QPX 1.1 pg view is keyed on.

The new class-test section mirrors the file+channel one on the same fixture and
additionally asserts the two levels agree. Confirmed to fail without the fix:
the cell reports 0 instead of 1000 (lines 1732/1737), the top_n gate section
fails at 1774, and TOPP_IsobaricWorkflow_1_out1 fails once the tool is re-run.

176 tests across PeptideAndProteinQuant, ProteinQuantifier, IsobaricWorkflow,
ProteomicsLFQ, MzTab and QPX pass.

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
#9852)

* [FIX,TEST] file+channel level: a stored zero is not a detected peptide

Same defect as at the sample level, in the array that feeds the
abundance|<file>|ch<N> columns and the QPX pg view. Stacked on #9847, which
rewrites this function.

calculateFileAndChannelLevelProteinAbundances_ contributed one value per selected
peptide and (fraction, file, channel) cell whether or not that peptide had a
reporter there. IsobaricChannelExtractor writes a reporter it could not find - or
one below 'min_reporter_intensity' - as an explicit 0.0 and inserts the handle
regardless, so undetected peptides both satisfied the per-file "at least N
peptides" gate and entered the aggregate. With the default median, a cell in
which most of a protein's peptides went undetected was reported as 0: absent from
a channel the protein was measured in.

Only detected (positive) abundances are collected and counted now. 'sum' is
numerically unaffected. A cell whose peptides were all undetected still keeps its
zero entry, so it does not drop out of the parallel (filename, channel,
abundance) arrays - the previous 'if (all_abundances.empty()) continue' guard was
unreachable, since the key was only ever created by a push, and is now the case
that must NOT be skipped.

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

Note the reference is internally inconsistent until #9851 lands: the sample-level
'abundances' array in the same file still carries the halved values, because that
is the other half of this fix and is independent of #9847. The two agree once
both are merged.

Label-free data is unaffected: a feature that was not found has no entry at all.
129/129 PeptideAndProteinQuant/ProteinQuantifier/IsobaricWorkflow/ProteomicsLFQ
tests pass.

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

* [FIX,TEST] fraction group level: a stored zero is not a detected peptide

The third and last copy of this aggregation. calculateFractionGroupLevelProteinAbundances_
pushed every stored abundance into its per-(fraction group, label) cell, zeros
included, so undetected peptides both satisfied its 'top_n' gate and dragged the
cell's median or mean towards zero - exactly what the sample level (#9851) and
the file+channel level (the commit before this one) already fix.

It now contributes only positive abundances while still touching every cell the
selected peptides reach, so a cell whose peptides all went undetected reports
zero rather than dropping out. Same idiom as its two siblings.

This is not a theoretical third site. The three levels describe one measurement
at different granularities and must agree where the granularities coincide, and
they did not: IsobaricWorkflow_1 is one file x 10 channels, so a cell IS a
sample, yet its fraction-group array sat at exactly half the sample-level values
in the six channels where a peptide went undetected - the signature of
mean(x, 0). All three arrays are now byte-identical there, which is the
invariant, and that one line of IsobaricWorkflow_1_out.consensusXML is the only
reference value that moves. The array feeds ProteinData::fraction_group_abundances,
which is what the QPX 1.1 pg view is keyed on.

The new class-test section mirrors the file+channel one on the same fixture and
additionally asserts the two levels agree. Confirmed to fail without the fix:
the cell reports 0 instead of 1000 (lines 1732/1737), the top_n gate section
fails at 1774, and TOPP_IsobaricWorkflow_1_out1 fails once the tool is re-run.

176 tests across PeptideAndProteinQuant, ProteinQuantifier, IsobaricWorkflow,
ProteomicsLFQ, MzTab and QPX pass.

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]>
timosachsenberg added a commit that referenced this pull request Aug 4, 2026
…9854)

Two defects in the '-ratios' / '-ratiosSILAC' columns, found while auditing the
"a stored zero is not a detected peptide" fixes (#9851, #9852). Both are
pre-existing and independent of those.

1. Undefined behaviour, and an unquantified protein reported as unchanged.

total_abundances is deliberately sparse: calculateProteinAbundances_ skips a
sample in which the protein has fewer than 'top:N' detected peptides. The ratio
blocks read it with find(0)->second and find(0)/find(1)/find(2)->second and no
end() check. The only guard is 'if (total_abundances.empty()) continue;', which
says the map has some key, not key 0 -- and fifteen lines earlier the same map is
read defensively for the abundance columns, so the writer contradicted itself.

Where the key did exist as 0.0 ("not detected") the division gave +-inf or NaN;
where it was absent the fallback printed 0.0, which in a log2-ratio column
asserts the sample is exactly equal to the reference. Reproducible on the shipped
fixture with stock defaults, exit code 0:

  "Protein" 1 0.9097 4  200.0 30.0 0.0  -inf -inf -2.7369655941662060

A ratio is now written only where both samples carry a positive abundance, and
'nan' otherwise, via SVOutStream::writeValueOrNan -- the missing-value
convention MSstats and every comparable tool use. Ratios of quantified proteins
are byte-identical: the original log(x)/log(2.0) is kept rather than std::log2,
which can differ in the last ulp, and the self-ratio stays the bare int 0.

2. Value columns the header never emitted.

writeProteinTableHeader_ emits the ratio names only in the branch it shares with
the sample-level abundance columns -- not for 'file_and_channel_level_output',
not for a single sample -- while the body wrote the values outside that branch
split. '-ratios -file_and_channel_level_output true' produced a 7-field header
over a 10-field row; pandas.read_csv then promotes column 0 to an index and
shifts every value. The body now uses the header's guard.

Tests. Neither defect was caught because TOPP_ProteinQuantifier_12/13, the only
tests exercising these flags, both pass 'top:include_all' -- the one
configuration in which no sample key can be missing. New _29 covers the sparse
case (one finite ratio next to two nan, so the finite path is pinned too) and
_30 the header/body mismatch.

Note for anyone extending this: FuzzyDiff compares these files numerically and
reports "No numeric differences were found" between 'nan' and '-inf', so a
reference diff alone CANNOT fail on defect 1 -- _29_out1 passes against the old
binary. _29_out2 asserts the token textually via FAIL_REGULAR_EXPRESSION, and
that one does fail pre-fix, as does _30_out1.

Whether these columns should exist at all is a separate question, raised in #9853:
nothing in the tree consumes them, and the field exchanges intensities rather
than precomputed ratios.

138 ProteinQuantifier / PeptideAndProteinQuant / IsobaricWorkflow / ProteomicsLFQ
tests pass; no existing reference file changes.


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