Repository navigation
fix: LinearResampler right_index clamped to wrong container size - #9127
Conversation
The bounds clamp for right_index used distance(first, last) (number of raw data points) instead of number_resampled_points. When resampled points far outnumber raw points (e.g. fine spacing over a wide m/z range), right_index pointed thousands of positions backward in the resampled grid, producing extreme intensity spikes. Bug was introduced in 2008 (8f00f1b) but masked because the TOPP Resampler tool uses LinearResamplerAlign which has an independent correct implementation. Adds a regression test with 3 raw points resampled at 0.1 spacing (101 resampled points >> 3 raw points). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughLinearResampler::raster now clamps the right_index using the resampled peak count (number_resampled_points - 1) and handles the last-point case by adding raw intensity directly when left_index == right_index. A regression test was added for scenarios with far more resampled than raw points. Changes
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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/tests/class_tests/openms/source/LinearResampler_test.cpp (1)
127-139: Consider switching numeric regression checks toFuzzyDiff.Lines 127-139 use scalar numeric assertions; a small FuzzyDiff-based reference check would better guard distribution-shape regressions in future changes.
As per coding guidelines, "Use
FuzzyDifffor numeric comparisons in tests; keep test data small and use whitelists for unstable lines".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/class_tests/openms/source/LinearResampler_test.cpp` around lines 127 - 139, The test uses scalar assertions TEST_REAL_SIMILAR and TEST_EQUAL on the spectrum intensities (variables/spec elements like spec, sum and spec[i].getIntensity()), so replace these with FuzzyDiff-based checks: compute the vector of intensities (or the summed value) and compare it to a small reference vector/value via FuzzyDiff (or FuzzyDiff::compare) with an appropriate epsilon, and mark any inherently unstable lines with the whitelist mechanism; update the assertions that check total intensity and per-point maxima to use FuzzyDiff comparisons instead of TEST_REAL_SIMILAR/TEST_EQUAL to better detect distribution-shape regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/tests/class_tests/openms/source/LinearResampler_test.cpp`:
- Around line 127-139: The test uses scalar assertions TEST_REAL_SIMILAR and
TEST_EQUAL on the spectrum intensities (variables/spec elements like spec, sum
and spec[i].getIntensity()), so replace these with FuzzyDiff-based checks:
compute the vector of intensities (or the summed value) and compare it to a
small reference vector/value via FuzzyDiff (or FuzzyDiff::compare) with an
appropriate epsilon, and mark any inherently unstable lines with the whitelist
mechanism; update the assertions that check total intensity and per-point maxima
to use FuzzyDiff comparisons instead of TEST_REAL_SIMILAR/TEST_EQUAL to better
detect distribution-shape regressions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 820fcdb1-485a-478a-83f4-52e281eff48d
📒 Files selected for processing (2)
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.hsrc/tests/class_tests/openms/source/LinearResampler_test.cpp
…s intensity When a raw data point falls exactly on the last resampled grid point, left_index == right_index and both interpolation distances become 0, silently dropping the point's entire intensity. Add a guard that assigns the full intensity directly to the single bin in this case. Fixes the LinearResampler_test regression introduced in 4d4f091.
Add missing changelog entries for commits merged after the last sync: - #9127: Fix LinearResampler right_index bounds clamping (intensity spike bug) - #9126: CometAdapter Bruker .d DDA-PASEF input support - #9121: PeptideDataBaseSearchFI runtime search diagnostics and tolerance estimation - #9122: PeptideDataBaseSearchFI automatic mass accuracy calibration (two-pass search) - #9123: PeptideDataBaseSearchFI protein-level FDR (picked-protein) - #9129: OpenSwathWorkflow Bruker DIA MS2 frame aggregation, denoising, and streaming Co-authored-by: Copilot <[email protected]>
Add missing changelog entries for commits merged after the last sync: - #9127: Fix LinearResampler right_index bounds clamping (intensity spike bug) - #9126: CometAdapter Bruker .d DDA-PASEF input support - #9121: PeptideDataBaseSearchFI runtime search diagnostics and tolerance estimation - #9122: PeptideDataBaseSearchFI automatic mass accuracy calibration (two-pass search) - #9123: PeptideDataBaseSearchFI protein-level FDR (picked-protein) - #9129: OpenSwathWorkflow Bruker DIA MS2 frame aggregation, denoising, and streaming Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
…dge cases (#9460) (#9526) Adds regression guards for the folded LinearResampler spike fix (#9127). The area-preserving raster() distributes each raw point's intensity onto its two grid neighbours and divides by the grid spacing (never by the raw-point gap), so a lone spike or coincident (zero-width interval) raw points must conserve total intensity, never be amplified into a spurious larger peak, and never produce NaN/Inf. The existing sections never exercised these degenerate inputs. Three [EXTRA] sections on raster(): - single data point (start_pos == end_pos): one output point carrying all intensity - isolated off-grid spike: area preserved, split across the two neighbours, not amplified, and not leaked to the far ends of the spectrum - coincident raw m/z (zero-width interval): total intensity conserved, all finite Verified: builds clean and the test runs PASSED. Co-authored-by: Claude Opus 4.8 <[email protected]>
Summary
LinearResampler::raster()—right_indexwas clamped todistance(first, last) - 1(number of raw points) instead ofnumber_resampled_points - 1, causing intensity to be distributed to completely wrong positions when the resampled grid has more points than the raw dataFixes #9119
Details
The bug was introduced in 2008 (commit 8f00f1b, "Adapted to STL-debug mode") when bounds clamping was added to fix an out-of-bounds access under STL debug mode. It remained latent because the TOPP
Resamplertool usesLinearResamplerAlign, which has an independent correct implementation.The one-line fix changes line 94 in
LinearResampler.h:Test plan
LinearResampler_testtests continue to pass (intensity conservation with similar raw/resampled counts)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests