Skip to content

Commit d077c0a

Browse files
Ethan WeinbergerEthan Weinberger
authored andcommitted
Pre-commit fixes
1 parent fa8837d commit d077c0a

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

scbs/MethylVI_batch.ipynb

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@
5454
}
5555
],
5656
"source": [
57+
"import os\n",
58+
"import tempfile\n",
59+
"\n",
60+
"import matplotlib.pyplot as plt\n",
5761
"import mudata\n",
58-
"import scanpy as sc\n",
5962
"import numpy as np\n",
60-
"import matplotlib.pyplot as plt\n",
63+
"import scanpy as sc\n",
6164
"import scvi\n",
6265
"import seaborn as sns\n",
6366
"import torch\n",
64-
"import os\n",
65-
"import tempfile\n",
66-
"\n",
6767
"from scvi.external import METHYLVI"
6868
]
6969
},
@@ -155,9 +155,7 @@
155155
"if not os.path.exists(mdata_path):\n",
156156
" os.system(f\"wget -q -O {mdata_path} https://figshare.com/ndownloader/files/49632108\")\n",
157157
"\n",
158-
"mdata = mudata.read_h5mu(\n",
159-
" mdata_path\n",
160-
")\n",
158+
"mdata = mudata.read_h5mu(mdata_path)\n",
161159
"mdata.mod"
162160
]
163161
},
@@ -185,7 +183,7 @@
185183
}
186184
],
187185
"source": [
188-
"mdata['mCG'].layers"
186+
"mdata[\"mCG\"].layers"
189187
]
190188
},
191189
{
@@ -224,7 +222,7 @@
224222
}
225223
],
226224
"source": [
227-
"mdata['mCG'].X"
225+
"mdata[\"mCG\"].X"
228226
]
229227
},
230228
{
@@ -240,11 +238,11 @@
240238
"metadata": {},
241239
"outputs": [],
242240
"source": [
243-
"sc.tl.pca(mdata['mCG'])\n",
244-
"sc.tl.pca(mdata['mCH'])\n",
241+
"sc.tl.pca(mdata[\"mCG\"])\n",
242+
"sc.tl.pca(mdata[\"mCH\"])\n",
245243
"\n",
246-
"ch_pcs = mdata['mCH'].obsm['X_pca']\n",
247-
"cg_pcs = mdata['mCG'].obsm['X_pca']\n",
244+
"ch_pcs = mdata[\"mCH\"].obsm[\"X_pca\"]\n",
245+
"cg_pcs = mdata[\"mCG\"].obsm[\"X_pca\"]\n",
248246
"\n",
249247
"# standardize the values of PCs from both modalities\n",
250248
"cg_pcs = cg_pcs / cg_pcs.std()\n",
@@ -253,7 +251,7 @@
253251
"# total_pcs\n",
254252
"total_pcs = np.hstack([ch_pcs, cg_pcs])\n",
255253
"\n",
256-
"mdata.obsm['X_pca'] = total_pcs"
254+
"mdata.obsm[\"X_pca\"] = total_pcs"
257255
]
258256
},
259257
{
@@ -290,8 +288,8 @@
290288
"\n",
291289
"fig, ax = plt.subplots(1, 2, figsize=(11, 5))\n",
292290
"\n",
293-
"sc.pl.umap(mdata, color='mCG:Platform', ax=ax[0], show=False, title=\"Sequencing protocol\")\n",
294-
"sc.pl.umap(mdata, color='mCG:CoarseType', ax=ax[1], show=False, title=\"Cell type\")\n",
291+
"sc.pl.umap(mdata, color=\"mCG:Platform\", ax=ax[0], show=False, title=\"Sequencing protocol\")\n",
292+
"sc.pl.umap(mdata, color=\"mCG:CoarseType\", ax=ax[1], show=False, title=\"Cell type\")\n",
295293
"\n",
296294
"plt.subplots_adjust(wspace=0.5)"
297295
]
@@ -316,7 +314,7 @@
316314
"source": [
317315
"Before training our model, we'll use methylVI's `setup_mudata` function to prepare our `MuData` object for training. \n",
318316
"\n",
319-
"First, we need to tell methylVI which modalities in our MuData object to consider via the `methylation_contexts` argument. Here we'll jointly model both CpG and non-CpG methylation features, so we'll set this argument to a list containing the names of both modalities. Next, methylVI directly models the total coverage and number of methylated cytosines in each region. Thus, for each modality in our `MuData` object, we need layers containing the coverage in each region (specified by `cov_layer`) and layers with the number of methylated cytosines (specified by `mc_layer`). Finally, we'll provide methylVI with a categorical covariate specifying the sequencing protocol used for each cell."
317+
"First, we need to tell methylVI which modalities in our MuData object to consider via the `methylation_contexts` argument. Here we'll jointly model both CpG and non-CpG methylation features, so we'll set this argument to a list containing the names of both modalities. Next, methylVI directly models the total coverage and number of methylated cytosines in each region. Thus, for each modality in our `MuData` object, we need layers containing the coverage in each region (specified by `cov_layer`) and layers with the number of methylated cytosines (specified by `mc_layer`). Finally, we'll provide methylVI with a categorical covariate specifying the sequencing protocol used for each cell.\n"
320318
]
321319
},
322320
{
@@ -336,11 +334,11 @@
336334
]
337335
},
338336
{
339-
"metadata": {},
340337
"cell_type": "markdown",
338+
"metadata": {},
341339
"source": [
342340
"```{note}\n",
343-
"Specify the modality of each argument via the `modalities` dictionary, which maps layer/key arguments to MuData modalities. In our case, both the `mCG` and `mCH` modalities contain the all of the fields specified in the `categorical_covariate_keys` argument (i.e., `Protocol`) in their respective `.obs`, so we arbitrarily choose `mCG` here.\n",
341+
"Specify the modality of each argument via the `modalities` dictionary, which maps layer/key arguments to MuData modalities. In our case, both the `mCG` and `mCH` modalities contain the all of the fields specified in the `categorical_covariate_keys` argument (i.e., `Protocol`) in their respective `.obs`, so we arbitrarily choose `mCG` here\n",
344342
"```"
345343
]
346344
},
@@ -360,7 +358,7 @@
360358
"name": "stdout",
361359
"output_type": "stream",
362360
"text": [
363-
"\u001B[34mINFO \u001B[0m The model has been initialized \n"
361+
"\u001b[34mINFO \u001b[0m The model has been initialized \n"
364362
]
365363
},
366364
{
@@ -407,7 +405,7 @@
407405
"metadata": {},
408406
"outputs": [],
409407
"source": [
410-
"mdata.obsm['methylVI'] = model.get_latent_representation()"
408+
"mdata.obsm[\"methylVI\"] = model.get_latent_representation()"
411409
]
412410
},
413411
{
@@ -439,13 +437,13 @@
439437
}
440438
],
441439
"source": [
442-
"sc.pp.neighbors(mdata, use_rep='methylVI')\n",
440+
"sc.pp.neighbors(mdata, use_rep=\"methylVI\")\n",
443441
"sc.tl.umap(mdata)\n",
444442
"\n",
445443
"fig, ax = plt.subplots(1, 2, figsize=(11, 5))\n",
446444
"\n",
447-
"sc.pl.umap(mdata, color='mCG:Platform', ax=ax[0], show=False, title=\"Sequencing protocol\")\n",
448-
"sc.pl.umap(mdata, color='mCG:CoarseType', ax=ax[1], show=False, title=\"Cell type\")\n",
445+
"sc.pl.umap(mdata, color=\"mCG:Platform\", ax=ax[0], show=False, title=\"Sequencing protocol\")\n",
446+
"sc.pl.umap(mdata, color=\"mCG:CoarseType\", ax=ax[1], show=False, title=\"Cell type\")\n",
449447
"\n",
450448
"plt.subplots_adjust(wspace=0.5)"
451449
]

0 commit comments

Comments
 (0)