From 264e753a767dc368412f8d09c04af27b25ed037c Mon Sep 17 00:00:00 2001 From: Sam Seaver Date: Thu, 17 Apr 2025 15:01:28 -0500 Subject: [PATCH 1/2] Fixing correct use of inheritance for build_constraint() function --- modelseedpy/fbapkg/flexiblebiomasspkg.py | 60 +++++++++++------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/modelseedpy/fbapkg/flexiblebiomasspkg.py b/modelseedpy/fbapkg/flexiblebiomasspkg.py index 223f778d..a116c8bd 100644 --- a/modelseedpy/fbapkg/flexiblebiomasspkg.py +++ b/modelseedpy/fbapkg/flexiblebiomasspkg.py @@ -77,11 +77,11 @@ def build_package(self, parameters): newrxns = [] class_coef = {"rna": {}, "dna": {}, "protein": {}, "energy": {}} refcpd = { - "cpd00001": None, - "cpd00009": None, - "cpd00012": None, - "cpd00067": None, - "cpd00002": None, + "cpd00001": None, # Water + "cpd00009": None, # Orthophosphate + "cpd00012": None, # Pyrophosphate + "cpd00067": None, # Proton + "cpd00002": None, # ATP } # Finding all reference compounds in the model msid_hash = self.modelutl.msid_hash() @@ -94,10 +94,10 @@ def build_package(self, parameters): met_class[metabolite] = None msid = MSModelUtil.metabolite_msid(metabolite) if ( - msid != "cpd11416" - and msid != "cpd11463" - and msid != "cpd11462" - and msid != "cpd11461" + msid != "cpd11416" # Biomass + and msid != "cpd11463" # Protein + and msid != "cpd11462" # RNA + and msid != "cpd11461" # DNA and msid != None ): if msid in refcpd: @@ -206,10 +206,10 @@ def build_package(self, parameters): self.model.add_reactions( [self.new_reactions[met_class + "_flex"]] ) - self.build_constraint( + super().build_constraint( self.new_reactions[met_class + "_flex"], "flxcls" ) - if parameters["add_total_biomass_constraint"]: + if self.parameters["add_total_biomass_constraint"]: self.build_constraint(self.parameters["bio_rxn"], "flxbio") def build_variable(self, object, type): # !!! can the function be removed? @@ -254,7 +254,7 @@ def build_constraint(self, cobra_obj, obj_type): if abs(massdiff) > 0.00001: coef[rxn.forward_variable] = massdiff coef[rxn.reverse_variable] = -massdiff - return BaseFBAPkg.build_constraint(self, obj_type, 0, 0, coef, cobra_obj) + return super().build_constraint(obj_type, 0, 0, coef, cobra_obj) elif obj_type == "flxcpd" or obj_type == "flxcls": first_entry = None second_entry = None @@ -293,7 +293,7 @@ def build_constraint(self, cobra_obj, obj_type): # If the value is positive, lock in the forward variable and set the reverse to zero if first_entry > 0: if product: - const = self.build_constraint( + const = super().build_constraint( "f" + obj_type, 0, 0, @@ -302,7 +302,7 @@ def build_constraint(self, cobra_obj, obj_type): ) object.lower_bound = 0 else: - const = self.build_constraint( + const = super().build_constraint( "f" + obj_type, 0, 0, @@ -313,7 +313,7 @@ def build_constraint(self, cobra_obj, obj_type): # If the value is negative, lock in the reverse variable and set the forward to zero elif first_entry < 0: if product: - const = self.build_constraint( + const = super().build_constraint( "r" + obj_type, 0, 0, @@ -322,7 +322,7 @@ def build_constraint(self, cobra_obj, obj_type): ) object.upper_bound = 0 else: - const = self.build_constraint( + const = super().build_constraint( "r" + obj_type, 0, 0, @@ -337,8 +337,7 @@ def build_constraint(self, cobra_obj, obj_type): elif second_entry >= 0: if first_entry >= 0: if product: - const = BaseFBAPkg.build_constraint( - self, + const = super().build_constraint( "f" + obj_type, 0, None, @@ -347,8 +346,7 @@ def build_constraint(self, cobra_obj, obj_type): ) object.lower_bound = 0 if first_entry > 0: - BaseFBAPkg.build_constraint( - self, + super().build_constraint( "r" + obj_type, 0, None, @@ -356,8 +354,7 @@ def build_constraint(self, cobra_obj, obj_type): cobra_obj, ) else: - const = BaseFBAPkg.build_constraint( - self, + const = super().build_constraint( "f" + obj_type, 0, None, @@ -366,8 +363,7 @@ def build_constraint(self, cobra_obj, obj_type): ) object.upper_bound = 0 if first_entry > 0: - BaseFBAPkg.build_constraint( - self, + super().build_constraint( "r" + obj_type, 0, None, @@ -376,14 +372,14 @@ def build_constraint(self, cobra_obj, obj_type): ) else: if product: - const = self.build_constraint( + const = super().build_constraint( "f" + obj_type, 0, None, {biovar: second_entry, object.forward_variable: -1}, cobra_obj, ) - self.build_constraint( + super().build_constraint( "r" + obj_type, 0, None, @@ -391,14 +387,14 @@ def build_constraint(self, cobra_obj, obj_type): cobra_obj, ) else: - const = self.build_constraint( + const = super().build_constraint( "f" + obj_type, 0, None, {biovar: second_entry, object.reverse_variable: -1}, cobra_obj, ) - self.build_constraint( + super().build_constraint( "r" + obj_type, 0, None, @@ -408,7 +404,7 @@ def build_constraint(self, cobra_obj, obj_type): else: if second_entry < 0: if product: - const = self.build_constraint( + const = super().build_constraint( "f" + obj_type, 0, None, @@ -416,7 +412,7 @@ def build_constraint(self, cobra_obj, obj_type): cobra_obj, ) else: - const = self.build_constraint( + const = super().build_constraint( "f" + obj_type, 0, None, @@ -424,7 +420,7 @@ def build_constraint(self, cobra_obj, obj_type): cobra_obj, ) if product: - self.build_constraint( + super().build_constraint( "r" + obj_type, 0, None, @@ -433,7 +429,7 @@ def build_constraint(self, cobra_obj, obj_type): ) object.lower_bound = 0 else: - self.build_constraint( + super().build_constraint( "r" + obj_type, 0, None, From 217edfdbad11e2e6ad20874b07c2b143d9efa243 Mon Sep 17 00:00:00 2001 From: Sam Seaver Date: Thu, 17 Apr 2025 15:14:22 -0500 Subject: [PATCH 2/2] Another fix for incorrect call --- modelseedpy/fbapkg/flexiblebiomasspkg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modelseedpy/fbapkg/flexiblebiomasspkg.py b/modelseedpy/fbapkg/flexiblebiomasspkg.py index a116c8bd..aa11ea2d 100644 --- a/modelseedpy/fbapkg/flexiblebiomasspkg.py +++ b/modelseedpy/fbapkg/flexiblebiomasspkg.py @@ -206,7 +206,7 @@ def build_package(self, parameters): self.model.add_reactions( [self.new_reactions[met_class + "_flex"]] ) - super().build_constraint( + self.build_constraint( self.new_reactions[met_class + "_flex"], "flxcls" ) if self.parameters["add_total_biomass_constraint"]: