Skip to content

fixes #6#7

Open
Adafede wants to merge 2 commits into
Philipbear:mainfrom
Adafede:main
Open

fixes #6#7
Adafede wants to merge 2 commits into
Philipbear:mainfrom
Adafede:main

Conversation

@Adafede

@Adafede Adafede commented Aug 18, 2025

Copy link
Copy Markdown

Suggested fix for #6

Copilot AI review requested due to automatic review settings February 3, 2026 12:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR attempts to address issue #6 where unrecognized adducts in MGF files lead to dummy formula/mass values, causing a ZeroDivisionError: division by zero. The fix adds validation to skip invalid formulas (mass <= 0 or no carbons) in two key functions.

Changes:

  • Added validation in _gen_arr_from_buddy_data to skip invalid formulas before generating ML feature arrays
  • Added validation in _fill_form_feature_arr_in_batch_data to assign zero features to invalid formulas as a fallback

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread msbuddy/ml.py
Comment on lines +46 to +48
# skip invalid formulas (mass <= 0 or no carbons)
if cf.formula.mass <= 0 or cf.formula.array[0] == 0:
continue

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

The fix prevents ZeroDivisionError in _gen_form_feature by filtering out invalid formulas, but there's an incomplete fix in the call chain. When gen_ml_feature is called from _predict_ml (line 442), it processes all candidate formulas including invalid ones. In gen_ml_feature_single (lines 207-208), if cand_form.charged_formula.mass is zero or negative (which can happen with unrecognized adducts), calculating theo_mass and mz_error will cause a ZeroDivisionError. Since the current approach assigns zero features to invalid formulas and includes them in processing, consider adding a guard in gen_ml_feature_single to handle formulas with mass <= 0, similar to how the H/C ratio is handled at line 214.

Copilot uses AI. Check for mistakes.
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