Skip to content

Add molecular multiplier support for multimer adduct annotation - #8431

Closed
timosachsenberg with Copilot wants to merge 5 commits into
developfrom
copilot/add-multimer-annotation-support
Closed

timosachsenberg with Copilot wants to merge 5 commits into
developfrom
copilot/add-multimer-annotation-support

Conversation

Copilot AI commented Dec 5, 2025 •

Copy link
Copy Markdown
Contributor

MetaboliteAdductDecharger cannot annotate multimeric adducts like [2M+H]+. While the adduct TSV files already contain these entries (e.g., 2M+H;1+), the Adduct class used by MetaboliteFeatureDeconvolution has no concept of molecular multipliers.

Changes

Adduct class

  • Add mol_multiplier_ field (default=1) for representing dimers, trimers, etc.
  • Add getMolMultiplier()/setMolMultiplier() accessors
  • Extend toAdductString() to format multimer annotations correctly

Compomer class

  • Add getMaxMolMultiplier(side) to retrieve max multiplier from adducts on a given side

MetaboliteFeatureDeconvolution

  • Extended adduct format to accept optional 6th parameter for mol_multiplier
  • Add max_multimer parameter for future multimer detection configuration
  • Annotate features with mol_multiplier metadata when present

Usage

# Adduct format (6th param is mol_multiplier):
# Elements:Charge:Probability[:RTShift[:Label[:MolMultiplier]]]

# Example: [2M+H]+ dimer
H:+:0.1:0::2

# Output annotation
[2M+H]+  # instead of [M+H]+

Note

This PR adds the API infrastructure. Full automatic detection of monomer-multimer relationships (features with mass ≈ n×M) requires additional MassExplainer algorithm changes, as the current edge-finding logic assumes neutral mass M cancels out between features.

Original prompt

This section details on the original issue you should resolve

<issue_title>MetaboliteAdductDecharger - multimer annotation</issue_title>
<issue_description>Hello and thank you for your tool!

I was wondering if there is a way for MetaboliteAdductDecharger to annotate multimeric adducts like [2M+H]+, or if there is another way in the OpenMS ecosystem to group such adducts?

In case this is not possible yet, I think that would be a great addition.

Thank you,
Yasin</issue_description>

<agent_instructions>perform an in depth analysis what would need to be done</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@cbielow In the original Decharger, this is not possible (since this usually does not happen for peptides), and I'm not seeing it added for the MTX variant. But maybe @FabianAicheler or @timosachsenberg know more. @timosachsenberg not that I know of. @axelwalter do you know by chance? @axelwalter With MetaboliteAdductDecharger it's not possible right now, but yes it would be a nice addition. For now, I would probably export the features with adduct annotations in pyopenms as pandas DataFrame and check for multimers.

E.g. calculate the neutral mass based on number of charges and adduct information and check if
there are multimers of that mass.</comment_new>
<comment_new>@timosachsenberg
@FabianAicheler as the original author. Do you know how much work that would be? Where to start etc.?</comment_new>
<comment_new>@timosachsenberg
Hi, I was fable to contact Fabian. According to him, this would need some implementation. Unfortunately, we currently don't have the resources to implement it, but if anyone takes a lead we are happy to help.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai

coderabbitai Bot commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 2 commits December 5, 2025 08:49
…liteAdductDecharger

- Add mol_multiplier_ field to Adduct class for multimer support (e.g., [2M+H]+)
- Add getMolMultiplier()/setMolMultiplier() methods to Adduct class
- Extend toAdductString() to include molecular multiplier in annotation
- Add getMaxMolMultiplier() method to Compomer class
- Update MetaboliteFeatureDeconvolution to parse mol_multiplier from adduct config
- Add max_multimer parameter for configuring multimer detection
- Annotate features with mol_multiplier metadata when detected
- Update Adduct tests for new mol_multiplier functionality

Co-authored-by: timosachsenberg <[email protected]>
Copilot AI changed the title [WIP] Add multimer annotation support for MetaboliteAdductDecharger Add molecular multiplier support for multimer adduct annotation Dec 5, 2025
Copilot AI requested a review from timosachsenberg December 5, 2025 08:54
@timosachsenberg

timosachsenberg commented Dec 5, 2025 •

Copy link
Copy Markdown
Contributor

for discussion... actual issue would also need implementation in decharger. @cbielow or @FabianAicheler

@timosachsenberg
timosachsenberg marked this pull request as ready for review February 2, 2026 14:37
timosachsenberg added a commit that referenced this pull request Mar 11, 2026
Design for mass-aware multimer detection (dimers, trimers, etc.) in the
MetaboliteFeatureDeconvolution algorithm. Uses exact algebraic M cancellation
for cross-multiplier matches, controlled by max_multimer parameter (default 1
preserves backward compatibility). Supersedes PR #8431's cosmetic-only approach.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
timosachsenberg added a commit that referenced this pull request Mar 11, 2026
Design for mass-aware multimer detection (dimers, trimers, etc.) in the
MetaboliteFeatureDeconvolution algorithm. Uses exact algebraic M cancellation
for cross-multiplier matches, controlled by max_multimer parameter (default 1
preserves backward compatibility). Supersedes PR #8431's cosmetic-only approach.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
timosachsenberg added a commit that referenced this pull request Mar 12, 2026
* docs: add multimer detection design for MetaboliteAdductDecharger

Design for mass-aware multimer detection (dimers, trimers, etc.) in the
MetaboliteFeatureDeconvolution algorithm. Uses exact algebraic M cancellation
for cross-multiplier matches, controlled by max_multimer parameter (default 1
preserves backward compatibility). Supersedes PR #8431's cosmetic-only approach.

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

* docs: add multimer detection implementation plan

9-task TDD plan covering: Compomer::getSideMass(), ChargePair multiplier fields,
Adduct::toAdductString with multiplier, MassExplainer::queryMultimer(),
MetaboliteFeatureDeconvolution parameter wiring, candidateEdges_() multiplier
loop, annotation updates, and integration tests.

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

* feat: add Compomer::getSideMass() for per-side adduct mass computation

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

* feat: add static Adduct::toAdductString with multiplier for multimer annotation

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

* feat: add mol_multiplier fields to ChargePair for multimer edges

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

* feat: add MassExplainer::queryMultimer() for cross-multiplier matching

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

* feat: add max_multimer and multimer_log_penalty parameters

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

* feat: wire multimer detection into candidateEdges_() with queryMultimer

Add multiplier loop (n1, n2) around the MassExplainer query in candidateEdges_().
Same-multiplier (n1==n2) uses existing binary search path unchanged.
Cross-multiplier (n1!=n2) uses queryMultimer() with exact algebraic M cancellation.
Extract hit processing into lambda for shared use by both paths.
Apply multimer_log_penalty to edge score for cross-multiplier edges.
Set multiplier info on ChargePair for downstream annotation.

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

* feat: annotate features with multiplier from ChargePair for multimer labels

Pass mol_multiplier from ChargePair through annotate_feature_() to produce
[2M+H]+ style adduct strings via static Adduct::toAdductString. Set
mol_multiplier metadata on features with multiplier > 1.

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

* feat: add multimer integration test and fix review issues

- Add end-to-end integration test for cross-adduct multimer detection
  ([M+Na]+ monomer / [2M+H]+ dimer) with regression test for
  max_multimer=1 backward compatibility
- Fix ILP penalty: use multiplicative exp(penalty) instead of additive
  to keep edge scores positive for the ILP maximizer
- Skip redundant same-multiplier queries (n1=n2>1 produces identical
  edges to n1=n2=1 since M cancels identically)
- Eliminate toAdductString code duplication: 2-param delegates to 3-param

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

* docs: add plan for multimer test gaps and same-adduct fix

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

* feat: add conditional identity compomers to MassExplainer for same-adduct multimers

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

* feat: enable identity compomers when max_multimer > 1

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

* test: add comprehensive multimer detection tests

- Same-adduct multimer [M+H]+ / [2M+H]+ (identity compomers)
- Annotation strings and trimer detection (n=3)
- Extreme penalty suppresses multimer edge selection
- Negative mode multimer [M-H]- / [2M-H]-
- Mixed-charge multimer [M+H]+ / [2M+2H]2+

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

* fix: copy max_neutrals_ in MassExplainer::operator= and strengthen test assertions

- Add missing max_neutrals_ to assignment operator (pre-existing bug)
- Make adducts annotation checks unconditional in trimer test

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

* docs: clarify identity compomer placement relative to neutral adduct loop

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

* chore: remove implementation plan documents

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

* fix: address review findings from PR #8888

- Replace pre-existing std::cout with OPENMS_LOG_DEBUG in MassExplainer
- Remove redundant best_hit tracking in same-multiplier path
- Tighten integration test assertions to verify exact group sizes
- Add queryMultimer unit test with non-zero net_charge

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

* fix: include mol_multiplier in ILP variant key to prevent contradictory assignments

Without the multiplier in the variant key, the ILP could activate edges
that assign the same feature different multipliers simultaneously (e.g.,
both monomer and dimer). Adding _m{multiplier} to the variant string
forces the solver to choose a single consistent interpretation per feature.

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

* feat: enumerate all same-adduct compomer amounts for charge-changing multimers

The identity compomer loop previously only generated A1_LEFT/A1_RIGHT,
which limited multimer detection to same-charge pairs like [M+H]+ <-> [2M+H]+.
Now enumerates Ai_LEFT/Aj_RIGHT for all valid amounts (bounded by charge_max),
enabling detection of charge-changing multimers like [M+H]+ <-> [2M+2H]2+
common in lipidomics (e.g. phospholipid dimers with divalent cations).

Tightens the mixed-charge test tolerance from 0.5 to 0.01 Da so the correct
H1_LEFT/H2_RIGHT compomer is required (the old loose tolerance allowed a
spurious match via H1_RIGHT with ~1 Da residual).

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

---------

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

MetaboliteAdductDecharger - multimer annotation

2 participants