Skip to content

Add Ion Mobility Support to FeatureFinderMetabo - #8758

Merged
timosachsenberg merged 10 commits into
OpenMS:developfrom
alhigaylan:FFM_pr
Feb 16, 2026
Merged

timosachsenberg merged 10 commits into
OpenMS:developfrom
alhigaylan:FFM_pr

Conversation

@alhigaylan

@alhigaylan alhigaylan commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Add ion mobility support to FeatureFinderMetabo.

  1. New parameter introduced 'local_im_range_' to filter candidate mass traces in the isotopic envelope detection steps.
  2. Implement 'ContainsIMData()' for MassTrace object. Switch to true if ion mobility value is set.
  3. has_im_data_ flag is used to guard ion mobility access (data with no ion mobility should continue to work as normal)
  4. Introduced a new class test for ion mobility. Also a new mzML file test with ion mobility values.

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 ion mobility data support throughout the feature finding pipeline for improved accuracy.
    • Enabled ion mobility-aware retention time matching to refine feature identification.
    • Ion mobility metadata now included in feature output when data is available.
  • Tests

    • Added comprehensive test coverage for ion mobility-aware feature detection workflows.

@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds comprehensive ion mobility (IM) support to the OpenMS feature finding pipeline. Changes include explicit IM data detection flags in MassTrace and FeatureFindingMetabo, accessor methods for IM queries, integration of IM-aware RT matching logic during mass trace clustering, and new tests with configuration files validating IM-aware processing end-to-end.

Changes

Cohort / File(s) Summary
Ion Mobility Data Tracking
src/openms/include/OpenMS/KERNEL/MassTrace.h, src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h
Added public containsIMData() accessor and private flag has_centroid_im_ to MassTrace. Added private has_im_data_ flag and local_im_range_ member to FeatureFindingMetabo. Added public getAllCentroidIM() method to FeatureHypothesis.
Ion Mobility Processing Logic
src/openms/source/FEATUREFINDER/ElutionPeakDetection.cpp, src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp
Updated ElutionPeakDetection to guard IM data copying with containsIMData() check. Enhanced FeatureFindingMetabo with IM data detection, IM-aware RT matching for mass trace clustering, and IM metadata emission in feature output.
Testing & Configuration
src/tests/class_tests/openms/source/FeatureFindingMetabo_test.cpp, src/tests/topp/CMakeLists.txt, src/tests/topp/FeatureFinderMetabo_6.ini
Added comprehensive test for IM-aware feature finding workflow validating IM data preservation through pipeline stages. Added TOPP test case TOPP_FeatureFinderMetabo_6 with input dataset and expected output. Introduced new ini configuration file for IM-aware FeatureFinderMetabo parameters.

Sequence Diagram(s)

sequenceDiagram
    participant Input as Input Data<br/>(mzML with IM)
    participant MTD as MassTrace<br/>Detection
    participant MassTrace as MassTrace<br/>(with IM flag)
    participant FFM as FeatureFinding<br/>Metabo
    participant Cluster as Clustering<br/>Logic
    participant FH as FeatureHypothesis
    participant Output as Output Features<br/>(IM metadata)

    Input->>MTD: Load LC-IMS-MS data
    MTD->>MassTrace: Create traces + detect IM data
    MassTrace->>MassTrace: Set has_centroid_im_ = true
    MTD-->>FFM: Pass MassTraces with IM info
    FFM->>FFM: Detect has_im_data_ presence
    FFM->>Cluster: Run clustering with IM awareness
    Cluster->>Cluster: Match by RT + IM proximity<br/>(if IM data present)
    Cluster->>FH: Group matching traces into isotope pattern
    FH->>FH: Collect IM values from all traces<br/>via getAllCentroidIM()
    FH->>Output: Emit features + masstrace_centroid_im metadata
Loading

Possibly related issues

Possibly related PRs

Suggested labels

enhancement, Review effort [1-5]: 3

Suggested reviewers

  • timosachsenberg
  • poshul

Poem

🐰 A rabbit hops through mass traces with glee,
Ion mobility flags now set wild and free!
RT and IM together, clustering tight,
Features bloom brighter with IM in sight! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.46% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately summarizes the main objective of the PR: adding ion mobility support to FeatureFinderMetabo, which is confirmed by all file changes.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

🤖 Fix all issues with AI agents
In `@src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h`:
- Around line 318-319: The member local_im_range_ is not given an in-class
default like has_im_data_, risking use-before-init; update the declaration of
local_im_range_ to include a sensible in-class initializer (e.g., 0.0) to match
the defensive pattern used for has_im_data_, and ensure consistency with
local_rt_range_ initialization; mention/update documentation/comments near the
member and confirm updateMembers_() (from DefaultParamHandler) still overwrites
it from parameters as intended.

In `@src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp`:
- Around line 875-883: The code sets has_im_data_ using std::any_of which can
cause getCentroidIM() to be called on traces without IM and produce spurious 0.0
values; change the logic to either set has_im_data_ with
std::all_of(input_mtraces.begin(), input_mtraces.end(), [](const MassTrace& mt){
return mt.containsIMData(); }) so you only treat IM as present when every trace
has it, or keep the any_of but guard every getCentroidIM() use (e.g., when
computing IM distances in the trace-pairing code that uses getCentroidIM()) with
per-trace containsIMData() checks and skip/adjust IM comparisons for traces that
lack IM data; update references to has_im_data_, getCentroidIM(), and
containsIMData() accordingly.
🧹 Nitpick comments (8)
src/openms/include/OpenMS/KERNEL/MassTrace.h (1)

186-190: Consider documenting the side-effect in the Doxygen comment for setCentroidIM.

Calling setCentroidIM now implicitly marks the trace as containing IM data (via has_centroid_im_ = true). The existing /// comment doesn't mention this. A brief note would help callers understand that containsIMData() will return true after this call.

📝 Suggested Doxygen update
-    void setCentroidIM(const double & im)
+    /// Sets the centroid ion mobility value and marks this trace as containing IM data.
+    void setCentroidIM(const double& im)
src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h (1)

69-69: Add Doxygen comment for the new public method getAllCentroidIM().

The coding guidelines require Doxygen documentation with @brief for new public methods in header files under src/openms/include/OpenMS/. The existing sibling methods (getAllCentroidMZ, getAllCentroidRT) also lack them, but new additions should comply.

📝 Suggested Doxygen
+    /// `@brief` Returns the centroid ion mobility values of all contained mass traces.
     std::vector<double> getAllCentroidIM() const;

As per coding guidelines: "Add Doxygen comments for new public methods and classes" for files matching src/openms/include/OpenMS/**/*.h.

src/tests/topp/FeatureFinderMetabo_6.ini (1)

38-49: The ffm section does not include the local_im_range parameter.

Since this test file is specifically for IM-aware testing, consider explicitly setting local_im_range in the ffm section to improve test clarity and self-documentation. The parameter has a default value of 0.02, but making it explicit would align expectations for IM-specific validation.

src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp (2)

202-211: Misleading doc-comment on getter method.

The comment on line 202 says "formulate a feature with meta values…" but this method simply collects and returns centroid IM values from the underlying mass traces — it doesn't formulate a feature or set any meta values. Consider aligning the comment with the actual behavior, similar to the neighboring getAllCentroidMZ() / getAllCentroidRT() methods (which have no misleading comments).

📝 Suggested comment fix
-  /// formulate a feature with meta values containing MassTrace IM values
+  /// collect centroid IM values from all mass traces in this hypothesis
   std::vector<double> FeatureHypothesis::getAllCentroidIM() const

263-263: Consider adding a unit-awareness warning for local_im_range.

The default of 0.02 is appropriate for 1/K0 (Vs/cm²) data but would be far too small for CCS (square angstroms) data. MassTraceDetection already has a warning for this scenario (see MassTraceDetection.cpp lines ~200-205 in the relevant snippet). A similar diagnostic here would help users who accidentally use CCS-unit data with a narrow tolerance.

src/tests/class_tests/openms/source/FeatureFindingMetabo_test.cpp (3)

111-111: Test data path uses relative traversal to reach a TOPP test file.

The path "../../../topp/FeatureFinderMetabo_6_input.mzML" traverses out of the class test data directory to reference a TOPP test file. This is fragile and couples this unit test to the TOPP test directory layout. As per coding guidelines, test data files should be placed in src/tests/class_tests/libs/data/ and prefixed with the class name (e.g., FeatureFindingMetabo_im_input.mzML).

If you want to avoid duplicating the file, at minimum consider a symlink or copying it to the expected location with the proper naming convention.

#!/bin/bash
# Check if the referenced test data file exists in the TOPP test directory
fd 'FeatureFinderMetabo_6_input.mzML' --type f

# Check what test data files already exist for this class
fd 'FeatureFindingMetabo' --type f src/tests/class_tests/

106-176: Good IM pipeline integration test, but consider adding concrete value assertions.

The test currently only checks that outputs are non-empty and that IM metadata exists. This makes it a smoke test, not a regression test — if the IM filtering logic regresses (e.g., producing wrong feature counts or incorrect IM values), this test won't catch it.

Consider adding:

  • A TEST_EQUAL on the expected feature count (like the existing non-IM tests on lines 80, 87, 101).
  • Spot-check an IM centroid value from one feature to verify correctness.
  • Optionally, a FuzzyDiff comparison against a reference featureXML output (consistent with the pattern on line 94).

125-133: Repeated IM-presence check loop could be extracted or simplified.

The same loop pattern (iterate traces, check containsIMData(), break on first hit) is duplicated on lines 125–133 and 143–151. You could use std::any_of for conciseness:

♻️ Example simplification
-  bool has_im = false;
-  for (const auto& mt : im_traces)
-  {
-    if (mt.containsIMData())
-    {
-      has_im = true;
-      break;
-    }
-  }
-  TEST_EQUAL(has_im, true);
+  TEST_EQUAL(std::any_of(im_traces.begin(), im_traces.end(),
+    [](const MassTrace& mt) { return mt.containsIMData(); }), true);

Also applies to: 143-151

Comment on lines 318 to +319
double local_rt_range_;
double local_im_range_;

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

🧩 Analysis chain

🏁 Script executed:

rg -n 'local_im_range_' --type=cpp --type=h -C 5

Repository: OpenMS/OpenMS

Length of output: 3291


🏁 Script executed:

rg -n 'local_rt_range_' --type=cpp --type=h -C 3

Repository: OpenMS/OpenMS

Length of output: 2223


🏁 Script executed:

rg -n 'updateMembers_' src/openms -A 20 --type=cpp

Repository: OpenMS/OpenMS

Length of output: 50370


🏁 Script executed:

rg -n 'has_im_data_' --type=cpp --type=h -C 3

Repository: OpenMS/OpenMS

Length of output: 3213


Inconsistency in member variable initialization: local_im_range_ should match has_im_data_ pattern.

local_im_range_ lacks an in-class default initializer (unlike has_im_data_ = false), relying instead on updateMembers_() to initialize it from parameters. While the DefaultParamHandler pattern ensures updateMembers_() is called in the constructor, the inconsistency creates risk if the object is misused or parameters are missing. Consider adding an in-class initializer (e.g., double local_im_range_ = 0.0;) for consistency and defensive programming, or document that updateMembers_() must be called before use.

🤖 Prompt for AI Agents
In `@src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h` around lines
318 - 319, The member local_im_range_ is not given an in-class default like
has_im_data_, risking use-before-init; update the declaration of local_im_range_
to include a sensible in-class initializer (e.g., 0.0) to match the defensive
pattern used for has_im_data_, and ensure consistency with local_rt_range_
initialization; mention/update documentation/comments near the member and
confirm updateMembers_() (from DefaultParamHandler) still overwrites it from
parameters as intended.

@timosachsenberg

Copy link
Copy Markdown
Contributor

Should we check an IM tolerance during feature assembly? e.g. to prevent combining two mass traces that look like isotope patter but even are from different charges (-> different IM).

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