A package for building time- and space-resolved metabolic models.
Project description
Cobra2D
Cobra2D is a Python package that extends COBRApy to automatically reconstruct time-resolved and/or multi-subsystem metabolic models. It generates context-specific submodels, adds linker and/or transfer reactions to connect them, and scales reactions to account for the lengths of the respective time intervals and the sizes of the subsystems. Cobra2D also provides a time interval- and subsystem size-aware weighted pFBA function.
General process
- Define time intervals (phases) and subsystems (e.g. cell types, tissues or organs)
- Contextualize submodels
- Adjusting compartment sizes
- Adjusting time intervals
- Defining linker reactions (auxiliary reactions that connect phases and allow storage metabolites to be transferred across consecutive phases)
- Defining transfer reactions (auxiliary reactions that connect subsystems and allow exchange metabolites to be transferred across subsystems)
- Adding context-specific constraints to submodels
- Construction of a new model containing all context-specific submodels and their respective constraints
For this process, this package provides functionalities to not only simplify this process, but also to easily save and share the defined settings with other people.
Quick start
Define the spatial submodels and time slots, connect phases, and apply the resulting constraints to a COBRApy model:
from cobra2d import Constraints
from cobra.io import load_model
model = load_model("textbook")
constraints = Constraints()
constraints.add_sub_models(["leaf", "root"], [2, 1])
constraints.add_time_slots(n_ranges=2, time=12)
constraints.add_linker_series("atp_c")
constraints.add_transfer_series("glc__D_e", ["leaf", "root"])
resolved_model = constraints.apply_to_model(model)
Constraints can also be saved as XML and shared:
constraints.save_as_xml("constraints.xml")
restored = Constraints.load_from_xml("constraints.xml")
See the constraints notebook for a complete introduction and linkage and phases for more advanced model construction.
Examples
The documentation includes notebooks for constraints, linkage and phases, and visualization. A sample XML configuration is available at docs/source/examples/data/conf.xml.
Visualization
The package also provides the possibility to obtain an overview of the created settings via an animated or static graphic.
Installation
After cloning the repository, the package can be installed in the current Python environment using pip. In a terminal, this can be done with the following commands:
git clone https://github.com/Toepfer-Lab/Cobra2D.git
cd Cobra2D
pip install .
The static GraphViz visualization (Constraints.create_graph) additionally requires the Graphviz system package. It is separate from the graphviz Python package and cannot be installed via pip, please refer to the documentation of graphviz.
Development
Tests, linting, formatting and type checks all run through tox. The test matrix covers Python 3.9 to 3.13, but you do not need to build those interpreters yourself: we use the tox-uv plugin, which builds every environment with uv and can supply the required CPython versions.
Setting up the same environment we use takes one command. With uv installed:
uv tool install tox --with tox-uv
Alternatively, if you prefer to keep tox in an existing environment, pip install tox tox-uv works as well.
Depending on how uv was installed, the interpreters may have to be fetched once manually:
uv python install 3.9 3.10 3.11 3.12 3.13
From the repository root you can then run:
tox # the full matrix: format, lint, types, and tests on 3.9-3.13
tox -e py312 # tests on a single version
tox -e format,lint # black (check only) and flake8
tox -e types # mypy
tox -e py310-req # tests against the pinned requirements.txt
tox -e py312 -- -k linker # arguments after -- are passed through to pytest
A few notes on the setup:
tox -e formatonly reports diffs, it does not rewrite files. Runblack src/cobra2d/ tests/ --line-length=79to actually apply the formatting.py310-reqis the reproducibility check. It installs the pinnedrequirements.txtrather than resolving dependencies fresh, which is why it is tied to Python 3.10 — the pins were generated withpip-compileunder that version. The remaining environments install fromsetup.cfgand therefore test against current releases of cobra and its dependencies.- Without tox-uv, tox falls back to
virtualenvand expects to findpython3.9,python3.10, … on yourPATH; environments for versions it cannot find will fail. Add--skip-missing-interpreters=trueif you deliberately want to run only the subset you have installed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cobra2d-0.7.1.tar.gz.
File metadata
- Download URL: cobra2d-0.7.1.tar.gz
- Upload date:
- Size: 37.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e1e20a08418b41da3637e1cc99007b1568551f6c0d8157faf4bbda734943e2a
|
|
| MD5 |
3f8a7f1c12d28f26001f93c05080c26e
|
|
| BLAKE2b-256 |
7a5ecd52ed1a9c0c03194dc98202535fbaca25391b98714ab1e4b28b1ab089e3
|
Provenance
The following attestation bundles were made for cobra2d-0.7.1.tar.gz:
Publisher:
test.yml on Toepfer-Lab/Cobra2D
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cobra2d-0.7.1.tar.gz -
Subject digest:
6e1e20a08418b41da3637e1cc99007b1568551f6c0d8157faf4bbda734943e2a - Sigstore transparency entry: 2257424420
- Sigstore integration time:
-
Permalink:
Toepfer-Lab/Cobra2D@4e769b72519b3c01ac848d8661ba41b55d8c2fdb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Toepfer-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@4e769b72519b3c01ac848d8661ba41b55d8c2fdb -
Trigger Event:
push
-
Statement type:
File details
Details for the file cobra2d-0.7.1-py3-none-any.whl.
File metadata
- Download URL: cobra2d-0.7.1-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73ca3b7fd2381c629d83ff7326147f1f12a331f2ff245a147b5c90ba9a1ad29c
|
|
| MD5 |
217e36b5a7a7b6747057eeef1e80922a
|
|
| BLAKE2b-256 |
d2bb2baaebe4dc232d96210c33b974c6e40626502d09feaa817ebb4d5136c0b2
|
Provenance
The following attestation bundles were made for cobra2d-0.7.1-py3-none-any.whl:
Publisher:
test.yml on Toepfer-Lab/Cobra2D
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cobra2d-0.7.1-py3-none-any.whl -
Subject digest:
73ca3b7fd2381c629d83ff7326147f1f12a331f2ff245a147b5c90ba9a1ad29c - Sigstore transparency entry: 2257424429
- Sigstore integration time:
-
Permalink:
Toepfer-Lab/Cobra2D@4e769b72519b3c01ac848d8661ba41b55d8c2fdb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Toepfer-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@4e769b72519b3c01ac848d8661ba41b55d8c2fdb -
Trigger Event:
push
-
Statement type: