Skip to content

Feature/tims calibration tiered - #8999

Merged
timosachsenberg merged 8 commits into
developfrom
feature/tims-calibration-tiered
Mar 25, 2026
Merged

timosachsenberg merged 8 commits into
developfrom
feature/tims-calibration-tiered

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

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
    • Added configurable TIMS calibration strategies (AUTO, Bruker SDK, rational function, linear) to optimize data processing based on specific requirements.
    • Introduced pressure compensation options (NONE, GLOBAL, PER_FRAME) for enhanced calibration accuracy in TIMS data analysis.
    • Added support for Bruker SDK path configuration to facilitate seamless TIMS data integration and processing.

timosachsenberg and others added 8 commits March 25, 2026 16:40
Introduces a three-tier calibration strategy for BrukerTimsFile:
Bruker SDK → rational function (TimsCalibration table) → linear.
The rational function model is the first open-source implementation
to use per-frame calibration from the TimsCalibration table.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
6-task plan covering: Config enums, RationalScan2ImConverter header/impl,
unit tests (TDD), tiered fallback wiring, and verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Implements the RationalScan2ImConverter class that reads per-frame
calibration coefficients from the Bruker TimsCalibration table and
applies the rational function model (ModelType=2) for scan-to-1/K0
conversion. Includes forward, inverse, and batch conversion methods,
singularity guards, and a factory function that reads from SQLite.

Also registers the new source file in sources.cmake.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Adds 5 test sections covering forward conversion, round-trip via
inverse_convert, per-frame calibration dispatch, description output,
and singularity edge cases. Also links opentims_cpp and sqlite3 to the
test target for header access, adds missing ProteinIdentification.h
include to fix a pre-existing incomplete type error.

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

openTimsDataHandle() now implements a three-tier strategy controlled by
Config::TimsCalibrationStrategy: attempt Bruker SDK (with optional pressure
compensation), fall back to rational model from TimsCalibration table, then
fall back to linear (GlobalMetadata). Both load() and transform() pass
the caller's Config through to the handle factory.

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

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR introduces a tiered calibration strategy system for TIMS (Trapped Ion Mobility Spectrometry) conversions, enabling users to select between Bruker SDK, rational-function-based, and linear calibration methods. A new RationalScan2ImConverter class implements rational-function-based ion mobility conversion using SQLite-stored coefficients, with fallback mechanisms and configurable pressure compensation.

Changes

Cohort / File(s) Summary
Configuration & API Definitions
src/openms/include/OpenMS/FORMAT/BrukerTimsFile.h, src/openms/include/OpenMS/FORMAT/RationalScan2ImConverter.h
Added TimsCalibrationStrategy (AUTO, BRUKER_SDK, RATIONAL, LINEAR) and PressureCompensation (NONE, GLOBAL, PER_FRAME) enums with bruker_sdk_path field to Config. New RationalScan2ImConverter class with Coefficients struct and factory function tryCreateRationalConverter.
Implementation
src/openms/source/FORMAT/BrukerTimsFile.cpp, src/openms/source/FORMAT/RationalScan2ImConverter.cpp
Refactored openTimsDataHandle() to implement tiered calibration strategy (SDK → rational → linear fallback). Added mapPressureCompensation() helper. New RationalScan2ImConverter implementation with rational formula conversion/inversion, calibration lookup, and SQLite-based factory function reading TimsCalibration table.
Build Configuration
src/openms/include/OpenMS/FORMAT/sources.cmake, src/openms/source/FORMAT/sources.cmake, src/tests/class_tests/openms/CMakeLists.txt
Added RationalScan2ImConverter.h and .cpp to FORMAT sources; linked BrukerTimsFile_test against opentims_cpp and sqlite3 libraries under WITH_OPENTIMS.
Tests
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
Added comprehensive unit tests for RationalScan2ImConverter covering forward/inverse conversion, per-frame calibration mapping, metadata validation, and singularity edge-case robustness.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Code
    participant Handle as openTimsDataHandle()
    participant SDK as BrukerScan2ImFactory
    participant DB as SQLite DB
    participant Rational as RationalConverter
    participant Linear as LinearConverter

    Client->>Handle: load/transform(path, config)
    Handle->>Handle: Determine calibration strategy
    
    alt AUTO or BRUKER_SDK strategy
        Handle->>SDK: Attempt SDK initialization
        alt SDK success
            SDK->>Handle: Replace with SDK converter
            Handle->>Handle: Log SDK mode
        else SDK failure
            Handle->>Handle: If BRUKER_SDK, throw; else debug log
        end
    end
    
    alt AUTO or RATIONAL strategy
        Handle->>DB: tryCreateRationalConverter(path)
        DB->>DB: Read TimsCalibration table
        alt Valid rational data
            DB->>Rational: Create converter with coefficients
            Rational->>Handle: Return RationalConverter
            Handle->>Handle: Replace with Rational converter
        else Invalid/missing data
            alt RATIONAL strategy
                DB->>Handle: throw FileNotReadable
            else AUTO strategy
                DB->>Handle: Return nullptr, continue
            end
        end
    end
    
    alt No strategy succeeded
        Handle->>Linear: Use linear converter
        Handle->>Handle: Log linear (GlobalMetadata)
    end
    
    Handle->>Client: Return configured TimsDataHandle
Loading

Suggested labels

codex

Suggested reviewers

  • jcharkow

Poem

🐰 Bunny hops through calibration tiers,
SDK, rational, linear—no fears!
Coefficients dance in SQLite's keep,
Ion mobility conversions run deep. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/tims calibration tiered' uses abbreviated/vague phrasing that doesn't clearly convey the main change to a reviewer quickly scanning history. Consider a more descriptive title such as 'Add tiered TIMS calibration strategy with rational function support' or 'Implement fallback TIMS calibration: SDK → rational → linear' for clarity.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 feature/tims-calibration-tiered

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/RationalScan2ImConverter.cpp (1)

47-67: Singularity guards use exact zero comparison.

The guards check == 0.0 rather than a tolerance-based near-zero check. This works for the tested edge cases but could miss values very close to zero (e.g., 1e-15) that would still cause numeric instability.

Given that:

  1. These conditions are "physically unreachable" as documented
  2. The tests verify std::isfinite output for known edge cases
  3. Real calibration data should never produce near-zero denominators

This is acceptable for the current use case. Consider adding a tolerance-based check if numeric issues are observed in practice.

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

In `@src/openms/source/FORMAT/RationalScan2ImConverter.cpp` around lines 47 - 67,
The singularity guards in RationalScan2ImConverter::applyFormula and
::invertFormula use exact comparisons (e.g., V == 0.0, denom == 0.0, inner_denom
== 0.0, slope_denom == 0.0); change these to tolerance-based near-zero checks
(e.g., fabs(x) < eps) and replace the value with the small fallback (1e-10) when
within that tolerance. Add a local constexpr double eps (e.g., 1e-12) near the
start of each function or as a static constant and use it to test V, denom,
inner_denom and slope_denom before substituting the guard value.
🤖 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/RationalScan2ImConverter.h`:
- Around line 1-4: Add the missing $Maintainer:$ marker to the header preamble
in RationalScan2ImConverter.h: update the file preamble (above the `#pragma` once
and the existing copyright lines) to include a line containing the
`$Maintainer:$` token so the header complies with the coding guidelines and
identifies the maintainer for the RationalScan2ImConverter declarations.

---

Nitpick comments:
In `@src/openms/source/FORMAT/RationalScan2ImConverter.cpp`:
- Around line 47-67: The singularity guards in
RationalScan2ImConverter::applyFormula and ::invertFormula use exact comparisons
(e.g., V == 0.0, denom == 0.0, inner_denom == 0.0, slope_denom == 0.0); change
these to tolerance-based near-zero checks (e.g., fabs(x) < eps) and replace the
value with the small fallback (1e-10) when within that tolerance. Add a local
constexpr double eps (e.g., 1e-12) near the start of each function or as a
static constant and use it to test V, denom, inner_denom and slope_denom before
substituting the guard value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e26213ff-e98a-494d-9990-40ba75dfadd6

📥 Commits

Reviewing files that changed from the base of the PR and between fdf7aba and dc1e0d2.

📒 Files selected for processing (8)
  • src/openms/include/OpenMS/FORMAT/BrukerTimsFile.h
  • src/openms/include/OpenMS/FORMAT/RationalScan2ImConverter.h
  • src/openms/include/OpenMS/FORMAT/sources.cmake
  • src/openms/source/FORMAT/BrukerTimsFile.cpp
  • src/openms/source/FORMAT/RationalScan2ImConverter.cpp
  • src/openms/source/FORMAT/sources.cmake
  • src/tests/class_tests/openms/CMakeLists.txt
  • src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp

Comment on lines +1 to +4
// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

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 | 🟡 Minor

Add $Maintainer:$ marker to header preamble.

Per coding guidelines, every header file must include the $Maintainer:$ marker in the preamble. This helps identify code ownership for future maintenance.

📝 Suggested fix
 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
 // SPDX-License-Identifier: BSD-3-Clause
+//
+// --------------------------------------------------------------------------
+// $Maintainer: Timo Sachsenberg $
+// $Authors: Timo Sachsenberg $
+// --------------------------------------------------------------------------

 `#pragma` once

As per coding guidelines: "Include file preamble with Copyright notice and $Maintainer:$ marker in every header file".

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

In `@src/openms/include/OpenMS/FORMAT/RationalScan2ImConverter.h` around lines 1 -
4, Add the missing $Maintainer:$ marker to the header preamble in
RationalScan2ImConverter.h: update the file preamble (above the `#pragma` once and
the existing copyright lines) to include a line containing the `$Maintainer:$`
token so the header complies with the coding guidelines and identifies the
maintainer for the RationalScan2ImConverter declarations.

@timosachsenberg
timosachsenberg merged commit 2df411d into develop Mar 25, 2026
40 of 41 checks passed
@timosachsenberg
timosachsenberg deleted the feature/tims-calibration-tiered branch March 25, 2026 20:00
github-actions Bot pushed a commit that referenced this pull request Mar 26, 2026
Add missing entries for:
- #8991: Arrow/Parquet made required dependency; WITH_PARQUET CMake option removed
- #8993: BREAKING IMFormat enum rename (CONCATENATED→IM_PEAK, MULTIPLE_SPECTRA→IM_SPECTRUM)
- #8997: Fix TOPPView performance regression when right-clicking in large mzML
- #8999: BrukerTimsFile tiered scan→1/K0 calibration with RationalScan2ImConverter

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 26, 2026
Add missing entries for:
- #8991: Arrow/Parquet made required dependency; WITH_PARQUET CMake option removed
- #8993: BREAKING IMFormat enum rename (CONCATENATED→IM_PEAK, MULTIPLE_SPECTRA→IM_SPECTRUM)
- #8997: Fix TOPPView performance regression when right-clicking in large mzML
- #8999: BrukerTimsFile tiered scan→1/K0 calibration with RationalScan2ImConverter

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.

1 participant