Skip to content

Commit 725f163

Browse files
committed
Complete restructuring
1 parent 440038a commit 725f163

File tree

73 files changed

+463892
-271702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+463892
-271702
lines changed

README.md

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
1-
[![PyPI version](https://badge.fury.io/py/commodepy-Paulocracy.svg)](https://badge.fury.io/py/commodepy-Paulocracy)
1+
[![PyPI version](https://badge.fury.io/py/commodelpy.svg)](https://badge.fury.io/py/commodelpy)
22

3-
# commodepy
3+
# ComModelPy
44

55
## Description
66

7-
commodepy is a collection of Python [dataclasses](https://docs.python.org/3/library/dataclasses.html) and associated functions which aim to help one in generating stoichiometric metabolic models of communities which consist of one or multiple species. All dataclasses and functions are based on [cobrapy](https://github.com/opencobra/cobrapy).
7+
ComModelPy is a collection of Python [dataclasses](https://docs.python.org/3/library/dataclasses.html) and associated functions which aim to help one in generating stoichiometric metabolic models of communities which consist of one or multiple species. All dataclasses and functions are based on [cobrapy](https://github.com/opencobra/cobrapy).
88

9-
The underlying method for the definition of the generation of the community models and their MILP-based FBA analyses is the "RedCom" method as published in the following paper (Note: commodepy's author is not directly associated with this publication, and commodepy was not used for this paper):
10-
11-
* Koch, S., Kohrs, F., Lahmann, P., Bissinger, T., Wendschuh, S., Benndorf, D., ... & Klamt, S. (2019). RedCom: A strategy for reduced metabolic modeling of complex microbial communities and its application for analyzing experimental datasets from anaerobic digestion. *PLoS computational biology*, 15(2), e1006759. [doi:10.1371/journal.pcbi.1006759]( https://doi.org/10.1371/journal.pcbi.1006759)
12-
13-
14-
## Documentation
15-
16-
A documentation of commodepy's features and functions can be found in the "docs" subfolder of this repository. The documentation's starting point is "index.html". The whole documentation was generated using [pdoc3](https://github.com/pdoc3/).
9+
The underlying methods for the generation and analysis of the community models is explained in more detail in ComModelPy's source code documentation.
1710

11+
An exemplary usage of ComModelPy is given in its publiation (Bekiaris & Klamt, in submission).
1812

1913
## Installation procedure
2014

2115
### Option 1: As PyPI module
2216

23-
You can install commodepy as Python module from [PyPI](https://pypi.org/project/autopacmen-Paulocracy/) using *pip*:
17+
You can install ComModelPy as Python module from [PyPI](https://pypi.org/project/commodelpy/) using *pip*:
2418

2519
<pre>
26-
pip install commodepy-Paulocracy
20+
pip install commodelpy
2721
</pre>
2822

29-
Afterwards, you can use commodepy just as any other Python module using *import* in your Python session/script:
23+
Afterwards, you can use ComModelPy just as any other Python module using *import* in your Python session/script:
3024
<pre>
31-
import commodepy
25+
import commodelpy
3226
</pre>
33-
34-
You can also access commodepy's documentation using Python's help function after importing commodepy, e.g. for the whole module:
27+
In order to import ComModelPy's main script with all major dataclasses and functions and which is called "commodelpy.py", you can import it using
3528
<pre>
36-
help(commodepy)
29+
import commodelpy.commodelpy
3730
</pre>
3831

39-
4032
### Option 2: Direct download
4133

42-
If you don't want to use commodepy as PyPI module, you can also download this repository directly. commodepy's main script file is the commodepy Python script in the "commodepy" subfolder.
34+
If you don't want to use ComModelPy as PyPI module, you can also download this repository directly. The main script file is the commodelpy.py Python script in the "commodelpy" subfolder.
35+
36+
## Repository structure
4337

38+
* The actual commodelpy pip package can be found in the "commodelpy" subfolder, where "commodelpy.py" contains all relevant functions and dataclasses.
39+
* All Python scripts which were used in ComModelPy's publication, which use ComModelPy's function for community models without defined growth and with fixed species ratios, can be found in the "publication_runs" subfolder, which is in the "commodelpy" subfolder. The scripts in the local subfolder "toy_model" contain the script for the generation of the toy model shown in the publication. The scripts in the local subfolder "ecoli_models" contain the generation of dG0 data using the [Equilibrator API](https://gitlab.com/equilibrator/equilibrator-api) as well as the ComModelPy-assisted generation of iML1515 and EcoliCore2 single-species community models. A complete call of all E. coli model scripts in the right order is given by the "execute_publication_ecoli_model_scripts.py" script in the main folder, a call of the toy model scripts is given by the "execute_publication_toy_model_script.py" script in the main folder.
40+
* An exemplary usage of ComModelPy with its function with a defined fixed growth rate and free species ratios can be found in the "balanced_growth_example" subfolder. A call of the relevant script is given in the "execute_balanced_growth_example.py" script in the main folder.
4441

45-
## Exemplary usage
42+
## Documentation
4643

47-
Exemplary usage of commodepy can be found in the "puc" subfolder of the "commodepy" folder. It contains the scripts for the generation
48-
of the "shinjired" toy model, as well as community versions (i.e., a community of two times the respective model) of iJO1366 and
49-
EColiCore2. See the "example"'s folder <span>README.md</span> for the references of these examples.
44+
A documentation of ComModelPy's features and functions can be found in the "docs/commodelpy/" subfolder of this repository. The documentation's starting point is "index.html". The whole documentation was generated using [pdoc3](https://github.com/pdoc3/).
5045

46+
You can also access ComModelPy's documentation using Python's help function after importing ComModelPy, e.g. for the whole module:
47+
<pre>
48+
help(commodelpy)
49+
</pre>
5150

52-
## Source code test range
51+
## Publication
5352

54-
A small test range for commodepy can be found in the "test" subfolder of the "commodepy" folder,
55-
it is contained in the "test_commodepy()" function of "test_commodepy.py". The test system works e.g. with
56-
[pytest](https://github.com/pytest-dev/pytest).
53+
ComModelPy is published in the following publication:
5754

55+
* Bekiaris & Klamt, 2021, *in submission*
5856

5957
## License
60-
commodepy is free and open source, using the Apache License, Version 2
58+
59+
ComModelPy is free and open source, using the Apache License, Version 2
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import cobra
2+
import copy
3+
from commodelpy.commodelpy import Community, SingleModel, create_community_model_with_balanced_growth
4+
from typing import Dict
5+
6+
growth_rate = 0.4
7+
# ecolicore double model
8+
# with internal exchanges for everything in the periplasm
9+
ecoli_model = cobra.io.read_sbml_model(
10+
"./publication_runs/ecoli_models/original_sbml_models/iML1515.xml")
11+
12+
# Deactivate all C sources except of glucose
13+
ecoli_model.reactions.EX_succ_e.lower_bound = 0
14+
ecoli_model.reactions.EX_glyc_e.lower_bound = 0
15+
ecoli_model.reactions.EX_ac_e.lower_bound = 0
16+
17+
# Test model with FBA
18+
with ecoli_model:
19+
print("Single model FBA solution:")
20+
fba_solution = ecoli_model.optimize()
21+
print(ecoli_model.summary())
22+
for reaction in ecoli_model.reactions:
23+
if not reaction.id.startswith("EX_"):
24+
continue
25+
if fba_solution.fluxes[reaction.id] != 0:
26+
print(f"{reaction.id}: {fba_solution.fluxes[reaction.id] }")
27+
print("~~~")
28+
29+
# Define essential and periplasmic metabolites (essential metabolites
30+
# were found by FBAs beforehand)
31+
essential_in_metabolites = [
32+
"fe2_e",
33+
"nh4_e",
34+
"cu2_e",
35+
"glc__D_e",
36+
"o2_e",
37+
"pi_e",
38+
"so4_e",
39+
"h_e",
40+
"h2o_e",
41+
]
42+
essential_out_metabolites = [
43+
"co2_e",
44+
"meoh_e",
45+
"ac_e",
46+
"h_e",
47+
"h2o_e",
48+
"etoh_e",
49+
"succ_e",
50+
"lac__D_e",
51+
"for_e",
52+
]
53+
all_essential_metabolites = list(
54+
set(essential_in_metabolites+essential_out_metabolites))
55+
essential_metabolite_mapping: Dict[str, str] = {}
56+
for met in essential_in_metabolites+essential_out_metabolites:
57+
essential_metabolite_mapping[met] = (met+"\b").replace("_e\b", "")
58+
59+
periplasmic_metabolites = [
60+
x for x in ecoli_model.metabolites if x.id.endswith("_p")]
61+
periplasmic_metabolites_cut = [(x.id+"\b").replace("_p\b", "")
62+
for x in periplasmic_metabolites]
63+
periplasmic_metabolites += [x for x in ecoli_model.metabolites
64+
if x.id.endswith("_c") and (((x.id+"\b").replace("_c\b", "") not in periplasmic_metabolites_cut))]
65+
periplasmic_metabolites = [x for x in periplasmic_metabolites
66+
if (((x.id+"\b").replace("_c\b", "_e") not in all_essential_metabolites)) and
67+
(((x.id+"\b").replace("_p\b", "_e") not in all_essential_metabolites))]
68+
all_input_metabolite_ids = []
69+
all_output_metabolite_ids = []
70+
all_inout_metabolite_ids_mapping: Dict[str, str] = {}
71+
for periplasmic_metabolite in periplasmic_metabolites:
72+
metabolite_id = periplasmic_metabolite.id
73+
all_input_metabolite_ids.append(metabolite_id)
74+
all_output_metabolite_ids.append(metabolite_id)
75+
all_inout_metabolite_ids_mapping[metabolite_id] = (
76+
metabolite_id+"\b").replace("_p\b", "").replace("_c\b", "")
77+
78+
combined_input_metabolite_ids = list(set(
79+
all_input_metabolite_ids + essential_in_metabolites + essential_out_metabolites))
80+
combined_output_metabolite_ids = list(set(
81+
all_output_metabolite_ids + essential_out_metabolites + essential_in_metabolites))
82+
combined_metabolite_ids_mapping = {
83+
**all_inout_metabolite_ids_mapping, **essential_metabolite_mapping}
84+
85+
# Define commodelpy SingleModel
86+
ecoli_1 = SingleModel(
87+
cobra_model=ecoli_model,
88+
species_abbreviation="ecoli1",
89+
objective_reaction_id="BIOMASS_Ec_iML1515_core_75p37M",
90+
exchange_reaction_id_prefix="EX_",
91+
input_metabolite_ids=combined_input_metabolite_ids,
92+
output_metabolite_ids=combined_output_metabolite_ids,
93+
model_metabolite_to_exchange_id_mapping=combined_metabolite_ids_mapping,
94+
)
95+
# Double it :D
96+
ecoli_2 = copy.deepcopy(ecoli_1)
97+
ecoli_2.species_abbreviation = "ecoli2"
98+
99+
# Create community model :D
100+
print("===\nGeneration of community model...")
101+
potential_product_metabolites = [x for x in periplasmic_metabolites]
102+
potential_product_metabolite_ids = [
103+
(x.id+"\b").replace("_p\b", "").replace("_c\b", "") for x in potential_product_metabolites]
104+
105+
community = Community(
106+
single_models=[ecoli_1, ecoli_2],
107+
exchange_compartment_id="exchg",
108+
exchange_reaction_id_prefix="EX_C_",
109+
input_metabolite_ids=[(x+"\b").replace("_e\b", "")
110+
for x in essential_in_metabolites],
111+
output_metabolite_ids=[(x+"\b").replace("_e\b", "").replace("\b", "")
112+
for x in essential_out_metabolites+potential_product_metabolite_ids]
113+
)
114+
community_model = create_community_model_with_balanced_growth(
115+
community, growth_rate)
116+
117+
118+
cobra.io.write_sbml_model(
119+
community_model, "./balanced_growth_example/models/community_model.xml")
120+
121+
with community_model:
122+
community_model.optimize()
123+
print(community_model.summary())
124+
125+
126+
def run():
127+
pass

0 commit comments

Comments
 (0)