From 7869839aa7a6419931d2385817686d478c81be48 Mon Sep 17 00:00:00 2001 From: Jayaram Kancherla Date: Wed, 29 May 2024 07:40:21 -0700 Subject: [PATCH] Register `save_dataset` for `SummarizedExperiment` class (#11) Update tests --- docs/conf.py | 1 + src/scrnaseq/save_dataset.py | 23 +++++++++++++++++------ tests/test_fetch_dataset.py | 1 + tests/test_polish_dataset.py | 1 + tests/test_save_dataset.py | 4 ++-- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 52b4089..16b0213 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -316,6 +316,7 @@ "gypsum_client": ("https://artifactdb.github.io/gypsum-py", None), "delayedarray": ("https://biocpy.github.io/DelayedArray", None), "dolomite_base": ("https://artifactdb.github.io/dolomite-base", None), + "anndata": ("https://anndata.readthedocs.io/en/latest/", None), } print(f"loading configurations for {project} {version} ...", file=sys.stderr) \ No newline at end of file diff --git a/src/scrnaseq/save_dataset.py b/src/scrnaseq/save_dataset.py index edb78c3..8d9a10c 100644 --- a/src/scrnaseq/save_dataset.py +++ b/src/scrnaseq/save_dataset.py @@ -7,6 +7,7 @@ import dolomite_base as dl from gypsum_client import fetch_metadata_schema, validate_metadata from singlecellexperiment import SingleCellExperiment +from summarizedexperiment import SummarizedExperiment from .utils import format_object_metadata @@ -22,7 +23,9 @@ def save_dataset(x: Any, path, metadata): Args: x: An object containing single-cell data. - May be a derivative of SummarizedExperiment or AnnData. + May be a derivative of + :py:class:`~summarizedexperiment.SummarizedExperiment.SummarizedExperiment` + or :py:class:`~anndata.AnnData`. path: Path to a new directory to save the dataset. @@ -80,13 +83,11 @@ def save_dataset(x: Any, path, metadata): ) -@save_dataset.register -def save_dataset_sce(x: SingleCellExperiment, path: str, metadata: dict): - """Save :py:class:`~singlecellexperiment.SingleCellExperiment.SingleCellExperiment` to disk.""" +def _save_se(x, path, metadata): schema = fetch_metadata_schema() if "bioconductor_version" not in metadata: - metadata["bioconductor_version"] = "3.14" # current release + metadata["bioconductor_version"] = "3.19" # current release validate_metadata(metadata, schema) @@ -109,7 +110,17 @@ def save_dataset_sce(x: SingleCellExperiment, path: str, metadata: dict): with open(os.path.join(path, "_bioconductor.json"), "w") as f: f.write(contents) - return + +@save_dataset.register +def save_dataset_sce(x: SingleCellExperiment, path: str, metadata: dict): + """Save :py:class:`~singlecellexperiment.SingleCellExperiment.SingleCellExperiment` to disk.""" + return _save_se(x, path, metadata) + + +@save_dataset.register +def save_dataset_se(x: SummarizedExperiment, path: str, metadata: dict): + """Save :py:class:`~summarizedexperiment.SummarizedExperiment.SummarizedExperiment` to disk.""" + return _save_se(x, path, metadata) has_anndata = False diff --git a/tests/test_fetch_dataset.py b/tests/test_fetch_dataset.py index f9ce31b..07acfca 100644 --- a/tests/test_fetch_dataset.py +++ b/tests/test_fetch_dataset.py @@ -35,6 +35,7 @@ def test_fetch_dataset(): assert all(isinstance(a, (np.ndarray)) for _, a in alt_exp_ass.items()) +@pytest.mark.skip("takes too long") def test_fetch_dataset_realizes_reduced_dimensions(): sce = fetch_dataset("aztekin-tail-2019", "2023-12-14", realize_reduced_dims=False) red_dim = sce.get_reduced_dims() diff --git a/tests/test_polish_dataset.py b/tests/test_polish_dataset.py index 9a310ff..415518f 100644 --- a/tests/test_polish_dataset.py +++ b/tests/test_polish_dataset.py @@ -168,6 +168,7 @@ def test_polish_dataset_forbids_highly_nested_altexps(): ) +@pytest.mark.skip("takes too long") def test_polish_existing_dataset(): sce = fetch_dataset("zeisel-brain-2015", "2023-12-14") diff --git a/tests/test_save_dataset.py b/tests/test_save_dataset.py index 08433a4..97be19b 100644 --- a/tests/test_save_dataset.py +++ b/tests/test_save_dataset.py @@ -44,7 +44,7 @@ def test_save_dataset_sce(): with open(os.path.join(tmp, "_bioconductor.json")) as f: saved_meta = json.load(f) - assert saved_meta["bioconductor_version"] == "3.14" # Placeholder version + assert saved_meta["bioconductor_version"] == "3.19" # Test validation failure meta["title"] = 1234 @@ -90,7 +90,7 @@ def test_save_dataset_anndata(): with open(os.path.join(tmp, "_bioconductor.json")) as f: saved_meta = json.load(f) - assert saved_meta["bioconductor_version"] == "3.14" # Placeholder version + assert saved_meta["bioconductor_version"] == "3.19" # Test validation failure meta["title"] = 1234