-
Notifications
You must be signed in to change notification settings - Fork 117
refactor(datasets): use the shared scverse-misc dataset registry + downloader #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
835eb9c
b845dc9
915df80
859a35f
947e68e
07387e4
0098171
c517bbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,10 +10,8 @@ | |||||||||||
| from pathlib import Path | ||||||||||||
| from typing import TYPE_CHECKING, Any, Literal | ||||||||||||
|
|
||||||||||||
| from scanpy import settings | ||||||||||||
|
|
||||||||||||
| from squidpy.datasets._downloader import get_downloader | ||||||||||||
| from squidpy.datasets._registry import DatasetType, get_registry | ||||||||||||
| from squidpy.datasets._downloader import download | ||||||||||||
| from squidpy.datasets._registry import dataset_names, get_registry | ||||||||||||
| from squidpy.read._utils import PathLike | ||||||||||||
|
|
||||||||||||
| if TYPE_CHECKING: | ||||||||||||
|
|
@@ -122,19 +120,11 @@ def visium( | |||||||||||
| :class:`anndata.AnnData` | ||||||||||||
| Spatial AnnData object. | ||||||||||||
| """ | ||||||||||||
| # Validate sample_id against known names | ||||||||||||
| downloader = get_downloader() | ||||||||||||
|
|
||||||||||||
| if sample_id not in downloader.registry: | ||||||||||||
| msg = f"Unknown Visium sample: {sample_id}. " | ||||||||||||
| msg += f"Available samples: {downloader.registry.visium_datasets}" | ||||||||||||
| raise ValueError(msg) | ||||||||||||
|
|
||||||||||||
| # Use scanpy.settings.datasetdir/visium if base_dir not specified | ||||||||||||
| if base_dir is None: | ||||||||||||
| base_dir = Path(settings.datasetdir) / "visium" | ||||||||||||
| if sample_id not in get_registry(): | ||||||||||||
| raise ValueError(f"Unknown Visium sample: {sample_id}. Available samples: {dataset_names('visium_10x')}") | ||||||||||||
|
Comment on lines
+123
to
+124
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. valid-but-wrong-type name (e.g. imc, an AnnData dataset) passes the guard, then fails deep inside the anndata loader with a confusing TypeError: read_h5ad() got an unexpected keyword argument 'include_hires_tiff' instead of a clear error.
Suggested change
|
||||||||||||
|
|
||||||||||||
| return downloader.download(sample_id, base_dir, include_hires_tiff=include_hires_tiff) | ||||||||||||
| # downloads land in <datasetdir>/visium_10x/<sample_id>/ | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this used to be but good to document |
||||||||||||
| return download(sample_id, base_dir, include_hires_tiff=include_hires_tiff) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def visium_hne_sdata(folderpath: Path | str | None = None) -> sd.SpatialData: | ||||||||||||
|
|
@@ -152,8 +142,7 @@ def visium_hne_sdata(folderpath: Path | str | None = None) -> sd.SpatialData: | |||||||||||
| :class:`spatialdata.SpatialData` | ||||||||||||
| The downloaded and extracted Visium H&E dataset. | ||||||||||||
| """ | ||||||||||||
| downloader = get_downloader() | ||||||||||||
| return downloader.download("visium_hne_sdata", folderpath) | ||||||||||||
| return download("visium_hne_sdata", folderpath) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def cells(folderpath: Path | str | None = None) -> sd.SpatialData: | ||||||||||||
|
|
@@ -171,8 +160,7 @@ def cells(folderpath: Path | str | None = None) -> sd.SpatialData: | |||||||||||
| :class:`spatialdata.SpatialData` | ||||||||||||
| The downloaded and extracted cells dataset. | ||||||||||||
| """ | ||||||||||||
| downloader = get_downloader() | ||||||||||||
| return downloader.download("cells", folderpath) | ||||||||||||
| return download("cells", folderpath) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| # ============================================================================= | ||||||||||||
|
|
@@ -204,9 +192,9 @@ class _DocParts: | |||||||||||
| return_type=":class:`squidpy.im.ImageContainer`\n The image data.", | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| _DOC_PARTS_BY_TYPE: dict[DatasetType, _DocParts] = { | ||||||||||||
| DatasetType.ANNDATA: _ANNDATA_DOC, | ||||||||||||
| DatasetType.IMAGE: _IMAGE_DOC, | ||||||||||||
| _DOC_PARTS_BY_TYPE: dict[str, _DocParts] = { | ||||||||||||
| "anndata": _ANNDATA_DOC, | ||||||||||||
| "image": _IMAGE_DOC, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -225,12 +213,12 @@ def _make_loader(dataset_name: str): | |||||||||||
| raise ValueError(f"Unsupported type for loader factory: {entry.type}") | ||||||||||||
|
|
||||||||||||
| def loader(path: PathLike | None = None, **kwargs: Any): | ||||||||||||
| return get_downloader().download(dataset_name, path, **kwargs) | ||||||||||||
| return download(dataset_name, path, **kwargs) | ||||||||||||
|
|
||||||||||||
| loader.__doc__ = f""" | ||||||||||||
| {entry.doc_header} | ||||||||||||
| {entry.metadata.get("doc_header")} | ||||||||||||
|
|
||||||||||||
| {doc_parts.shape_prefix} ``{entry.shape}``. | ||||||||||||
| {doc_parts.shape_prefix} ``{entry.metadata.get("shape")}``. | ||||||||||||
|
|
||||||||||||
| Parameters | ||||||||||||
| ---------- | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the diff here, can you undo it?