Skip to content

refactor: extract loadMS1Spectrum helper in BrukerTimsFile - #9152

Merged
timosachsenberg merged 1 commit into
developfrom
refactor/bruker-ms1-frame-loader
Apr 15, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
refactor/bruker-ms1-frame-loader

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Dedupe the `if (do_centroid) centroidMS1Frame(...) else frameToSpectrum(..., 1)` branch that was copy-pasted in four MS1 loading loops (`loadDIA_`, `loadDDA_`, `loadDIAStreaming`, `loadFrameMode_`) into a single static helper `loadMS1Spectrum(frame, spec, config, centroider)`.

Motivation

Preparation for an upcoming `dia_ms1_n_neighbors` MS1 frame-aggregation feature. Collapsing the duplicated branch first keeps that PR focused on the aggregation logic itself rather than mechanical copy-paste fixes.

Contract

Pure refactor — no observable behavior change. The helper just dispatches on `isCentroidingEnabled(config)`.

  • `loadMS1Spectrum` is a static file-local helper; no header change.
  • `centroidMS1Frame` is now called only from `loadMS1Spectrum`; `isCentroidingEnabled` is only read there as well.

Diff size

`src/openms/source/FORMAT/BrukerTimsFile.cpp`: +18 / −30 (net −12).

Test Plan

  • `BrukerTimsFile_test` passes (13/13 sections, 457 s on OPENTIMS_DIA_TEST_DATA + OPENTIMS_DDA_TEST_DATA) — covers all four modified call sites: DIA non-streaming, DDA, DIA streaming, FRAME export mode.
  • No new tests required — existing tests are the refactor contract.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Consolidated MS1 spectrum handling to remove duplicated centroiding logic across multiple loading paths.
    • Centroiding is now applied only for MS1 level; non‑MS1 levels follow the profile conversion flow.
    • Reduced code duplication, streamlined spectrum construction, and clarified level-specific processing for better maintainability.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec7f7e88-7712-4785-8020-0aaee5a180ee

📥 Commits

Reviewing files that changed from the base of the PR and between 236b372 and 894b0d8.

📒 Files selected for processing (1)
  • src/openms/source/FORMAT/BrukerTimsFile.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/source/FORMAT/BrukerTimsFile.cpp

📝 Walkthrough

Walkthrough

Introduces an internal static helper loadMS1Spectrum(...) to centralize MS1 spectrum construction and centroiding selection. Replaces duplicated centroid-vs-profile branching across multiple MS1 load paths by routing MS1 frames through the new helper; non-MS1 levels still use frameToSpectrum(...).

Changes

Cohort / File(s) Summary
MS1 Spectrum Construction Refactor
src/openms/source/FORMAT/BrukerTimsFile.cpp
Added loadMS1Spectrum(TimsFrame&, MSSpectrum&, const BrukerTimsFile::Config&, FrameCentroider&). Removed repeated do_centroid setup and duplicate centroid/profile branching from MS1 load paths (loadDIAStreaming, loadDDA_, loadDIA_, loadFrames_). In loadFrames_, MS1 frames now call loadMS1Spectrum(...); non-MS1 levels still use frameToSpectrum(frame, spec, level).

Sequence Diagram(s)

(omitted — changes are an internal refactor of MS1 centroiding logic)

Possibly related PRs

Suggested reviewers

  • jcharkow
  • alhigaylan

Poem

🐰 A tiny hop in C++ light,
One helper bounds and tidies the night.
Centroids now follow a single lane,
Less branching, less chase—what a gain! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: extract loadMS1Spectrum helper in BrukerTimsFile' accurately describes the main change: extracting a helper function to reduce duplication in MS1 spectrum loading logic.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ 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 refactor/bruker-ms1-frame-loader

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.

The centroid-or-copy branch for MS1 frame loading was duplicated across
four call sites (loadDIA_, loadDDA_, loadDIAStreaming, loadFrameMode_).
Extract a static loadMS1Spectrum(frame, spec, config, centroider) that
runs IM-centroiding when configured and falls back to frameToSpectrum()
otherwise. Each call site drops the local do_centroid bool and the
if/else branch.

Pure refactor: no behavior change. Existing BrukerTimsFile_test suite
(13 sections including all DIA/DDA integration paths) passes unchanged.

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