diff --git a/pyxa_v1_io/README.md b/pyxa_v1_io/README.md new file mode 100644 index 0000000..8ed9e46 --- /dev/null +++ b/pyxa_v1_io/README.md @@ -0,0 +1,9 @@ +# Stellaromics Pyxa (v1 output files) + +The `xsmall` subset of the [Stellaromics/demo](https://huggingface.co/datasets/Stellaromics/demo) dataset on the +Hugging Face Hub (BSD 3-Clause): a 100 × 100 × 100 µm cube (187 cells, ~23k transcripts) with the four Pyxa output +files and a DAPI mosaic (multiscale OME-Zarr), ~8 MB in total. It is the same subset used in the spatialdata-io CI +tests for the experimental `pyxa` reader. + +`download.py` fetches it into `data/`, and `to_zarr.py` converts it with `spatialdata_io.experimental.pyxa()`. The +full demo region (`small/`, ~290 MB) has the same layout. diff --git a/pyxa_v1_io/download.py b/pyxa_v1_io/download.py new file mode 100644 index 0000000..47f2145 --- /dev/null +++ b/pyxa_v1_io/download.py @@ -0,0 +1,32 @@ +## +import os +import subprocess +import zipfile +from pathlib import Path + +# from https://huggingface.co/datasets/Stellaromics/demo (BSD 3-Clause) +# xsmall/: a 100 x 100 x 100 um cube cropped from the full demo region (small/), ~8 MB + +BASE_URL = "https://huggingface.co/datasets/Stellaromics/demo/resolve/main/xsmall" +FILES = [ + "cell_assigned_gene_v1.csv", + "cell_by_gene_v1.csv", + "cell_metadata_v1.csv", + "segmentation_geometries_v1.parquet", + "mosaic_3d.ome.zarr.zip", +] + +data_dir = Path(__file__).resolve().parent / "data" +os.makedirs(data_dir, exist_ok=True) + +## +# download the data +for filename in FILES: + command = f"curl -L -C - -o {data_dir / filename} {BASE_URL}/{filename}" + subprocess.run(command, shell=True, check=True) + +## +# unzip the DAPI mosaic (a zipped OME-Zarr store containing mosaic_3d.ome.zarr/) +with zipfile.ZipFile(data_dir / "mosaic_3d.ome.zarr.zip") as zf: + zf.extractall(data_dir) +os.remove(data_dir / "mosaic_3d.ome.zarr.zip") diff --git a/pyxa_v1_io/to_zarr.py b/pyxa_v1_io/to_zarr.py new file mode 100644 index 0000000..65a6509 --- /dev/null +++ b/pyxa_v1_io/to_zarr.py @@ -0,0 +1,40 @@ +# /// script +# requires-python = ">=3.12" +# dependencies = [ +# # the pyxa reader is pending review in scverse/spatialdata-io +# "spatialdata-io @ git+https://github.com/ckmah/spatialdata-io.git@pyxa-reader", +# ] +# /// +## +from spatialdata_io.experimental import pyxa +import spatialdata as sd + +## +from pathlib import Path +import shutil + +## +path = Path().resolve() +# luca's workaround for pycharm +if not str(path).endswith("pyxa_v1_io"): + path /= "pyxa_v1_io" + assert path.exists() + +path_read = path / "data" +path_write = path / "data.zarr" + +## +print("parsing the data... ", end="") +sdata = pyxa(path_read, image_path=path_read / "mosaic_3d.ome.zarr") +print("done") + +## +print("writing the data... ", end="") +if path_write.exists(): + shutil.rmtree(path_write) +sdata.write(path_write) +print("done") + +## +sdata = sd.SpatialData.read(path_write) +print(sdata)