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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

* MINOR CHANGE: Bump Viash to 0.9.7.

* MAJOR CHANGE: Split the scRNA-seq workflows into loading and processing. `load_cellxgene_census` and `load_openproblems_op3` (optionally subsample and) write a raw dataset, and `process_scrnaseq` turns any raw dataset into a common dataset with a single normalisation (log CP10k). They replace `process_cellxgene_census` and `process_openproblems_op3`.

* NEW FUNCTIONALITY: `validation/validate_dataset` checks a raw or common dataset against its format in `src/api`. The load and process workflows run it before publishing, so an invalid dataset fails the run.

* MINOR CHANGE: `load_cellxgene_census` requires a dated Census release, since `latest` and `stable` give different datasets over time.

* MINOR CHANGE: Pin BLAS, OpenMP and numba to 4 threads in every Docker image. The PCA (and with it the kNN graph) depended on the number of cores of the machine.

* MAJOR CHANGE: Raw scRNA-seq datasets must have CELLxGENE-style ontology term ids for the assay, cell type, developmental stage, disease, self-reported ethnicity, sex and tissue. The multimodal loaders use a new `file_multimodal_raw` spec, in which these stay optional.

* BUG FIX: The loaders store `uns['dataset_reference']` and `uns['dataset_organism']` as lists, as declared in `src/api`, since a dataset can have several references and organisms. The OP3 loader takes both as arguments instead of hardcoding them.
Expand Down
4 changes: 2 additions & 2 deletions _viash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ links:

config_mods: |
.runners[.type == "nextflow"].config.labels := { lowmem : "memory = 20.Gb", midmem : "memory = 50.Gb", highmem : "memory = 100.Gb", lowcpu : "cpus = 5", midcpu : "cpus = 15", highcpu : "cpus = 30", lowtime : "time = 1.h", midtime : "time = 4.h", hightime : "time = 8.h", veryhightime : "time = 24.h" }
.engines[.type == "docker"].setup += { type: "docker", env: ["ANNDATA_ZARR_WRITE_FORMAT=3"] }
.engines[.type == "docker"].setup += { type: "docker", env: ["ANNDATA_ZARR_WRITE_FORMAT=3", "OMP_NUM_THREADS=4", "OPENBLAS_NUM_THREADS=4", "MKL_NUM_THREADS=4", "NUMBA_NUM_THREADS=4"] }

repositories:
- name: openproblems
Expand All @@ -32,6 +32,6 @@ repositories:
info:
test_resources:
# created by scripts/create_test_resources/cxg_mouse_pancreas_atlas.ipynb
- path: lamin://openproblems/data-dev/collection/Ajn1Lo8zZomVzKtQ0001
- path: lamin://openproblems/data-dev/collection/Ajn1Lo8zZomVzKtQ0003
dest: resources_test/common/cxg_mouse_pancreas_atlas
strip_prefix: resources_test/datasets/cxg_mouse_pancreas_atlas/
10 changes: 2 additions & 8 deletions scripts/create_resources/cellxgene_census.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,8 @@ param_list:
dataset_reference: steuernagel2022hypomap
dataset_organism: mus_musculus

normalization_methods: [log_cp10k, sqrt_cp10k, l1_sqrt]
output_dataset: '$id/dataset.anndata.zarr'
output_raw: '$id/raw.anndata.zarr'
output_state: '$id/state.yaml'
output_raw: force_null
output_normalized: force_null
output_pca: force_null
output_hvg: force_null
output_knn: force_null
publish_dir: s3://openproblems-data/resources/datasets/scrnaseq
HERE

Expand All @@ -144,7 +138,7 @@ HERE
tw launch https://github.com/openproblems-bio/datasets.git \
--revision build/main \
--pull-latest \
--main-script target/nextflow/workflows/scrnaseq/process_cellxgene_census/main.nf \
--main-script target/nextflow/workflows/scrnaseq/load_cellxgene_census/main.nf \
--workspace 53907369739130 \
--compute-env 6TeIFgV5OY4pJCk8I0bfOh \
--params-file "/tmp/params.yaml" \
Expand Down
13 changes: 3 additions & 10 deletions scripts/create_resources/openproblems_op3.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
#It is an example how to set parameters and execute processing for the op3 dataset.
# Load the OP3 dataset as a raw dataset.
set -e

params_file="/tmp/datasets_op3.yaml"
Expand All @@ -13,16 +13,9 @@ param_list:
dataset_description: "The OP3 dataset is to-date the largest single-cell small molecule perturbation dataset in primary tissue with multiple donor replicates."
dataset_url: "https://ftp.ncbi.nlm.nih.gov/geo/series/GSE279nnn/GSE279945/suppl/GSE279945_sc_counts_processed.h5ad"
dataset_reference: GSE279945
normalization_methods:
- log_cp10k
output_dataset: '$id/dataset.anndata.zarr'
do_subsample: False
output_raw: '$id/raw.anndata.zarr'
output_state: '$id/state.yaml'
output_raw: force_null
output_normalized: force_null
output_pca: force_null
output_hvg: force_null
output_knn: force_null
publish_dir: s3://openproblems-data/resources/datasets
HERE

Expand All @@ -38,7 +31,7 @@ HERE
tw launch https://github.com/openproblems-bio/datasets.git \
--revision build/main \
--pull-latest \
--main-script target/nextflow/workflows/scrnaseq/process_openproblems_op3/main.nf \
--main-script target/nextflow/workflows/scrnaseq/load_openproblems_op3/main.nf \
--workspace 53907369739130 \
--params-file "$params_file" \
--labels op3,dataset_loader \
Expand Down
24 changes: 14 additions & 10 deletions scripts/create_resources/openproblems_op3_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ HERE

set -x
nextflow run . \
-main-script target/nextflow/workflows/scrnaseq/process_openproblems_op3/main.nf \
-main-script target/nextflow/workflows/scrnaseq/load_openproblems_op3/main.nf \
-profile docker \
-resume \
--input https://ftp.ncbi.nlm.nih.gov/geo/series/GSE279nnn/GSE279945/suppl/GSE279945_sc_counts_processed.h5ad \
--id openproblems_sop3 \
--id openproblems_op3 \
--dataset_name "OP3: single-cell multimodal dataset in PBMCs for perturbation prediction benchmarking" \
--dataset_summary "The Open Problems Perurbation Prediction (OP3) dataset with small molecule perturbations in PBMCs" \
--dataset_description "The OP3 dataset is to-date the largest single-cell small molecule perturbation dataset in primary tissue with multiple donor replicates." \
--dataset_url "https://ftp.ncbi.nlm.nih.gov/geo/series/GSE279nnn/GSE279945/suppl/GSE279945_sc_counts_processed.h5ad" \
--dataset_reference GSE279945 \
--do_subsample False \
--normalization_methods log_cp10k \
--output_dataset '$id/dataset.anndata.zarr' \
--output_state '$id/state.yaml' \
--output_raw force_null \
--output_normalized force_null \
--output_pca force_null \
--output_hvg force_null \
--output_knn force_null \
--output_raw '$id/raw.anndata.zarr' \
--output_state '$id/load_state.yaml' \
--publish_dir $DATASET_DIR \
-config /tmp/nextflow.config

nextflow run . \
-main-script target/nextflow/workflows/scrnaseq/process_scrnaseq/main.nf \
-profile docker \
-resume \
--id openproblems_op3 \
--input "$DATASET_DIR/openproblems_op3/raw.anndata.zarr" \
--output_dataset '$id/dataset.anndata.zarr' \
--output_state '$id/process_state.yaml' \
--publish_dir $DATASET_DIR
42 changes: 28 additions & 14 deletions scripts/create_test_resources/cxg_immune_cell_atlas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,14 @@
],
"id": "90648396"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Process\n",
"\n",
"The counts are normalised to log counts per 10,000 (log CP10k). We then select the 1000 most highly variable genes, compute a 50-dimensional PCA on those genes, and build a 15-nearest-neighbour graph on the PCA embedding."
],
"id": "21501390"
},
{
"cell_type": "code",
"execution_count": null,
"id": "82c148a7",
"metadata": {},
"outputs": [],
"source": [
"output_dir = helpers.run_workflow(\"scrnaseq/process_cellxgene_census\", {\n",
"output_dir = helpers.run_workflow(\"scrnaseq/load_cellxgene_census\", {\n",
" \"id\": \"cxg_immune_cell_atlas\",\n",
" \"species\": \"homo_sapiens\",\n",
" \"census_version\": \"2023-07-25\",\n",
Expand All @@ -69,10 +60,33 @@
" \"n_obs\": 600,\n",
" \"n_vars\": 1500,\n",
" \"seed\": 123,\n",
" \"normalization_methods\": [\"log_cp10k\"],\n",
" \"output_dataset\": \"$id/dataset.anndata.zarr\",\n",
" \"output_state\": \"$id/state.yaml\",\n",
" \"output_raw\": \"$id/raw.anndata.zarr\",\n",
" \"output_state\": \"$id/load_state.yaml\",\n",
"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Process\n",
"\n",
"The counts are normalised to log counts per 10,000 (log CP10k). We then select the 1000 most highly variable genes, compute a 50-dimensional PCA on those genes, and build a 15-nearest-neighbour graph on the PCA embedding."
],
"id": "21501390"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output_dir = helpers.run_workflow(\"scrnaseq/process_scrnaseq\", {\n",
" \"id\": \"cxg_immune_cell_atlas\",\n",
" \"input\": str(output_dir / \"cxg_immune_cell_atlas\" / \"raw.anndata.zarr\"),\n",
" \"output_dataset\": \"$id/dataset.anndata.zarr\",\n",
" \"output_state\": \"$id/process_state.yaml\",\n",
"}, output_dir=output_dir)"
],
"id": "59d861f0"
},
Expand Down
46 changes: 30 additions & 16 deletions scripts/create_test_resources/cxg_mouse_pancreas_atlas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,16 @@
],
"id": "18351d38"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Process\n",
"\n",
"The counts are normalised to log counts per 10,000 (log CP10k). We then select the 1000 most highly variable genes, compute a 50-dimensional PCA on those genes, and build a 15-nearest-neighbour graph on the PCA embedding.\n",
"\n",
"We keep the result of every step, so that each of them can be tested on its own."
],
"id": "7e40b79b"
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e0cc2ba",
"metadata": {},
"outputs": [],
"source": [
"steps = [\"raw\", \"normalized\", \"hvg\", \"pca\", \"dataset\"]\n",
"\n",
"output_dir = helpers.run_workflow(\"scrnaseq/process_cellxgene_census\", {\n",
"output_dir = helpers.run_workflow(\"scrnaseq/load_cellxgene_census\", {\n",
" \"id\": \"cxg_mouse_pancreas_atlas\",\n",
" \"species\": \"mus_musculus\",\n",
" \"census_version\": \"2023-07-25\",\n",
Expand All @@ -73,10 +62,35 @@
" \"n_obs\": 600,\n",
" \"n_vars\": 1500,\n",
" \"seed\": 123,\n",
" \"normalization_methods\": [\"log_cp10k\"],\n",
" **{f\"output_{step}\": f\"$id/{step}.anndata.zarr\" for step in steps},\n",
" \"output_state\": \"$id/state.yaml\",\n",
" \"output_raw\": \"$id/raw.anndata.zarr\",\n",
" \"output_state\": \"$id/load_state.yaml\",\n",
"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Process\n",
"\n",
"The counts are normalised to log counts per 10,000 (log CP10k). We then select the 1000 most highly variable genes, compute a 50-dimensional PCA on those genes, and build a 15-nearest-neighbour graph on the PCA embedding.\n",
"\n",
"We keep the result of every step, so that each of them can be tested on its own."
],
"id": "7e40b79b"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output_dir = helpers.run_workflow(\"scrnaseq/process_scrnaseq\", {\n",
" \"id\": \"cxg_mouse_pancreas_atlas\",\n",
" \"input\": str(output_dir / \"cxg_mouse_pancreas_atlas\" / \"raw.anndata.zarr\"),\n",
" **{f\"output_{step}\": f\"$id/{step}.anndata.zarr\" for step in steps[1:]},\n",
" \"output_state\": \"$id/process_state.yaml\",\n",
"}, output_dir=output_dir)"
],
"id": "81cb2eab"
},
Expand Down
9 changes: 5 additions & 4 deletions scripts/create_test_resources/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ def link_to_github(notebook):
transform.save()


def run_workflow(workflow, params, highmem=None):
def run_workflow(workflow, params, highmem=None, output_dir=None):
"""Run a workflow of this repository, return the directory with its outputs.

`highmem` overrides the memory of processes labelled `highmem` (e.g. "64.GB"),
for workflows that load large source files.
for workflows that load large source files. Pass the `output_dir` of a previous
run to publish into the same directory.
"""
output_dir = Path(tempfile.mkdtemp())
params_file = output_dir / "params.json"
output_dir = Path(output_dir or tempfile.mkdtemp())
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"]
if highmem is not None:
Expand Down
32 changes: 32 additions & 0 deletions src/validation/validate_dataset/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: validate_dataset
namespace: validation
description: |
Check that a dataset matches its file format in `src/api`. Fails when a required
slot is missing, so that an invalid dataset is never published.
argument_groups:
- name: Inputs
description: Pass one or more of these files.
arguments:
- name: --input_raw
__merge__: /src/api/file_raw.yaml
direction: input
required: false
- name: --input_dataset
__merge__: /src/api/file_common_dataset.yaml
direction: input
required: false
resources:
- type: python_script
path: script.py
test_resources:
- type: python_script
path: test.py
- path: /resources_test/common/cxg_mouse_pancreas_atlas
engines:
- type: docker
image: openproblems/base_python:1
runners:
- type: executable
- type: nextflow
directives:
label: [lowtime, midmem, lowcpu]
32 changes: 32 additions & 0 deletions src/validation/validate_dataset/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import yaml
from openproblems.project.component_tests.run_and_check_output import check_format

## VIASH START
par = {
"input_raw": "resources_test/common/cxg_mouse_pancreas_atlas/raw.anndata.zarr",
"input_dataset": "resources_test/common/cxg_mouse_pancreas_atlas/dataset.anndata.zarr",
}
meta = {
"config": "target/executable/validation/validate_dataset/.config.vsh.yaml",
}
## VIASH END

# read the file formats from the built config, in which viash has resolved the merges
with open(meta["config"]) as f:
config = yaml.safe_load(f)
arguments = [
arg
for group in config.get("argument_groups", [])
for arg in group["arguments"]
]

# check every input that was passed
inputs = [arg for arg in arguments if par.get(arg["name"].lstrip("-")) is not None]
assert inputs, "Pass at least one of " + ", ".join(arg["name"] for arg in arguments)

for arg in inputs:
clean_name = arg["name"].lstrip("-")
print(f">> Checking {clean_name} against '{arg['label']}'", flush=True)
check_format({**arg, "clean_name": clean_name, "value": par[clean_name]})

print(">> All inputs match their format", flush=True)
51 changes: 51 additions & 0 deletions src/validation/validate_dataset/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import shutil
import subprocess
from pathlib import Path

import anndata as ad

## VIASH START
meta = {
"executable": "target/executable/validation/validate_dataset/validate_dataset",
"resources_dir": "resources_test/common",
"temp_dir": "/tmp",
}
## VIASH END

resources = Path(meta["resources_dir"]) / "cxg_mouse_pancreas_atlas"
raw = resources / "raw.anndata.zarr"
dataset = resources / "dataset.anndata.zarr"


def validate(*args):
return subprocess.run([meta["executable"], *args], capture_output=True, text=True)


print(">> Valid raw and processed datasets pass", flush=True)
for args in [
["--input_raw", raw],
["--input_dataset", dataset],
["--input_raw", raw, "--input_dataset", dataset],
]:
out = validate(*map(str, args))
assert out.returncode == 0, out.stdout + out.stderr

print(">> A raw dataset is not a processed dataset", flush=True)
out = validate("--input_dataset", str(raw))
assert out.returncode != 0
assert "is missing slot" in out.stdout + out.stderr, out.stdout + out.stderr

print(">> A raw dataset without a required obs column fails", flush=True)
adata = ad.read_zarr(raw)
del adata.obs["cell_type_ontology_term_id"]
broken = Path(meta["temp_dir"]) / "broken.anndata.zarr"
shutil.rmtree(broken, ignore_errors=True)
adata.write_zarr(broken)
out = validate("--input_raw", str(broken))
assert out.returncode != 0
assert "cell_type_ontology_term_id" in out.stdout + out.stderr, out.stdout + out.stderr

print(">> Passing no input fails", flush=True)
assert validate().returncode != 0

print(">> All tests passed", flush=True)
Loading
Loading