Skip to content

experimental opentims integration - #8975

Merged
timosachsenberg merged 75 commits into
developfrom
opentims
Mar 24, 2026
Merged

timosachsenberg merged 75 commits into
developfrom
opentims

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

This pull request introduces support for reading Bruker TimsTOF .d files using the open-source C++ library opentims, replacing the previous Rust-based timsrust bridge. It integrates opentims into the build system, patches it for compatibility, and provides options for open-source calibration converters. The public API remains unchanged, but all Rust dependencies are eliminated. The CMake build, configuration, and test infrastructure are updated accordingly. A detailed migration design document is also included.

Build System & Dependency Integration:

  • Added new CMake options WITH_OPENTIMS (default ON) and ENABLE_OPENTIMS_TESTS (default OFF) to control the inclusion and testing of opentims support. Test data for integration tests is fetched conditionally. (CMakeLists.txt, [1] [2]
  • Integrated opentims as a C++ dependency using FetchContent. The build patches opentims source files for compatibility (e.g., direct SQLite linkage, public getter for internal paths, variadic template fix) and compiles only the necessary C++ sources, linking against OpenMS's own sqlite3 library. (cmake/cmake_findExternalLibs.cmake, cmake/cmake_findExternalLibs.cmakeR276-R385)
  • Updated OpenMS's private library dependencies and compile definitions to include opentims_cpp and set WITH_OPENTIMS=1 when enabled. (src/openms/CMakeLists.txt, [1] [2]
  • Exported the WITH_OPENTIMS configuration in the OpenMS CMake config for downstream consumers. (cmake/OpenMSConfig.cmake.in, cmake/OpenMSConfig.cmake.inR72)

Documentation & Design:

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features

    • Native support for Bruker TimsTOF .d (TDF): new reader, configurable export modes, IM-aware centroiding/streaming, and calibration converters.
  • Behavior Changes

    • Search tools accept .d inputs, annotate ion-mobility on identifications, and offer optional PSM-level FDR filtering.
    • Several TOPP tools updated to accept Bruker .d.
  • Tests & Docs

    • Extensive unit/integration tests and migration/design documentation added.
  • Build

    • New options to enable opentims integration and optional test-data downloads.

timosachsenberg and others added 30 commits March 23, 2026 19:27
…_bridge

Covers DDA-PASEF, DIA-PASEF, and raw frame-level 4D access with
FileConverter integration, CMake FetchContent acquisition, and
streaming support via IMSDataConsumer.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Use qualified Interfaces::IMSDataConsumer type
- Fix IM FloatDataArray: use IMDataConverter::setIMUnit() with
  DriftTimeUnit::VSSC (name "raw inverse reduced ion mobility array",
  CV MS:1003008) instead of incorrect "Ion Mobility" + MS:1002815
- Fix typeToMZML string to PSI-MS term "Bruker TDF format"
- Add FileConverter low-memory branch extension for BRUKER_TDF
- Add directory-aware FileHandler flow (skip computeFileHash, handle
  trailing slash in basename)
- Fix setExpectedSize computation per export mode
- Add missing files: OpenMSConfig.cmake.in, FileTypes_test.cpp
- Model timsrust_calibrate as string toggle per TOPP conventions
- Add "d" to FileConverter input format list
- Note tims_file_info() lacks instrument identity

Co-Authored-By: Claude Opus 4.6 <[email protected]>
11 tasks covering CMake infrastructure, file type registration,
FileHandler directory detection, BrukerTimsFile reader (DDA/DIA/frame),
streaming, FileConverter integration, and test infrastructure.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Review checkpoints after each chunk boundary and critical tasks:
- Gate 1: Infrastructure (CMake + FileTypes + FileHandler)
- Gate 2: BrukerTimsFile skeleton and RAII wrappers
- Gate 3: frameToSpectrum_ core conversion
- Gate 4: DDA loading path
- Gate 5: DIA loading path (critical, most complex)
- Gate 6: Complete reader (full review before Chunk 3)
- Gate 7: FileConverter integration
- Gate 8: Final end-to-end review

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…p_bridge

Add CMake infrastructure for optional Bruker TimsTOF .d file support:
- WITH_TIMSRUST option (default ON) and ENABLE_TIMSRUST_TESTS option
- FetchContent-based download of pre-built timsrust_cpp_bridge archives
  with platform detection (Linux x86_64/aarch64, macOS arm64, Windows)
- Link timsrust_cpp_bridge as private dependency of libOpenMS
- Propagate WITH_TIMSRUST compile definition and export in OpenMSConfig

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add BRUKER_TDF to the FileTypes enum with extension "d" and properties
PROVIDES_EXPERIMENT + READABLE. Register in TypeNameBinding array (before
XML which must remain last), add typeToMZML entry, and update test
assertions for the new type count.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…r TDF

Add BRUKER_TDF directory validation in getType() (checks for analysis.tdf
or analysis.tdf_bin marker files), loadExperiment() dispatch stub behind
WITH_TIMSRUST guard, hash computation skip for directories, and path
normalization for trailing-slash handling in source file metadata.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Paths like sample.d/ (from shell tab-completion) would fail to be
recognized as BRUKER_TDF because getTypeByFileName() sees an empty
basename. Move slash-stripping before the type lookup call.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…dispatch

Add BrukerTimsFile header and source skeleton guarded by WITH_TIMSRUST.
Includes RAII wrappers for tims_dataset and tims_config handles,
helper functions for error reporting and dataset opening, and stub
implementations for load/transform/loadDDA_/loadDIA_/loadFrames_/
frameToSpectrum_ methods. Register in sources.cmake (conditional)
and wire up FileHandler BRUKER_TDF case to use BrukerTimsFile.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace the frameToSpectrum_ stub with full implementation that batch-converts
TOF indices to m/z and scan indices to inverse ion mobility (1/K0), builds
per-peak IM values from CSR scan offsets, and attaches a properly labeled
FloatDataArray via IMDataConverter::setIMUnit(). Add BrukerTimsFile_test
skeleton with #ifdef WITH_TIMSRUST guards and FileHandler detection tests.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace the loadFrames_ stub with an implementation that iterates both
MS levels (1 and 2), loading all frames via frameToSpectrum_. Replace
the load() placeholder with the real dispatch logic: FRAME mode calls
loadFrames_(), SPECTRUM mode always calls loadDDA_(), and AUTO mode
detects DDA vs DIA via isDIA_() and routes accordingly. Results are
sorted by RT after loading.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…l data

Add FetchContent-based download of DDA and DIA test .d directories
(gated by ENABLE_TIMSRUST_TESTS) and integration test sections that
verify MS1/MS2 spectra, IM data, precursor info, and drift time units.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- getTimsError() now handles null dataset handle (possible on tims_open
  failure)
- FileConverter warns that -process_lowmemory with .d input does not
  actually reduce memory usage yet

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Fix FetchContent URL to match release archive naming (v0.1.0 in filename)
- Replace default arg `Config() = {}` with overloads (GCC aggregate init issue)
- Fix FileNotReadable constructor call (4 args, not 5)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Fix metavalue key "selected_ion_mz" -> "selected ion m/z" to match
  mzML convention (MzMLHandler reads/writes "selected ion m/z")
- Extract getTimsConfig_() helper in FileConverter to deduplicate
  config-building code between low-memory and normal branches
- Check tims_get_swath_windows return status in transform() expected
  size computation

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Adapted from Sage's PeakBuffer/fastcentroid_frame algorithm (Lazear 2023,
doi:10.1021/acs.jproteome.3c00486). Integrates IM-dimension centroiding
as a config-driven load-time option to reduce MS1 peak counts.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Fix header visibility: FrameCentroider stays in .cpp, not exposed in
  frameToSpectrum_() signature. Centroiding handled in load methods.
- Fix intensity type: uint32_t* from tims_frame::intensities, not float*
- Fix expandScanOffsets: template<T> to serve both float and double callers
- Fix MS1 processing description: MS1 always uses raw frames, never
  timsrust SpectrumReader
- Add partial config validation (warn if only one param set)
- Add SpectrumSettings::CENTROID metadata on centroided MS1 spectra
- Clarify MAX_CENTROID_PEAKS drop behavior is intentional
- Adjust test plan: black-box via public API (FrameCentroider not testable
  directly from anonymous namespace)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
4 tasks across 3 chunks:
1. Config + helpers + refactored call sites (single buildable commit)
2. FrameCentroider integration into load methods
3. FileConverter TOPP parameters
4. Integration tests (centroiding, partial config, IM array, m/z sort)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…S1 IM centroiding

Add FrameCentroider struct (adapted from Sage's PeakBuffer, Lazear 2023,
doi:10.1021/acs.jproteome.3c00486) and expandScanOffsets<T> helper to
BrukerTimsFile.cpp. Add ms1_centroid_mz_ppm/ms1_centroid_im_pct config
fields to BrukerTimsFile::Config. Update loadDDA_/loadDIA_/loadFrames_
signatures to accept const Config&. Refactor inline scan-offset expansion
to use the shared expandScanOffsets template.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
When ms1_centroid_mz_ppm and ms1_centroid_im_pct are both > 0, MS1 frames
are centroided across the IM dimension before building MSSpectrum objects.
Centroided spectra are marked with SpectrumType::CENTROID. Algorithm
adapted from Sage (Lazear 2023, doi:10.1021/acs.jproteome.3c00486).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Adds timsrust:ms1_centroid_mz_ppm and timsrust:ms1_centroid_im_pct
parameters for controlling IM-dimension centroiding of MS1 frames.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Verifies centroiding reduces MS1 peak count, leaves MS2 unaffected,
preserves IM FloatDataArray, and marks spectra as CENTROID type. Also
tests that partial config (only one tolerance set) does not enable
centroiding.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Rename in_mzML parameter to in_spectra since the file-based search
methods now accept both mzML and Bruker .d (TDF) formats. Add
FileTypes::BRUKER_TDF to loadExperiment calls and register "d" as
a valid input format in the TOPP tool.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
timosachsenberg and others added 13 commits March 24, 2026 10:10
- Clamp negative values in inverse_convert to prevent UB on double→uint32_t
  cast, use rounding instead of truncation for better round-trip accuracy
- Document thread-safety constraint on global factory registration
- Use actual window_group from SQL instead of array index in DIA nativeIDs

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Use find_package(zstd) to prefer system/package-managed zstd for TDF
frame decompression. Falls back to compiling opentims's bundled
zstddeclib.c when no system zstd is available (e.g. isolated wheel
builds).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
# Conflicts:
#	cmake/cmake_findExternalLibs.cmake
- Update opentims commit hash to 85e1dfba which includes proper
  CMakeLists.txt with OPENTIMS_BUILD_CPP_LIB, OPENTIMS_LINK_SQLITE_STATICALLY
  options — eliminates need for all our CMake patches
- Remove dead needed_frames set and unused #include <set>

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

Merge PR #8982 which moves calibration converters into opentims upstream.
Update opentims to 02ad97dc (includes OSS converters, CMake options,
sqlite static linking). Removes ~300 lines of OpenMS converter code.

- Delete OpenTimsCalibration.h/.cpp (now in opentims)
- Replace setAsDefault<> calls with setup_opensource()
- Fix include paths to match opentims's PUBLIC include directory

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The ZSTD fallback compiles zstddeclib.c (a C file), but opentims only
declares CXX language. When system zstd is unavailable (wheel builds),
CMake fails with "CMAKE_C_COMPILE_OBJECT not set". Fix by enabling C
language before FetchContent.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Port timsrust's spectrum processing pipeline to C++:
- group_and_sum: merge duplicate TOF bins across scans/frames
- smooth(window=1): symmetric neighbor intensity sharing in TOF space
- centroid(window=1): sparse local maximum apex picking

Applied to DDA MS2 spectra before m/z conversion. This produces cleaner,
centroided spectra matching timsrust's output quality. Search engine
identification rates improve significantly (target PSMs +32%, decoy
PSMs -57% on HeLa DDA test data).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Make the code a bit safer

* Use opentims v1.2.0b1
@OpenMS OpenMS deleted a comment from coderabbitai Bot Mar 24, 2026
@timosachsenberg
timosachsenberg merged commit 41ce6cf into develop Mar 24, 2026
40 of 41 checks passed
@timosachsenberg
timosachsenberg deleted the opentims branch March 24, 2026 15:24
github-actions Bot pushed a commit that referenced this pull request Mar 25, 2026
- Update QPX output filenames to quantms.* scheme (#8974)
- Add GenericWrapper removal (BREAKING) (#8981)
- Add ModifiedSincSmoother new algorithm (#8217)
- Add experimental BrukerTimsFile/BRUKER_TDF format support (#8975)

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 25, 2026
- Update QPX output filenames to quantms.* scheme (#8974)
- Add GenericWrapper removal (BREAKING) (#8981)
- Add ModifiedSincSmoother new algorithm (#8217)
- Add experimental BrukerTimsFile/BRUKER_TDF format support (#8975)

Co-authored-by: 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.

2 participants