Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

* MAJOR CHANGE: All loaders, components and workflows write AnnData zarr stores instead of h5ad files, and the file formats in `src/api` are now `anndata_zarr`. Every Docker image sets `ANNDATA_ZARR_WRITE_FORMAT=3`. Multimodal datasets are still two AnnData stores, spatial datasets one.

* NEW FUNCTIONALITY: Test resource artifacts in LaminDB are annotated with what the OpenProblems website shows about a dataset (`scripts/create_test_resources/lamin_annotate.py`): a schema with every slot of the `src/api` file format, the ontology terms in `obs`, the `dataset_*` metadata, the structure of the store, cell counts per category, processing parameters, the modality and references with their DOI. The notebooks record the workflow parameters on their run.

* MAJOR CHANGE: Test resources are generated by notebooks in `scripts/create_test_resources` and stored as one collection per notebook in the public LaminDB instance `openproblems/data-dev`. CI syncs them with `edaro/viash-actions`. `pancreas.ipynb` replaces `pancreas.sh`.

* MINOR CHANGE: The CELLxGENE immune cell atlas, CELLxGENE mouse pancreas atlas, Visium mouse brain, NeurIPS 2021 bone marrow and sci-CAR cell lines test resources are generated by notebooks too. Their subsampling is now seeded, and the CELLxGENE ones no longer pass cell cycle gene symbols as `keep_features`, which never matched their Ensembl gene ids. `neurips2022_pbmc.sh` is not converted yet.
Expand Down
4 changes: 3 additions & 1 deletion scripts/create_test_resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ Each notebook in this directory creates one set of test resources: it runs a wor
You need Docker, Nextflow, the components built with `viash ns build --setup cachedbuild`, and write access to `openproblems/data-dev`. The `.lamin` directory in the root of this repository connects it to that instance. Run a notebook with:

```bash
uv run --with 'lamindb[aws]' --with nbconvert --with ipykernel \
uv run --with 'lamindb[aws,bionty]' --with 'anndata>=0.13' --with nbconvert --with ipykernel \
scripts/create_test_resources/run_notebook.sh scripts/create_test_resources/pancreas.ipynb
```

This tracks the run in LaminDB with the project `openproblems-bio/datasets`, links it to the notebook on GitHub if the notebook is committed and pushed, and saves the executed notebook as the report of the run.

The workflows are deterministic, so rerunning a notebook without changes returns the existing artifacts and collection. If the outputs change, the collection gets a new version; update its uid in `_viash.yaml` if this repository's own tests use it.

Each dataset artifact is also annotated with what the OpenProblems website shows about a dataset (`lamin_annotate.py`): a schema with every slot of its file format in `src/api`, the ontology terms in `obs`, the `dataset_*` metadata, the structure of the store, counts of cells per category, processing parameters and its references.

`helpers.py` holds the steps the notebooks share.
2 changes: 2 additions & 0 deletions scripts/create_test_resources/cxg_immune_cell_atlas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
" output_dir / \"cxg_immune_cell_atlas\",\n",
" [\"dataset.anndata.zarr\"],\n",
" key=\"resources_test/datasets/cxg_immune_cell_atlas\",\n",
" specs=helpers.SCRNASEQ_SPECS,\n",
" modality=\"scrnaseq\",\n",
" description=\"Immune Cell Atlas (CELLxGENE), three donors, subsampled to 600 cells and 1500 genes\",\n",
")"
],
Expand Down
2 changes: 2 additions & 0 deletions scripts/create_test_resources/cxg_mouse_pancreas_atlas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
" output_dir / \"cxg_mouse_pancreas_atlas\",\n",
" [f\"{step}.anndata.zarr\" for step in steps],\n",
" key=\"resources_test/datasets/cxg_mouse_pancreas_atlas\",\n",
" specs=helpers.SCRNASEQ_SPECS,\n",
" modality=\"scrnaseq\",\n",
" description=\"Mouse pancreatic islet atlas (CELLxGENE), three donors, subsampled to 600 cells and 1500 genes\",\n",
")"
],
Expand Down
38 changes: 33 additions & 5 deletions scripts/create_test_resources/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import lamindb as ln

import lamin_annotate

INSTANCE = "openproblems/data-dev"
PROJECT = "openproblems-bio/datasets"
REPO_URL = "https://github.com/openproblems-bio/datasets"
Expand All @@ -23,6 +25,15 @@ def git(*args):

REPO_ROOT = Path(git("rev-parse", "--show-toplevel"))

# file format of each processing step of a scRNA-seq dataset
SCRNASEQ_SPECS = {
"raw.anndata.zarr": "src/api/file_raw.yaml",
"normalized.anndata.zarr": "src/api/file_normalized.yaml",
"hvg.anndata.zarr": "src/api/file_hvg.yaml",
"pca.anndata.zarr": "src/api/file_pca.yaml",
"dataset.anndata.zarr": "src/api/file_common_dataset.yaml",
}


def check_instance():
"""Make sure the .lamin dev-dir in the repo root selected the right instance."""
Expand Down Expand Up @@ -54,6 +65,13 @@ def run_workflow(workflow, params, highmem=None, output_dir=None):
run to publish into the same directory.
"""
output_dir = Path(output_dir or tempfile.mkdtemp())

# record the parameters on the run, e.g. which source release and query a dataset came from
run = ln.context.run
if run is not None:
run.params = {**(run.params or {}), workflow: params}
run.save()

params_file = output_dir / f"params_{workflow.replace('/', '_')}.json"
params_file.write_text(json.dumps({**params, "publish_dir": str(output_dir)}))
configs = ["-c", "common/nextflow_helpers/labels_ci.config"]
Expand All @@ -76,20 +94,30 @@ def run_workflow(workflow, params, highmem=None, output_dir=None):
return output_dir


def save_collection(output_dir, files, key, description):
def save_collection(output_dir, files, key, description, specs=None, modality=None):
"""Store each file as an artifact under `key` and group them in a collection with that key.

Earlier versions keep their files, so a pinned version of the collection stays downloadable.
Files with a file format in `specs` are annotated with everything the website shows about
a dataset (see `lamin_annotate`).
"""
artifacts = [
ln.Artifact(
specs = specs or {}
artifacts = []
for file in files:
artifact = ln.Artifact(
output_dir / file,
key=f"{key}/{file}",
description=f"{description}: {file}",
overwrite_versions=False,
).save()
for file in files
]
if file in specs:
lamin_annotate.annotate_artifact(
artifact,
REPO_ROOT / specs[file],
modality=modality,
bib_path=REPO_ROOT / "common/library.bib",
)
artifacts.append(artifact)
collection = ln.Collection(artifacts, key=key, description=description).save()
print(f"lamin://{INSTANCE}/collection/{collection.uid}")
return collection
Loading