Skip to content

[FIX,TEST] ProteinQuantifier: a ratio needs two quantified samples - #9854

Merged
timosachsenberg merged 1 commit into
developfrom
fix/protein-quantifier-ratio-columns
Aug 4, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
fix/protein-quantifier-ratio-columns

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two defects in ProteinQuantifier's -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 — the fixture that reproduces them contains no zero-intensity handles at all.

Whether these columns should exist at all is a separate question, raised in #9853. This PR makes them correct; that issue asks whether to delete them.

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 no end() check:

double ref_abundance = q.second.total_abundances.find(0)->second;                 // :726
double light  = q.second.total_abundances.find(0)->second;                        // :738
double middle = q.second.total_abundances.find(1)->second;                        // :739
double heavy  = q.second.total_abundances.find(2)->second;                        // :740

The only guard is if (q.second.total_abundances.empty()) continue;, which says the map has some key, not key 0. Fifteen lines earlier the same map is read defensively for the abundance columns (pos != end() ? pos->second : 0.0), so the writer contradicts itself about the same map.

Where the key does exist as 0.0 ("not detected") the division gives ±inf/NaN. Where it is absent, the old fallback printed 0.0 — which in a log₂-ratio column asserts exactly equal to the reference, so a protein that could not be quantified was reported as unchanged.

Reproducible on the shipped fixture with stock defaults, exit code 0:

$ ProteinQuantifier -in src/tests/topp/ProteinQuantifier_input.consensusXML -ratiosSILAC -out out.csv
"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.

Quantified proteins are byte-identical. The original log(x) / log(2.0) is kept rather than std::log2(x), which can differ in the last ulp, and the self-ratio stays the bare int 0 rather than becoming 0.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, and not for a single sample — while writeProteinTable_ wrote the values outside that branch split.

invocation header row
-ratios -file_and_channel_level_output true 7 fields 10 fields
-ratios on single-sample input 5 fields 6 fields

pandas.read_csv on a row with more fields than the header promotes column 0 to an index and shifts every value. The body now uses the header's guard.

Why this was never caught, and a trap for the next person

TOPP_ProteinQuantifier_12 and _13 are the only tests exercising these flags, and both pass -top:include_all — the one configuration in which no sample key can be missing.

There is a second trap worth recording: FuzzyDiff compares these files numerically and reports "No numeric differences were found" between nan and -inf. A reference diff alone therefore 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.

Verification

check pre-fix post-fix
TOPP_ProteinQuantifier_29_out2 (textual nan / no inf) ❌ Error regular expression found in output. Regex=[inf] ✅
TOPP_ProteinQuantifier_30_out1 (header/row field counts) ❌ ✅
TOPP_ProteinQuantifier_29_out1 (reference diff) ⚠️ passes either way — see the FuzzyDiff note ✅

New _29 covers the sparse case with one finite ratio next to two nan, so the finite path is pinned as well as the missing one; _30 covers the header/body mismatch.

138 tests across ProteinQuantifier, PeptideAndProteinQuant, IsobaricWorkflow and ProteomicsLFQ pass. No existing reference file changes.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

Summary by CodeRabbit

  • Bug Fixes

    • Protein ratios now show nan when abundance data is missing or non-positive, avoiding invalid or misleading values.
    • Ratio columns are omitted when the selected output format does not support them, keeping headers and data aligned.
  • Documentation

    • Clarified when ratio and SILAC ratio calculations apply and how unavailable values are represented.
  • Tests

    • Added regression coverage for missing abundances and unsupported ratio output modes.

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.

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

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: ec812290-5716-4e86-b129-dfb778ad74ca

📥 Commits

Reviewing files that changed from the base of the PR and between 186ce27 and 6c2d413.

📒 Files selected for processing (5)
  • CHANGELOG
  • src/tests/topp/CMakeLists.txt
  • src/tests/topp/ProteinQuantifier_29_output.txt
  • src/tests/topp/ProteinQuantifier_30_output.txt
  • src/topp/ProteinQuantifier.cpp

📝 Walkthrough

Walkthrough

Changes

ProteinQuantifier ratio handling

Layer / File(s) Summary
Ratio validation and output alignment
src/topp/ProteinQuantifier.cpp, CHANGELOG
Ratio output now requires present, positive abundances. Invalid values produce nan. Ratio fields are emitted only when matching headers exist.
Ratio regression coverage
src/tests/topp/CMakeLists.txt, src/tests/topp/ProteinQuantifier_29_output.txt, src/tests/topp/ProteinQuantifier_30_output.txt
Tests cover sparse SILAC abundances and file-and-channel-level output without ratio columns.

Possibly related issues

Possibly related PRs

  • OpenMS/OpenMS#9793: Both changes update ProteinQuantifier ratio output and add related regression coverage.

Suggested reviewers: cbielow, copilot

Poem

A rabbit checks each ratio line,
And marks bad numbers nan in time.
Sparse samples no longer leap,
Headers and rows their promise keep.
The tests now guard the burrow bright.

🚥 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 ProteinQuantifier ratio fix and matches the main changes in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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/protein-quantifier-ratio-columns

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.

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