Skip to content

Conversation

@joewandy
Copy link
Member

@joewandy joewandy commented Jan 27, 2026

WIP -- need human review

Motivation

  • Improve realism of simulated isotope envelopes by moving from a C-only/binomial shortcut to multi-element isotope convolution so tests better reflect real elemental patterns.
  • Provide configurable adduct priors and named adduct profile presets plus per-compound/profile selection so adduct mixtures can match different ESI regimes.
  • Add a small, intensity-aware deisotoping implementation to validate the new generator while leaving UnknownChemical behavior unchanged so ROI-derived workflows are not altered.

Description

  • Added multi-element isotope data and adduct prior presets in vimms/Common.py (NATURAL_ISOTOPES, ADDUCT_PRIOR_POS, ADDUCT_PRIOR_NEG, ADDUCT_PROFILE_PRESETS).
  • Reworked Isotopes in vimms/Chemicals.py to compute isotope envelopes by element-wise convolution with exposed parameters (min_prob, max_peaks, max_states, mass_precision) for a fidelity/performance tradeoff.
  • Enhanced Adducts in vimms/Chemicals.py to accept adduct_profile and adduct_concentration (Dirichlet), support callable/ per-formula priors, apply cutoff + sum normalization, and propagated profile settings through ChemicalMixtureCreator.
  • Added vimms/Deisotoping.py implementing Deisotoper with multi-element isotope mass-diff candidates and intensity-aware clustering rules to support heavier-isotope patterns (e.g., Cl/Br M+2).
  • Added tests in tests/test_deisotoping.py covering multi-element isotope generation, a chlorine M+2 check, and end-to-end deisotoping scenarios (including an M+2-only case).

Testing

  • Ran pytest -q tests/test_deisotoping.py which attempted to exercise the new isotope and deisotoper tests but failed with ModuleNotFoundError: No module named 'numpy' in this environment and so the automated tests did not complete successfully.
  • No other automated test suites were executed in this environment after the changes were applied.

Codex Task

@joewandy joewandy changed the title Make isotope/adduct modeling configurable and add improved deisotoper Improve adduct/isotope generation [WIP] Jan 27, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36ddc497a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +136 to +138
distribution = [(shift, prob) for shift, prob in distribution if prob >= min_prob]
distribution.sort(key=lambda x: x[0])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve monoisotope when pruning isotope distribution

The new filtering step drops any peaks below min_prob (and peaks may already be dropped by max_states), but nothing guarantees the zero-shift monoisotopic peak survives. For large formulas or tighter min_prob/max_states, the monoisotope can be pruned, so get_isotopes returns a list where index 0 is no longer monoisotopic. Downstream code treats isotopes[0] as the monoisotopic reference (e.g., get_mz_msn in vimms/MassSpecUtils.py subtracts isotopes[0][0]), so this can shift all m/z offsets and intensities. Consider explicitly retaining the zero-shift peak (or re-inserting it) before normalization.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants