Skip to content

Commit 9d3ab38

Browse files
authored
Merge branch 'main' into Ori-update-intrep-with-fastshap
2 parents ce17fcf + e8b4ab6 commit 9d3ab38

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

.github/workflows/run_linux_cuda.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ on:
5656
default: "3.12"
5757
type: choice
5858
options:
59+
- "3.13"
5960
- "3.12"
6061
- "3.11"
61-
- "3.10"
6262

6363
cuda-version:
6464
description: CUDA version

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ repos:
3434
)$
3535
3636
- repo: https://github.com/astral-sh/ruff-pre-commit
37-
rev: v0.9.9
37+
rev: v0.9.10
3838
hooks:
3939
- id: ruff
4040
args: [--fix, --exit-non-zero-on-fix]

scrna/velovi.ipynb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"source": [
3131
"!pip install --quiet scvi-colab\n",
3232
"from scvi_colab import install\n",
33+
"\n",
3334
"install()"
3435
]
3536
},
@@ -47,15 +48,14 @@
4748
}
4849
],
4950
"source": [
51+
"import matplotlib.pyplot as plt\n",
5052
"import numpy as np\n",
5153
"import pandas as pd\n",
5254
"import scanpy as sc\n",
5355
"import scvelo as scv\n",
56+
"import seaborn as sns\n",
5457
"import torch\n",
55-
"from velovi import preprocess_data, VELOVI\n",
56-
"\n",
57-
"import matplotlib.pyplot as plt\n",
58-
"import seaborn as sns"
58+
"from velovi import VELOVI, preprocess_data"
5959
]
6060
},
6161
{
@@ -221,13 +221,11 @@
221221
" adata.var[\"fit_beta\"] = vae.get_rates()[\"beta\"] / scaling\n",
222222
" adata.var[\"fit_gamma\"] = vae.get_rates()[\"gamma\"] / scaling\n",
223223
" adata.var[\"fit_t_\"] = (\n",
224-
" torch.nn.functional.softplus(vae.module.switch_time_unconstr)\n",
225-
" .detach()\n",
226-
" .cpu()\n",
227-
" .numpy()\n",
224+
" torch.nn.functional.softplus(vae.module.switch_time_unconstr).detach().cpu().numpy()\n",
228225
" ) * scaling\n",
229226
" adata.layers[\"fit_t\"] = latent_time.values * scaling[np.newaxis, :]\n",
230-
" adata.var['fit_scaling'] = 1.0\n",
227+
" adata.var[\"fit_scaling\"] = 1.0\n",
228+
"\n",
231229
"\n",
232230
"add_velovi_outputs_to_adata(adata, vae)"
233231
]
@@ -297,7 +295,7 @@
297295
}
298296
],
299297
"source": [
300-
"scv.pl.velocity_embedding_stream(adata, basis='umap')"
298+
"scv.pl.velocity_embedding_stream(adata, basis=\"umap\")"
301299
]
302300
},
303301
{
@@ -507,7 +505,7 @@
507505
],
508506
"source": [
509507
"sc.pl.umap(\n",
510-
" adata, \n",
508+
" adata,\n",
511509
" color=\"directional_cosine_sim_variance\",\n",
512510
" cmap=\"Greys\",\n",
513511
" vmin=\"p1\",\n",
@@ -529,15 +527,16 @@
529527
"outputs": [],
530528
"source": [
531529
"def compute_extrinisic_uncertainty(adata, vae, n_samples=25) -> pd.DataFrame:\n",
532-
" from velovi._model import _compute_directional_statistics_tensor\n",
533-
" from scvi.utils import track\n",
534-
" from contextlib import redirect_stdout\n",
535530
" import io\n",
531+
" from contextlib import redirect_stdout\n",
532+
"\n",
533+
" from scvi.utils import track\n",
534+
" from velovi._model import _compute_directional_statistics_tensor\n",
536535
"\n",
537536
" extrapolated_cells_list = []\n",
538537
" for i in track(range(n_samples)):\n",
539538
" with io.StringIO() as buf, redirect_stdout(buf):\n",
540-
" vkey = \"velocities_velovi_{i}\".format(i=i)\n",
539+
" vkey = f\"velocities_velovi_{i}\"\n",
541540
" v = vae.get_velocity(n_samples=1, velo_statistic=\"mean\")\n",
542541
" adata.layers[vkey] = v\n",
543542
" scv.tl.velocity_graph(adata, vkey=vkey, sqrt_transform=False, approx=True)\n",
@@ -1134,10 +1133,10 @@
11341133
],
11351134
"source": [
11361135
"sc.pl.umap(\n",
1137-
" adata, \n",
1136+
" adata,\n",
11381137
" color=\"directional_cosine_sim_variance_extrinisic\",\n",
1139-
" vmin=\"p1\", \n",
1140-
" vmax=\"p99\", \n",
1138+
" vmin=\"p1\",\n",
1139+
" vmax=\"p99\",\n",
11411140
")"
11421141
]
11431142
},

use_cases/interpretability.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@
11821182
"cell_type": "markdown",
11831183
"metadata": {},
11841184
"source": [
1185-
"SHAP (SHapley Additive exPlanations) values are a popular interpretability technique based on cooperative game theory. The core idea is to fairly allocate the \"credit\" for a model's prediction to each feature, by considering all possible combinations of features and their impact on the prediction. SHAP values are additive, meaning the sum of the SHAP values for all features equals the difference between the model’s output and the average prediction. This method works for any model type, providing a consistent way to explain individual predictions, making it highly versatile and widely applicable. Deep SHAP is an extension of the SHAP method designed specifically for deep learning models, such as the ones in SCVI-Tools. For more information see [this](\"https://www.nature.com/articles/s41592-024-02511-3\")\n",
1185+
"SHAP (SHapley Additive exPlanations) values are a popular interpretability technique based on cooperative game theory. The core idea is to fairly allocate the \"credit\" for a model's prediction to each feature, by considering all possible combinations of features and their impact on the prediction. SHAP values are additive, meaning the sum of the SHAP values for all features equals the difference between the model’s output and the average prediction. This method works for any model type, providing a consistent way to explain individual predictions, making it highly versatile and widely applicable. Deep SHAP is an extension of the SHAP method designed specifically for deep learning models, such as the ones in SCVI-Tools. For more information see [this](https://www.nature.com/articles/s41592-024-02511-3)\n",
11861186
"\n",
11871187
"Calcualtion of SHAP for SC data usually takes a lot of time. In SCVI-Tools we are running an approximation of FastSHAP in order to reduce runtime, where we train a shallow surrogate model to imitate the original model prediction and than run the SHAP over the surrogate model. See [this](\"https://arxiv.org/abs/2107.07436\")"
11881188
]

0 commit comments

Comments
 (0)