Repository navigation
Add Ion Mobility Support to FeatureFinderMetabo - #8758
Conversation
…n MSSpectrum for MassTrace object
📝 WalkthroughWalkthroughThis 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
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
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 forsetCentroidIM.Calling
setCentroidIMnow implicitly marks the trace as containing IM data (viahas_centroid_im_ = true). The existing///comment doesn't mention this. A brief note would help callers understand thatcontainsIMData()will returntrueafter 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 methodgetAllCentroidIM().The coding guidelines require Doxygen documentation with
@brieffor new public methods in header files undersrc/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: Theffmsection does not include thelocal_im_rangeparameter.Since this test file is specifically for IM-aware testing, consider explicitly setting
local_im_rangein theffmsection 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 forlocal_im_range.The default of
0.02is appropriate for 1/K0 (Vs/cm²) data but would be far too small for CCS (square angstroms) data.MassTraceDetectionalready has a warning for this scenario (seeMassTraceDetection.cpplines ~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 insrc/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_EQUALon 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
FuzzyDiffcomparison against a referencefeatureXMLoutput (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 usestd::any_offor 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
| double local_rt_range_; | ||
| double local_im_range_; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
rg -n 'local_im_range_' --type=cpp --type=h -C 5Repository: OpenMS/OpenMS
Length of output: 3291
🏁 Script executed:
rg -n 'local_rt_range_' --type=cpp --type=h -C 3Repository: OpenMS/OpenMS
Length of output: 2223
🏁 Script executed:
rg -n 'updateMembers_' src/openms -A 20 --type=cppRepository: OpenMS/OpenMS
Length of output: 50370
🏁 Script executed:
rg -n 'has_im_data_' --type=cpp --type=h -C 3Repository: 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.
|
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). |
Description
Add ion mobility support to FeatureFinderMetabo.
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
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.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Tests