Skip to content

MSBuilder.build() drops the gap-filler's reversed reactions, so the model can fail to grow on its own gap-fill medium #3

Open

Description

@jplfaria

What happens

MSBuilder.build() gap-fills the model and then keeps only gapfill_res["new"] (msbuilder.py:1041-L1053):

gapfill_res = gapfill.run_gapfilling(gapfill_media)
...
for rxn_id, d in gapfill_res["new"].items():
    if rxn_id[:-1] in self.template.reactions:
        gap_sol[rxn_id[:-1]] = get_reaction_constraints_from_direction(d)
model_gapfilled = model_base.copy()
MSBuilder.integrate_gapfill_solution(self.template, model_gapfilled, gap_sol)

run_gapfilling also returns "reversed": reactions already in the model that the solution needs in a direction their bounds forbid. build() never applies them, and the static MSBuilder.integrate_gapfill_solution (L963-L976) only adds reactions. The returned model lacks part of its own gap-fill solution and can fail to grow on the medium it was gap-filled on.

The library's other integration paths already apply reversals: MSGapfill.integrate_gapfill_solution (msgapfill.py:334-L341) and MSBuilder.gapfill_model. build() is the one path that does not. (Its "new" filter also drops non-template entries such as gap-filled exchanges; add_exchanges_to_model usually re-creates those, so that part is minor.)

How to reproduce

Wiring test with ATP correction and gap-fill stubbed, run against dev's build():

import cobra, modelseedpy
import modelseedpy.core.msatpcorrection as atpmod
from modelseedpy.core.msbuilder import MSBuilder
m = cobra.Model("m"); a, b = cobra.Metabolite("A_c0", compartment="c0"), cobra.Metabolite("B_c0", compartment="c0")
r = cobra.Reaction("rxn00001_c0", lower_bound=0, upper_bound=1000); r.add_metabolites({a: -1, b: 1}); m.add_reactions([r])
class StubATP:
    def __init__(s, *a, **k): pass
    evaluate_growth_media = determine_growth_media = apply_growth_media_gapfilling = expand_model_to_genome_scale = lambda s: None
    def build_tests(s): return []
class StubGF:
    def __init__(s, *a, **k): pass
    def run_gapfilling(s, media): return {"new": {}, "reversed": {"rxn00001_c0": "<"}}
MSBuilder.build_base_model = lambda self, *a, **k: m
atpmod.load_default_medias = lambda *a, **k: []
modelseedpy.MSATPCorrection, modelseedpy.MSGapfill = StubATP, StubGF
bld = MSBuilder.__new__(MSBuilder); bld.template = cobra.Model("t"); bld.template_core = None
model, *_ = bld.build("m", None, add_maintenance_atp_reaction=False)
print(model.reactions.rxn00001_c0.bounds)   # (0, 1000): the reversal to '<' was dropped

Reproduced on ModelSEED/ModelSEEDpy dev at 062714b (Python 3.10, cobra 0.32.1, CPLEX 22.1.1), using dev's own test fixtures (tests/test_data/e_coli_core.json, template_core_bigg.json).

Impact

  • Andrew Freiburger's prFBA benchmark (2,362 gap-filled models from 200 genomes, complete medium): 107 models need a reversal. Four of them, rebuilt through the package's builder, grow at 0.0 with the reversal dropped and at 4.6-16.7 with it applied (details in his PR below).
  • In our own 62 genome-scale builds (31 Gram-negative genomes, GramNeg templates v7.0 and v7.1, minimal glucose) no gap-fill happened to need a reversal (0 of 62), so this did not change our models. Our build script applies reversals anyway.

Suggested fix

Apply gapfill_res["reversed"] after integrating the new reactions: open each reaction in the direction the gap-filler chose, keep the other bound, never narrow a bound. This is exactly Andrew's freiburgermsu/ModelSEEDpy PR #19 (MSBuilder.apply_gapfill_reversals, 5 tests). His fork has renamed build() to build_and_gapfill(); on dev the change goes into build() at the lines above.

Credit: found and fixed by Andrew Freiburger (freiburgermsu/ModelSEEDpy PR ModelSEED#19); we confirmed it on dev 062714b.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 6, 2026
  2. jplfaria commented on Nov 6, 2026

    @jplfaria
    OwnerAuthor

    Proposed upstream: ModelSEED#163

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions