Skip to content

feat: allow Bruker DIA MS2 centroiding without denoising - #9151

Merged
timosachsenberg merged 1 commit into
developfrom
feat/bruker-dia-ms2-skip-denoise
Apr 15, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
feat/bruker-dia-ms2-skip-denoise

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Lower CLI floor on -bruker:dia_ms2_min_support from 1 to 0 in FileConverter, so users can run frame-aggregated DIA MS2 centroiding without the 3×3 neighbor filter.
  • Short-circuit the denoise step in DIAFrameAggregator when min_support <= 0, avoiding a wasteful 8-probe hashmap lookup per grid cell.
  • Add regression-guard section in BrukerTimsFile_test.cpp that locks in the new contract.

Motivation

The existing Bruker DIA MS2 path always applied spatial denoising (drop cells with no occupied 3×3 neighbors) even when the user wanted pure centroiding. The CLI clamped min_support to a minimum of 1, leaving no way to disable the filter. This PR exposes the already-supported min_support = 0 path through the CLI and adds a fast-path that skips the lookup loop when denoising is off.

Usage

FileConverter -in foo.d -out foo.mzML \
  -bruker:dia_ms2_n_neighbors 1 \
  -bruker:dia_ms2_min_support 0 \
  -bruker:dia_ms2_centroid true

Test Plan

  • BrukerTimsFile_test passes (13/13 sections, 770 s on OPENTIMS_DIA_TEST_DATA)
  • New DIA MS2 centroiding without denoising (min_support=0) section asserts:
    • min_support=0 centroid run produces more peaks than min_support=1 (fixture: 106.5 M vs 15.9 M, ~6.7× more centroids retained)
    • Spectrum count >= denoised count (empty-after-denoise drops are avoided)
    • Output spectra still IM_CENTROIDED with per-peak IM data and precursors
  • Existing DIA MS2 aggregation and DIA MS2 centroiding sections (min_support=1 default) still pass — no regression
  • FileConverter --helphelp shows (default: '1') (min: '0') for -bruker:dia_ms2_min_support and the updated help text

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Updated DIA MS2 denoising behavior for Bruker TimsTOF data processing; denoising can now be disabled via configuration option, with the default setting changed.
  • Tests

    • Added test coverage for MS2 centroiding without denoising.

Lower the CLI floor on -bruker:dia_ms2_min_support from 1 to 0 so users
can run frame-aggregated MS2 centroiding without the 3x3 neighbor filter.
With centroid=true and min_support=0, every populated grid cell becomes a
local-maxima candidate instead of being dropped when isolated.

Also short-circuit the denoise step in DIAFrameAggregator when
min_support<=0 to skip the now-useless 8-probe hashmap lookup per cell.

Regression guard added: with the test fixture, min_support=0 retains
~6.7x more centroids (106.5M vs 15.9M peaks) than min_support=1, with
spectra still emitted as IM_CENTROIDED.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR modifies the DIA MS2 denoising logic in BrukerTimsFile to allow skipping denoising when dia_ms2_min_support is set to 0. The core implementation expands the skip condition, a new test validates the behavior, and FileConverter updates its CLI parameter default from 1 to 0 with updated documentation.

Changes

Cohort / File(s) Summary
DIA MS2 Denoising Control
src/openms/source/FORMAT/BrukerTimsFile.cpp
Expanded skip_denoise condition to also bypass denoising when config.dia_ms2_min_support <= 0, enabling pure centroiding without noise filtering.
Test Coverage
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
Added DIA test section validating centroiding without denoising (min_support=0), asserting that denoising is bypassed and results in more peaks retained compared to the denoised path.
CLI Parameter Update
src/topp/FileConverter.cpp
Changed bruker:dia_ms2_min_support default and minimum integer value from 1 to 0, with updated help text documenting that 0 disables denoising.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • jpfeuffer
  • cbielow
  • singjc

Poem

🐰 A hop through denoising's gentle gate,
Where zero means we centroid, pure and straight,
No filtering fuss, just peaks on display,
Sweet aggregation blooms the OpenMS way! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main feature: enabling Bruker DIA MS2 centroiding without denoising by lowering the min_support minimum to 0.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/bruker-dia-ms2-skip-denoise

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 and usage tips.

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/openms/source/FORMAT/BrukerTimsFile.cpp (1)

1863-1873: Use contributing-frame count for skip_denoise instead of index span.

Line 1870 still keys off (hi - lo), which can run denoising even when only one frame actually contributes peaks after window filtering. That can over-prune valid isolated peaks.

♻️ Suggested refinement
-            // Aggregate peaks from all neighbor frames
+            // Aggregate peaks from all neighbor frames
+            Size contributing_frames = 0;
             for (size_t ni = lo; ni <= hi; ++ni)
             {
               TimsFrame& nframe = handle.get_frame(frame_ids[ni]);
               if (nframe.num_peaks == 0) continue;
+              bool frame_contributed = false;

               std::vector<uint32_t> scan_ids(nframe.num_peaks);
               std::vector<uint32_t> intensities(nframe.num_peaks);
               std::vector<double> mzs(nframe.num_peaks);
@@
               for (uint32_t p = 0; p < nframe.num_peaks; ++p)
               {
                 // Filter by scan bounds (integer comparison, no IM conversion needed)
                 if (scan_ids[p] >= win->scan_begin && scan_ids[p] <= win->scan_end)
                 {
                   aggregator.addPeak(mzs[p], intensities[p], scan_ids[p]);
+                  frame_contributed = true;
                 }
               }
+              if (frame_contributed) ++contributing_frames;
             }

-            bool skip_denoise = (hi - lo) < 1 || config.dia_ms2_min_support <= 0;
+            bool skip_denoise = (contributing_frames <= 1) || config.dia_ms2_min_support <= 0;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/FORMAT/BrukerTimsFile.cpp` around lines 1863 - 1873,
Replace the current skip_denoise check that uses the index span (hi - lo) with a
test based on the actual number of frames that contributed peaks to the
aggregator/grid: compute a contributing_frames count from the aggregator (e.g.,
a method or by counting non-empty frame entries in the grid) and set
skip_denoise = (contributing_frames <= 1) || config.dia_ms2_min_support <= 0;
then pass that skip_denoise into aggregator.finalize(...) /
finalizeCentroided(...) as before (references: skip_denoise, hi, lo,
config.dia_ms2_min_support, aggregator.finalizeCentroided, aggregator.finalize).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp`:
- Around line 794-797: STATUS currently divides by denoise_peaks unguarded which
can produce inf/unstable output when denoise_peaks == 0; update the logging line
in BrukerTimsFile_test.cpp (the STATUS call that references no_denoise_peaks and
denoise_peaks) to compute the ratio only if denoise_peaks > 0 and otherwise
print a clear placeholder (e.g., "N/A" or "inf") or skip the division, ensuring
the log message concatenates the chosen placeholder instead of performing the
division when denoise_peaks is zero.

---

Nitpick comments:
In `@src/openms/source/FORMAT/BrukerTimsFile.cpp`:
- Around line 1863-1873: Replace the current skip_denoise check that uses the
index span (hi - lo) with a test based on the actual number of frames that
contributed peaks to the aggregator/grid: compute a contributing_frames count
from the aggregator (e.g., a method or by counting non-empty frame entries in
the grid) and set skip_denoise = (contributing_frames <= 1) ||
config.dia_ms2_min_support <= 0; then pass that skip_denoise into
aggregator.finalize(...) / finalizeCentroided(...) as before (references:
skip_denoise, hi, lo, config.dia_ms2_min_support, aggregator.finalizeCentroided,
aggregator.finalize).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c06ca449-07a0-4fe1-a365-7218d9bebf6b

📥 Commits

Reviewing files that changed from the base of the PR and between 237a6c9 and 6f7f300.

📒 Files selected for processing (3)
  • src/openms/source/FORMAT/BrukerTimsFile.cpp
  • src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
  • src/topp/FileConverter.cpp

@timosachsenberg
timosachsenberg merged commit 165abcd into develop Apr 15, 2026
22 checks passed
@timosachsenberg
timosachsenberg deleted the feat/bruker-dia-ms2-skip-denoise branch April 15, 2026 09:36
github-actions Bot pushed a commit that referenced this pull request Apr 16, 2026
Add three missing entries for changes merged after the 2026-04-15 sync:
- #9154: BrukerTimsFile spectra marked as CENTROID
- #9148/#9147: system opentims install fallback before FetchContent
- #9151: Bruker DIA MS2 centroiding without denoising (min_support=0)

Co-authored-by: Copilot <[email protected]>
timosachsenberg added a commit that referenced this pull request Apr 16, 2026
…r loops

Previously skip_denoise was based on the index span (hi - lo), which
could run denoising when neighbor frames existed in the range but
contributed no peaks after the SWATH-window filter. Now the outer
loop counts frames that actually added peaks to the grid, and uses
that as the denoise predicate.

Closes the pre-existing TODO from #9151 and prepares the same logic
for reuse in the upcoming MS1 aggregation path.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 16, 2026
Add three missing entries for changes merged after the 2026-04-15 sync:
- #9154: BrukerTimsFile spectra marked as CENTROID
- #9148/#9147: system opentims install fallback before FetchContent
- #9151: Bruker DIA MS2 centroiding without denoising (min_support=0)

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
timosachsenberg added a commit that referenced this pull request Apr 16, 2026
…r loops

Previously skip_denoise was based on the index span (hi - lo), which
could run denoising when neighbor frames existed in the range but
contributed no peaks after the SWATH-window filter. Now the outer
loop counts frames that actually added peaks to the grid, and uses
that as the denoise predicate.

Closes the pre-existing TODO from #9151 and prepares the same logic
for reuse in the upcoming MS1 aggregation path.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
timosachsenberg added a commit that referenced this pull request Apr 16, 2026
* refactor: rename DIAFrameAggregator to FrameAggregator

The aggregator is scope-agnostic (no SWATH assumptions inside; the MS2
scan-window filter lives in the outer loop, not the class). Renaming
prepares for reuse from the MS1 aggregation path.

Pure refactor: no behavior change.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* refactor: parameterize FrameAggregator m/z bin width

Lift MZ_BIN_WIDTH from static constexpr to a constructor parameter.
Default 0.02 Da preserves existing MS2 behavior; MS1 callers will
pass a smaller value (0.01 Da) tuned for timsTOF MS1 mass accuracy.

Pure refactor: no behavior change.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: guard FrameAggregator neighbor lookups against uint32 wrap at scan_id=0

finalize() and finalizeCentroided() compute scan_id + ds and mz_bin + dm
with negative offsets. When either axis is 0 and the offset is negative,
the unsigned arithmetic wraps to 0xFFFFFFFF and hits phantom cells.

Latent in MS2 (edge scans rare), but exposed at MS1 density where peaks
at scan_id == 0 are common. Fixed at all five negative-offset lookup
sites via a shared neighborKey() helper that returns std::nullopt on
wrap.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* refactor: use contributing_frames count for skip_denoise in aggregator loops

Previously skip_denoise was based on the index span (hi - lo), which
could run denoising when neighbor frames existed in the range but
contributed no peaks after the SWATH-window filter. Now the outer
loop counts frames that actually added peaks to the grid, and uses
that as the denoise predicate.

Closes the pre-existing TODO from #9151 and prepares the same logic
for reuse in the upcoming MS1 aggregation path.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* refactor: add FrameCentroider::loadFrame(const double*) overload

The upcoming MS1 aggregation path sums per-peak intensities across
adjacent frames into FrameAggregator::Cell::intensity_sum (double).
For MS1 with N=2 and a 10^9-intensity base peak, the sum reaches
5*10^9 and overflows uint32_t. Internal storage is already float
(ImsPeak::intensity), so the new overload just casts double->float
at the entry point.

The existing uint32_t overload is untouched; MS2 callers see no change.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* feat: add ms1_n_neighbors, ms1_min_support, ms1_max_rt_distance_sec

Plumb three new knobs for Bruker MS1 frame aggregation through the
Config struct and the FileConverter CLI. The library side is wired
up in follow-up commits; this commit is purely surface-level and
has no runtime effect (defaults 0/0.0 preserve existing behavior).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* test: add DIA MS1 default config regression section

Locks in the "zero behavior change at defaults" guarantee for the
upcoming MS1 frame aggregation feature. Snapshots MS1 spectrum count,
peak count, and cumulative intensity with Config{} defaults, and
independently reproduces with the new knobs explicitly set to 0 /
0.0 — asserts both paths produce identical numbers.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* test: add RED test for DIA MS1 frame aggregation

Asserts that ms1_n_neighbors=1 produces an intensity-boosted MS1
output relative to the raw per-frame path. Fails until
loadAggregatedMS1Spectrum is implemented (next task).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* feat: implement MS1 frame aggregation in Bruker DIA loader

Add loadAggregatedMS1Spectrum() helper that builds one aggregated MS1
spectrum per center frame from a sliding window of 2N+1 adjacent MS1
frames, using FrameAggregator with a 0.01 Da bin (finer than the MS2
default). Composes with FrameCentroider for within-frame IM centroiding
when ms1_centroid_mz_ppm/pct are set.

Wires the new helper into loadDIA_ via an explicit branch on
config.ms1_n_neighbors > 0, preserving the per-frame code path when
aggregation is disabled. Also adds FrameAggregator::reserve() to
pre-size the grid bucket array (MS1 grids reach ~300k cells per
center at 0.01 Da bins on dense diaPASEF MS1).

DIA MS1 aggregation test bounds re-tuned to [2.5, 3.1] — MS1 ion
populations are more stable across adjacent frames than MS2 fragments,
so 3-frame aggregation gives close to the naive 3x sum (empirical
2.99) rather than MS2's ~1.28x.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* feat: MS1 frame aggregation for Bruker DDA-PASEF loader

Extend the ms1_n_neighbors dispatch to loadDDA_ and add a DDA-specific
test section validating both the aggregation intensity boost and the
ms1_max_rt_distance_sec cap's ability to truncate the neighbor window
on irregular DDA frame cadences.

The STATUS line reports cap_reduction so future test-runners can
re-tune the cap if the fixture's MS1 cadence changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* feat: MS1 frame aggregation in Bruker DIA streaming loader

Extend the ms1_n_neighbors dispatch to loadDIAStreaming so OpenSwath
consumers see an aggregated MS1 survey when requested. Preserves the
per-center-frame cadence invariant that SwathFileConsumer relies on.

Adds a streaming-specific test section validating spectrum count
equality with the raw MS1 frame count.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* test: MS1 aggregation composition, min_support, RT cap, FRAME mode

Four new test sections exercising every leaf of the MS1 aggregation feature:

- DIA MS1 aggregation with centroiding test — confirms composition with
  FrameCentroider. Centroider caps output at MAX_CENTROID_PEAKS=10000
  per frame, so on dense MS1 surveys (~600k aggregated peaks/frame) the
  top 10k carry ≈0.32 of total intensity. Bounds [0.1, 1.0] accept this.

- DIA MS1 aggregation min_support test — confirms denoise works:
  drop_frac ≈ 0.52, intensity still 1.8× raw (signal peaks survive).

- DIA MS1 RT cap test — 0.5s cap at N=2 reduces intensity by 80%
  (DIA MS1 cadence ~1.5s; tight cap collapses the window to just the
  center frame, so intensity goes from 5x raw down to 1x raw).

- FRAME mode ignores ms1_n_neighbors test — FRAME export emits one
  spectrum per raw MS1 frame regardless of the aggregation knob.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* feat: warn-and-ignore + partial-config warnings for MS1 aggregation

- loadFrames_: warn when ms1_n_neighbors > 0 in FRAME export mode,
  proceed per-frame (preserves FRAME's "raw frames" contract).
- warnPartialMS1AggregationConfig(): one-shot warnings for three cases:
  - ms1_min_support > 0 with ms1_n_neighbors == 0 (knob inert)
  - ms1_max_rt_distance_sec > 0 with ms1_n_neighbors == 0 (knob inert)
  - 2*N+1 > ms1_frame_count (window clamped at run edges)
  Called from loadDIA_, loadDDA_, and loadDIAStreaming after ms1_frame_ids
  is populated.

Mirrors the existing isCentroidingEnabled partial-config warn pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs: CHANGELOG entry for Bruker MS1 frame aggregation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* feat: ms1_centroid_max_peaks knob + per-load cap-hit summary

The FrameCentroider had a hardcoded MAX_CENTROID_PEAKS=10000 cap that
silently dropped up to 68% of intensity on aggregated MS1 surveys
(flagged by Codex review of PR #9158). Exposing the cap as a knob and
raising the default to 100000 makes the loss recoverable.

Changes:
- New Config::ms1_centroid_max_peaks field (default 100000).
- New CLI option -bruker:ms1_centroid_max_peaks (default 100000, min 1).
- Plumbed through FileConverter::getBrukerConfig_.
- FrameCentroider::centroid() signature accepts max_peaks parameter;
  default constant renamed to DEFAULT_CENTROID_MAX_PEAKS (=10000).
- FrameCentroider tracks cap-hit count + max dropped-peak intensity
  per load; reportCapSummary() emits ONE summary WARN per load()
  (not one per spectrum). Warning only fires when dropped peaks are
  above noise floor (>200 intensity counts).
- reportCapSummary() called at the end of loadDIA_, loadDDA_,
  loadDIAStreaming, and loadFrames_ level-1 loops.

On the DIA test fixture: at the 100k default the cap is hit on ~97%
of spectra but only noise-floor peaks are dropped, so the summary
warning stays silent. Intensity retention jumps from 32% (at 10k)
to 70% (at 100k).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs,test: address CodeRabbit review comments on PR #9158

All four comments were Minor but legitimate:

1. CHANGELOG used an ambiguous "ms1_centroid_mz_ppm/pct" shorthand.
   Spell out both identifiers explicitly, plus the new
   ms1_centroid_max_peaks knob.

2. FRAME mode test locked only spectrum count. A silent content
   corruption (e.g. aggregation partially running but writing to
   per-frame output) would pass. Now also asserts peak count and
   cumulative intensity equality between ref and agg runs.

3. DIA MS1 streaming aggregation test only asserted the cadence
   invariant (meta.nr_ms1_spectra), which is independent of whether
   ms1_n_neighbors is honored at all. Now also runs a non-aggregated
   streaming baseline and asserts total MS1 peaks(agg) > peaks(ref) —
   proof that aggregation actually ran. Also replaces swath_maps.front()
   with a proper m.ms1-flag lookup.

4. -bruker:ms1_min_support accepted any non-negative integer, but in
   a 3x3 grid with center excluded the max possible neighbors is 8.
   Added setMaxInt_(..., 8); values >8 are now rejected at the CLI
   boundary instead of silently dropping every peak.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (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.

1 participant