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
4 changes: 3 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,9 @@ is the first suspect.
the archive) and reads it as the workflow's `spatialdata` type does, asserting the
points are left out, the session and the sidecar open on the chosen table, and the
wells are stitched into `obsm['spatial_global']` (and that world coordinates already
in `obsm['spatial']` are not stitched again).
in `obsm['spatial']` are not stitched again). It then runs the workflow's
`nextflow/bin/dataset_metrics.py` on that checkpoint and asserts it summarises the
chosen table rather than whichever sorts first.
- `cd backend && PYTHONPATH=. python test_compression.py` — dataset-free unit test
for `SelectiveGZipMiddleware`: which content types compress, round-trip/passthrough
correctness, and the regression guard that gzip runs off the event loop (a
Expand Down
15 changes: 15 additions & 0 deletions backend/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io
import json
import os
import subprocess
import sys
import tempfile

Expand Down Expand Up @@ -228,6 +229,20 @@ def check_foreign_store(cli) -> int:
assert sidecar["world_key"]["cells"] == "spatial_global", sidecar["world_key"]
print("[ok] checkpoint written with the store at the archive root; its sidecar opens "
"the viewer on 'cells' drawn from obsm['spatial_global']")

# The workflow's MultiQC step reads the same checkpoint, and has to pick the
# table the session opened on out of several ('a-guides' sorts first).
metrics_dir = os.path.join(tmp, "metrics")
os.makedirs(metrics_dir)
subprocess.run([sys.executable, os.path.join(_REPO_ROOT, "nextflow", "bin", "dataset_metrics.py"),
"--sample", "store_result", "--data-type", "spatialdata", "--status", "ok",
"--checkpoint", out_zip, "--source-dir", tmp, "--outdir", metrics_dir],
check=True)
with open(os.path.join(metrics_dir, "store_result_analysis_mqc.json")) as f:
summary = json.load(f)["data"]["store_result"]
assert summary == {"cells": table.n_obs, "features": table.n_vars}, summary
print(f"[ok] the workflow's metrics step reads the 'cells' table of a multi-table "
f"checkpoint ({summary})")
return 0


Expand Down
14 changes: 10 additions & 4 deletions nextflow/bin/dataset_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ def _parse_args():


def _read_checkpoint(checkpoint: str) -> tuple[pd.DataFrame, pd.DataFrame, dict]:
"""`obs` and `var` of the checkpoint's single table, plus its `app_state`."""
"""`obs` and `var` of the table the checkpoint opens on, plus its `app_state`.

A checkpoint imported from a SpatialData store keeps every table the store had, and
the one the analysis worked on is the first in the `viewer/` sidecar's `table_keys`
(the order the session saved them in; zarr lists them sorted by name)."""
with zarr.storage.ZipStore(checkpoint, mode="r") as store:
root = zarr.open_group(store, mode="r")
root = zarr.open_group(store, mode="r", use_consolidated=False)
tables = root["tables"]
keys = list(tables)
if len(keys) != 1:
raise SystemExit(f"{checkpoint}: expected exactly one table, found {keys}")
if len(keys) > 1:
keys = root["viewer"].attrs["table_keys"]
if not keys:
raise SystemExit(f"{checkpoint}: has no table")
group = tables[keys[0]]
return read_elem(group["obs"]), read_elem(group["var"]), dict(root.attrs).get("app_state", {})

Expand Down
Loading