Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 68 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Test
name: Test, build and publish Cobra2D to PyPI
on:
workflow_dispatch:

schedule:
- cron: "0 5 * * 1"

pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
Expand All @@ -23,12 +26,11 @@ jobs:
run: python -m tox -e format

types:
needs: [lint-format]
needs: [ lint-format ]
runs-on: ubuntu-latest
strategy:
matrix:
python: [ '3.9', '3.10', '3.11', '3.12', '3.13' ]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -40,7 +42,7 @@ jobs:
run: python -m tox -e types

test-dev:
needs: [lint-format, types]
needs: [ lint-format, types ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -52,38 +54,68 @@ jobs:
- name: Run dev env test
run: python -m tox -e py310-req

build:
needs: [ types ]
runs-on: ubuntu-latest
outputs:
file-path: ${{ steps.path.outputs.file-path }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: python -m pip install --upgrade pip build
- name: Build package
run: python -m build
- name: Get wheel file name
id: path
run: echo "file-path=$(cd dist && find . -type f -iname 'cobra2d-*.whl')" >> "$GITHUB_OUTPUT"
- name: Archive package as artifact
uses: actions/upload-artifact@v4
with:
name: cobra2d-dist
path: dist

test:
needs: [test-dev]
needs: [ build ]
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.9', '3.10', '3.11', '3.12', '3.13' ]
runs-on: ${{ matrix.os}}

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Download built package
uses: actions/download-artifact@v4
with:
name: cobra2d-dist
- name: Install tox
run: python -m pip install tox tox-uv
- name: Set up test suite (install the built wheel)
run: python -m tox -e py --notest --installpkg ${{ needs.build.outputs.file-path }}
- name: Run tests
run: tox -e py
run: python -m tox -e py --skip-pkg-install

create-tag:
needs: [test]
needs: [ test, test-dev ]
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- uses: actions/checkout@v4
- run: |
output=$(python setup.py --version)
echo "version=$output" >> "$GITHUB_OUTPUT"
- name: Get version
id: version

run: |
version=$(grep -Po '(?<=^__version__ = ")[^"]+' src/cobra2d/__init__.py)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Create tag
if: github.event.pull_request.merged == true
uses: actions/github-script@v5
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
Expand All @@ -93,30 +125,31 @@ jobs:
sha: context.sha
})

build-publish:
needs: [ lint-format, types, test ]
name: Build and publish the package to TestPyPI
publish-to-pypi:
needs: [ test, test-dev ]
name: Publish Cobra2D 📦 to PyPI
if: github.event.pull_request.merged == true && github.event_name != 'schedule'
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/cobra2d
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Download built package
uses: actions/download-artifact@v4
with:
name: cobra2d-dist
path: dist
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build twine
- name: Build package
run: python -m build
python-version: '3.13'
- name: Install twine
run: python -m pip install --upgrade pip twine
- name: Check the package
run: twine check dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run:
twine upload --non-interactive dist/*
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
54 changes: 38 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
![Generic badge](<https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue>)
![Tests](https://github.com/Toepfer-Lab/model_duplication/actions/workflows/test.yml/badge.svg)
![GitHub last commit](https://img.shields.io/github/last-commit/Toepfer-Lab/model_duplication)
![GitHub pull requests](https://img.shields.io/github/issues-pr/Toepfer-Lab/model_duplication)
# Cobra2D

![Python versions](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)
![Tests](https://github.com/Toepfer-Lab/Cobra2D/actions/workflows/test.yml/badge.svg)
![GitHub last commit](https://img.shields.io/github/last-commit/Toepfer-Lab/Cobra2D)
![GitHub pull requests](https://img.shields.io/github/issues-pr/Toepfer-Lab/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:
### General process

* Define time intervals (phases) and subsystems (e.g. cell types, tissues or organs)
* Contextualizing sub-models
* 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)
Expand All @@ -19,32 +21,52 @@ Cobra2D is a Python package that extends COBRApy to automatically reconstruct ti
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.

### Use cases for this package
### Quick start

Define the spatial submodels and time slots, connect phases, and apply the resulting constraints to a COBRApy model:

```python
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:

```python
constraints.save_as_xml("constraints.xml")
restored = Constraints.load_from_xml("constraints.xml")
```

There are two ways to use this package: functions implemented in Python can be used to define phases and constraints directly, or an XML file can be created and read in to generate a new model.
See the [constraints notebook](docs/source/examples/Constraints.ipynb) for a complete introduction and [linkage and phases](docs/source/examples/LinkageAndPhases.ipynb) for more advanced model construction.

### Examples

Examples of package usage can be found in the examples folder, including scripts that demonstrate the core functions and a sample XML file showing how parameters are stored.
The documentation includes notebooks for [constraints](docs/source/examples/Constraints.ipynb), [linkage and phases](docs/source/examples/LinkageAndPhases.ipynb), and [visualization](docs/source/examples/Visualization/cytoscape.ipynb). A sample XML configuration is available at [docs/source/examples/data/conf.xml](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.

<object data="../../assets/media/ConInteractive.gif" type="image/gif">
<object data="https://github.com/Toepfer-Lab/model_duplication/blob/c42dfdac52524a93323e78e1f3d996aef5e01714/assets/media/ConInteractive.gif" type="image/gif">
<img src="./assets/media/ConInteractive.gif" alt="ConInteractive.gif">
</object>
</object>
![Interactive Cytoscape visualization of Cobra2D constraints](assets/media/ConInteractive.gif)

### 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/model_duplication
git clone https://github.com/Toepfer-Lab/Cobra2D.git

cd model_duplication
cd Cobra2D

pip install .
```
Expand Down
5 changes: 3 additions & 2 deletions docs/source/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Examples

examples/Constraints
examples/LinkageAndPhases
examples/Visualization/cytoscape.ipynb

examples/Visualization/classic
examples/Visualization/cytoscape
examples/converter
3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Cobra2D
:glob:
:maxdepth: 2

README <self>
Getting started <self>
Structural design <structure>
Linker and transfer reactions <transport>
Visualisation <visualization>
Naming convention <convention>
Examples <example>
API reference <api>

Indices and tables
==================
Expand Down
12 changes: 9 additions & 3 deletions docs/source/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ The visualization can be created with the following command.
.. figure:: ../../assets/media/GraphViz.png
:scale: 50 %
:alt: Example of visualization using GraphViz
Example of visualization with GraphViz where ATP is transported to the following time period respectively.

Example of a GraphViz visualization in which ATP is transported to each
following time period.

Cytoscape visualizes the same as GraphViz but in an interactive environment. Thus, much more information is available
than is available when using Graphviz. However, this information is not all displayed at the same time,
Expand All @@ -62,7 +64,9 @@ Below is a brief example of this visualization.
.. figure:: ../../assets/media/ConInteractive.gif
:scale: 50 %
:alt: Example of visualization using Cytoscape
Example of visualization with Cytoscape where ATP is transported to the following time period respectively.

Example of an interactive Cytoscape visualization in which ATP is
transported to each following time period.


Metexplore
Expand All @@ -83,4 +87,6 @@ The pathways are sorted alphabetically and the metabolites are sorted based on t
.. figure:: ../../assets/media/MetExploreVizInterface.png
:scale: 50 %
:alt: Example of the MetExploreViz interface
Example of the interface used to select groups and hide metabolites before visualizing a COBRApy model with MetExploreViz.

Interface for selecting groups and hiding metabolites before visualizing a
COBRApy model with MetExploreViz.
Loading