Skip to content

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

Merged
timosachsenberg merged 2 commits into
developfrom
fix/file-channel-zeros-not-detected
Aug 4, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
fix/file-channel-zeros-not-detected

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #9847 — base is codex/fix-best-charge-and-fraction, which rewrites the function this touches. Merge after it. Companion to #9851, which fixes the same defect at the sample level.

Summary

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 (IsobaricChannelExtractor.cpp:620/658/663), so undetected peptides both satisfied the per-file "at least N peptides" gate and entered the aggregate.

With the default top:aggregate 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. This is the array that feeds the abundance|<file>|ch<N> columns and the QPX pg view.

Only detected (positive) abundances are collected and counted now. sum is numerically unaffected, since summing zeros changes nothing.

The previous if (all_abundances.empty()) continue; guard was unreachable — the key was only ever created by a push_back — and is now exactly the case that must not be skipped, so a cell whose peptides were all undetected keeps its zero entry instead of dropping out of the parallel (filename, channel, abundance) arrays.

The reference change is the proof

IsobaricWorkflow_1_out.consensusXML — one changed line, the file+channel 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. The four channels where both peptides were detected are byte-identical.

One thing to know while reviewing

That reference is internally inconsistent until #9851 lands: the sample-level indistinguishable_proteins_1_abundances array in the same file still carries the halved values, because that is the other half of the same defect and is independent of #9847. The two arrays agree once both PRs are merged — they must, since for unfractionated isobaric data one (file, channel) cell is one sample.

Verification

  • New class-test section covers median under top:include_all (the shipped isobaric path — IsobaricWorkflow sets it), the sum invariant, and the per-file gate now counting detected peptides.
  • 129/129 PeptideAndProteinQuant_test + TOPP_ProteinQuantifier_* + TOPP_IsobaricWorkflow_* + TOPP_ProteomicsLFQ_*.
  • Label-free is unaffected — a feature that was not found has no entry at all, rather than an entry of zero.

Consistency with other tools

Treating a zero reporter as missing rather than as a measurement is the standard convention: MSstatsTMT treats missing values as censored NA and drops features with too few measurements per run; scp ships zeroIsNA() because "0 values are not true zeros but rather signal that is too weak to be detected"; TMT-Integrator filters low-intensity PSMs and requires reference-channel intensity > 0. OpenMS already applied the rule in normalizePeptides_(), just not here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ


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.

Summary by CodeRabbit

  • Bug Fixes

    • Improved protein abundance aggregation for isobaric data by excluding undetected peptide values from peptide counts and non-sum calculations.
    • Preserved zero-valued reporter entries when all peptides are undetected.
    • Ensured top-N filtering counts only detected peptides across file/channel and fraction-group results.
    • Kept sum aggregation and label-free quantification behavior unchanged.
    • Updated calculated abundance results for affected isobaric protein outputs.
  • Tests

    • Added regression coverage for zero-intensity reporters and aggregation behavior.

@jpfeuffer

Copy link
Copy Markdown
Contributor

yeah obvious bug

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b862023-0ece-4acf-9b0d-95d134e92393

📥 Commits

Reviewing files that changed from the base of the PR and between 1f519da and 178742a.

📒 Files selected for processing (4)
  • CHANGELOG
  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
  • src/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cpp
  • src/tests/topp/IsobaricWorkflow_1_out.consensusXML
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
  • src/tests/topp/IsobaricWorkflow_1_out.consensusXML

📝 Walkthrough

Walkthrough

File/channel and fraction-group protein aggregation now excludes undetected peptide values from counts and non-sum calculations. Zero-only cells remain in output arrays. Tests and workflow results cover median, sum, and top-N behavior.

Changes

Protein quantification aggregation

Layer / File(s) Summary
Zero-aware protein aggregation
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp, CHANGELOG
File/channel and fraction-group aggregation uses only positive peptide abundances for counts, top-N eligibility, and non-sum aggregation. Zero-only cells remain represented with zero values.
Regression coverage and workflow output
src/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cpp, src/tests/topp/IsobaricWorkflow_1_out.consensusXML
Tests cover median, sum, and top-N behavior. The PROTB abundance fixture uses recalculated values.

Possibly related PRs

Poem

A rabbit counts the signals bright,
And leaves undetected zeros light.
The sums stay true,
Top-N counts the few,
While medians use measured might.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix: stored zero intensities are not detected peptides at the file/channel level.
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.
✨ 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/file-channel-zeros-not-detected

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)

1560-1569: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Correct the sample-level filtering claim.

The file/channel path now excludes stored zero values. The current sample-level path still aggregates them. Keep both comments limited to the file/channel behavior, or state that sample-level handling is separate work.

  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp#L1560-L1569: replace the statement that calculateProteinAbundances_() uses the same rule.
  • CHANGELOG#L51-L51: replace “same rule as at the sample level” with an accurate scope statement.

Based on PR objectives, PR #9851 covers the corresponding sample-level fix.

🤖 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 1560 - 1569, The comment in PeptideAndProteinQuant.cpp should describe
only the file/channel filtering implemented here: remove the claim that
calculateProteinAbundances_() and normalizePeptides_() use the same rule, or
explicitly identify sample-level handling as separate work. In CHANGELOG at the
specified line, replace “same rule as at the sample level” with wording that
accurately limits the change to file/channel behavior; update both affected
files as requested.
🤖 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 1560-1569: The comment in PeptideAndProteinQuant.cpp should
describe only the file/channel filtering implemented here: remove the claim that
calculateProteinAbundances_() and normalizePeptides_() use the same rule, or
explicitly identify sample-level handling as separate work. In CHANGELOG at the
specified line, replace “same rule as at the sample level” with wording that
accurately limits the change to file/channel behavior; update both affected
files as requested.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 702cf4a3-c01e-445a-8722-6a94ab293eee

📥 Commits

Reviewing files that changed from the base of the PR and between 4af0cde and c7f6701.

📒 Files selected for processing (4)
  • CHANGELOG
  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
  • src/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cpp
  • src/tests/topp/IsobaricWorkflow_1_out.consensusXML

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 force-pushed the fix/file-channel-zeros-not-detected branch from c7f6701 to 1f519da Compare August 4, 2026 17:49
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
timosachsenberg merged commit 186ce27 into develop Aug 4, 2026
11 checks passed
@timosachsenberg
timosachsenberg deleted the fix/file-channel-zeros-not-detected branch August 4, 2026 19:20
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.

2 participants