From d077c0ade08e4394a368fe10e36d274d8a8156c9 Mon Sep 17 00:00:00 2001 From: Ethan Weinberger Date: Tue, 8 Oct 2024 13:41:04 -0700 Subject: [PATCH] Pre-commit fixes --- scbs/MethylVI_batch.ipynb | 48 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/scbs/MethylVI_batch.ipynb b/scbs/MethylVI_batch.ipynb index 3f54c8c..85768ec 100644 --- a/scbs/MethylVI_batch.ipynb +++ b/scbs/MethylVI_batch.ipynb @@ -54,16 +54,16 @@ } ], "source": [ + "import os\n", + "import tempfile\n", + "\n", + "import matplotlib.pyplot as plt\n", "import mudata\n", - "import scanpy as sc\n", "import numpy as np\n", - "import matplotlib.pyplot as plt\n", + "import scanpy as sc\n", "import scvi\n", "import seaborn as sns\n", "import torch\n", - "import os\n", - "import tempfile\n", - "\n", "from scvi.external import METHYLVI" ] }, @@ -155,9 +155,7 @@ "if not os.path.exists(mdata_path):\n", " os.system(f\"wget -q -O {mdata_path} https://figshare.com/ndownloader/files/49632108\")\n", "\n", - "mdata = mudata.read_h5mu(\n", - " mdata_path\n", - ")\n", + "mdata = mudata.read_h5mu(mdata_path)\n", "mdata.mod" ] }, @@ -185,7 +183,7 @@ } ], "source": [ - "mdata['mCG'].layers" + "mdata[\"mCG\"].layers" ] }, { @@ -224,7 +222,7 @@ } ], "source": [ - "mdata['mCG'].X" + "mdata[\"mCG\"].X" ] }, { @@ -240,11 +238,11 @@ "metadata": {}, "outputs": [], "source": [ - "sc.tl.pca(mdata['mCG'])\n", - "sc.tl.pca(mdata['mCH'])\n", + "sc.tl.pca(mdata[\"mCG\"])\n", + "sc.tl.pca(mdata[\"mCH\"])\n", "\n", - "ch_pcs = mdata['mCH'].obsm['X_pca']\n", - "cg_pcs = mdata['mCG'].obsm['X_pca']\n", + "ch_pcs = mdata[\"mCH\"].obsm[\"X_pca\"]\n", + "cg_pcs = mdata[\"mCG\"].obsm[\"X_pca\"]\n", "\n", "# standardize the values of PCs from both modalities\n", "cg_pcs = cg_pcs / cg_pcs.std()\n", @@ -253,7 +251,7 @@ "# total_pcs\n", "total_pcs = np.hstack([ch_pcs, cg_pcs])\n", "\n", - "mdata.obsm['X_pca'] = total_pcs" + "mdata.obsm[\"X_pca\"] = total_pcs" ] }, { @@ -290,8 +288,8 @@ "\n", "fig, ax = plt.subplots(1, 2, figsize=(11, 5))\n", "\n", - "sc.pl.umap(mdata, color='mCG:Platform', ax=ax[0], show=False, title=\"Sequencing protocol\")\n", - "sc.pl.umap(mdata, color='mCG:CoarseType', ax=ax[1], show=False, title=\"Cell type\")\n", + "sc.pl.umap(mdata, color=\"mCG:Platform\", ax=ax[0], show=False, title=\"Sequencing protocol\")\n", + "sc.pl.umap(mdata, color=\"mCG:CoarseType\", ax=ax[1], show=False, title=\"Cell type\")\n", "\n", "plt.subplots_adjust(wspace=0.5)" ] @@ -316,7 +314,7 @@ "source": [ "Before training our model, we'll use methylVI's `setup_mudata` function to prepare our `MuData` object for training. \n", "\n", - "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." + "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" ] }, { @@ -336,11 +334,11 @@ ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "```{note}\n", - "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", + "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", "```" ] }, @@ -360,7 +358,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001B[34mINFO \u001B[0m The model has been initialized \n" + "\u001b[34mINFO \u001b[0m The model has been initialized \n" ] }, { @@ -407,7 +405,7 @@ "metadata": {}, "outputs": [], "source": [ - "mdata.obsm['methylVI'] = model.get_latent_representation()" + "mdata.obsm[\"methylVI\"] = model.get_latent_representation()" ] }, { @@ -439,13 +437,13 @@ } ], "source": [ - "sc.pp.neighbors(mdata, use_rep='methylVI')\n", + "sc.pp.neighbors(mdata, use_rep=\"methylVI\")\n", "sc.tl.umap(mdata)\n", "\n", "fig, ax = plt.subplots(1, 2, figsize=(11, 5))\n", "\n", - "sc.pl.umap(mdata, color='mCG:Platform', ax=ax[0], show=False, title=\"Sequencing protocol\")\n", - "sc.pl.umap(mdata, color='mCG:CoarseType', ax=ax[1], show=False, title=\"Cell type\")\n", + "sc.pl.umap(mdata, color=\"mCG:Platform\", ax=ax[0], show=False, title=\"Sequencing protocol\")\n", + "sc.pl.umap(mdata, color=\"mCG:CoarseType\", ax=ax[1], show=False, title=\"Cell type\")\n", "\n", "plt.subplots_adjust(wspace=0.5)" ]