Repository navigation
[FIX,TEST] file+channel level: a stored zero is not a detected peptide - #9852
Conversation
|
yeah obvious bug |
ffa250d to
c7f6701
Compare
|
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 (2)
📝 WalkthroughWalkthroughFile/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. ChangesProtein quantification aggregation
Possibly related PRs
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp (1)
1560-1569: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCorrect 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 thatcalculateProteinAbundances_()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
#9851covers 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
📒 Files selected for processing (4)
CHANGELOGsrc/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cppsrc/tests/class_tests/openms/source/PeptideAndProteinQuant_test.cppsrc/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
c7f6701 to
1f519da
Compare
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
…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]>
Summary
calculateFileAndChannelLevelProteinAbundances_contributed one value per selected peptide and(fraction, file, channel)cell whether or not that peptide had a reporter there.IsobaricChannelExtractorwrites a reporter it could not find — or one belowmin_reporter_intensity— as an explicit0.0and 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 theabundance|<file>|ch<N>columns and the QPXpgview.Only detected (positive) abundances are collected and counted now.
sumis numerically unaffected, since summing zeros changes nothing.The previous
if (all_abundances.empty()) continue;guard was unreachable — the key was only ever created by apush_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):The old
median(x, 0) = x/2reported 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_abundancesarray 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
medianundertop:include_all(the shipped isobaric path —IsobaricWorkflowsets it), thesuminvariant, and the per-file gate now counting detected peptides.PeptideAndProteinQuant_test+TOPP_ProteinQuantifier_*+TOPP_IsobaricWorkflow_*+TOPP_ProteomicsLFQ_*.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
NAand drops features with too few measurements per run; scp shipszeroIsNA()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 innormalizePeptides_(), 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.
codex/fix-best-charge-and-fractionfix/file-channel-zeros-not-detectedfix/zero-abundances-not-evidencefix/qpx-feature-key-and-atomic-exportsrc/tests/topp/IsobaricWorkflow_1_out.consensusXML, on adjacent lines — [FIX,TEST] PeptideAndProteinQuant: a stored zero is not a detected peptide #9851 the sample-levelindistinguishable_proteins_1_abundances, [FIX,TEST] file+channel level: a stored zero is not a detected peptide #9852 the..._file_channel_level_abundance. Resolution: take both. They are the two halves of one fix, and afterwards the two arrays are byte-identical, which is the invariant to check (one file × N channels means a cell is a sample).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
Tests