Repository navigation
[FIX,TEST] ProteinQuantifier: a ratio needs two quantified samples - #9854
Merged
Merged
Conversation
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
Contributor
|
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 (5)
📝 WalkthroughWalkthroughChangesProteinQuantifier ratio handling
Possibly related issues
Possibly related PRs
Suggested reviewers: 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 |
This was referenced Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two defects in
ProteinQuantifier's-ratios/-ratiosSILACcolumns, 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_abundancesis deliberately sparse —calculateProteinAbundances_skips a sample in which the protein has fewer thantop:Ndetected peptides. The ratio blocks read it with noend()check:The only guard is
if (q.second.total_abundances.empty()) continue;, which says the map has some key, not key0. 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 printed0.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:
A ratio is now written only where both samples carry a positive abundance, and
nanotherwise, viaSVOutStream::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 thanstd::log2(x), which can differ in the last ulp, and the self-ratio stays the bare int0rather than becoming0.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 forfile_and_channel_level_output, and not for a single sample — whilewriteProteinTable_wrote the values outside that branch split.-ratios -file_and_channel_level_output true-ratioson single-sample inputpandas.read_csvon 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_12and_13are 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
nanand-inf. A reference diff alone therefore cannot fail on defect 1 —_29_out1passes against the old binary._29_out2asserts the token textually viaFAIL_REGULAR_EXPRESSION, and that one does fail pre-fix.Verification
TOPP_ProteinQuantifier_29_out2(textualnan/ noinf)Error regular expression found in output. Regex=[inf]TOPP_ProteinQuantifier_30_out1(header/row field counts)TOPP_ProteinQuantifier_29_out1(reference diff)New
_29covers the sparse case with one finite ratio next to twonan, so the finite path is pinned as well as the missing one;_30covers 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
nanwhen abundance data is missing or non-positive, avoiding invalid or misleading values.Documentation
Tests