Skip to content

Commit

Permalink
build: move pooch to dependencies decorator (#3118)
Browse files Browse the repository at this point in the history
Co-authored-by: Lumberbot (aka Jack) <[email protected]>
Co-authored-by: Martin Kim <[email protected]>
Co-authored-by: Can Ergen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Justin Hong <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: ori-kron-wis <[email protected]>
Co-authored-by: Yishen Miao <[email protected]>
Co-authored-by: Ramon Viñas <[email protected]>
Co-authored-by: Martin Kim <[email protected]>
Co-authored-by: Ethan Weinberger <[email protected]>
Co-authored-by: Ethan Weinberger <[email protected]>
Co-authored-by: access <[email protected]>
  • Loading branch information
14 people authored Jan 1, 2025
1 parent 81321fa commit 874f8da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/scvi/data/_built_in_data/_dataset_10x.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from scvi import settings
from scvi.data._download import _download
from scvi.utils import dependencies

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,6 +75,7 @@
}


@dependencies("scanpy")
def _load_dataset_10x(
dataset_name: str = None,
filename: str = None,
Expand All @@ -83,10 +85,7 @@ def _load_dataset_10x(
remove_extracted_data: bool = False,
**scanpy_read_10x_kwargs,
):
try:
import scanpy
except ImportError as err:
raise ImportError("Please install scanpy -- `pip install scanpy`") from err
import scanpy

# form data url and filename unless manual override
if dataset_name is not None:
Expand Down
15 changes: 14 additions & 1 deletion src/scvi/data/_built_in_data/_loom.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import logging
import os

import pooch
from anndata import AnnData, read_h5ad

from scvi.utils import dependencies

logger = logging.getLogger(__name__)


@dependencies("pooch")
def _load_retina(save_path: str = "data/") -> AnnData:
"""Loads retina dataset.
The dataset of bipolar cells contains after their original pipeline for filtering 27,499 cells
and 13,166 genes coming from two batches. We use the cluster annotation from 15 cell-types from
the author. We also extract their normalized data with Combat and use it for benchmarking.
"""
import pooch

save_path = os.path.abspath(save_path)
adata = read_h5ad(
pooch.retrieve(
Expand All @@ -27,11 +31,14 @@ def _load_retina(save_path: str = "data/") -> AnnData:
return adata


@dependencies("pooch")
def _load_prefrontalcortex_starmap(save_path: str = "data/") -> AnnData:
"""Loads a starMAP dataset from the mouse pre-frontal cortex :cite:p:`Wang18`.
Contains 3,704 cells and 166 genes.
"""
import pooch

save_path = os.path.abspath(save_path)
adata = read_h5ad(
pooch.retrieve(
Expand All @@ -45,7 +52,10 @@ def _load_prefrontalcortex_starmap(save_path: str = "data/") -> AnnData:
return adata


@dependencies("pooch")
def _load_frontalcortex_dropseq(save_path: str = "data/") -> AnnData:
import pooch

save_path = os.path.abspath(save_path)
adata = read_h5ad(
pooch.retrieve(
Expand All @@ -62,6 +72,7 @@ def _load_frontalcortex_dropseq(save_path: str = "data/") -> AnnData:
return adata


@dependencies("pooch")
def _load_annotation_simulation(name: str, save_path: str = "data/") -> AnnData:
"""Simulated datasets for scANVI tutorials.
Expand All @@ -75,6 +86,8 @@ def _load_annotation_simulation(name: str, save_path: str = "data/") -> AnnData:
save_path
Location for saving the dataset.
"""
import pooch

if name == "1":
fileid = "51086192"
known_hash = "5d604adce93b3034885646605c2e9a72f5ccf8163caffb2930485f93a9fcb3a3"
Expand Down
6 changes: 5 additions & 1 deletion src/scvi/data/_built_in_data/_smfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import anndata
import pandas as pd
import pooch

from scvi.utils import dependencies

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,7 +42,10 @@
}


@dependencies("pooch")
def _load_smfish(save_path: str = "data/", use_high_level_cluster=True) -> anndata.AnnData:
import pooch

save_path = os.path.abspath(save_path)
adata = anndata.read_h5ad(
pooch.retrieve(
Expand Down

0 comments on commit 874f8da

Please sign in to comment.