Skip to content

Commit d109a89

Browse files
authored
Merge pull request #155 from samseaver/flexiblebiomass_fixes_250417
Fixing correct use of inheritance for build_constraint() function
2 parents cc095d6 + 217edfd commit d109a89

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

modelseedpy/fbapkg/flexiblebiomasspkg.py

+27-31
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ def build_package(self, parameters):
7777
newrxns = []
7878
class_coef = {"rna": {}, "dna": {}, "protein": {}, "energy": {}}
7979
refcpd = {
80-
"cpd00001": None,
81-
"cpd00009": None,
82-
"cpd00012": None,
83-
"cpd00067": None,
84-
"cpd00002": None,
80+
"cpd00001": None, # Water
81+
"cpd00009": None, # Orthophosphate
82+
"cpd00012": None, # Pyrophosphate
83+
"cpd00067": None, # Proton
84+
"cpd00002": None, # ATP
8585
}
8686
# Finding all reference compounds in the model
8787
msid_hash = self.modelutl.msid_hash()
@@ -94,10 +94,10 @@ def build_package(self, parameters):
9494
met_class[metabolite] = None
9595
msid = MSModelUtil.metabolite_msid(metabolite)
9696
if (
97-
msid != "cpd11416"
98-
and msid != "cpd11463"
99-
and msid != "cpd11462"
100-
and msid != "cpd11461"
97+
msid != "cpd11416" # Biomass
98+
and msid != "cpd11463" # Protein
99+
and msid != "cpd11462" # RNA
100+
and msid != "cpd11461" # DNA
101101
and msid != None
102102
):
103103
if msid in refcpd:
@@ -209,7 +209,7 @@ def build_package(self, parameters):
209209
self.build_constraint(
210210
self.new_reactions[met_class + "_flex"], "flxcls"
211211
)
212-
if parameters["add_total_biomass_constraint"]:
212+
if self.parameters["add_total_biomass_constraint"]:
213213
self.build_constraint(self.parameters["bio_rxn"], "flxbio")
214214

215215
def build_variable(self, object, type): # !!! can the function be removed?
@@ -254,7 +254,7 @@ def build_constraint(self, cobra_obj, obj_type):
254254
if abs(massdiff) > 0.00001:
255255
coef[rxn.forward_variable] = massdiff
256256
coef[rxn.reverse_variable] = -massdiff
257-
return BaseFBAPkg.build_constraint(self, obj_type, 0, 0, coef, cobra_obj)
257+
return super().build_constraint(obj_type, 0, 0, coef, cobra_obj)
258258
elif obj_type == "flxcpd" or obj_type == "flxcls":
259259
first_entry = None
260260
second_entry = None
@@ -293,7 +293,7 @@ def build_constraint(self, cobra_obj, obj_type):
293293
# If the value is positive, lock in the forward variable and set the reverse to zero
294294
if first_entry > 0:
295295
if product:
296-
const = self.build_constraint(
296+
const = super().build_constraint(
297297
"f" + obj_type,
298298
0,
299299
0,
@@ -302,7 +302,7 @@ def build_constraint(self, cobra_obj, obj_type):
302302
)
303303
object.lower_bound = 0
304304
else:
305-
const = self.build_constraint(
305+
const = super().build_constraint(
306306
"f" + obj_type,
307307
0,
308308
0,
@@ -313,7 +313,7 @@ def build_constraint(self, cobra_obj, obj_type):
313313
# If the value is negative, lock in the reverse variable and set the forward to zero
314314
elif first_entry < 0:
315315
if product:
316-
const = self.build_constraint(
316+
const = super().build_constraint(
317317
"r" + obj_type,
318318
0,
319319
0,
@@ -322,7 +322,7 @@ def build_constraint(self, cobra_obj, obj_type):
322322
)
323323
object.upper_bound = 0
324324
else:
325-
const = self.build_constraint(
325+
const = super().build_constraint(
326326
"r" + obj_type,
327327
0,
328328
0,
@@ -337,8 +337,7 @@ def build_constraint(self, cobra_obj, obj_type):
337337
elif second_entry >= 0:
338338
if first_entry >= 0:
339339
if product:
340-
const = BaseFBAPkg.build_constraint(
341-
self,
340+
const = super().build_constraint(
342341
"f" + obj_type,
343342
0,
344343
None,
@@ -347,17 +346,15 @@ def build_constraint(self, cobra_obj, obj_type):
347346
)
348347
object.lower_bound = 0
349348
if first_entry > 0:
350-
BaseFBAPkg.build_constraint(
351-
self,
349+
super().build_constraint(
352350
"r" + obj_type,
353351
0,
354352
None,
355353
{biovar: -first_entry, object.forward_variable: 1},
356354
cobra_obj,
357355
)
358356
else:
359-
const = BaseFBAPkg.build_constraint(
360-
self,
357+
const = super().build_constraint(
361358
"f" + obj_type,
362359
0,
363360
None,
@@ -366,8 +363,7 @@ def build_constraint(self, cobra_obj, obj_type):
366363
)
367364
object.upper_bound = 0
368365
if first_entry > 0:
369-
BaseFBAPkg.build_constraint(
370-
self,
366+
super().build_constraint(
371367
"r" + obj_type,
372368
0,
373369
None,
@@ -376,29 +372,29 @@ def build_constraint(self, cobra_obj, obj_type):
376372
)
377373
else:
378374
if product:
379-
const = self.build_constraint(
375+
const = super().build_constraint(
380376
"f" + obj_type,
381377
0,
382378
None,
383379
{biovar: second_entry, object.forward_variable: -1},
384380
cobra_obj,
385381
)
386-
self.build_constraint(
382+
super().build_constraint(
387383
"r" + obj_type,
388384
0,
389385
None,
390386
{biovar: -first_entry, object.reverse_variable: -1},
391387
cobra_obj,
392388
)
393389
else:
394-
const = self.build_constraint(
390+
const = super().build_constraint(
395391
"f" + obj_type,
396392
0,
397393
None,
398394
{biovar: second_entry, object.reverse_variable: -1},
399395
cobra_obj,
400396
)
401-
self.build_constraint(
397+
super().build_constraint(
402398
"r" + obj_type,
403399
0,
404400
None,
@@ -408,23 +404,23 @@ def build_constraint(self, cobra_obj, obj_type):
408404
else:
409405
if second_entry < 0:
410406
if product:
411-
const = self.build_constraint(
407+
const = super().build_constraint(
412408
"f" + obj_type,
413409
0,
414410
None,
415411
{biovar: second_entry, object.reverse_variable: 1},
416412
cobra_obj,
417413
)
418414
else:
419-
const = self.build_constraint(
415+
const = super().build_constraint(
420416
"f" + obj_type,
421417
0,
422418
None,
423419
{biovar: second_entry, object.forward_variable: 1},
424420
cobra_obj,
425421
)
426422
if product:
427-
self.build_constraint(
423+
super().build_constraint(
428424
"r" + obj_type,
429425
0,
430426
None,
@@ -433,7 +429,7 @@ def build_constraint(self, cobra_obj, obj_type):
433429
)
434430
object.lower_bound = 0
435431
else:
436-
self.build_constraint(
432+
super().build_constraint(
437433
"r" + obj_type,
438434
0,
439435
None,

0 commit comments

Comments
 (0)