Skip to content

Commit ca05193

Browse files
author
Christopher Henry
committedApr 5, 2025·
Merge commit 'cc095d6d49959f1d9018ec71e6f31ee3eb8a2d25'
# Conflicts: # modelseedpy/core/msatpcorrection.py # modelseedpy/core/msmodel.py # modelseedpy/core/mstemplate.py # setup.py
2 parents 9560c4b + cc095d6 commit ca05193

22 files changed

+571
-94
lines changed
 

‎.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [ubuntu-latest]
18-
python-version: ['3.8', '3.9', '3.10']
18+
python-version: ['3.9', '3.10', '3.11']
1919
steps:
2020
- uses: actions/checkout@v2
2121
- uses: actions/setup-python@v3

‎.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest, macos-latest, windows-latest]
14-
python-version: ['3.8', '3.9', '3.10']
14+
python-version: ['3.9', '3.10', '3.11']
1515
steps:
1616
- uses: actions/checkout@v3
1717
- name: Set up Python

‎.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: python
22
python:
3-
- 3.7
4-
- 3.8
53
- 3.9
4+
- 3.10
5+
- 3.11
66
before_install:
77
- python --version
88
- pip install -U pip

‎README.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ________________________________________________________________________
2525
:target: https://pepy.tech/project/modelseedpy
2626
:alt: Downloads
2727

28+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
29+
:target: https://github.com/ambv/black
30+
:alt: Black
31+
2832

2933
Metabolic modeling is an pivotal method for computational research in synthetic biology and precision medicine. The metabolic models, such as the constrint-based flux balance analysis (FBA) algorithm, are improved with comprehensive datasets that capture more metabolic chemistry in the model and improve the accuracy of simulation predictions. We therefore developed ModelSEEDpy as a comprehensive suite of packages that bootstrap metabolic modeling with the ModelSEED Database (`Seaver et al., 2021 <https://academic.oup.com/nar/article/49/D1/D575/5912569?login=true>`_ ). These packages parse and manipulate (e.g. gapfill missing reactions or calculated chemical properties of metabolites), constrain (with kinetic, thermodynamics, and nutrient uptake), and simulate cobrakbase models (both individual models and communities). This is achieved by standardizing COBRA models through the ``cobrakbase`` module into a form that is amenable with the KBase/ModelSEED ecosystem. These functionalities are exemplified in `Python Notebooks <https://github.com/ModelSEED/ModelSEEDpy/examples>`_ . Please submit errors, inquiries, or suggestions as `GitHub issues <https://github.com/ModelSEED/ModelSEEDpy/issues>`_ where they can be addressed by our developers.
3034

@@ -33,11 +37,11 @@ Metabolic modeling is an pivotal method for computational research in synthetic
3337
Installation
3438
----------------------
3539

36-
ModelSEEDpy will soon be installable via the ``PyPI`` channel::
40+
PIP (latest stable version 0.4.0)::
3741

3842
pip install modelseedpy
3943

40-
but, until then, the repository must cloned::
44+
GitHub dev build (latest working version)::
4145

4246
git clone https://github.com/ModelSEED/ModelSEEDpy.git
4347

@@ -51,8 +55,3 @@ The associated ModelSEED Database, which is required for a few packages, is simp
5155
git clone https://github.com/ModelSEED/ModelSEEDDatabase.git
5256

5357
and the path to this repository is passed as an argument to the corresponding packages.
54-
55-
**Windows users** must separately install the ``pyeda`` module: 1) download the appropriate wheel for your Python version from `this website <https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyeda>`_ ; and 2) install the wheel through the following commands in a command prompt/powershell console::
56-
57-
cd path/to/pyeda/wheel
58-
pip install pyeda_wheel_name.whl

‎modelseedpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
__author__ = "Christopher Henry"
1616
__email__ = "chenry@anl.gov"
17-
__version__ = "0.3.3"
17+
__version__ = "0.4.2"
1818

1919
logger = logging.getLogger(__name__)
2020

‎modelseedpy/biochem/modelseed_biochem.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,56 @@ def _load_metabolites(
273273
return metabolites
274274

275275

276+
def build_modelseed_reaction(
277+
o, names, aliases, ec_numbers, metabolites_indexed, metabolites
278+
):
279+
if "id" in o and o["id"]:
280+
rxn_names = set()
281+
if o["id"] in names:
282+
rxn_names |= names[o["id"]]
283+
(
284+
lower_bound,
285+
upper_bound,
286+
) = get_reaction_constraints_from_direction(o.get("reversibility"))
287+
stoichiometry = o.get("stoichiometry")
288+
reaction_metabolites = {}
289+
for s in stoichiometry:
290+
cmp_token = s["compartment"]
291+
value = s["coefficient"]
292+
cpd = metabolites[s["compound"]]
293+
cpd_index_id = f"{cpd.id}_{cmp_token}"
294+
if cpd_index_id not in metabolites_indexed:
295+
cpd_token = cpd.copy()
296+
cpd_token.id = f"{cpd.id}_{cmp_token}"
297+
cpd_token.base_id = cpd.id
298+
cpd_token.compartment = cmp_token
299+
metabolites_indexed[cpd_index_id] = cpd_token
300+
reaction_metabolites[metabolites_indexed[cpd_index_id]] = value
301+
rxn = ModelSEEDReaction2(
302+
o["id"],
303+
o.get("name"),
304+
"",
305+
lower_bound,
306+
upper_bound,
307+
"",
308+
rxn_names,
309+
o.get("deltag"),
310+
o.get("deltagerr"),
311+
o.get("is_obsolete"),
312+
None,
313+
o.get("status"),
314+
o.get("source"),
315+
)
316+
rxn.add_metabolites(reaction_metabolites)
317+
if rxn.id in aliases:
318+
rxn.annotation.update(aliases[rxn.id])
319+
if rxn.id in ec_numbers:
320+
rxn.annotation["ec-code"] = ec_numbers[rxn.id]
321+
return rxn
322+
else:
323+
raise ValueError("unable to build reaction")
324+
325+
276326
def _load_reactions(
277327
database_path: str, metabolites: dict, aliases=None, names=None, ec_numbers=None
278328
) -> (dict, dict):
@@ -330,6 +380,7 @@ def _load_reactions(
330380
None,
331381
o.get("status"),
332382
o.get("source"),
383+
pathways=o.get("pathways"),
333384
)
334385
if "linked_reaction" in o and o.get("linked_reaction"):
335386
ids = o.get("linked_reaction").split(";")

‎modelseedpy/biochem/modelseed_compound.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def __init__(
5757
self.flags |= set(flags)
5858

5959
def to_template_compartment_compound(self, compartment):
60-
cpd_id = f"{self.seed_id}_{compartment}"
60+
cpd_id = f"{self.seed_id}"
61+
if compartment:
62+
cpd_id += f"_{compartment}"
6163
# build Template Compound
6264
metabolite = MSTemplateMetabolite(
6365
self.seed_id,
@@ -71,6 +73,8 @@ def to_template_compartment_compound(self, compartment):
7173
self.abbr,
7274
)
7375
# build Template Compartment Compound
76+
if compartment is None:
77+
compartment = "x"
7478
res = MSTemplateSpecies(cpd_id, self.charge, compartment, metabolite.id)
7579

7680
# assign Compound to Compartment Compound

‎modelseedpy/biochem/modelseed_reaction.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def __init__(
134134
status=None,
135135
source=None,
136136
flags=None,
137+
pathways=None,
137138
):
138139

139140
super().__init__(rxn_id, name, subsystem, lower_bound, upper_bound)
@@ -165,6 +166,8 @@ def __init__(
165166
if flags:
166167
self.flags |= set(flags)
167168

169+
self.pathways = pathways
170+
168171
@property
169172
def compound_ids(self):
170173
return None
@@ -174,8 +177,11 @@ def to_template_reaction(self, compartment_setup=None):
174177
raise ValueError("invalid compartment setup")
175178
from modelseedpy.core.msmodel import get_cmp_token
176179

180+
rxn_id = f"{self.id}"
177181
reaction_compartment = get_cmp_token(compartment_setup.values())
178-
rxn_id = f"{self.id}_{reaction_compartment}"
182+
if reaction_compartment:
183+
rxn_id += f"_{reaction_compartment}"
184+
179185
name = f"{self.name}"
180186
metabolites = {}
181187
for m, v in self.metabolites.items():

‎modelseedpy/core/msatpcorrection.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
# -*- coding: utf-8 -*-
22
import logging
3-
import cobra
4-
import copy
53
import json
6-
import time
74
import pandas as pd
8-
from os.path import abspath as _abspath
9-
from os.path import dirname as _dirname
10-
from optlang.symbolics import Zero, add
11-
from modelseedpy.core.rast_client import RastClient
12-
from modelseedpy.core.msgenome import normalize_role
13-
from modelseedpy.core.msmodel import (
14-
get_gpr_string,
15-
get_reaction_constraints_from_direction,
16-
)
17-
from cobra.core import Gene, Metabolite, Model, Reaction
185
from modelseedpy.core.msmodelutl import MSModelUtil
196
from modelseedpy.core.mstemplate import MSTemplateBuilder
207
from modelseedpy.core import FBAHelper, MSGapfill, MSMedia
218
from modelseedpy.fbapkg.mspackagemanager import MSPackageManager
229
from modelseedpy.helpers import get_template
2310

2411
logger = logging.getLogger(__name__)
25-
logger.setLevel(
26-
logging.INFO
27-
) # When debugging - set this to INFO then change needed messages below from DEBUG to INFO
28-
29-
_path = _dirname(_abspath(__file__))
3012

3113
min_gap = {
3214
"Glc.O2": 5,
@@ -106,8 +88,9 @@ def __init__(
10688

10789
self.media_hash = {}
10890
self.atp_medias = []
91+
10992
if load_default_medias:
110-
self.load_default_medias()
93+
self.load_default_medias(default_media_path)
11194

11295
self.forced_media = []
11396
for media_id in forced_media:
@@ -151,8 +134,13 @@ def load_default_template(self):
151134
get_template("template_core"), None
152135
).build()
153136

154-
def load_default_medias(self):
155-
filename = self.default_media_path
137+
def load_default_medias(self, default_media_path=None):
138+
if default_media_path is None:
139+
import os.path as _path
140+
141+
current_file_path = _path.dirname(_path.abspath(__file__))
142+
default_media_path = f"{current_file_path}/../data/atp_medias.tsv"
143+
filename = default_media_path
156144
medias = pd.read_csv(filename, sep="\t", index_col=0).to_dict()
157145
for media_id in medias:
158146
media_d = {}

‎modelseedpy/core/msbuilder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,8 @@ def build_full_template_model(template, model_id=None, index="0"):
10601060
:param index: index for the metabolites
10611061
:return:
10621062
"""
1063+
from modelseedpy.core.msmodel import MSModel
1064+
10631065
model = MSModel(model_id if model_id else template.id, template=template)
10641066
all_reactions = []
10651067
for rxn in template.reactions:

0 commit comments

Comments
 (0)
Please sign in to comment.