|
36 | 36 | import cobra |
37 | 37 | import copy |
38 | 38 | from dataclasses import dataclass |
39 | | -from typing import Dict, List |
| 39 | +from typing import Dict, List, Tuple |
40 | 40 |
|
41 | 41 |
|
42 | 42 | # DATACLASS DEFINITIONS SECTION |
@@ -442,7 +442,7 @@ def generate_community_model_with_no_growth(community: Community, fractions: Dic |
442 | 442 | return merged_model |
443 | 443 |
|
444 | 444 |
|
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: |
446 | 446 | """Creates a combined community model with an stoichiometric-matrix-integrated balanced growth approach. |
447 | 447 |
|
448 | 448 | Description |
@@ -518,8 +518,11 @@ def create_community_model_with_balanced_growth(community: Community, growth_rat |
518 | 518 |
|
519 | 519 | Arguments |
520 | 520 | ---------- |
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. |
523 | 526 | """ |
524 | 527 | # Get number of SingleModel instances in Community instance |
525 | 528 | num_single_models = len(community.single_models) |
@@ -676,6 +679,16 @@ def create_community_model_with_balanced_growth(community: Community, growth_rat |
676 | 679 |
|
677 | 680 | merged_model.add_reactions([reaction_out]) |
678 | 681 |
|
| 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 | + |
679 | 692 | # Add minimal and maximal bound constraints using pseudo-metabolites and pseudo-reactions |
680 | 693 | reaction_ids = [x.id for x in merged_model.reactions] |
681 | 694 | for reaction_id in reaction_ids: |
|
0 commit comments