Skip to content

fix: read whole-number YAML charges as ints - #164

Merged
edkerk merged 1 commit into
developfrom
fix-yaml-integer-charges
Sep 29, 2026
Merged

edkerk merged 1 commit into
developfrom
fix-yaml-integer-charges

Conversation

@edkerk

@edkerk edkerk commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

read_yaml_model now reads whole-number charges as ints.

writeYAMLmodel.m (RAVEN 3) and write_yaml_model write every number as a float, so a charge arrives as -1.0. cobra models charge as an int. Its SBML writer passes the value unchanged to libsbml's setCharge, which does not keep a float, so every metabolite charge was lost when a model read from a RAVEN 3-format YAML was written to SBML.

This was found in Human-GEM's release checks (SysBioChalmers/Human-GEM#1123): reading the 2.1.0 YAML and writing it to SBML set all charges to 0.

  • _integer_charges turns a float charge that is a whole number into an int when reading. Other charges (fractional ones, or none) are left as they are.
  • Test: a RAVEN 3-style file with charge: -1.0 and charge: 0.5 gives an int -1, which survives an SBML round-trip; 0.5 is kept. The test fails without the fix.

On Vera, the four YAML test files (50 tests) and ruff check src tests pass. In the full suite, only tests/test_io_git.py::test_standard_gem_layout fails, because openpyxl is missing from that environment; it fails the same way without this change.

writeYAMLmodel.m (RAVEN 3) and write_yaml_model write every number as a float,
so charges arrive as -1.0. cobra's SBML writer passes the charge unchanged to
libsbml's setCharge, which does not keep a float, so every charge was lost when
such a model was written to SBML.
@edkerk
edkerk merged commit 56b1a11 into develop Sep 29, 2026
8 checks passed
@edkerk
edkerk deleted the fix-yaml-integer-charges branch September 29, 2026 20:41
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.

1 participant