Skip to content

Commit

Permalink
Pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Weinberger authored and Ethan Weinberger committed Oct 8, 2024
1 parent fa8837d commit d077c0a
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions scbs/MethylVI_batch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -185,7 +183,7 @@
}
],
"source": [
"mdata['mCG'].layers"
"mdata[\"mCG\"].layers"
]
},
{
Expand Down Expand Up @@ -224,7 +222,7 @@
}
],
"source": [
"mdata['mCG'].X"
"mdata[\"mCG\"].X"
]
},
{
Expand All @@ -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",
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -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)"
]
Expand All @@ -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"
]
},
{
Expand All @@ -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",
"```"
]
},
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -407,7 +405,7 @@
"metadata": {},
"outputs": [],
"source": [
"mdata.obsm['methylVI'] = model.get_latent_representation()"
"mdata.obsm[\"methylVI\"] = model.get_latent_representation()"
]
},
{
Expand Down Expand Up @@ -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)"
]
Expand Down

0 comments on commit d077c0a

Please sign in to comment.