Skip to content

Commit

Permalink
Register save_dataset for SummarizedExperiment class (#11)
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
jkanche authored May 29, 2024
1 parent 5f2d588 commit 7869839
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 17 additions & 6 deletions src/scrnaseq/save_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_fetch_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/test_polish_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_save_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7869839

Please sign in to comment.