Skip to content

Commit 3eabf1f

Browse files
committed
Add option for set exchange bounds
1 parent aa89be1 commit 3eabf1f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

commmodelpy/commmodelpy.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import cobra
3737
import copy
3838
from dataclasses import dataclass
39-
from typing import Dict, List
39+
from typing import Dict, List, Tuple
4040

4141

4242
# DATACLASS DEFINITIONS SECTION
@@ -442,7 +442,7 @@ def generate_community_model_with_no_growth(community: Community, fractions: Dic
442442
return merged_model
443443

444444

445-
def create_community_model_with_balanced_growth(community: Community, growth_rate: float) -> cobra.Model:
445+
def create_community_model_with_balanced_growth(community: Community, growth_rate: float, organism_exchange_bounds: Dict[str, Tuple[float, float]] = {}) -> cobra.Model:
446446
"""Creates a combined community model with an stoichiometric-matrix-integrated balanced growth approach.
447447
448448
Description
@@ -518,8 +518,11 @@ def create_community_model_with_balanced_growth(community: Community, growth_rat
518518
519519
Arguments
520520
----------
521-
* community: Community ~
522-
* growth_rate: float ~
521+
* community: Community ~ A CommModelPy Community instance.
522+
* growth_rate: float ~ The growth rate to which the community shall be fixed.
523+
* organism_exchange_bounds: Dict[Tuple[float, float]] ~ A dictionary containing reaction IDs
524+
(which may also include the EXCHG_ reactions introduced by this function) as keys
525+
and, in the float tuple at index 0 a set lower bound and at index 1 a set upper bound.
523526
"""
524527
# Get number of SingleModel instances in Community instance
525528
num_single_models = len(community.single_models)
@@ -676,6 +679,16 @@ def create_community_model_with_balanced_growth(community: Community, growth_rat
676679

677680
merged_model.add_reactions([reaction_out])
678681

682+
# Add organism-specific reaction bounds
683+
bound_reaction_ids = [x.id for x in merged_model.reactions
684+
if x.id in list(organism_exchange_bounds.keys())]
685+
for bound_reaction_id in bound_reaction_ids:
686+
lower_bound = organism_exchange_bounds[bound_reaction_id][0]
687+
upper_bound = organism_exchange_bounds[bound_reaction_id][1]
688+
reaction = merged_model.reactions.get_by_id(bound_reaction_id)
689+
reaction.lower_bound = lower_bound
690+
reaction.upper_bound = upper_bound
691+
679692
# Add minimal and maximal bound constraints using pseudo-metabolites and pseudo-reactions
680693
reaction_ids = [x.id for x in merged_model.reactions]
681694
for reaction_id in reaction_ids:

0 commit comments

Comments
 (0)