Skip to content
Draft
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
5 changes: 2 additions & 3 deletions .github/workflows/test_demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ on: [push, pull_request]

jobs:
test_demos:
# Pinned: the datrie sdist (via snakemake 7) does not compile with the GCC on ubuntu-26.04.
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Install vitessce
run: uv sync --extra dev --extra all --extra demos
run: uv sync --extra demos
- name: Run tests
working-directory: ./demos
run: uv run snakemake -j 1 --dry-run
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ vitessce/yarn.lock
tests-widget/test-results/
tests-widget/playwright-report/
tests-widget/blob-report/
tests-widget/playwright/.cache/
tests-widget/playwright/.cache/

TODO.md
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ uv run marimo export html docs/notebooks/marimo.py -o docs/notebooks/marimo.html
cd tests-widget && pnpm install && pnpm exec playwright test
```

Demo pipelines: `cd demos && uv run snakemake -j 1 --dry-run` (needs `--extra demos`).
Demo pipelines: `cd demos && uv run snakemake -j 1 --dry-run` (needs `--extra demos`). Each demo is a Snakemake module of `demos/Snakefile`; its `src/` scripts declare dependencies with PEP 723 inline metadata and run via `uv run --script`.

## Architecture

Expand Down
1 change: 0 additions & 1 deletion demos/.envrc

This file was deleted.

61 changes: 44 additions & 17 deletions demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,38 @@ However, now that there are consensus single-cell file formats (e.g., h5ad) and

### Setup

Set up the `vitessce-python-demos` environment using conda.
The demos use [uv](https://docs.astral.sh/uv/) for environment management, and must have `uv` on the `PATH`.

The outer Snakemake environment is defined by the `demos` extra in the root `pyproject.toml`:

```sh
uv sync --extra demos
```

Each processing script in `./{demo_dir}/src/` declares its own dependencies using [PEP 723 inline script metadata](https://peps.python.org/pep-0723/) and is run by the Snakemake rules with `uv run --script`, so uv creates an isolated (cached) environment per script. The scripts depend on the local (repository) version of `vitessce` via `[tool.uv.sources]`.

To run a script manually:

```sh
cd demos
conda env create -f environment.yml
conda activate vitessce-python-demos
pip install -e "..[dev]"
uv run --script ./habib-2017/src/convert_to_zarr.py -i input.h5ad -o output.h5ad.zarr
```

### Run

From within the `demos` directory:

```sh
snakemake --cores all --rerun-triggers mtime
uv run snakemake --cores all --rerun-triggers mtime
```

> NOTE: You will need to refresh the cellxgene urls as they are valid only for a week - please see snakemake files for instructions.
Use `--dry-run` to list the jobs without running them.

Each demo is a Snakemake [module](https://snakemake.readthedocs.io/en/stable/snakefiles/modularization.html#modules) of the main `./Snakefile`, with rule names prefixed by the demo key (e.g., `habib_2017_convert_to_zarr`). Each demo can also be run on its own:

```sh
cd habib-2017
uv run snakemake --cores all
```

### Serve data locally

Expand All @@ -38,10 +54,12 @@ To add a new demo, run
```

Then,
- Add a subworkflow entry to the main demos workflow in `./Snakefile`
- Add the demo directory name to `DEMO_DIRS` and add a `module` and `use rule` entry to the main demos workflow in `./Snakefile` (the script prints these)
- Specify the output filenames in the `output` list in `./{new_demo_dir}/config.yml`
- Fill in the Snakefile in `./{new_demo_dir}/Snakefile`
- Write a test Vitessce configuration in `./{new_demo_dir}/vitessce.template.json`
- Write the processing script(s) in `./{new_demo_dir}/src/`, declaring their dependencies in the PEP 723 `# /// script` block, and call them from rules via `uv run --script {params.script}`
- Write a `./{new_demo_dir}/README.md` describing the data source (with citations/links) and the dataset's data sharing policy
- Build the Vitessce configuration in `./{new_demo_dir}/src/vitessce_config.py` using the `VitessceConfig` and wrapper class (e.g., `AnnDataWrapper`, `SpatialDataWrapper`) APIs. The demo Snakefile's `vitessce_config` rule runs it to generate `vitessce.template.json` (see below). Do not write `vitessce.template.json` by hand.
- Test the demo by running the Vitessce frontend locally and navigating to `http://localhost:3000/?url=http://localhost:8000/{new_demo_dir}/vitessce.json`

See existing demo Snakefiles and scripts for examples.
Expand All @@ -53,28 +71,37 @@ Note that the name of `new_demo_dir` should match the intended key in `https://g

### Render all Vitessce config templates

To use the same configuration for both development (with localhost file URLs) and production/testing (with AWS/GCP file URLs), we write them as Jinja2 templates in the `vitessce.template.json` files where `{{ base_url }}` and `{{ base_url_gcp }}` are replaced at template render time.
To use the same configuration for both development (with localhost file URLs) and production/testing (with AWS/GCP file URLs), each demo's configuration is a Jinja2 template, `vitessce.template.json`, where `{{ base_url }}` and `{{ base_url_gcp }}` are replaced at template render time.

The template is not written by hand. Each demo's `src/vitessce_config.py` builds it with the `VitessceConfig` and wrapper class APIs, passing file URLs such as `sdata_url="{{ base_url }}/my.spatialdata.zarr"` to the wrappers (use `{{ base_url_gcp }}` for `.ome.zarr` outputs, which are uploaded to GCS). Each demo Snakefile has a `vitessce_config` rule that runs this script to write `vitessce.template.json`, and the demo's `all` rule depends on it. See `./spatialdata-xenium-rep1/src/vitessce_config.py` for an example.

We can render the template to `vitessce.local.json` and `vitessce.remote.json` using the following commands:
We can generate every template (via each demo's `vitessce_config` rule) and render it to `vitessce.local.json` and `vitessce.remote.json` using the following command:

```sh
snakemake fill_templates -j 1
uv run snakemake fill_templates -j 1
```

Be sure to re-run after making changes to `vitessce.template.json`.
Templates are regenerated automatically when `src/vitessce_config.py` changes.

#### Render an individual template
#### Generate and render an individual template

Template (from within the demo directory):

```sh
cd habib-2017
uv run snakemake -j 1 vitessce.template.json
```

Local:

```sh
python fill_template.py -d codeluppi-2018 -t local > ./codeluppi-2018/vitessce.local.json
uv run --script fill_template.py -d habib-2017 -t local > ./habib-2017/vitessce.local.json
```

Remote:

```sh
python fill_template.py -d codeluppi-2018 -t remote -v 0.0.33 > ./codeluppi-2018/vitessce.remote.json
uv run --script fill_template.py -d habib-2017 -t remote -v 0.0.33 > ./habib-2017/vitessce.remote.json
```

### Configure AWS and Google Cloud CLIs
Expand All @@ -90,5 +117,5 @@ Configure the Google Cloud CLI by running `gcloud auth login` ([reference](https
### Run and deploy

```sh
snakemake --cores all --rerun-triggers mtime --config upload=true
uv run snakemake --cores all --rerun-triggers mtime --config upload=true
```
Loading
Loading