Skip to content

Commit ecd756e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 97ce337 commit ecd756e

1 file changed

Lines changed: 52 additions & 30 deletions

File tree

use_cases/custom_dl/tiledb.ipynb

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@
140140
"source": [
141141
"min_nnz\n",
142142
"experiment_name = \"mus_musculus\"\n",
143-
"#obs_val_filt = ('is_primary_data == True and tissue_general in [\"spleen\", \"kidney\"] '\n",
143+
"# obs_val_filt = ('is_primary_data == True and tissue_general in [\"spleen\", \"kidney\"] '\n",
144144
"# 'and nnz >= 500')\n",
145-
"obs_val_filt = ('is_primary_data == True and tissue_general in [\"kidney\"] '\n",
146-
" 'and nnz >= 500 and donor_id not in [\"pooled\"]')\n",
147-
"#obs_val_filt = ('is_primary_data == True and tissue_general in [\"liver\", \"heart\"] '\n",
145+
"obs_val_filt = (\n",
146+
" 'is_primary_data == True and tissue_general in [\"kidney\"] '\n",
147+
" 'and nnz >= 500 and donor_id not in [\"pooled\"]'\n",
148+
")\n",
149+
"# obs_val_filt = ('is_primary_data == True and tissue_general in [\"liver\", \"heart\"] '\n",
148150
"# 'and nnz >= 500')\n",
149-
"obs_val_filt = ('is_primary_data == True and cell_type in [\"B cell\",\"T cell\", \"macrophage\",\"fibroblast\",\"endothelial\",\"myeloid\",\"lymphocyte\",\"natural killer cell\",\"CD4-positive, alpha-beta T cell\",\"CD8-positive, alpha-beta T cell\"] '\n",
150-
" 'and donor_id not in [\"pooled\"] and dataset_id in [\"98e5ea9f-16d6-47ec-a529-686e76515e39\",\"58b01044-c5e5-4b0f-8a2d-6ebf951e01ff\",\"48b37086-25f7-4ecd-be66-f5bb378e3aea\"] and tissue_general not in [\"vasculature\"] and nnz >= 300')"
151+
"obs_val_filt = (\n",
152+
" 'is_primary_data == True and cell_type in [\"B cell\",\"T cell\", \"macrophage\",\"fibroblast\",\"endothelial\",\"myeloid\",\"lymphocyte\",\"natural killer cell\",\"CD4-positive, alpha-beta T cell\",\"CD8-positive, alpha-beta T cell\"] '\n",
153+
" 'and donor_id not in [\"pooled\"] and dataset_id in [\"98e5ea9f-16d6-47ec-a529-686e76515e39\",\"58b01044-c5e5-4b0f-8a2d-6ebf951e01ff\",\"48b37086-25f7-4ecd-be66-f5bb378e3aea\"] and tissue_general not in [\"vasculature\"] and nnz >= 300'\n",
154+
")"
151155
]
152156
},
153157
{
@@ -163,7 +167,7 @@
163167
"metadata": {},
164168
"outputs": [],
165169
"source": [
166-
"batch_keys = [\"dataset_id\",\"donor_id\",\"assay\",\"tissue_general\"]"
170+
"batch_keys = [\"dataset_id\", \"donor_id\", \"assay\", \"tissue_general\"]"
167171
]
168172
},
169173
{
@@ -248,7 +252,7 @@
248252
" dataloader_kwargs={\"num_workers\": 64, \"persistent_workers\": False},\n",
249253
" accelerator=\"gpu\",\n",
250254
" device=1,\n",
251-
" return_sparse_X=False\n",
255+
" return_sparse_X=False,\n",
252256
")\n",
253257
"print(datamodule.n_obs, datamodule.n_vars, datamodule.n_batch)"
254258
]
@@ -300,8 +304,7 @@
300304
"source": [
301305
"# creating the dataloader for trainset\n",
302306
"training_dataloader = (\n",
303-
" datamodule.on_before_batch_transfer(batch, None)\n",
304-
" for batch in datamodule.train_dataloader()\n",
307+
" datamodule.on_before_batch_transfer(batch, None) for batch in datamodule.train_dataloader()\n",
305308
")"
306309
]
307310
},
@@ -358,10 +361,11 @@
358361
],
359362
"source": [
360363
"import time\n",
364+
"\n",
361365
"start = time.time()\n",
362366
"model.train(\n",
363367
" datamodule=training_dataloader,\n",
364-
" #datamodule=datamodule,\n",
368+
" # datamodule=datamodule,\n",
365369
" max_epochs=100,\n",
366370
" batch_size=1024,\n",
367371
" # accelerator=\"gpu\",\n",
@@ -572,8 +576,8 @@
572576
"metadata": {},
573577
"outputs": [],
574578
"source": [
575-
"#adata = adata[~adata.obs[\"cell_type\"].str.contains(\"kidney\", na=False)]\n",
576-
"#adata.obs.loc[adata.obs.cell_type.isin([\"CD8-positive, alpha-beta T cell\",\"CD4-positive, alpha-beta T cell\"],\"cell_type\"] = \"T cell\""
579+
"# adata = adata[~adata.obs[\"cell_type\"].str.contains(\"kidney\", na=False)]\n",
580+
"# adata.obs.loc[adata.obs.cell_type.isin([\"CD8-positive, alpha-beta T cell\",\"CD4-positive, alpha-beta T cell\"],\"cell_type\"] = \"T cell\""
577581
]
578582
},
579583
{
@@ -603,8 +607,11 @@
603607
}
604608
],
605609
"source": [
606-
"sc.pl.umap(adata, color=[\"dataset_id\",\"donor_id\"], \n",
607-
" title=[\"SCVI_\"+x for x in [\"dataset_id\",\"donor_id\"]])"
610+
"sc.pl.umap(\n",
611+
" adata,\n",
612+
" color=[\"dataset_id\", \"donor_id\"],\n",
613+
" title=[\"SCVI_\" + x for x in [\"dataset_id\", \"donor_id\"]],\n",
614+
")"
608615
]
609616
},
610617
{
@@ -624,8 +631,11 @@
624631
}
625632
],
626633
"source": [
627-
"sc.pl.umap(adata, color=[\"assay\",\"tissue_general\"], \n",
628-
" title=[\"SCVI_\"+x for x in [\"assay\",\"tissue_general\"]])"
634+
"sc.pl.umap(\n",
635+
" adata,\n",
636+
" color=[\"assay\", \"tissue_general\"],\n",
637+
" title=[\"SCVI_\" + x for x in [\"assay\", \"tissue_general\"]],\n",
638+
")"
629639
]
630640
},
631641
{
@@ -754,9 +764,7 @@
754764
"metadata": {},
755765
"outputs": [],
756766
"source": [
757-
"scvi.model.SCVI.setup_anndata(adata, \n",
758-
" layer=\"counts\",\n",
759-
" categorical_covariate_keys=batch_keys)"
767+
"scvi.model.SCVI.setup_anndata(adata, layer=\"counts\", categorical_covariate_keys=batch_keys)"
760768
]
761769
},
762770
{
@@ -858,8 +866,11 @@
858866
}
859867
],
860868
"source": [
861-
"sc.pl.umap(adata, color=[\"dataset_id\",\"donor_id\"], \n",
862-
" title=[\"SCVI_adata_\"+x for x in [\"dataset_id\",\"donor_id\"]])"
869+
"sc.pl.umap(\n",
870+
" adata,\n",
871+
" color=[\"dataset_id\", \"donor_id\"],\n",
872+
" title=[\"SCVI_adata_\" + x for x in [\"dataset_id\", \"donor_id\"]],\n",
873+
")"
863874
]
864875
},
865876
{
@@ -879,8 +890,11 @@
879890
}
880891
],
881892
"source": [
882-
"sc.pl.umap(adata, color=[\"assay\",\"tissue_general\"], \n",
883-
" title=[\"SCVI_adata_\"+x for x in [\"assay\",\"tissue_general\"]])"
893+
"sc.pl.umap(\n",
894+
" adata,\n",
895+
" color=[\"assay\", \"tissue_general\"],\n",
896+
" title=[\"SCVI_adata_\" + x for x in [\"assay\", \"tissue_general\"]],\n",
897+
")"
884898
]
885899
},
886900
{
@@ -1039,9 +1053,9 @@
10391053
"metadata": {},
10401054
"outputs": [],
10411055
"source": [
1042-
"#model_scanvi.save(\n",
1056+
"# model_scanvi.save(\n",
10431057
"# \"census_model_scanvi\", save_anndata=False, overwrite=True, datamodule=datamodule_scanvi\n",
1044-
"#)"
1058+
"# )"
10451059
]
10461060
},
10471061
{
@@ -1126,8 +1140,11 @@
11261140
}
11271141
],
11281142
"source": [
1129-
"sc.pl.umap(adata, color=[\"dataset_id\",\"donor_id\"], \n",
1130-
" title=[\"SCANVI_\"+x for x in [\"dataset_id\",\"donor_id\"]])"
1143+
"sc.pl.umap(\n",
1144+
" adata,\n",
1145+
" color=[\"dataset_id\", \"donor_id\"],\n",
1146+
" title=[\"SCANVI_\" + x for x in [\"dataset_id\", \"donor_id\"]],\n",
1147+
")"
11311148
]
11321149
},
11331150
{
@@ -1147,8 +1164,11 @@
11471164
}
11481165
],
11491166
"source": [
1150-
"sc.pl.umap(adata, color=[\"assay\",\"tissue_general\"], \n",
1151-
" title=[\"SCANVI_\"+x for x in [\"assay\",\"tissue_general\"]])"
1167+
"sc.pl.umap(\n",
1168+
" adata,\n",
1169+
" color=[\"assay\", \"tissue_general\"],\n",
1170+
" title=[\"SCANVI_\" + x for x in [\"assay\", \"tissue_general\"]],\n",
1171+
")"
11521172
]
11531173
},
11541174
{
@@ -1247,6 +1267,7 @@
12471267
"df = adata.obs.groupby([\"cell_type\", \"predictions_scanvi\"]).size().unstack(fill_value=0)\n",
12481268
"norm_df = df / df.sum(axis=0)\n",
12491269
"import matplotlib.pyplot as plt\n",
1270+
"\n",
12501271
"plt.figure(figsize=(8, 8))\n",
12511272
"_ = plt.pcolor(norm_df)\n",
12521273
"_ = plt.xticks(np.arange(0.5, len(df.columns), 1), df.columns, rotation=90)\n",
@@ -1349,6 +1370,7 @@
13491370
],
13501371
"source": [
13511372
"from scib_metrics.benchmark import Benchmarker\n",
1373+
"\n",
13521374
"bm = Benchmarker(\n",
13531375
" adata,\n",
13541376
" batch_key=\"batch\",\n",

0 commit comments

Comments
 (0)