diff --git a/.readthedocs.yaml b/.readthedocs.yaml index e52bb7d..a990826 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -25,3 +25,4 @@ python: path: . extra_requirements: - doc + diff --git a/docs/api.md b/docs/api.md index cde1922..b349087 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,8 +1,15 @@ # API -## scanvi_explainer +``` +import scanvi_explainer +``` -### Utilities: `utils` +```{eval-rst} +.. currentmodule:: scanvi_explainer + +``` + +## SCANVIDeep ```{eval-rst} .. currentmodule:: scanvi_explainer @@ -10,13 +17,13 @@ ```{eval-rst} .. autosummary:: - :toctree: generated + :toctree: generated/ :nosignatures: - utils.train_test_group_split + scanvi_deep.SCANVIDeep ``` -### Plots: `plots` +## Utilities ```{eval-rst} .. currentmodule:: scanvi_explainer @@ -24,13 +31,13 @@ ```{eval-rst} .. autosummary:: - :toctree: generated :nosignatures: + :toctree: generated/ - plots.feature_plot + utils.train_test_group_split ``` -## SCANVIDeep +## Plots ```{eval-rst} .. currentmodule:: scanvi_explainer @@ -38,8 +45,8 @@ ```{eval-rst} .. autosummary:: - :toctree: generated + :toctree: generated/ :nosignatures: - scanvi_deep + plots.feature_plot ``` diff --git a/docs/conf.py b/docs/conf.py index 209e1d5..ce8c3ec 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -123,5 +123,7 @@ nitpick_ignore = [ # If building the documentation fails because of a missing link that is outside your control, # you can add an exception to this list. - ("optional"), + ("py:class", "type"), + ("py:class", "scvi.model.SCANVI"), + ("py:class", "scvi.model._scanvi.SCANVI"), ] diff --git a/pyproject.toml b/pyproject.toml index 8476c33..93fbb89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "scanvi-explainer" -version = "0.2.0" +version = "0.2.1" description = "Exapliner of scANVI using SHAP" authors = [ {name = "Martin Proks", email = "martin.proks@sund.ku.dk"}, @@ -17,6 +17,8 @@ keywords = ["shap", "scanvi", "explainer", "interpretability"] dependencies = [ "anndata", "rich", + "seaborn", + "scvi-tools", "shap>=0.41.0", ] classifiers = [ @@ -36,10 +38,10 @@ Issues = "https://github.com/brickmanlab/scanvi-explainer/issues" Changelog = "https://github.com/brickmanlab/scanvi-explainer/blob/master/CHANGELOG.md" [project.optional-dependencies] -dev = ["ruff", "scvi-tools", "huggingface_hub"] +dev = ["ruff", "huggingface_hub"] doc = [ "setuptools", - "sphinx", + "sphinx>=4.0", "myst-nb>=1.1", "sphinx-book-theme>=1", "sphinxcontrib-bibtex>=1" diff --git a/src/scanvi_explainer/__init__.py b/src/scanvi_explainer/__init__.py index 3b099e0..74cbfdc 100644 --- a/src/scanvi_explainer/__init__.py +++ b/src/scanvi_explainer/__init__.py @@ -6,6 +6,6 @@ raise ImportError("Missing torch package! Run pip install torch") if not importlib.util.find_spec("scvi"): - raise ImportError("Missing torch package! Run pip install torch") + raise ImportError("Missing torch package! Run pip install scvi-tools") __all__ = ["SCANVIDeep", "utils", "plots"] diff --git a/src/scanvi_explainer/plots.py b/src/scanvi_explainer/plots.py index 9dc1deb..b85200d 100644 --- a/src/scanvi_explainer/plots.py +++ b/src/scanvi_explainer/plots.py @@ -1,5 +1,5 @@ import matplotlib.pyplot as plt -import numpy.typing as npt +import numpy as np import pandas as pd import seaborn as sns from scvi import REGISTRY_KEYS @@ -9,7 +9,7 @@ def feature_plot( explainer: SCANVIDeep, - shap_values: npt.NDArray, + shap_values: np.ndarray, subset: bool = False, top_n: int = 10, ) -> None: @@ -17,11 +17,11 @@ def feature_plot( Parameters ---------- - explainer : SCANVIDeep - SCANVIDeep explainer - shap_values : npt.NDArray - Expected SHAP values - subset : bool, optional + explainer + :class:`~scanvi_explainer.scanvi_deep.SCANVIDeep` explainer + shap_values + :class:`~numpy.ndarray` Expected SHAP values + subset When set to true, calculate contribution by subsetting for test cells which belong to that particual classifier. When set to false, be generic and return contributing features even when testing set has diff --git a/src/scanvi_explainer/scanvi_deep.py b/src/scanvi_explainer/scanvi_deep.py index d232db3..33d99a5 100644 --- a/src/scanvi_explainer/scanvi_deep.py +++ b/src/scanvi_explainer/scanvi_deep.py @@ -5,7 +5,7 @@ import rich from packaging import version from scvi import REGISTRY_KEYS -from scvi.model._scanvi import SCANVI +from scvi.model import SCANVI from shap import Explainer from torch import Tensor from tqdm.auto import tqdm @@ -20,7 +20,7 @@ class SCANVIDeep(Explainer): Parameters ---------- - Explainer : type[Explainer] + Explainer Main Explainer class from shap package """ @@ -36,12 +36,12 @@ def __init__( Parameters ---------- - model : SCANVI - Trained scANVI model - train_size : float, optional - Training size (background), by default 0.8 - batch_size : int, optional - Number of cells used from each group, by default 128 + model + Trained :class:`~scvi.model.SCANVI` model + train_size + :obj:`float` Training size (background), by default 0.8 + batch_size + :obj:`int` Number of cells used from each group, by default 128 To ignore the batch_size subsetting, set batch_size=-1 """ import torch diff --git a/src/scanvi_explainer/utils.py b/src/scanvi_explainer/utils.py index 8553875..85347a0 100644 --- a/src/scanvi_explainer/utils.py +++ b/src/scanvi_explainer/utils.py @@ -4,7 +4,7 @@ import numpy as np import torch from scvi import REGISTRY_KEYS -from scvi.model._scanvi import SCANVI +from scvi.model import SCANVI from sklearn.model_selection import train_test_split @@ -14,7 +14,7 @@ def get_labels_key(model: SCANVI) -> str: Parameters ---------- model : SCANVI - SCANVI model + :class:`~scvi.model.SCANVI` model Returns ------- @@ -29,8 +29,8 @@ def get_layer_key(model: SCANVI) -> str: Parameters ---------- - model : SCANVI - SCANVI model + model + :class:`~scvi.model.SCANVI` model Returns ------- @@ -56,14 +56,14 @@ def train_test_group_split( Parameters ---------- - adata : anndata.AnnData - Annotated dataset + adata + :class:`~anndata.AnnData` Annotated dataset groupby : str Column in metadata by which the dataset should be split by - train_size : float, optional - Training size (background), by default 0.8 - batch_size : int, optional - Number of cells used from each group, by default 128 + train_size + :obj:`float` Training size (background), by default 0.8 + batch_size + :obj:`int` Number of cells used from each group, by default 128 Returns -------