Skip to content

Commit

Permalink
reformat with black
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseabright96 committed Jun 18, 2024
1 parent 485fb53 commit 0573377
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions docs/tutorials/scgen_perturbation_prediction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
")"
]
},
{
Expand All @@ -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()"
]
},
{
Expand Down Expand Up @@ -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",
")"
]
},
Expand Down Expand Up @@ -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",
")"
]
},
{
Expand Down Expand Up @@ -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\""
]
},
{
Expand Down Expand Up @@ -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",
"]"
]
},
{
Expand Down Expand Up @@ -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",
")"
]
},
{
Expand Down Expand Up @@ -466,7 +478,7 @@
}
],
"source": [
"CD4T = train[train.obs[\"cell_type\"] ==\"CD4T\"]"
"CD4T = train[train.obs[\"cell_type\"] == \"CD4T\"]"
]
},
{
Expand Down Expand Up @@ -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",
")"
]
},
Expand Down Expand Up @@ -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",
")"
]
},
Expand Down

0 comments on commit 0573377

Please sign in to comment.