Repository navigation
feat(pyOpenMS): expose BrukerTimsFile loader via nanobind - #9379
Conversation
Adds bindings for OpenMS::BrukerTimsFile (load + readDIAMetadata) with the nested Config struct, ExportMode/TimsCalibrationStrategy/ PressureCompensation enums, and DIAStreamingMetadata. Gated by #ifdef WITH_OPENTIMS; feature-detectable via hasattr(pyopenms, "BrukerTimsFile"). The Bruker SDK is not bundled in the wheel and is dlopen'd at runtime from OPENMS_BRUKER_SDK_PATH or Config.bruker_sdk_path. Tests skip cleanly when WITH_OPENTIMS is off; real-data tests gate on OPENTIMS_DDA_TEST_DATA / OPENTIMS_DIA_TEST_DATA env vars, mirroring the BrukerTimsFile_test CMake pattern. The pyopenms ctest registration now forwards those CMake variables to the pytest environment when set. Streaming consumer paths (loadDIAStreaming, transform) are deferred. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR adds Python (nanobind) bindings for OpenMS's BrukerTimsFile loader, enabling Python users to load Bruker TIMS ChangesBrukerTimsFile Python Bindings
Possibly Related PRs
Suggested Reviewers
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.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@src/pyOpenMS/bindings/bind_format.cpp`:
- Around line 153-170: The BrukerTimsFile binding (and its nested types
BrukerTimsFile::Config and BrukerTimsFile::DIAStreamingMetadata) currently only
expose default construction; add copy construction and Python copy/deepcopy
support similar to other bindings: add nb::init<const OpenMS::BrukerTimsFile&>()
for BrukerTimsFile (and nb::init<const OpenMS::BrukerTimsFile::Config&>() /
nb::init<const OpenMS::BrukerTimsFile::DIAStreamingMetadata&>() for the nested
classes), and implement __copy__ and __deepcopy__ that return a new instance
constructed from the const& copy (use the same pattern used for
CachedmzML/ChromeleonFile bindings). Ensure the __deepcopy__ accepts a memo arg
and ignores it, and register these on the same nb::class_ declarations for
BrukerTimsFile, Config, and DIAStreamingMetadata.
In `@src/pyOpenMS/tests/unittests/test_BrukerTimsFile.py`:
- Around line 48-63: The tests currently use tautological assertions (comparing
a set to itself) in test_export_mode_enum_values,
test_calibration_strategy_enum_values, and
test_pressure_compensation_enum_values; replace those with assertions that
compare the observed enum members to an explicit expected set (e.g., build
expected = {pyopenms.BrukerTimsFile.Config.ExportMode.AUTO,
pyopenms.BrukerTimsFile.Config.ExportMode.SPECTRUM,
pyopenms.BrukerTimsFile.Config.ExportMode.FRAME} and assert observed ==
expected), doing the same for Config.TimsCalibrationStrategy and
Config.PressureCompensation so the tests fail if members are removed or renamed.
🪄 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: 1015890b-d8ac-4c7f-8ed0-d153d11aa9e4
📒 Files selected for processing (4)
CHANGELOGsrc/pyOpenMS/CMakeLists.txtsrc/pyOpenMS/bindings/bind_format.cppsrc/pyOpenMS/tests/unittests/test_BrukerTimsFile.py
| auto brukertimsfile_class = nb::class_<OpenMS::BrukerTimsFile>(m, "BrukerTimsFile", | ||
| R"doc( | ||
| Reader for Bruker TimsTOF .d directories via opentims. | ||
|
|
||
| Supports DDA-PASEF, DIA-PASEF, and raw frame-level 4D access. | ||
| Ion mobility data is stored in VSSC (1/K0) units using IM_PEAK format | ||
| for MS1 and DIA MS2, and scalar drift times for DDA MS2. | ||
|
|
||
| This class is only available when OpenMS is built with | ||
| ``WITH_OPENTIMS=ON`` (the default). The Bruker SDK | ||
| (``timsdata.dll`` / ``libtimsdata.so``) is not bundled with pyOpenMS; | ||
| supply it via the ``OPENMS_BRUKER_SDK_PATH`` environment variable or | ||
| ``Config.bruker_sdk_path``. | ||
|
|
||
| Use ``hasattr(pyopenms, "BrukerTimsFile")`` to feature-detect at | ||
| runtime. | ||
| )doc"); | ||
| brukertimsfile_class |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
cd src/pyOpenMS/bindings && head -300 bind_format.cpp | tail -150Repository: OpenMS/OpenMS
Length of output: 11956
Add missing copy constructor and copy/deepcopy bindings for BrukerTimsFile and nested classes.
BrukerTimsFile, BrukerTimsFile.Config, and BrukerTimsFile.DIAStreamingMetadata currently expose only default construction. Per coding guidelines, add nb::init<const ...&>(), __copy__, and __deepcopy__ for consistency with other bindings in this file (e.g., CachedmzML, ChromeleonFile).
Proposed patch
brukertimsfile_class
.def(nb::init<>())
+ .def(nb::init<const OpenMS::BrukerTimsFile&>())
+ .def("__copy__", [](const OpenMS::BrukerTimsFile& self) { return OpenMS::BrukerTimsFile(self); })
+ .def("__deepcopy__", [](const OpenMS::BrukerTimsFile& self, nb::dict) { return OpenMS::BrukerTimsFile(self); }, "memo"_a)
.def("load", [](OpenMS::BrukerTimsFile& self, const OpenMS::String& path) {
OpenMS::MSExperiment exp; self.load(path, exp); return exp;
}, "path"_a, "Load a .d directory into a new MSExperiment using default configuration")
@@
auto brukertimsfile_config = nb::class_<OpenMS::BrukerTimsFile::Config>(brukertimsfile_class, "Config",
"Processing and export configuration for BrukerTimsFile.load() and readDIAMetadata()")
.def(nb::init<>())
+ .def(nb::init<const OpenMS::BrukerTimsFile::Config&>())
+ .def("__copy__", [](const OpenMS::BrukerTimsFile::Config& self) { return OpenMS::BrukerTimsFile::Config(self); })
+ .def("__deepcopy__", [](const OpenMS::BrukerTimsFile::Config& self, nb::dict) { return OpenMS::BrukerTimsFile::Config(self); }, "memo"_a)
.def_rw("calibration_tolerance", &OpenMS::BrukerTimsFile::Config::calibration_tolerance, "m/z recalibration tolerance in Da (0 = default 0.1 Da)")
@@
nb::class_<OpenMS::BrukerTimsFile::DIAStreamingMetadata>(brukertimsfile_class, "DIAStreamingMetadata",
"Metadata describing DIA SWATH layout for streaming consumers")
.def(nb::init<>())
+ .def(nb::init<const OpenMS::BrukerTimsFile::DIAStreamingMetadata&>())
+ .def("__copy__", [](const OpenMS::BrukerTimsFile::DIAStreamingMetadata& self) { return OpenMS::BrukerTimsFile::DIAStreamingMetadata(self); })
+ .def("__deepcopy__", [](const OpenMS::BrukerTimsFile::DIAStreamingMetadata& self, nb::dict) { return OpenMS::BrukerTimsFile::DIAStreamingMetadata(self); }, "memo"_a)
.def_rw("boundaries", &OpenMS::BrukerTimsFile::DIAStreamingMetadata::boundaries, "One SwathMap per DIA window (MS2 only)")Also applies to: 192-194, 233-235
🤖 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/pyOpenMS/bindings/bind_format.cpp` around lines 153 - 170, The
BrukerTimsFile binding (and its nested types BrukerTimsFile::Config and
BrukerTimsFile::DIAStreamingMetadata) currently only expose default
construction; add copy construction and Python copy/deepcopy support similar to
other bindings: add nb::init<const OpenMS::BrukerTimsFile&>() for BrukerTimsFile
(and nb::init<const OpenMS::BrukerTimsFile::Config&>() / nb::init<const
OpenMS::BrukerTimsFile::DIAStreamingMetadata&>() for the nested classes), and
implement __copy__ and __deepcopy__ that return a new instance constructed from
the const& copy (use the same pattern used for CachedmzML/ChromeleonFile
bindings). Ensure the __deepcopy__ accepts a memo arg and ignores it, and
register these on the same nb::class_ declarations for BrukerTimsFile, Config,
and DIAStreamingMetadata.
| def test_export_mode_enum_values(): | ||
| Em = pyopenms.BrukerTimsFile.Config.ExportMode | ||
| assert {Em.AUTO, Em.SPECTRUM, Em.FRAME} == {Em.AUTO, Em.SPECTRUM, Em.FRAME} | ||
|
|
||
|
|
||
| def test_calibration_strategy_enum_values(): | ||
| Cs = pyopenms.BrukerTimsFile.Config.TimsCalibrationStrategy | ||
| assert {Cs.AUTO, Cs.BRUKER_SDK, Cs.RATIONAL, Cs.LINEAR} == { | ||
| Cs.AUTO, Cs.BRUKER_SDK, Cs.RATIONAL, Cs.LINEAR | ||
| } | ||
|
|
||
|
|
||
| def test_pressure_compensation_enum_values(): | ||
| Pc = pyopenms.BrukerTimsFile.Config.PressureCompensation | ||
| assert {Pc.NONE, Pc.GLOBAL, Pc.PER_FRAME} == {Pc.NONE, Pc.GLOBAL, Pc.PER_FRAME} | ||
|
|
There was a problem hiding this comment.
Enum value tests are tautologies and won’t catch regressions.
These assertions compare each set to itself, so they always pass even if the binding changes.
Proposed fix
def test_export_mode_enum_values():
Em = pyopenms.BrukerTimsFile.Config.ExportMode
- assert {Em.AUTO, Em.SPECTRUM, Em.FRAME} == {Em.AUTO, Em.SPECTRUM, Em.FRAME}
+ assert hasattr(Em, "AUTO")
+ assert hasattr(Em, "SPECTRUM")
+ assert hasattr(Em, "FRAME")
+ assert len({Em.AUTO, Em.SPECTRUM, Em.FRAME}) == 3
@@
def test_calibration_strategy_enum_values():
Cs = pyopenms.BrukerTimsFile.Config.TimsCalibrationStrategy
- assert {Cs.AUTO, Cs.BRUKER_SDK, Cs.RATIONAL, Cs.LINEAR} == {
- Cs.AUTO, Cs.BRUKER_SDK, Cs.RATIONAL, Cs.LINEAR
- }
+ assert hasattr(Cs, "AUTO")
+ assert hasattr(Cs, "BRUKER_SDK")
+ assert hasattr(Cs, "RATIONAL")
+ assert hasattr(Cs, "LINEAR")
+ assert len({Cs.AUTO, Cs.BRUKER_SDK, Cs.RATIONAL, Cs.LINEAR}) == 4
@@
def test_pressure_compensation_enum_values():
Pc = pyopenms.BrukerTimsFile.Config.PressureCompensation
- assert {Pc.NONE, Pc.GLOBAL, Pc.PER_FRAME} == {Pc.NONE, Pc.GLOBAL, Pc.PER_FRAME}
+ assert hasattr(Pc, "NONE")
+ assert hasattr(Pc, "GLOBAL")
+ assert hasattr(Pc, "PER_FRAME")
+ assert len({Pc.NONE, Pc.GLOBAL, Pc.PER_FRAME}) == 3🤖 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/pyOpenMS/tests/unittests/test_BrukerTimsFile.py` around lines 48 - 63,
The tests currently use tautological assertions (comparing a set to itself) in
test_export_mode_enum_values, test_calibration_strategy_enum_values, and
test_pressure_compensation_enum_values; replace those with assertions that
compare the observed enum members to an explicit expected set (e.g., build
expected = {pyopenms.BrukerTimsFile.Config.ExportMode.AUTO,
pyopenms.BrukerTimsFile.Config.ExportMode.SPECTRUM,
pyopenms.BrukerTimsFile.Config.ExportMode.FRAME} and assert observed ==
expected), doing the same for Config.TimsCalibrationStrategy and
Config.PressureCompensation so the tests fail if members are removed or renamed.
…) and IMAGING module (#9381) (#9385) Two recent feature commits (both merged Tue May 19 2026) did not have CHANGELOG entries in the 3.6.0 section: - #9380: BrukerTimsFile IM-axis hill-based centroiding (PASEFHillCentroider) with new Config fields for hill params, isotopic prefilter, and per-mode centroid-algorithm selection; Greedy2D path retained as back-compat default. - #9381: New OpenMS/IMAGING module — IonImage, MSImagingGeometry, MSImagingExperiment — providing in-memory data structures for imaging MS; first phase of imzML/MSI support. Also adds the missing (#9379) PR reference tag to the existing pyOpenMS BrukerTimsFile bindings line so the entry is traceable. Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: timosachsenberg <[email protected]>
Summary
OpenMS::BrukerTimsFileinsrc/pyOpenMS/bindings/bind_format.cpp:load()(default + explicitConfig),readDIAMetadata()returning(DIAStreamingMetadata, ExperimentalSettings), plus the nestedConfigstruct, the three nested enums (ExportMode,TimsCalibrationStrategy,PressureCompensation), andDIAStreamingMetadata.#ifdef WITH_OPENTIMSso the class is only exposed when OpenMS was built with-DWITH_OPENTIMS=ON(the project default). No new CMake change was needed for propagation —target_compile_definitions(OpenMS PUBLIC WITH_OPENTIMS=1)already inherits into_pyopenms_formatvia the public link toOpenMS.BrukerTimsFile_testdata-fixture pattern:src/pyOpenMS/CMakeLists.txtnow forwards configure-timeOPENTIMS_DDA_TEST_DATA/OPENTIMS_DIA_TEST_DATApaths as environment variables to thepyopenms_unittestsctest, and the newtests/unittests/test_BrukerTimsFile.pyskips real-data tests cleanly when those env vars are absent.loadDIAStreaming,transform) are intentionally deferred to a follow-up — bindingIMSDataConsumer/FullSwathFileConsumertrampolines is its own scope.Packaging notes
timsdata.dll/libtimsdata.so) is not bundled in the wheel; users supply it at runtime viaOPENMS_BRUKER_SDK_PATHenv var orBrukerTimsFile.Config.bruker_sdk_path. The docstring on the class spells this out.opentimsitself is built as a static archive (OPENTIMS_BUILD_LIB=ON,OPENTIMS_LINK_SQLITE_STATICALLY=ON) and its symbols are absorbed intolibOpenMS.so, so no new shared lib needs to be copied beyond what wheel packaging already handles.WITH_OPENTIMS=ON) is deferred — flagging here so it can be checked in a follow-up if needed.Test plan
cmake --build OpenMS-build --target pyopenms -j$(nproc)succeedstest_BrukerTimsFile.py: 7 pass / 3 skip without env varstest_BrukerTimsFile.py: 10/10 pass in ~20s withOPENTIMS_DDA_TEST_DATAandOPENTIMS_DIA_TEST_DATApointed at the fetched opentims test fixturespyopenms_unittestskeeps passing on all platforms (real-data tests will skip in CI since the env vars are not forwarded there yet)🤖 Generated with Claude Code
Summary by CodeRabbit