From 819b28b07eb9b4b4912ab141c598412f9f3e4a3b Mon Sep 17 00:00:00 2001 From: Jan-Niklas Weder Date: Mon, 27 Jul 2026 14:00:55 +0200 Subject: [PATCH] Updated github workflow Changes to some of the documentation because of package naming --- .github/workflows/test.yml | 103 ++++++++++++++++++++++------------ README.md | 54 ++++++++++++------ docs/source/example.rst | 5 +- docs/source/index.rst | 3 +- docs/source/visualization.rst | 12 +++- 5 files changed, 120 insertions(+), 57 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e14d21..5f9403c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 @@ -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 @@ -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({ @@ -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 diff --git a/README.md b/README.md index 3ee1c89..48331e4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ -![Generic badge]() -![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) @@ -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. - - - ConInteractive.gif - - +![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 . ``` diff --git a/docs/source/example.rst b/docs/source/example.rst index f514c12..be25ac6 100644 --- a/docs/source/example.rst +++ b/docs/source/example.rst @@ -6,5 +6,6 @@ Examples examples/Constraints examples/LinkageAndPhases - examples/Visualization/cytoscape.ipynb - + examples/Visualization/classic + examples/Visualization/cytoscape + examples/converter diff --git a/docs/source/index.rst b/docs/source/index.rst index 51d8640..a14a8ea 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -8,12 +8,13 @@ Cobra2D :glob: :maxdepth: 2 - README + Getting started Structural design Linker and transfer reactions Visualisation Naming convention Examples + API reference Indices and tables ================== diff --git a/docs/source/visualization.rst b/docs/source/visualization.rst index c7e4d10..7a941ff 100644 --- a/docs/source/visualization.rst +++ b/docs/source/visualization.rst @@ -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, @@ -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 @@ -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. \ No newline at end of file + + Interface for selecting groups and hiding metabolites before visualizing a + COBRApy model with MetExploreViz.