From 26a417a729b69a9c91806b43e0325f0913210301 Mon Sep 17 00:00:00 2001 From: Andrew Freiburger Date: Wed, 26 Aug 2026 14:49:02 -0500 Subject: [PATCH] Sync modelseedpy/fbapkg/totalfluxpkg.py from freiburgermsu fork File-level sync to the state of this file in freiburgermsu/ModelSEEDpy@971df5d, submitted as an individual PR so each module's divergence can be reviewed independently. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_017rcBA87xipNeaukuFW8N2G --- modelseedpy/fbapkg/totalfluxpkg.py | 81 ++++++++++++++---------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/modelseedpy/fbapkg/totalfluxpkg.py b/modelseedpy/fbapkg/totalfluxpkg.py index b8eb87c8..a85a7cdd 100644 --- a/modelseedpy/fbapkg/totalfluxpkg.py +++ b/modelseedpy/fbapkg/totalfluxpkg.py @@ -1,44 +1,37 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import - -import logging -import re -from optlang.symbolics import Zero, add -import json as _json -from cobra.core import Gene, Metabolite, Model, Reaction -from modelseedpy.fbapkg.basefbapkg import BaseFBAPkg - -# Adding a few exception classes to handle different types of errors -class FeasibilityError(Exception): - """Error in FBA formulation""" - - pass - - -# Base class for FBA packages -class TotalFluxPkg(BaseFBAPkg): - def __init__(self, model): - BaseFBAPkg.__init__( - self, model, "totalflux", {"tf": "reaction"}, {"tf": "reaction"} - ) - - def build_package(self, reaction_filter=None, upper_bound=100): - for reaction in self.model.reactions: - # Checking that variable has not yet been created - if reaction.id not in self.variables["tf"]: - # Checking that reaction passes input filter if one is provided - if reaction_filter == None or reaction.id in reaction_filter: - self.variables["tf"][reaction.id] = self.model.problem.Variable( - reaction.id + "_tf", lb=0, ub=upper_bound - ) - self.model.add_cons_vars(self.variables["tf"][reaction.id]) - self.constraints["tf"][reaction.id] = self.model.problem.Constraint( - reaction.forward_variable - + reaction.reverse_variable - - self.variables["tf"][reaction.id], - lb=0, - ub=0, - name=reaction.id + "_tf", - ) - self.model.add_cons_vars(self.constraints["tf"][reaction.id]) +# -*- coding: utf-8 -*- + +from __future__ import absolute_import + +import logging +import re +from optlang.symbolics import Zero, add +import json as _json +from cobra.core import Gene, Metabolite, Model, Reaction +from modelseedpy.fbapkg.basefbapkg import BaseFBAPkg +from modelseedpy.core.exceptions import FeasibilityError + + +# Base class for FBA packages +class TotalFluxPkg(BaseFBAPkg): + def __init__(self, model): + BaseFBAPkg.__init__( + self, model, "totalflux", {"tf": "reaction"}, {"tf": "reaction"} + ) + + def build_package(self, reaction_filter=None, upper_bound=100): + for reaction in self.model.reactions: + # Checking that variable has not yet been created + if reaction.id not in self.variables["tf"]: + # Checking that reaction passes input filter if one is provided + if reaction_filter == None or reaction.id in reaction_filter: + self.variables["tf"][reaction.id] = self.model.problem.Variable( + reaction.id + "_tf", lb=0, ub=upper_bound + ) + self.model.add_cons_vars(self.variables["tf"][reaction.id]) + self.constraints["tf"][reaction.id] = self.model.problem.Constraint( + reaction.forward_variable + reaction.reverse_variable - self.variables["tf"][reaction.id], + lb=0, + ub=0, + name=reaction.id + "_tf", + ) + self.model.add_cons_vars(self.constraints["tf"][reaction.id])