Skip to content

Improve isotope/adduct RT grouping for low-intensity mass traces (#4483) - #9711

Merged
timosachsenberg merged 4 commits into
developfrom
claude/openms-issue-4483-b415p6
Jul 7, 2026
Merged

timosachsenberg merged 4 commits into
developfrom
claude/openms-issue-4483-b415p6

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #4483.

Low-intensity isotope and adduct mass traces are usually much shorter in RT than the intense monoisotopic / [M+H]+ trace. The previous RT-overlap criteria measured the overlap against the longer trace (isotope grouping) or the union of both RT ranges (adduct grouping), so these genuine peaks were often rejected — the union/longer length is dominated by the long, intense trace while the intersection is bounded by the short one. This is especially relevant for metabolites containing Cl, F, Br, etc.

Both changes are opt-in and default to the historic behavior, so existing results and reference tests are unchanged (see the note at the bottom).

FeatureFindingMetabo::scoreRT_ (isotope grouping)

  • New advanced parameter isotope_rt_overlap_reference (longer | shorter, default longer):
    • longer — historic behavior: overlap must be ≥ min_isotope_rt_overlap of the longer trace.
    • shorter — overlap is measured against the shorter trace, and additionally the apex of the longer trace must fall within the RT range of the shorter trace. This groups low-intensity isotope traces that are much shorter than the monoisotopic trace.
  • New advanced parameter min_isotope_rt_overlap (default 0.7, range [0, 1]) exposes the overlap threshold that was previously hard-coded to 0.7. With isotope_rt_overlap_reference=shorter, 0.95–0.99 is recommended (per the issue discussion).

MetaboliteFeatureDeconvolution (adduct grouping)

  • New advanced parameter rt_overlap_reference (union | shorter, default union):
    • union — historic behavior (intersection / union of both RT ranges).
    • shorter — intersection / shorter feature RT range, which groups adducts with strongly differing intensities/elution widths (e.g. an intense [M+H]+ and a weak [M+Na]+). Fails closed for degenerate zero-width features.

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.)

Note on defaults: Both improvements ship off by default so that no reference outputs change and CI stays green. Making the shorter behavior the default would change FeatureFindingMetabo's output (feature counts / FeatureFindingMetabo_output1.featureXML and the TOPP_FeatureFinderMetabo_{1,5,6}_out references), which should be regenerated and validated on representative data by a maintainer. Happy to flip the defaults and update the reference data if preferred.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added advanced RT overlap controls for feature deconvolution, including a “shorter” normalization option.
    • Introduced advanced isotopic RT overlap settings for isotopic mass-trace grouping, with selectable overlap reference and a configurable minimum overlap threshold.
  • Bug Fixes
    • Improved isotopic RT scoring to honor the selected overlap reference and to prevent grouping when the longer trace apex RT falls outside the shorter trace’s FWHM-elution range.
  • Documentation
    • Updated parameter descriptions for isotopic RT overlap gating to reflect the new reference and threshold behavior.

Low-intensity isotope and adduct mass traces are much shorter in RT than
the intense monoisotopic/[M+H]+ trace, so the previous RT-overlap criteria
(which measured against the longer/union RT range) failed to group them.

FeatureFindingMetabo::scoreRT_:
- Measure the RT overlap against the shorter co-eluting trace instead of the
  longer one, i.e. require the shorter trace to lie almost entirely within
  the longer trace. The threshold is exposed as the advanced parameter
  'min_isotope_rt_overlap' (default 0.95).
- Additionally require the apex of the longer trace to fall within the RT
  range of the shorter trace.

MetaboliteFeatureDeconvolution:
- Add advanced parameter 'rt_overlap_reference' to select the reference for
  the RT overlap fraction: 'union' (historic behavior, default) or 'shorter'
  (divide by the shorter feature's RT range) to group adducts with strongly
  differing intensities/elution widths.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1W3i5Pc8zT4GYfQQ8NVwT
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Claude

Please consider applying the following patch:

--- AUTHORS	2026-07-07 05:35:34.273588631 +0000
+++ AUTHORS.new	2026-07-07 05:35:39.322715679 +0000
@@ -25,6 +25,7 @@
  - Chris Bielow
  - Christian Ehrlich
  - Christie Mathews
+ - Claude
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7ddb5f4-f8c8-4737-845a-31c6cc63d7f9

📥 Commits

Reviewing files that changed from the base of the PR and between 8b7188b and a5a71b5.

📒 Files selected for processing (1)
  • src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp

📝 Walkthrough

Walkthrough

Adds configurable RT-overlap reference modes for isotope grouping and adduct candidate pruning, replacing fixed overlap normalization with parameterized longer-or-shorter span checks.

Changes

RT overlap grouping fixes

Layer / File(s) Summary
Isotope RT overlap scoring in FeatureFindingMetabo
src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h, src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp
Adds the new overlap threshold state and parameter handling, then reworks scoreRT_() to compare overlap against the selected trace length and require the longer trace apex to fall within the shorter trace range in shorter-reference mode.
Adduct candidate RT overlap normalization in MetaboliteFeatureDeconvolution
src/openms/source/ANALYSIS/DECHARGING/MetaboliteFeatureDeconvolution.cpp
Adds rt_overlap_reference, derives the shorter-reference flag, and updates candidate pruning to normalize overlap by either the union span or the shorter feature span.

Sequence Diagram(s)

sequenceDiagram
  participant FeatureFindingMetabo
  participant scoreRT_
  participant Params

  FeatureFindingMetabo->>Params: read min_isotope_rt_overlap
  FeatureFindingMetabo->>scoreRT_: score trace pair
  scoreRT_->>scoreRT_: choose longer_trace and shorter_trace
  scoreRT_->>scoreRT_: compute overlap vs selected reference length
  scoreRT_->>scoreRT_: require apex RT inside shorter trace range
  scoreRT_-->>FeatureFindingMetabo: score or 0.0
Loading
sequenceDiagram
  participant MetaboliteFeatureDeconvolution
  participant candidateEdges_
  participant Params

  MetaboliteFeatureDeconvolution->>Params: read rt_overlap_reference
  MetaboliteFeatureDeconvolution->>candidateEdges_: evaluate feature pair
  candidateEdges_->>candidateEdges_: derive reference_length
  candidateEdges_->>candidateEdges_: compare overlap ratio to min_rt_overlap
  candidateEdges_-->>MetaboliteFeatureDeconvolution: keep or skip candidate
Loading

Related issues: #4483
Suggested reviewers: cbielow

Poem

A rabbit hopped through peaks and time,
and chose the shorter trace to prime.
With overlap made clear and kind,
the right pairs now are easier to find.
Hoppity! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the isotope/adduct RT grouping improvement in this PR.
Linked Issues check ✅ Passed The PR adds shorter-trace RT overlap handling, apex containment, and configurable adduct overlap normalization as requested.
Out of Scope Changes check ✅ Passed The changes are confined to the metabolite RT grouping enhancement and related parameter handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 claude/openms-issue-4483-b415p6

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.

@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 (2)
src/openms/source/ANALYSIS/DECHARGING/MetaboliteFeatureDeconvolution.cpp (1)

461-474: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No test coverage for rt_overlap_reference = "shorter".

The existing regression test (MetaboliteFeatureDeconvolution_test.cpp) exercises only the default "union" behavior. Given the edge case above, a test covering the "shorter" option (including a narrow/point-like feature) would help catch regressions.

🤖 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/openms/source/ANALYSIS/DECHARGING/MetaboliteFeatureDeconvolution.cpp`
around lines 461 - 474, Add regression coverage in
MetaboliteFeatureDeconvolution_test.cpp for the rt_overlap_reference = "shorter"
path in MetaboliteFeatureDeconvolution, since only the default union behavior is
currently tested. Create a case that sets rt_overlap_use_shorter via the
relevant deconvolution configuration and includes a narrow or point-like feature
so the shorter-reference overlap logic is exercised, then assert the expected
grouping/deconvolution result.
src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h (1)

268-282: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

scoreRT_ Doxygen doc is now stale.

The doc still states "the overlap between the two peaks at FHWM needs to exceed a certain threshold. The threshold is set at 0.7 (i.e. 70 % overlap) as also described in Kenar et al." The implementation now uses a configurable min_isotope_rt_overlap_ (default 0.95) measured against the shorter trace, plus a new apex-containment requirement. Consider updating the doc to reflect the new behavior so future readers aren't misled.

🤖 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/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h` around lines
268 - 282, Update the Doxygen for scoreRT_ in FeatureFindingMetabo to match the
current scoring logic: remove the outdated fixed 0.7 FHWM overlap description
and document that the overlap is now checked against the configurable
min_isotope_rt_overlap_ threshold (default 0.95) relative to the shorter trace,
along with the new apex-containment requirement. Keep the summary aligned with
the actual behavior so readers understand the current conditions under which
scoreRT_ computes retention time similarity.
🤖 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/openms/source/ANALYSIS/DECHARGING/MetaboliteFeatureDeconvolution.cpp`:
- Around line 461-474: The RT overlap check in MetaboliteFeatureDeconvolution
should fail closed when rt_overlap_use_shorter selects a zero-width reference.
In the overlap logic around reference_length, use the existing feature hull
bounds from f1 and f2 to detect degenerate RT length and reject the pair instead
of skipping the check when reference_length is 0.0, matching the zero-length
handling in FeatureFindingMetabo::scoreRT_.

---

Nitpick comments:
In `@src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h`:
- Around line 268-282: Update the Doxygen for scoreRT_ in FeatureFindingMetabo
to match the current scoring logic: remove the outdated fixed 0.7 FHWM overlap
description and document that the overlap is now checked against the
configurable min_isotope_rt_overlap_ threshold (default 0.95) relative to the
shorter trace, along with the new apex-containment requirement. Keep the summary
aligned with the actual behavior so readers understand the current conditions
under which scoreRT_ computes retention time similarity.

In `@src/openms/source/ANALYSIS/DECHARGING/MetaboliteFeatureDeconvolution.cpp`:
- Around line 461-474: Add regression coverage in
MetaboliteFeatureDeconvolution_test.cpp for the rt_overlap_reference = "shorter"
path in MetaboliteFeatureDeconvolution, since only the default union behavior is
currently tested. Create a case that sets rt_overlap_use_shorter via the
relevant deconvolution configuration and includes a narrow or point-like feature
so the shorter-reference overlap logic is exercised, then assert the expected
grouping/deconvolution result.
🪄 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: faa67de0-0810-4f24-a2c2-ae11c720bc54

📥 Commits

Reviewing files that changed from the base of the PR and between 91c73c4 and 7bc7ce5.

📒 Files selected for processing (3)
  • src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h
  • src/openms/source/ANALYSIS/DECHARGING/MetaboliteFeatureDeconvolution.cpp
  • src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp

claude added 2 commits July 7, 2026 05:42
…T_ docs

- MetaboliteFeatureDeconvolution: when 'rt_overlap_reference' is 'shorter' and
  a feature has a zero-width RT hull, reject the pair instead of skipping the
  overlap check (fail closed), matching the zero-length handling in
  FeatureFindingMetabo::scoreRT_.
- FeatureFindingMetabo: update the stale scoreRT_ Doxygen to describe the
  shorter-trace overlap ('min_isotope_rt_overlap') and apex-containment criteria.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1W3i5Pc8zT4GYfQQ8NVwT
The shorter-trace overlap + apex-containment logic changed the default output
of FeatureFindingMetabo, breaking FeatureFindingMetabo_test and the
TOPP_FeatureFinderMetabo_{1,5,6}_out reference tests.

Gate the new logic behind the advanced parameter 'isotope_rt_overlap_reference'
(values 'longer'/'shorter', default 'longer'), mirroring the 'rt_overlap_reference'
switch already used in MetaboliteFeatureDeconvolution. With the default 'longer'
and 'min_isotope_rt_overlap' = 0.7, scoreRT_ reproduces the historic behavior
exactly (overlap / longer trace < 0.7). Setting it to 'shorter' enables the
shorter-trace normalization and apex-containment check from issue #4483.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1W3i5Pc8zT4GYfQQ8NVwT

Copy link
Copy Markdown
Contributor Author

The initial commit made the improved isotope grouping the default, which changed FeatureFindingMetabo's output and failed 4 reference tests (FeatureFindingMetabo_test + TOPP_FeatureFinderMetabo_{1,5,6}_out).

I've refactored so both improvements are opt-in and the defaults reproduce the historic behavior exactly (isotope: overlap / longer_trace < 0.7; adduct: intersect / union), so those tests should go green again. The new behavior is enabled via isotope_rt_overlap_reference=shorter and rt_overlap_reference=shorter.

Open question for you: do you want the shorter-based grouping to be the default instead? That's the actual fix for #4483, but it changes FeatureFindingMetabo output for everyone and needs the reference featureXMLs + expected feature counts regenerated and validated on real data — I can't validate those in this environment. If you'd like, I can flip the defaults and regenerate the references for your review.


Generated by Claude Code

@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.

🧹 Nitpick comments (1)
src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp (1)

662-672: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Inconsistent zero-length guard between the two branches.

The new shorter branch guards against min_length == 0 (Line 681: (min_length > 0.0) ? (overlap / min_length) : 0.0), but the historic longer branch's overlap / max_length (Line 666) has no equivalent guard. If both traces have a degenerate zero-length FWHM, 0.0 / 0.0 yields NaN, and NaN < min_isotope_rt_overlap_ evaluates to false, so the RT filter would be silently bypassed instead of rejecting the pair. This is pre-existing behavior now made more visible by branching, and the edge case is rare (FWHM is normally a small positive interpolated value), so it's low priority, but worth aligning for consistency.

🛡️ Optional consistency fix
       // Historic behavior: the overlap must exceed the given fraction of the
       // longer trace (default 0.7, i.e. 70 %, as described in Kenar et al.).
-      double proportion(overlap / max_length);
+      double proportion = (max_length > 0.0) ? (overlap / max_length) : 0.0;
       if (proportion < min_isotope_rt_overlap_)
       {
         return 0.0;
       }
🤖 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/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp` around lines 662 -
672, The RT-overlap check in FeatureFindingMetabo::computeCosineSim_ has an
inconsistent zero-length guard between the shorter and longer branches, so align
the historic longer-trace path with the safer handling used in the shorter path.
Update the branch that computes proportion from overlap/max_length to explicitly
handle max_length == 0 before comparing against min_isotope_rt_overlap_, using
the same zero-safe pattern already present in the shorter branch, so degenerate
traces are rejected consistently instead of producing NaN-based bypass behavior.
🤖 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.

Nitpick comments:
In `@src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp`:
- Around line 662-672: The RT-overlap check in
FeatureFindingMetabo::computeCosineSim_ has an inconsistent zero-length guard
between the shorter and longer branches, so align the historic longer-trace path
with the safer handling used in the shorter path. Update the branch that
computes proportion from overlap/max_length to explicitly handle max_length == 0
before comparing against min_isotope_rt_overlap_, using the same zero-safe
pattern already present in the shorter branch, so degenerate traces are rejected
consistently instead of producing NaN-based bypass behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a78cb46-3e6d-42da-9a97-94810233971c

📥 Commits

Reviewing files that changed from the base of the PR and between c6ed1f1 and 8b7188b.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.h
  • src/openms/source/FEATUREFINDER/FeatureFindingMetabo.cpp

Guard the historic 'longer' overlap path against a zero-length reference
(overlap / max_length) the same way the 'shorter' path already does, so a
degenerate pair with zero FWHM is rejected instead of bypassing the RT filter
via NaN comparison.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1W3i5Pc8zT4GYfQQ8NVwT
@timosachsenberg
timosachsenberg merged commit f2d5af7 into develop Jul 7, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the claude/openms-issue-4483-b415p6 branch July 7, 2026 13:19
timosachsenberg added a commit that referenced this pull request Jul 8, 2026
PR #9711 (RT-overlap reference options for isotope/adduct mass-trace
grouping, fixes #4483) merged without a CHANGELOG entry.

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

[Enhancement] Isotope and adduct grouping for metabolites

2 participants