From a20bc03417c1191c9c585243b46950625490661e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:39:26 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.1.0 → 24.10.0](https://github.com/psf/black/compare/23.1.0...24.10.0) - [github.com/asottile/blacken-docs: 1.13.0 → 1.19.1](https://github.com/asottile/blacken-docs/compare/1.13.0...1.19.1) - [github.com/pre-commit/mirrors-prettier: v3.0.0-alpha.6 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v3.0.0-alpha.6...v4.0.0-alpha.8) - https://github.com/charliermarsh/ruff-pre-commit → https://github.com/astral-sh/ruff-pre-commit - [github.com/astral-sh/ruff-pre-commit: v0.0.254 → v0.8.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.254...v0.8.4) - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v5.0.0) --- .pre-commit-config.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c9c14d3..c8a74c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,20 +2,20 @@ fail_fast: false default_language_version: python: python3 default_stages: - - commit - - push + - pre-commit + - pre-push minimum_pre_commit_version: 2.16.0 repos: - repo: https://github.com/psf/black - rev: "23.1.0" + rev: "24.10.0" hooks: - id: black - repo: https://github.com/asottile/blacken-docs - rev: 1.13.0 + rev: 1.19.1 hooks: - id: blacken-docs - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.6 + rev: v4.0.0-alpha.8 hooks: - id: prettier # Newer versions of node don't work on systems that have an older version of GLIBC @@ -24,13 +24,13 @@ repos: # See https://github.com/scverse/cookiecutter-scverse/issues/143 and # https://github.com/jupyterlab/jupyterlab/issues/12675 language_version: "17.9.1" - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.254 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.4 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: detect-private-key - id: check-ast From ae6fa00a529005740c97cfdb416a694d509d3196 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:40:07 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/tutorial.ipynb | 10 +++++----- velovi/_model.py | 19 ++++++++++++------- velovi/_module.py | 3 +++ velovi/_utils.py | 1 + 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/docs/tutorial.ipynb b/docs/tutorial.ipynb index 15cdf41..ebf0f5a 100644 --- a/docs/tutorial.ipynb +++ b/docs/tutorial.ipynb @@ -507,7 +507,7 @@ ], "source": [ "sc.pl.umap(\n", - " adata, \n", + " adata,\n", " color=\"directional_cosine_sim_variance\",\n", " cmap=\"Greys\",\n", " vmin=\"p1\",\n", @@ -537,7 +537,7 @@ " extrapolated_cells_list = []\n", " for i in track(range(n_samples)):\n", " with io.StringIO() as buf, redirect_stdout(buf):\n", - " vkey = \"velocities_velovi_{i}\".format(i=i)\n", + " vkey = f\"velocities_velovi_{i}\"\n", " v = vae.get_velocity(n_samples=1, velo_statistic=\"mean\")\n", " adata.layers[vkey] = v\n", " scv.tl.velocity_graph(adata, vkey=vkey, sqrt_transform=False, approx=True)\n", @@ -1134,10 +1134,10 @@ ], "source": [ "sc.pl.umap(\n", - " adata, \n", + " adata,\n", " color=\"directional_cosine_sim_variance_extrinisic\",\n", - " vmin=\"p1\", \n", - " vmax=\"p99\", \n", + " vmin=\"p1\",\n", + " vmax=\"p99\",\n", ")" ] }, diff --git a/velovi/_model.py b/velovi/_model.py index df8ee5d..a62415c 100644 --- a/velovi/_model.py +++ b/velovi/_model.py @@ -49,6 +49,7 @@ class VELOVI(VAEMixin, UnsupervisedTrainingMixin, BaseModelClass): Use a linear decoder from latent space to time. **model_kwargs Keyword args for :class:`~velovi.VELOVAE` + """ def __init__( @@ -108,13 +109,8 @@ def __init__( **model_kwargs, ) self._model_summary_string = ( - "VELOVI Model with the following params: \nn_hidden: {}, n_latent: {}, n_layers: {}, dropout_rate: " - "{}" - ).format( - n_hidden, - n_latent, - n_layers, - dropout_rate, + f"VELOVI Model with the following params: \nn_hidden: {n_hidden}, n_latent: {n_latent}, n_layers: {n_layers}, dropout_rate: " + f"{dropout_rate}" ) self.init_params_ = self._get_init_params(locals()) @@ -164,6 +160,7 @@ def train( `train()` will overwrite values present in `plan_kwargs`, when appropriate. **trainer_kwargs Other keyword args for :class:`~scvi.train.Trainer`. + """ user_plan_kwargs = plan_kwargs.copy() if isinstance(plan_kwargs, dict) else {} plan_kwargs = {"lr": lr, "weight_decay": weight_decay, "optimizer": "AdamW"} @@ -238,6 +235,7 @@ def get_state_assignment( ------- If `n_samples` > 1 and `return_mean` is False, then the shape is `(samples, cells, genes)`. Otherwise, shape is `(cells, genes)`. In this case, return type is :class:`~pandas.DataFrame` unless `return_numpy` is True. + """ adata = self._validate_anndata(adata) scdl = self._make_data_loader( @@ -342,6 +340,7 @@ def get_latent_time( ------- If `n_samples` > 1 and `return_mean` is False, then the shape is `(samples, cells, genes)`. Otherwise, shape is `(cells, genes)`. In this case, return type is :class:`~pandas.DataFrame` unless `return_numpy` is True. + """ adata = self._validate_anndata(adata) if indices is None: @@ -484,6 +483,7 @@ def get_velocity( ------- If `n_samples` > 1 and `return_mean` is False, then the shape is `(samples, cells, genes)`. Otherwise, shape is `(cells, genes)`. In this case, return type is :class:`~pandas.DataFrame` unless `return_numpy` is True. + """ adata = self._validate_anndata(adata) if indices is None: @@ -658,6 +658,7 @@ def get_expression_fit( ------- If `n_samples` > 1 and `return_mean` is False, then the shape is `(samples, cells, genes)`. Otherwise, shape is `(cells, genes)`. In this case, return type is :class:`~pandas.DataFrame` unless `return_numpy` is True. + """ adata = self._validate_anndata(adata) @@ -813,6 +814,7 @@ def get_gene_likelihood( ------- If `n_samples` > 1 and `return_mean` is False, then the shape is `(samples, cells, genes)`. Otherwise, shape is `(cells, genes)`. In this case, return type is :class:`~pandas.DataFrame` unless `return_numpy` is True. + """ adata = self._validate_anndata(adata) scdl = self._make_data_loader( @@ -919,6 +921,7 @@ def setup_anndata( Returns ------- %(returns)s + """ setup_method_args = cls._get_setup_method_args(**locals()) anndata_fields = [ @@ -969,6 +972,7 @@ def get_permutation_scores( ------- Tuple of DataFrame and AnnData. DataFrame is genes by cell types with score per cell type. AnnData is the permutated version of the original AnnData. + """ adata = self._validate_anndata(adata) adata_manager = self.get_anndata_manager(adata) @@ -1092,6 +1096,7 @@ def _directional_statistics_per_cell( ---------- tensor Shape of samples by genes for a given cell. + """ n_samples = tensor.shape[0] # over samples axis diff --git a/velovi/_module.py b/velovi/_module.py index 2515b16..9a7ec9a 100644 --- a/velovi/_module.py +++ b/velovi/_module.py @@ -1,4 +1,5 @@ """Main module.""" + from typing import Callable, Iterable, Literal, Optional import numpy as np @@ -44,6 +45,7 @@ class DecoderVELOVI(nn.Module): Whether to use layer norm in layers linear_decoder Whether to use linear decoder for time + """ def __init__( @@ -183,6 +185,7 @@ class VELOVAE(BaseModuleClass): var_activation Callable used to ensure positivity of the variational distributions' variance. When `None`, defaults to `torch.exp`. + """ def __init__( diff --git a/velovi/_utils.py b/velovi/_utils.py index bfffbeb..d16cc48 100644 --- a/velovi/_utils.py +++ b/velovi/_utils.py @@ -56,6 +56,7 @@ def preprocess_data( Returns ------- Preprocessed adata. + """ if min_max_scale: scaler = MinMaxScaler()