{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Differential expression between annotated cell types and between leiden clusters in CITE-seq input data (train and test)","metadata":{}},{"cell_type":"code","source":"%%capture\n!pip3 install scanpy[leiden]","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-10T15:20:37.844014Z","iopub.execute_input":"2022-12-10T15:20:37.844581Z","iopub.status.idle":"2022-12-10T15:20:51.086285Z","shell.execute_reply.started":"2022-12-10T15:20:37.844473Z","shell.execute_reply":"2022-12-10T15:20:51.084560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport sys","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:20:51.089422Z","iopub.execute_input":"2022-12-10T15:20:51.089987Z","iopub.status.idle":"2022-12-10T15:20:51.096659Z","shell.execute_reply.started":"2022-12-10T15:20:51.089927Z","shell.execute_reply":"2022-12-10T15:20:51.095227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR_RAW = \"/kaggle/input/msci-raw-counts-anndata\"\n# Cite\nFP_CITE_RAW_TRAIN_INPUTS = os.path.join(DATA_DIR_RAW,\"train_cite_inputs_raw.ann.h5\")\nFP_CITE_RAW_TRAIN_TARGETS = os.path.join(DATA_DIR_RAW,\"train_cite_targets_raw.ann.h5\")\nFP_CITE_RAW_TEST_INPUTS = os.path.join(DATA_DIR_RAW,\"test_cite_inputs_raw.ann.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:20:51.098280Z","iopub.execute_input":"2022-12-10T15:20:51.098674Z","iopub.status.idle":"2022-12-10T15:20:51.112661Z","shell.execute_reply.started":"2022-12-10T15:20:51.098640Z","shell.execute_reply":"2022-12-10T15:20:51.111378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gc\n\nimport anndata as ad\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport scanpy as sc\n\nsc.settings.verbosity = 3\nsc.set_figure_params(dpi=150)\nsns.set_style(\"ticks\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:20:51.115273Z","iopub.execute_input":"2022-12-10T15:20:51.116118Z","iopub.status.idle":"2022-12-10T15:20:54.088415Z","shell.execute_reply.started":"2022-12-10T15:20:51.116068Z","shell.execute_reply":"2022-12-10T15:20:54.087219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metadata_fp = \"/kaggle/input/open-problems-multimodal/metadata.csv\"\nadd_metadata_fp = \"/kaggle/input/open-problems-multimodal/metadata_cite_day_2_donor_27678.csv\"\nmetadata = pd.read_csv(metadata_fp)\nadd_metadata = pd.read_csv(add_metadata_fp)\nmetadata = pd.concat([metadata, add_metadata])\nmetadata.set_index(\"cell_id\", inplace=True)\nmetadata.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:20:54.089963Z","iopub.execute_input":"2022-12-10T15:20:54.090364Z","iopub.status.idle":"2022-12-10T15:20:54.620346Z","shell.execute_reply.started":"2022-12-10T15:20:54.090327Z","shell.execute_reply":"2022-12-10T15:20:54.619152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def annotate(adata: ad.AnnData, metadata: pd.DataFrame, f_donors: [str]):\n    adata.obs[\"cell_type\"] = metadata[\"cell_type\"][adata.obs_names]\n    adata.obs[\"day\"] = metadata[\"day\"][adata.obs_names].astype(str)\n    adata.obs[\"donor\"] = metadata[\"donor\"][adata.obs_names].astype(str)\n    adata.obs[\"gender\"] = \"m\"\n    adata.obs.loc[adata.obs[\"donor\"].isin(f_donors), \"gender\"] = \"f\"\n    adata.obs[\"n_genes_counts\"] = (adata.X > 0).sum(axis=1).A1\n    adata.obs[\"read_depth\"] = adata.X.sum(axis=1).A1","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:20:54.621932Z","iopub.execute_input":"2022-12-10T15:20:54.622335Z","iopub.status.idle":"2022-12-10T15:20:54.630554Z","shell.execute_reply.started":"2022-12-10T15:20:54.622298Z","shell.execute_reply":"2022-12-10T15:20:54.629338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Input raw data","metadata":{}},{"cell_type":"code","source":"cite_raw_train = sc.read_h5ad(FP_CITE_RAW_TRAIN_INPUTS)\ncite_raw_test = sc.read_h5ad(FP_CITE_RAW_TEST_INPUTS)\ncite_raw = ad.concat([cite_raw_train, cite_raw_test], merge=\"same\")\ndel cite_raw_train\ndel cite_raw_test\ngc.collect()\nannotate(cite_raw, metadata, f_donors = [\"13176\", ])\ncite_raw.layers[\"counts\"] = cite_raw.X.copy()\nadata = cite_raw","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:20:54.632157Z","iopub.execute_input":"2022-12-10T15:20:54.632935Z","iopub.status.idle":"2022-12-10T15:21:55.282941Z","shell.execute_reply.started":"2022-12-10T15:20:54.632894Z","shell.execute_reply":"2022-12-10T15:21:55.281612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get HVG and normalise variance with analytical pearson residuals, count PCA","metadata":{}},{"cell_type":"code","source":"sc.experimental.pp.highly_variable_genes(adata, n_top_genes=3000, batch_key=\"donor\")\nsc.experimental.pp.normalize_pearson_residuals_pca(adata)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:21:55.284903Z","iopub.execute_input":"2022-12-10T15:21:55.285398Z","iopub.status.idle":"2022-12-10T15:24:55.125872Z","shell.execute_reply.started":"2022-12-10T15:21:55.285358Z","shell.execute_reply":"2022-12-10T15:24:55.124556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot PCA on analytical pearson residuals","metadata":{}},{"cell_type":"code","source":"sc.pl.pca(cite_raw, color=[\"cell_type\", \"donor\", \"day\", \"n_genes_counts\"])","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:24:55.127404Z","iopub.execute_input":"2022-12-10T15:24:55.127769Z","iopub.status.idle":"2022-12-10T15:24:59.250880Z","shell.execute_reply.started":"2022-12-10T15:24:55.127738Z","shell.execute_reply":"2022-12-10T15:24:59.249504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot UMAP","metadata":{}},{"cell_type":"code","source":"sc.pp.neighbors(cite_raw, n_pcs=15, n_neighbors=20)\nsc.tl.umap(cite_raw, min_dist=0.2)\nsc.pl.umap(cite_raw, color=[\"cell_type\", \"donor\", \"day\"], frameon=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:24:59.255720Z","iopub.execute_input":"2022-12-10T15:24:59.256783Z","iopub.status.idle":"2022-12-10T15:28:19.897209Z","shell.execute_reply.started":"2022-12-10T15:24:59.256711Z","shell.execute_reply":"2022-12-10T15:28:19.894949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_raw.obs[\"EryP\"] = (cite_raw.obs.cell_type == \"EryP\").astype(\"str\")\ncite_raw.obs[\"MkP\"] = (cite_raw.obs.cell_type == \"MkP\").astype(\"str\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:28:19.899045Z","iopub.execute_input":"2022-12-10T15:28:19.899961Z","iopub.status.idle":"2022-12-10T15:28:20.020745Z","shell.execute_reply.started":"2022-12-10T15:28:19.899916Z","shell.execute_reply":"2022-12-10T15:28:20.019740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"G1S_genes_Tirosh = ['ENSG00000100297', 'ENSG00000132646', 'ENSG00000176890', 'ENSG00000168496', 'ENSG00000073111', 'ENSG00000104738', 'ENSG00000167325', 'ENSG00000076248', 'ENSG00000131153', 'ENSG00000076003', 'ENSG00000144354', 'ENSG00000143476', 'ENSG00000198056', 'ENSG00000276043', 'ENSG00000151725', 'ENSG00000119969', 'ENSG00000049541', 'ENSG00000117748', 'ENSG00000132780', 'ENSG00000111247', 'ENSG00000112312', 'ENSG00000092470', 'ENSG00000163950', 'ENSG00000175305', 'ENSG00000012963', 'ENSG00000077514', 'ENSG00000095002', 'ENSG00000156802', 'ENSG00000051180', 'ENSG00000171848', 'ENSG00000093009', 'ENSG00000094804', 'ENSG00000174371', 'ENSG00000075131', 'ENSG00000136982', 'ENSG00000197299', 'ENSG00000118412', 'ENSG00000162607', 'ENSG00000092853', 'ENSG00000101868', 'ENSG00000159259', 'ENSG00000136492', 'ENSG00000129173']\nG2M_genes_Tirosh = ['ENSG00000164104', 'ENSG00000170312', 'ENSG00000137804', 'ENSG00000175063', 'ENSG00000089685', 'ENSG00000088325', 'ENSG00000131747', 'ENSG00000080986', 'ENSG00000123975', 'ENSG00000143228', 'ENSG00000173207', 'ENSG00000148773', 'ENSG00000120802', 'ENSG00000117724', 'ENSG00000013810', 'ENSG00000129195', 'ENSG00000113810', 'ENSG00000157456', 'ENSG00000169607', 'ENSG00000136108', 'ENSG00000178999', 'ENSG00000169679', 'ENSG00000138160', 'ENSG00000143401', 'ENSG00000188229', 'ENSG00000075218', 'ENSG00000138182', 'ENSG00000123485', 'ENSG00000111665', 'ENSG00000189159', 'ENSG00000117399', 'ENSG00000112742', 'ENSG00000158402', 'ENSG00000142945', 'ENSG00000100401', 'ENSG00000010292', 'ENSG00000126787', 'ENSG00000184661', 'ENSG00000134690', 'ENSG00000114346', 'ENSG00000137807', 'ENSG00000072571', 'ENSG00000087586', 'ENSG00000134222', 'ENSG00000011426', 'ENSG00000143815', 'ENSG00000175216', 'ENSG00000138778', 'ENSG00000102974', 'ENSG00000117650', 'ENSG00000092140', 'ENSG00000139354', 'ENSG00000094916', 'ENSG00000115163']","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:31:41.633398Z","iopub.execute_input":"2022-12-10T15:31:41.634294Z","iopub.status.idle":"2022-12-10T15:31:41.647522Z","shell.execute_reply.started":"2022-12-10T15:31:41.634226Z","shell.execute_reply":"2022-12-10T15:31:41.645980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_raw.var[\"ensembl_ids\"] = [ t.split('_')[0] for t in cite_raw.var_names]\ncite_raw.var[\"gene_names\"] = [ t.split('_')[1] for t in cite_raw.var_names]","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:23:46.767907Z","iopub.execute_input":"2022-12-10T16:23:46.768631Z","iopub.status.idle":"2022-12-10T16:23:46.801692Z","shell.execute_reply.started":"2022-12-10T16:23:46.768572Z","shell.execute_reply":"2022-12-10T16:23:46.800327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_raw.obs[\"G1S_genes_Tirosh_mean\"] = cite_raw[:,cite_raw.var[\"ensembl_ids\"].isin(G1S_genes_Tirosh)].X.sum(axis=1).A1 / len(G1S_genes_Tirosh)\ncite_raw.obs[\"G2M_genes_Tirosh_mean\"] = cite_raw[:,cite_raw.var[\"ensembl_ids\"].isin(G2M_genes_Tirosh)].X.sum(axis=1).A1 / len(G2M_genes_Tirosh)\ncite_raw.obs[\"G1S+2M_genes_Tirosh_mean\"] = cite_raw[:,cite_raw.var[\"ensembl_ids\"].isin(G1S_genes_Tirosh + G2M_genes_Tirosh)].X.sum(axis=1).A1 / len(G1S_genes_Tirosh + G2M_genes_Tirosh)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:35:18.531048Z","iopub.execute_input":"2022-12-10T15:35:18.531532Z","iopub.status.idle":"2022-12-10T15:35:22.857139Z","shell.execute_reply.started":"2022-12-10T15:35:18.531494Z","shell.execute_reply":"2022-12-10T15:35:22.855847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.umap(cite_raw, color=[\"cell_type\", \"EryP\", \"MkP\", \"G1S+2M_genes_Tirosh_mean\", \"n_genes_counts\", \"read_depth\", \"day\", \"donor\"], frameon=False, ncols=3)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:35:25.320347Z","iopub.execute_input":"2022-12-10T15:35:25.320788Z","iopub.status.idle":"2022-12-10T15:35:33.237700Z","shell.execute_reply.started":"2022-12-10T15:35:25.320753Z","shell.execute_reply":"2022-12-10T15:35:33.236373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.umap(cite_raw, color=[\"cell_type\", \"G1S+2M_genes_Tirosh_mean\", \"n_genes_counts\", \"read_depth\", \"day\", \"donor\"], frameon=False, ncols=3)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:36:54.491498Z","iopub.execute_input":"2022-12-10T15:36:54.492001Z","iopub.status.idle":"2022-12-10T15:37:00.473337Z","shell.execute_reply.started":"2022-12-10T15:36:54.491965Z","shell.execute_reply":"2022-12-10T15:37:00.472308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Normalise data for differential expression","metadata":{}},{"cell_type":"code","source":"# Для отрисовки и дифференциальной экспрессии\nsc.pp.normalize_total(adata, target_sum=1e4)\nsc.pp.log1p(adata)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:37:00.475224Z","iopub.execute_input":"2022-12-10T15:37:00.475813Z","iopub.status.idle":"2022-12-10T15:37:16.893892Z","shell.execute_reply.started":"2022-12-10T15:37:00.475776Z","shell.execute_reply":"2022-12-10T15:37:16.892581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Differential expression between annotated cell types","metadata":{}},{"cell_type":"markdown","source":"## Wilcoxon","metadata":{}},{"cell_type":"code","source":"sc.tl.rank_genes_groups(adata, groupby=\"cell_type\", method=\"wilcoxon\", key_added=\"rank_genes_groups_cell_type\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:37:16.895707Z","iopub.execute_input":"2022-12-10T15:37:16.896242Z","iopub.status.idle":"2022-12-10T15:46:10.773232Z","shell.execute_reply.started":"2022-12-10T15:37:16.896185Z","shell.execute_reply":"2022-12-10T15:46:10.771767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.rank_genes_groups(adata, key=\"rank_genes_groups_cell_type\", gene_symbols=\"gene_names\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:24:32.819669Z","iopub.execute_input":"2022-12-10T16:24:32.820130Z","iopub.status.idle":"2022-12-10T16:24:34.795028Z","shell.execute_reply.started":"2022-12-10T16:24:32.820094Z","shell.execute_reply":"2022-12-10T16:24:34.793897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.rank_genes_groups_heatmap(adata, key=\"rank_genes_groups_cell_type\", gene_symbols=\"gene_names\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T17:09:38.271909Z","iopub.execute_input":"2022-12-10T17:09:38.272339Z","iopub.status.idle":"2022-12-10T17:09:44.941709Z","shell.execute_reply.started":"2022-12-10T17:09:38.272301Z","shell.execute_reply":"2022-12-10T17:09:44.940590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.rank_genes_groups_matrixplot(\n    adata,\n    n_genes=5, key=\"rank_genes_groups_cell_type\",\n    values_to_plot=\"logfoldchanges\",\n    cmap='bwr',\n    vmin=-4,\n    vmax=4,\n    min_logfoldchange=2,\n    colorbar_title='log fold change',\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T17:16:15.657648Z","iopub.execute_input":"2022-12-10T17:16:15.658134Z","iopub.status.idle":"2022-12-10T17:16:24.601862Z","shell.execute_reply.started":"2022-12-10T17:16:15.658099Z","shell.execute_reply":"2022-12-10T17:16:24.600610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for cell_type in adata.obs.cell_type.unique():\n    de_df = sc.get.rank_genes_groups_df(adata, group=cell_type, key=\"rank_genes_groups_cell_type\")\n    de_df.to_csv(f\"wilcoxon_{cell_type}_vs_rest.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T17:22:48.386616Z","iopub.execute_input":"2022-12-10T17:22:48.387093Z","iopub.status.idle":"2022-12-10T17:22:52.469900Z","shell.execute_reply.started":"2022-12-10T17:22:48.387043Z","shell.execute_reply":"2022-12-10T17:22:52.469002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## logreg","metadata":{}},{"cell_type":"code","source":"sc.tl.rank_genes_groups(adata, groupby=\"cell_type\", method=\"logreg\", key_added=\"rank_genes_groups_logreg_cell_type\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:27:36.696571Z","iopub.execute_input":"2022-12-10T16:27:36.697131Z","iopub.status.idle":"2022-12-10T16:44:39.792449Z","shell.execute_reply.started":"2022-12-10T16:27:36.697081Z","shell.execute_reply":"2022-12-10T16:44:39.790755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.rank_genes_groups(adata, key=\"rank_genes_groups_logreg_cell_type\", gene_symbols=\"gene_names\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:44:39.797097Z","iopub.execute_input":"2022-12-10T16:44:39.797676Z","iopub.status.idle":"2022-12-10T16:44:41.961852Z","shell.execute_reply.started":"2022-12-10T16:44:39.797620Z","shell.execute_reply":"2022-12-10T16:44:41.960432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Leiden clustering","metadata":{}},{"cell_type":"code","source":"for resolution in [0.2, 0.5, 1, 2]:\n    sc.tl.leiden(adata, resolution=resolution, key_added=f\"leiden_{resolution}\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:46:11.230829Z","iopub.execute_input":"2022-12-10T15:46:11.231171Z","iopub.status.idle":"2022-12-10T15:54:18.361457Z","shell.execute_reply.started":"2022-12-10T15:46:11.231140Z","shell.execute_reply":"2022-12-10T15:54:18.360174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cluster_keys = [\"cell_type\", \"G1S+2M_genes_Tirosh_mean\", \"read_depth\", \"day\", \"donor\"] + [f\"leiden_{resolution}\" for resolution in [0.2, 0.5]]\nsc.pl.umap(\n    adata,\n    color=cluster_keys,\n    frameon=False,\n#     legend_loc=\"on data\",\n    legend_fontoutline=2,\n    ncols=3\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:54:18.363060Z","iopub.execute_input":"2022-12-10T15:54:18.363480Z","iopub.status.idle":"2022-12-10T15:54:26.159121Z","shell.execute_reply.started":"2022-12-10T15:54:18.363442Z","shell.execute_reply":"2022-12-10T15:54:26.157910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.dendrogram(adata, groupby=\"leiden_0.2\", n_pcs=15, use_rep=\"X_pca\")\nsc.pl.dendrogram(adata, groupby=\"leiden_0.2\", orientation=\"left\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:57:59.821399Z","iopub.execute_input":"2022-12-10T16:57:59.821995Z","iopub.status.idle":"2022-12-10T16:58:00.120028Z","shell.execute_reply.started":"2022-12-10T16:57:59.821950Z","shell.execute_reply":"2022-12-10T16:58:00.118833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.dendrogram(adata, groupby=\"cell_type\", n_pcs=15, use_rep=\"X_pca\")\nsc.pl.dendrogram(adata, groupby=\"cell_type\", orientation=\"left\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T17:03:17.471407Z","iopub.execute_input":"2022-12-10T17:03:17.471954Z","iopub.status.idle":"2022-12-10T17:03:17.750465Z","shell.execute_reply.started":"2022-12-10T17:03:17.471910Z","shell.execute_reply":"2022-12-10T17:03:17.749139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cluster_keys = [\"cell_type\", ] + [f\"leiden_{resolution}\" for resolution in [0.2,]]\nsc.pl.umap(\n    adata,\n    color=cluster_keys,\n    frameon=False,\n    legend_loc=\"on data\",\n    legend_fontoutline=2,\n    ncols=3\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:49:58.986625Z","iopub.execute_input":"2022-12-10T16:49:58.987692Z","iopub.status.idle":"2022-12-10T16:50:01.165465Z","shell.execute_reply.started":"2022-12-10T16:49:58.987642Z","shell.execute_reply":"2022-12-10T16:50:01.164460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Differential expression between leiden clusters","metadata":{}},{"cell_type":"code","source":"sc.tl.rank_genes_groups(adata, groupby=\"leiden_0.2\", method=\"wilcoxon\", key_added=\"rank_genes_groups_leiden_0.2\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T15:54:31.550720Z","iopub.execute_input":"2022-12-10T15:54:31.551163Z","iopub.status.idle":"2022-12-10T16:04:00.479087Z","shell.execute_reply.started":"2022-12-10T15:54:31.551125Z","shell.execute_reply":"2022-12-10T16:04:00.477646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.rank_genes_groups(adata, key=\"rank_genes_groups_leiden_0.2\", gene_symbols=\"gene_names\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:44:41.963422Z","iopub.execute_input":"2022-12-10T16:44:41.963835Z","iopub.status.idle":"2022-12-10T16:44:44.982038Z","shell.execute_reply.started":"2022-12-10T16:44:41.963798Z","shell.execute_reply":"2022-12-10T16:44:44.980759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for cluster in adata.obs[\"leiden_0.2\"].unique():\n    de_df = sc.get.rank_genes_groups_df(adata, group=cluster, key=\"rank_genes_groups_leiden_0.2\")\n    de_df.to_csv(f\"wilcoxon_leiden_0.2_{cluster}_vs_rest.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T17:25:30.303901Z","iopub.execute_input":"2022-12-10T17:25:30.304378Z","iopub.status.idle":"2022-12-10T17:25:36.116923Z","shell.execute_reply.started":"2022-12-10T17:25:30.304336Z","shell.execute_reply":"2022-12-10T17:25:36.115943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.rank_genes_groups(adata, groupby=\"leiden_0.2\", method=\"wilcoxon\", key_added=\"rank_genes_groups_leiden_0.2_5_6vs1\", groups=[\"5\", \"6\"], reference=\"1\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:09:56.971817Z","iopub.execute_input":"2022-12-10T16:09:56.972332Z","iopub.status.idle":"2022-12-10T16:13:36.797991Z","shell.execute_reply.started":"2022-12-10T16:09:56.972294Z","shell.execute_reply":"2022-12-10T16:13:36.795531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.rank_genes_groups(adata, key=\"rank_genes_groups_leiden_0.2_5_6vs1\", gene_symbols=\"gene_names\")","metadata":{"execution":{"iopub.status.busy":"2022-12-10T16:44:44.985093Z","iopub.execute_input":"2022-12-10T16:44:44.985898Z","iopub.status.idle":"2022-12-10T16:44:45.666105Z","shell.execute_reply.started":"2022-12-10T16:44:44.985845Z","shell.execute_reply":"2022-12-10T16:44:45.665162Z"},"trusted":true},"execution_count":null,"outputs":[]}]}