diff --git a/docs/tutorials/scgen_perturbation_prediction.ipynb b/docs/tutorials/scgen_perturbation_prediction.ipynb index 7fc94c6..bc456fd 100644 --- a/docs/tutorials/scgen_perturbation_prediction.ipynb +++ b/docs/tutorials/scgen_perturbation_prediction.ipynb @@ -14,7 +14,8 @@ "outputs": [], "source": [ "import sys\n", - "#if branch is stable, will install via pypi, else will install from source\n", + "\n", + "# if branch is stable, will install via pypi, else will install from source\n", "branch = \"stable\"\n", "IN_COLAB = \"google.colab\" in sys.modules\n", "\n", @@ -78,8 +79,10 @@ } ], "source": [ - "train = sc.read(\"./tests/data/train_kang.h5ad\",\n", - " backup_url='https://drive.google.com/uc?id=1r87vhoLLq6PXAYdmyyd89zG90eJOFYLk')" + "train = sc.read(\n", + " \"./tests/data/train_kang.h5ad\",\n", + " backup_url=\"https://drive.google.com/uc?id=1r87vhoLLq6PXAYdmyyd89zG90eJOFYLk\",\n", + ")" ] }, { @@ -95,8 +98,9 @@ "metadata": {}, "outputs": [], "source": [ - "train_new = train[~((train.obs[\"cell_type\"] == \"CD4T\") &\n", - " (train.obs[\"condition\"] == \"stimulated\"))].copy()" + "train_new = train[\n", + " ~((train.obs[\"cell_type\"] == \"CD4T\") & (train.obs[\"condition\"] == \"stimulated\"))\n", + "].copy()" ] }, { @@ -198,10 +202,7 @@ ], "source": [ "model.train(\n", - " max_epochs=100,\n", - " batch_size=32,\n", - " early_stopping=True,\n", - " early_stopping_patience=25\n", + " max_epochs=100, batch_size=32, early_stopping=True, early_stopping_patience=25\n", ")" ] }, @@ -258,8 +259,13 @@ "source": [ "sc.pp.neighbors(latent_adata)\n", "sc.tl.umap(latent_adata)\n", - "sc.pl.umap(latent_adata, color=['condition', 'cell_type'], wspace=0.4, frameon=False,\n", - " save='latentspace_batch32_klw000005_z100__100e.pdf')" + "sc.pl.umap(\n", + " latent_adata,\n", + " color=[\"condition\", \"cell_type\"],\n", + " wspace=0.4,\n", + " frameon=False,\n", + " save=\"latentspace_batch32_klw000005_z100__100e.pdf\",\n", + ")" ] }, { @@ -339,11 +345,9 @@ ], "source": [ "pred, delta = model.predict(\n", - " ctrl_key='control',\n", - " stim_key='stimulated',\n", - " celltype_to_predict='CD4T'\n", + " ctrl_key=\"control\", stim_key=\"stimulated\", celltype_to_predict=\"CD4T\"\n", ")\n", - "pred.obs['condition'] = 'pred'" + "pred.obs[\"condition\"] = \"pred\"" ] }, { @@ -380,8 +384,12 @@ "metadata": {}, "outputs": [], "source": [ - "ctrl_adata = train[((train.obs['cell_type'] == 'CD4T') & (train.obs['condition'] == 'control'))]\n", - "stim_adata = train[((train.obs['cell_type'] == 'CD4T') & (train.obs['condition'] == 'stimulated'))]" + "ctrl_adata = train[\n", + " ((train.obs[\"cell_type\"] == \"CD4T\") & (train.obs[\"condition\"] == \"control\"))\n", + "]\n", + "stim_adata = train[\n", + " ((train.obs[\"cell_type\"] == \"CD4T\") & (train.obs[\"condition\"] == \"stimulated\"))\n", + "]" ] }, { @@ -433,8 +441,12 @@ ], "source": [ "sc.tl.pca(eval_adata)\n", - "sc.pl.pca(eval_adata, color=\"condition\", frameon=False,\n", - " save='pred_stim_b32_klw000005_z100__100e.pdf')" + "sc.pl.pca(\n", + " eval_adata,\n", + " color=\"condition\",\n", + " frameon=False,\n", + " save=\"pred_stim_b32_klw000005_z100__100e.pdf\",\n", + ")" ] }, { @@ -466,7 +478,7 @@ } ], "source": [ - "CD4T = train[train.obs[\"cell_type\"] ==\"CD4T\"]" + "CD4T = train[train.obs[\"cell_type\"] == \"CD4T\"]" ] }, { @@ -527,7 +539,7 @@ " labels={\"x\": \"predicted\", \"y\": \"ground truth\"},\n", " path_to_save=\"./reg_mean1.pdf\",\n", " show=True,\n", - " legend=False\n", + " legend=False,\n", ")" ] }, @@ -567,11 +579,11 @@ " eval_adata,\n", " axis_keys={\"x\": \"pred\", \"y\": \"stimulated\"},\n", " gene_list=diff_genes[:10],\n", - " top_100_genes= diff_genes,\n", - " labels={\"x\": \"predicted\",\"y\": \"ground truth\"},\n", + " top_100_genes=diff_genes,\n", + " labels={\"x\": \"predicted\", \"y\": \"ground truth\"},\n", " path_to_save=\"./reg_mean1.pdf\",\n", " show=True,\n", - " legend=False\n", + " legend=False,\n", ")" ] },