Skip to content
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

Backport PR #3118 on branch 1.2.x (build: move pooch to dependencies decorator) #3119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading