Skip to content

feat: integrate BrukerTimsFile directly into OpenSwath chromatogram pipeline - #9019

Merged
timosachsenberg merged 3 commits into
developfrom
claude/integrate-bruker-chromatogram-aLwlK
Mar 27, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
claude/integrate-bruker-chromatogram-aLwlK

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Allow Bruker .d (TDF) files to be passed directly to OpenSwathWorkflow
without prior mzML conversion. The integration bridges BrukerTimsFile's
DIA-PASEF output into the existing SwathMap infrastructure.

Key changes:

  • BrukerTimsFile::loadDIA_(): add "ion mobility lower/upper limit" meta
    values to MS2 spectra so PASEF windows sharing the same m/z range but
    differing in IM are correctly distinguished by countScansInSwath_()
  • SwathFile::loadBrukerTdf(): new method that loads .d via BrukerTimsFile,
    discovers SWATH windows, and partitions spectra via RegularSwathFileConsumer
  • OpenSwathBase::loadSwathFiles_(): dispatch BRUKER_TDF file type to the
    new loadBrukerTdf() method (both multi-file and single-file branches)
  • OpenSwathWorkflow: accept "d" as valid input format (WITH_OPENTIMS only)

https://claude.ai/code/session_01QSsBJj9apkny9nrxgQNmrT

Summary by CodeRabbit

  • New Features
    • Optional support for loading Bruker TDF (.d) TIMS data in OpenSwath workflows (when TIMS support is enabled).
    • Spectra now include ion mobility lower/upper boundary metadata to better distinguish PASEF/SWATH windows.
    • Input-format validation updated to recognize Bruker TDF alongside mzML, mzXML, and sqMass.

…ipeline

Allow Bruker .d (TDF) files to be passed directly to OpenSwathWorkflow
without prior mzML conversion. The integration bridges BrukerTimsFile's
DIA-PASEF output into the existing SwathMap infrastructure.

Key changes:
- BrukerTimsFile::loadDIA_(): add "ion mobility lower/upper limit" meta
  values to MS2 spectra so PASEF windows sharing the same m/z range but
  differing in IM are correctly distinguished by countScansInSwath_()
- SwathFile::loadBrukerTdf(): new method that loads .d via BrukerTimsFile,
  discovers SWATH windows, and partitions spectra via RegularSwathFileConsumer
- OpenSwathBase::loadSwathFiles_(): dispatch BRUKER_TDF file type to the
  new loadBrukerTdf() method (both multi-file and single-file branches)
- OpenSwathWorkflow: accept "d" as valid input format (WITH_OPENTIMS only)

https://claude.ai/code/session_01QSsBJj9apkny9nrxgQNmrT
@coderabbitai

coderabbitai Bot commented Mar 27, 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: e9b58ab3-118a-487d-ba36-d53bcea2754b

📥 Commits

Reviewing files that changed from the base of the PR and between 785cc6a and 199c0b1.

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

📝 Walkthrough

Walkthrough

Adds conditional Bruker TDF (TIMS) SWATH input support: new guarded API loadBrukerTdf, integration into OpenSwath input dispatch and CLI validation, and propagation of ion-mobility bounds metadata on generated MS2 spectra.

Changes

Cohort / File(s) Summary
API Declaration
src/openms/include/OpenMS/FORMAT/SwathFile.h
Added loadBrukerTdf() declaration guarded by #ifdef WITH_OPENTIMS and included OpenMS/config.h.
Core Implementation
src/openms/source/FORMAT/SwathFile.cpp
Implemented SwathFile::loadBrukerTdf() (guarded by WITH_OPENTIMS): loads PeakMap via BrukerTimsFile, derives SWATH boundaries, feeds spectra to RegularSwathFileConsumer, and returns std::vector<OpenSwath::SwathMap>.
Bruker TIMS parsing
src/openms/source/FORMAT/BrukerTimsFile.cpp
When splitting DIA windows, set per-spectrum meta values "ion mobility lower limit" and "ion mobility upper limit" using window IM bounds.
Integration & CLI
src/openms/source/APPLICATIONS/OpenSwathBase.cpp, src/topp/OpenSwathWorkflow.cpp
Added dispatch for FileTypes::BRUKER_TDF to call loadBrukerTdf() and updated CLI input-format validation to conditionally include .d when WITH_OPENTIMS is defined.
Build/config include
src/topp/OpenSwathWorkflow.cpp, src/openms/include/OpenMS/FORMAT/SwathFile.h
Added #include <OpenMS/config.h> to enable compile-flag-controlled declarations and behavior.

Sequence Diagram

sequenceDiagram
    participant User as "User / OpenSwathWorkflow"
    participant OSB as "OpenSwathBase"
    participant SF as "SwathFile"
    participant BTF as "BrukerTimsFile"
    participant Consumer as "RegularSwathFileConsumer"

    User->>OSB: request load (file type: BRUKER_TDF)
    OSB->>SF: loadBrukerTdf(file)
    SF->>BTF: load(file)
    BTF-->>SF: PeakMap (spectra with IM metadata)
    SF->>SF: countScansInSwath_(spectra)
    SF->>Consumer: setExperimentalSettings(...)
    loop per spectrum
        SF->>Consumer: consumeSpectrum(spectrum with IM bounds)
    end
    Consumer-->>SF: retrieveSwathMaps()
    SF-->>OSB: return vector<SwathMap>
    OSB-->>User: SWATH maps available
Loading

Possibly related PRs

Suggested Reviewers

  • cbielow

Poem

🐰 I hopped through TDFs with whiskers bright,
IM bounds stitched into spectra's light,
SWATH windows tidy, each PASEF lane true,
Timely maps assembled — a bunny's woohoo!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% 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 describes the main change: integrating BrukerTimsFile into the OpenSwath pipeline, which aligns with the core objective of enabling Bruker TDF file support in OpenSwath workflows.

✏️ 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 claude/integrate-bruker-chromatogram-aLwlK

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: 3

🤖 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/openms/include/OpenMS/FORMAT/SwathFile.h`:
- Around line 85-87: Add complete Doxygen for the public function loadBrukerTdf:
document the input file parameter with `@param`[in] file explaining it is the path
to a Bruker .d (TDF) directory, document the exp_meta parameter with `@param`[out]
exp_meta (or `@param`[in,out] if it is both read and modified) describing that it
will be filled with ExperimentalSettings metadata, and document the return value
with `@return` describing that the function returns a
std::vector<OpenSwath::SwathMap> representing the loaded Swath maps; place these
tags immediately above the loadBrukerTdf declaration in the header.

In `@src/openms/source/APPLICATIONS/OpenSwathBase.cpp`:
- Line 146: The error text in OpenSwathBase.cpp currently always advertises ".d
(Bruker TDF)" support even when OpenTIMS is disabled; update the two message
occurrences (the string literal used in the input-file validation around the
checks at/near the two occurrences) so that the ".d (Bruker TDF)" part is only
included when WITH_OPENTIMS is enabled — e.g. build the message conditionally
using `#ifdef` WITH_OPENTIMS or append the suffix at runtime only when the
WITH_OPENTIMS flag is true; apply the same conditional change to both
occurrences so the runtime message accurately reflects available formats.

In `@src/openms/source/FORMAT/SwathFile.cpp`:
- Line 292: Replace direct std::cout/std::cerr use with OpenMS logging macros:
change the std::cout line that prints "Loading Bruker TDF file " << file to use
the OpenMS logger (e.g. LOG_INFO << "Loading Bruker TDF file " << file << '\n';)
and likewise replace any uses of std::endl in this new TDF path with '\n' when
using the logging stream; update the statements in SwathFile.cpp (the
TDF-loading block that currently uses std::cout and std::endl) to use LOG_INFO
(or the project-standard OpenMS log macro) and newline characters instead of
std::endl.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1df2254e-b1cf-42b8-88b0-6475bb7dafae

📥 Commits

Reviewing files that changed from the base of the PR and between ff4eabe and 6bb6d2b.

📒 Files selected for processing (5)
  • src/openms/include/OpenMS/FORMAT/SwathFile.h
  • src/openms/source/APPLICATIONS/OpenSwathBase.cpp
  • src/openms/source/FORMAT/BrukerTimsFile.cpp
  • src/openms/source/FORMAT/SwathFile.cpp
  • src/topp/OpenSwathWorkflow.cpp

Comment thread src/openms/source/FORMAT/SwathFile.cpp Resolved
@coderabbitai

coderabbitai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 3 file(s) based on 3 unresolved review comments.

Files modified:

  • src/openms/include/OpenMS/FORMAT/SwathFile.h
  • src/openms/source/APPLICATIONS/OpenSwathBase.cpp
  • src/openms/source/FORMAT/SwathFile.cpp

Commit: 785cc6a158bf52d73068a32c62a572a90be427ea

The changes have been pushed to the claude/integrate-bruker-chromatogram-aLwlK branch.

Time taken: 2m 50s

Fixed 3 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <[email protected]>

@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

🤖 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/openms/source/APPLICATIONS/OpenSwathBase.cpp`:
- Around line 133-135: The BRUKER_TDF dispatch uses the extension-only
in_file_type (set via getTypeByFileName) which misclassifies directory-based .d
inputs; replace those checks that compare in_file_type to FileTypes::BRUKER_TDF
(e.g., the branch that calls swath_file.loadBrukerTdf and the similar block at
lines ~179-181) to instead call FileHandler::getType(path) (or use
FileHandler::getType(...) where in_file_type is derived) so directory validation
and trailing-slash handling are respected; update all occurrences where
getTypeByFileName is used for .d detection to use FileHandler::getType() before
invoking loadBrukerTdf.
🪄 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: 2a60ffa3-362d-4604-82c4-a996c12e6f5d

📥 Commits

Reviewing files that changed from the base of the PR and between 6bb6d2b and 785cc6a.

📒 Files selected for processing (3)
  • src/openms/include/OpenMS/FORMAT/SwathFile.h
  • src/openms/source/APPLICATIONS/OpenSwathBase.cpp
  • src/openms/source/FORMAT/SwathFile.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openms/source/FORMAT/SwathFile.cpp
  • src/openms/include/OpenMS/FORMAT/SwathFile.h

Comment on lines +133 to +135
else if (in_file_type == FileTypes::BRUKER_TDF)
{
auto maps = swath_file.loadBrukerTdf(f, exp_meta);

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.

⚠️ Potential issue | 🟠 Major

Use FileHandler::getType() for .d dispatch to handle directory validation and trailing-slash inputs.

BRUKER_TDF loading here relies on in_file_type, but Line 103 and Line 157 still derive it with getTypeByFileName(...) (extension-only). For directory-based .d, this can misclassify valid paths (e.g., trailing /) and skip marker-file validation.

Suggested fix
-        FileTypes::Type in_file_type = FileHandler::getTypeByFileName(f);
+        FileTypes::Type in_file_type = FileHandler::getType(f);
...
-      FileTypes::Type in_file_type = FileHandler::getTypeByFileName(file_list[0]);
+      FileTypes::Type in_file_type = FileHandler::getType(file_list[0]);

Also applies to: 179-181

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/APPLICATIONS/OpenSwathBase.cpp` around lines 133 - 135, The
BRUKER_TDF dispatch uses the extension-only in_file_type (set via
getTypeByFileName) which misclassifies directory-based .d inputs; replace those
checks that compare in_file_type to FileTypes::BRUKER_TDF (e.g., the branch that
calls swath_file.loadBrukerTdf and the similar block at lines ~179-181) to
instead call FileHandler::getType(path) (or use FileHandler::getType(...) where
in_file_type is derived) so directory validation and trailing-slash handling are
respected; update all occurrences where getTypeByFileName is used for .d
detection to use FileHandler::getType() before invoking loadBrukerTdf.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@coderabbitai Your auto-fix in 785cc6a replaced std::cout with the deprecated LOG_INFO macro instead of the correct OPENMS_LOG_INFO, breaking the build on all 5 CI platforms. The correct macro was already used 17 lines below in the same function. Please be more careful with macro name suggestions.

@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@timosachsenberg, I sincerely apologize for this mistake. Using LOG_INFO instead of OPENMS_LOG_INFO was an error on my part — I should have checked the surrounding code context more carefully before suggesting the fix, since the correct macro was already present just 17 lines below. I'm sorry for the CI breakage this caused across all five platforms.

I'm adding a precise learning to avoid this mistake in future reviews.


✏️ Learnings added
Learnt from: timosachsenberg
URL: https://github.com/OpenMS/OpenMS/pull/9019

Timestamp: 2026-03-27T09:01:16.629Z
Learning: In OpenMS (OpenMS/OpenMS), the correct logging macros are `OPENMS_LOG_INFO`, `OPENMS_LOG_WARN`, `OPENMS_LOG_ERROR`, `OPENMS_LOG_DEBUG`, etc. (i.e., with the `OPENMS_` prefix). The older `LOG_INFO`, `LOG_WARN`, `LOG_ERROR`, `LOG_DEBUG` macros (without the `OPENMS_` prefix) are deprecated and must not be used or suggested. Always verify against nearby code context before suggesting logging macro replacements.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-25T11:21:29.196Z
Learning: Applies to **/*.{h,cpp,cc,cxx} : Use OpenMS logging macros and `OpenMS::LogStream`; avoid `std::cout`/`std::err` directly

Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8841
File: src/topp/MascotAdapterOnline.cpp:143-145
Timestamp: 2026-03-06T11:18:42.157Z
Learning: In OpenMS (OpenMS/OpenMS), paths constructed from `File::getTempDirectory() + File::getUniqueName()` in `src/topp/MascotAdapterOnline.cpp` and similar TOPP tools produce ASCII-only paths (system temp directory + UUID/counter-based name). Wrapping these in `std::filesystem::path` for Unicode/non-ASCII safety is unnecessary and should not be flagged.

Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-25T11:21:29.196Z
Learning: CMake minimum version is 3.21; C++ standard is C++20; use out-of-tree builds in `OpenMS-build/`

Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8975
File: src/openms/source/FORMAT/BrukerTimsFile.cpp:559-568
Timestamp: 2026-03-24T08:16:16.811Z
Learning: In OpenMS BrukerTimsFile.cpp (WITH_OPENTIMS), the correct PSI-MS CV term for Bruker TimsTOF TDF nativeID format is MS:1002818 ("Bruker TDF nativeID format"), not MS:1000776 ("scan number only nativeID format"). The mandated nativeID string pattern for MS:1002818 is `frame=<FRAME_ID> scan=<SCAN_ID>`. The SourceFile metadata call should use setNativeIDTypeAccession("MS:1002818") and setNativeIDType("Bruker TDF nativeID format").

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

The setup looks fine to me. I think we have a test diaPASEF mzML file that's used in the TOPP tests. I think we should add a class test to compare the swath loading from an mzML and bruker tdf, to make sure the data is the same.

Though I'm not sure how the test diaPASEF mzML file was generated actually, if it was simulated or sampled from a TDF file.

At some point, we probably also would want to try implement the option to stream the data (by swath maybe), because loading all the data into memory would probably require a fair amount of memory.

@timosachsenberg
timosachsenberg merged commit cb6c7d1 into develop Mar 27, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the claude/integrate-bruker-chromatogram-aLwlK branch March 27, 2026 17:26
github-actions Bot pushed a commit that referenced this pull request Mar 28, 2026
Add missing changelog entries for commits after the 2026-03-26 sync:
- #9019: OpenSwathWorkflow direct Bruker .d (TDF) file input
- #9018: IM_PEAK format checks in Resampler, FeatureFinderCentroided, FeatureFinderMultiplex, PeakPickerHiRes
- #9003: TMT 32-plex and 35-plex quantitation support
- #9007: IMPeakType enum added, IMFormat::CENTROIDED deprecated
- #9011: BREAKING IMFormat::MIXED removed; determineIMFormat requires ms_level

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 28, 2026
Add missing changelog entries for commits after the 2026-03-26 sync:
- #9019: OpenSwathWorkflow direct Bruker .d (TDF) file input
- #9018: IM_PEAK format checks in Resampler, FeatureFinderCentroided, FeatureFinderMultiplex, PeakPickerHiRes
- #9003: TMT 32-plex and 35-plex quantitation support
- #9007: IMPeakType enum added, IMFormat::CENTROIDED deprecated
- #9011: BREAKING IMFormat::MIXED removed; determineIMFormat requires ms_level

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[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.

5 participants