{"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":"Relevant tutorials:\n- [scRNA-seq (scanpy)](https://scanpy-tutorials.readthedocs.io/en/latest/pbmc3k.html)\n- [multiome (muon)](https://muon-tutorials.readthedocs.io/en/latest/single-cell-rna-atac/index.html)\n- [CITE-seq (muon)](https://muon-tutorials.readthedocs.io/en/latest/cite-seq/1-CITE-seq-PBMC-5k.html)","metadata":{}},{"cell_type":"code","source":"!pip install tables\n!pip install muon","metadata":{"execution":{"iopub.status.busy":"2022-08-16T16:51:56.895587Z","iopub.execute_input":"2022-08-16T16:51:56.895999Z","iopub.status.idle":"2022-08-16T16:52:26.833284Z","shell.execute_reply.started":"2022-08-16T16:51:56.895967Z","shell.execute_reply":"2022-08-16T16:52:26.832101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nimport numpy as np\nimport pandas as pd\nfrom scipy.sparse import csr_matrix\nimport mudata\nfrom mudata import AnnData, MuData\nimport scanpy as sc\nimport muon as mu","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:46:16.031125Z","iopub.execute_input":"2022-08-16T18:46:16.032249Z","iopub.status.idle":"2022-08-16T18:46:29.049808Z","shell.execute_reply.started":"2022-08-16T18:46:16.032139Z","shell.execute_reply":"2022-08-16T18:46:29.048794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = Path(\"../input/open-problems-multimodal\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:46:29.051648Z","iopub.execute_input":"2022-08-16T18:46:29.052539Z","iopub.status.idle":"2022-08-16T18:46:29.057361Z","shell.execute_reply.started":"2022-08-16T18:46:29.052497Z","shell.execute_reply":"2022-08-16T18:46:29.056322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For demonstration purposes, only first 1000 cells will be loaded. For full data, free tier on Kaggle might not be enough.","metadata":{}},{"cell_type":"code","source":"N = 1000","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:46:48.409522Z","iopub.execute_input":"2022-08-16T18:46:48.409906Z","iopub.status.idle":"2022-08-16T18:46:48.415417Z","shell.execute_reply.started":"2022-08-16T18:46:48.409871Z","shell.execute_reply":"2022-08-16T18:46:48.414176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# CITE-seq\n\n1. Load CITE-seq data into AnnData/MuData format.\n2. Run PCA/UMAP to visualize the data.","metadata":{}},{"cell_type":"markdown","source":"## anndata/mudata","metadata":{}},{"cell_type":"code","source":"rna_df = pd.read_hdf(DATA_DIR / \"train_cite_inputs.h5\", start=0, stop=N)\nprot_df = pd.read_hdf(DATA_DIR / \"train_cite_targets.h5\", start=0, stop=N)\n\n# # full data:\n# rna_df = pd.read_hdf(DATA_DIR / \"train_cite_inputs.h5\")\n# prot_df = pd.read_hdf(DATA_DIR / \"train_cite_targets.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:46:55.931803Z","iopub.execute_input":"2022-08-16T18:46:55.932854Z","iopub.status.idle":"2022-08-16T18:46:56.843927Z","shell.execute_reply.started":"2022-08-16T18:46:55.932814Z","shell.execute_reply":"2022-08-16T18:46:56.842874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna = AnnData(csr_matrix(rna_df))\nrna.obs_names = rna_df.index.values\nrna.var_names = rna_df.columns.values","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:47:02.466799Z","iopub.execute_input":"2022-08-16T18:47:02.467545Z","iopub.status.idle":"2022-08-16T18:47:03.273916Z","shell.execute_reply.started":"2022-08-16T18:47:02.467508Z","shell.execute_reply":"2022-08-16T18:47:03.272860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prot = AnnData(csr_matrix(prot_df))\nprot.obs_names = prot_df.index.values\nprot.var_names = prot_df.columns.values","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:47:04.525714Z","iopub.execute_input":"2022-08-16T18:47:04.526132Z","iopub.status.idle":"2022-08-16T18:47:04.541322Z","shell.execute_reply.started":"2022-08-16T18:47:04.526096Z","shell.execute_reply":"2022-08-16T18:47:04.540253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite = MuData({\"rna\": rna, \"prot\": prot})","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:47:26.625216Z","iopub.execute_input":"2022-08-16T18:47:26.626272Z","iopub.status.idle":"2022-08-16T18:47:26.659931Z","shell.execute_reply.started":"2022-08-16T18:47:26.626210Z","shell.execute_reply":"2022-08-16T18:47:26.658779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metadata = pd.read_csv(DATA_DIR / \"metadata.csv\")\ncite.obs = cite.obs.join(metadata.set_index(\"cell_id\"))\n\ncite.obs.donor = cite.obs.donor.astype(\"category\")\ncite.obs.cell_type = cite.obs.cell_type.astype(\"category\")\ncite.obs.day = cite.obs.day.astype(\"category\")\ncite.obs.technology = cite.obs.technology.astype(\"category\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:47:51.627398Z","iopub.execute_input":"2022-08-16T18:47:51.628149Z","iopub.status.idle":"2022-08-16T18:47:51.892758Z","shell.execute_reply.started":"2022-08-16T18:47:51.628101Z","shell.execute_reply":"2022-08-16T18:47:51.891500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with mudata.set_options(display_style=\"html\", display_html_expand=0b100):\n    display(cite)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:47:55.669624Z","iopub.execute_input":"2022-08-16T18:47:55.670634Z","iopub.status.idle":"2022-08-16T18:47:55.684082Z","shell.execute_reply.started":"2022-08-16T18:47:55.670592Z","shell.execute_reply":"2022-08-16T18:47:55.682740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [rna] scanpy","metadata":{"execution":{"iopub.status.busy":"2022-08-16T16:34:51.279064Z","iopub.execute_input":"2022-08-16T16:34:51.280386Z","iopub.status.idle":"2022-08-16T16:34:51.285373Z","shell.execute_reply.started":"2022-08-16T16:34:51.280340Z","shell.execute_reply":"2022-08-16T16:34:51.284011Z"}}},{"cell_type":"markdown","source":"### Feature selection","metadata":{}},{"cell_type":"code","source":"sc.pp.highly_variable_genes(rna, min_mean=0.05, max_mean=8, min_disp=0.5)\nsc.pl.highly_variable_genes(rna)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:47:59.096291Z","iopub.execute_input":"2022-08-16T18:47:59.096970Z","iopub.status.idle":"2022-08-16T18:48:00.471074Z","shell.execute_reply.started":"2022-08-16T18:47:59.096928Z","shell.execute_reply":"2022-08-16T18:48:00.470090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.sum(rna.var.highly_variable)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:02.626614Z","iopub.execute_input":"2022-08-16T18:48:02.627279Z","iopub.status.idle":"2022-08-16T18:48:02.634875Z","shell.execute_reply.started":"2022-08-16T18:48:02.627238Z","shell.execute_reply":"2022-08-16T18:48:02.633708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna.layers[\"data\"] = rna.X.copy()\nsc.pp.scale(rna)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:05.092709Z","iopub.execute_input":"2022-08-16T18:48:05.093239Z","iopub.status.idle":"2022-08-16T18:48:05.378787Z","shell.execute_reply.started":"2022-08-16T18:48:05.093195Z","shell.execute_reply":"2022-08-16T18:48:05.377657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### PCA","metadata":{}},{"cell_type":"code","source":"sc.tl.pca(rna)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:07.634931Z","iopub.execute_input":"2022-08-16T18:48:07.635601Z","iopub.status.idle":"2022-08-16T18:48:08.152813Z","shell.execute_reply.started":"2022-08-16T18:48:07.635562Z","shell.execute_reply":"2022-08-16T18:48:08.150876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(cite, basis=\"rna:X_pca\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:09.954479Z","iopub.execute_input":"2022-08-16T18:48:09.954893Z","iopub.status.idle":"2022-08-16T18:48:10.615666Z","shell.execute_reply.started":"2022-08-16T18:48:09.954859Z","shell.execute_reply":"2022-08-16T18:48:10.614731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### UMAP","metadata":{}},{"cell_type":"code","source":"sc.pp.neighbors(rna)\nsc.tl.umap(rna, random_state=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:18.404432Z","iopub.execute_input":"2022-08-16T18:48:18.404867Z","iopub.status.idle":"2022-08-16T18:48:25.438438Z","shell.execute_reply.started":"2022-08-16T18:48:18.404829Z","shell.execute_reply":"2022-08-16T18:48:25.437214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(cite, basis=\"rna:X_umap\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:25.440468Z","iopub.execute_input":"2022-08-16T18:48:25.441205Z","iopub.status.idle":"2022-08-16T18:48:26.024964Z","shell.execute_reply.started":"2022-08-16T18:48:25.441155Z","shell.execute_reply":"2022-08-16T18:48:26.023865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [prot] scanpy","metadata":{"execution":{"iopub.status.busy":"2022-08-16T16:34:51.279064Z","iopub.execute_input":"2022-08-16T16:34:51.280386Z","iopub.status.idle":"2022-08-16T16:34:51.285373Z","shell.execute_reply.started":"2022-08-16T16:34:51.280340Z","shell.execute_reply":"2022-08-16T16:34:51.284011Z"}}},{"cell_type":"code","source":"prot.layers[\"data\"] = prot.X.copy()\nsc.pp.scale(prot)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:29.171680Z","iopub.execute_input":"2022-08-16T18:48:29.172125Z","iopub.status.idle":"2022-08-16T18:48:29.182874Z","shell.execute_reply.started":"2022-08-16T18:48:29.172086Z","shell.execute_reply":"2022-08-16T18:48:29.181687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### PCA","metadata":{}},{"cell_type":"code","source":"sc.tl.pca(prot)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:32.188297Z","iopub.execute_input":"2022-08-16T18:48:32.188794Z","iopub.status.idle":"2022-08-16T18:48:32.279657Z","shell.execute_reply.started":"2022-08-16T18:48:32.188749Z","shell.execute_reply":"2022-08-16T18:48:32.278403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(cite, basis=\"prot:X_pca\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:35.106374Z","iopub.execute_input":"2022-08-16T18:48:35.106790Z","iopub.status.idle":"2022-08-16T18:48:35.503302Z","shell.execute_reply.started":"2022-08-16T18:48:35.106753Z","shell.execute_reply":"2022-08-16T18:48:35.502297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.neighbors(prot)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:39.026551Z","iopub.execute_input":"2022-08-16T18:48:39.027241Z","iopub.status.idle":"2022-08-16T18:48:39.160767Z","shell.execute_reply.started":"2022-08-16T18:48:39.027200Z","shell.execute_reply":"2022-08-16T18:48:39.159338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [rna+atac] muon","metadata":{}},{"cell_type":"code","source":"cite.update()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:44.396042Z","iopub.execute_input":"2022-08-16T18:48:44.396921Z","iopub.status.idle":"2022-08-16T18:48:44.433733Z","shell.execute_reply.started":"2022-08-16T18:48:44.396879Z","shell.execute_reply":"2022-08-16T18:48:44.432676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite\n# cite.write(\"/kaggle/tmp/train_cite.h5mu\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:48:47.884831Z","iopub.execute_input":"2022-08-16T18:48:47.885590Z","iopub.status.idle":"2022-08-16T18:48:48.353122Z","shell.execute_reply.started":"2022-08-16T18:48:47.885548Z","shell.execute_reply":"2022-08-16T18:48:48.351976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Multiome\n\n1. Load Multiome data into AnnData/MuData format.\n2. Run PCA/UMAP to visualize the data.","metadata":{}},{"cell_type":"markdown","source":"## anndata/mudata","metadata":{}},{"cell_type":"code","source":"atac_df = pd.read_hdf(DATA_DIR / \"train_multi_inputs.h5\", start=0, stop=N)\nrna_df = pd.read_hdf(DATA_DIR / \"train_multi_targets.h5\", start=0, stop=N)\n\n# # full data:\n# rna_df = pd.read_hdf(DATA_DIR / \"train_multi_inputs.h5\")\n# prot_df = pd.read_hdf(DATA_DIR / \"train_multi_targets.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:50:33.792769Z","iopub.execute_input":"2022-08-16T18:50:33.793234Z","iopub.status.idle":"2022-08-16T18:50:37.997446Z","shell.execute_reply.started":"2022-08-16T18:50:33.793195Z","shell.execute_reply":"2022-08-16T18:50:37.996344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna = AnnData(csr_matrix(rna_df))\nrna.obs_names = rna_df.index.values\nrna.var_names = rna_df.columns.values","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:50:40.844744Z","iopub.execute_input":"2022-08-16T18:50:40.845164Z","iopub.status.idle":"2022-08-16T18:50:41.380962Z","shell.execute_reply.started":"2022-08-16T18:50:40.845124Z","shell.execute_reply":"2022-08-16T18:50:41.379861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"atac = AnnData(csr_matrix(atac_df))\natac.obs_names = atac_df.index.values\natac.var_names = atac_df.columns.values","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:50:45.525278Z","iopub.execute_input":"2022-08-16T18:50:45.526075Z","iopub.status.idle":"2022-08-16T18:50:49.637055Z","shell.execute_reply.started":"2022-08-16T18:50:45.526014Z","shell.execute_reply":"2022-08-16T18:50:49.635941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multiome = MuData({\"rna\": rna, \"atac\": atac})","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:50:49.638935Z","iopub.execute_input":"2022-08-16T18:50:49.639364Z","iopub.status.idle":"2022-08-16T18:50:49.810657Z","shell.execute_reply.started":"2022-08-16T18:50:49.639324Z","shell.execute_reply":"2022-08-16T18:50:49.809612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metadata = pd.read_csv(DATA_DIR / \"metadata.csv\")\nmultiome.obs = multiome.obs.join(metadata.set_index(\"cell_id\"))\nmultiome.obs.donor = multiome.obs.donor.astype(\"category\")\nmultiome.obs.cell_type = multiome.obs.cell_type.astype(\"category\")\nmultiome.obs.day = multiome.obs.day.astype(\"category\")\nmultiome.obs.technology = multiome.obs.technology.astype(\"category\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:50:52.333530Z","iopub.execute_input":"2022-08-16T18:50:52.334721Z","iopub.status.idle":"2022-08-16T18:50:52.592008Z","shell.execute_reply.started":"2022-08-16T18:50:52.334668Z","shell.execute_reply":"2022-08-16T18:50:52.590968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with mudata.set_options(display_style=\"html\", display_html_expand=0b100):\n    display(multiome)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:50:54.682973Z","iopub.execute_input":"2022-08-16T18:50:54.683861Z","iopub.status.idle":"2022-08-16T18:50:54.696348Z","shell.execute_reply.started":"2022-08-16T18:50:54.683818Z","shell.execute_reply":"2022-08-16T18:50:54.694756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [rna] scanpy","metadata":{"execution":{"iopub.status.busy":"2022-08-16T16:34:51.279064Z","iopub.execute_input":"2022-08-16T16:34:51.280386Z","iopub.status.idle":"2022-08-16T16:34:51.285373Z","shell.execute_reply.started":"2022-08-16T16:34:51.280340Z","shell.execute_reply":"2022-08-16T16:34:51.284011Z"}}},{"cell_type":"markdown","source":"### Feature selection","metadata":{}},{"cell_type":"code","source":"sc.pp.highly_variable_genes(rna, min_mean=0.2, max_mean=6, min_disp=0.8)\nsc.pl.highly_variable_genes(rna)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:51:39.872898Z","iopub.execute_input":"2022-08-16T18:51:39.873675Z","iopub.status.idle":"2022-08-16T18:51:41.207778Z","shell.execute_reply.started":"2022-08-16T18:51:39.873636Z","shell.execute_reply":"2022-08-16T18:51:41.206763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.sum(rna.var.highly_variable)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:51:42.532018Z","iopub.execute_input":"2022-08-16T18:51:42.533137Z","iopub.status.idle":"2022-08-16T18:51:42.542580Z","shell.execute_reply.started":"2022-08-16T18:51:42.533083Z","shell.execute_reply":"2022-08-16T18:51:42.541199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rna.layers[\"data\"] = rna.X.copy()\nsc.pp.scale(rna)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:51:43.616904Z","iopub.execute_input":"2022-08-16T18:51:43.617659Z","iopub.status.idle":"2022-08-16T18:51:43.895332Z","shell.execute_reply.started":"2022-08-16T18:51:43.617617Z","shell.execute_reply":"2022-08-16T18:51:43.893695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### PCA","metadata":{}},{"cell_type":"code","source":"sc.tl.pca(rna)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:51:51.589012Z","iopub.execute_input":"2022-08-16T18:51:51.589424Z","iopub.status.idle":"2022-08-16T18:51:52.005921Z","shell.execute_reply.started":"2022-08-16T18:51:51.589381Z","shell.execute_reply":"2022-08-16T18:51:52.004498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(cite, basis=\"rna:X_pca\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:51:53.188693Z","iopub.execute_input":"2022-08-16T18:51:53.189117Z","iopub.status.idle":"2022-08-16T18:51:53.589866Z","shell.execute_reply.started":"2022-08-16T18:51:53.189082Z","shell.execute_reply":"2022-08-16T18:51:53.588952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### UMAP","metadata":{}},{"cell_type":"code","source":"sc.pp.neighbors(rna)\nsc.tl.umap(rna, random_state=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:51:56.796664Z","iopub.execute_input":"2022-08-16T18:51:56.797085Z","iopub.status.idle":"2022-08-16T18:51:59.366642Z","shell.execute_reply.started":"2022-08-16T18:51:56.797043Z","shell.execute_reply":"2022-08-16T18:51:59.365554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(multiome, basis=\"rna:X_umap\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:52:08.043135Z","iopub.execute_input":"2022-08-16T18:52:08.043531Z","iopub.status.idle":"2022-08-16T18:52:08.476970Z","shell.execute_reply.started":"2022-08-16T18:52:08.043497Z","shell.execute_reply":"2022-08-16T18:52:08.476063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [atac] scanpy","metadata":{"execution":{"iopub.status.busy":"2022-08-16T16:34:51.279064Z","iopub.execute_input":"2022-08-16T16:34:51.280386Z","iopub.status.idle":"2022-08-16T16:34:51.285373Z","shell.execute_reply.started":"2022-08-16T16:34:51.280340Z","shell.execute_reply":"2022-08-16T16:34:51.284011Z"}}},{"cell_type":"markdown","source":"### Feature selection","metadata":{}},{"cell_type":"code","source":"sc.pp.highly_variable_genes(atac, min_mean=0.5, max_mean=8, min_disp=1.0)\nsc.pl.highly_variable_genes(atac)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:56:10.637326Z","iopub.execute_input":"2022-08-16T18:56:10.637965Z","iopub.status.idle":"2022-08-16T18:56:26.055219Z","shell.execute_reply.started":"2022-08-16T18:56:10.637924Z","shell.execute_reply":"2022-08-16T18:56:26.052226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.sum(atac.var.highly_variable)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:56:26.057309Z","iopub.execute_input":"2022-08-16T18:56:26.057920Z","iopub.status.idle":"2022-08-16T18:56:26.066113Z","shell.execute_reply.started":"2022-08-16T18:56:26.057879Z","shell.execute_reply":"2022-08-16T18:56:26.065058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### PCA","metadata":{}},{"cell_type":"code","source":"mu.atac.tl.lsi(atac)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:56:54.080598Z","iopub.execute_input":"2022-08-16T18:56:54.081655Z","iopub.status.idle":"2022-08-16T18:57:12.913634Z","shell.execute_reply.started":"2022-08-16T18:56:54.081611Z","shell.execute_reply":"2022-08-16T18:57:12.912380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(multiome, basis=\"atac:X_lsi\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:57:18.614778Z","iopub.execute_input":"2022-08-16T18:57:18.615437Z","iopub.status.idle":"2022-08-16T18:57:19.674660Z","shell.execute_reply.started":"2022-08-16T18:57:18.615391Z","shell.execute_reply":"2022-08-16T18:57:19.673701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### UMAP","metadata":{}},{"cell_type":"code","source":"sc.pp.neighbors(atac, use_rep=\"X_lsi\")\nsc.tl.umap(atac, random_state=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:59:24.793016Z","iopub.execute_input":"2022-08-16T18:59:24.793843Z","iopub.status.idle":"2022-08-16T18:59:27.920286Z","shell.execute_reply.started":"2022-08-16T18:59:24.793804Z","shell.execute_reply":"2022-08-16T18:59:27.919070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mu.pl.embedding(multiome, basis=\"atac:X_umap\", color=[\"cell_type\", \"donor\", \"day\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:59:29.016388Z","iopub.execute_input":"2022-08-16T18:59:29.016797Z","iopub.status.idle":"2022-08-16T18:59:29.429881Z","shell.execute_reply.started":"2022-08-16T18:59:29.016759Z","shell.execute_reply":"2022-08-16T18:59:29.428973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [rna+atac] muon","metadata":{}},{"cell_type":"code","source":"multiome.update()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:59:38.190154Z","iopub.execute_input":"2022-08-16T18:59:38.191330Z","iopub.status.idle":"2022-08-16T18:59:38.228178Z","shell.execute_reply.started":"2022-08-16T18:59:38.191287Z","shell.execute_reply":"2022-08-16T18:59:38.227156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multiome\n# multiome.write(\"/kaggle/tmp/train_multiome.h5mu\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T18:59:39.539841Z","iopub.execute_input":"2022-08-16T18:59:39.540702Z","iopub.status.idle":"2022-08-16T18:59:39.552515Z","shell.execute_reply.started":"2022-08-16T18:59:39.540652Z","shell.execute_reply":"2022-08-16T18:59:39.551580Z"},"trusted":true},"execution_count":null,"outputs":[]}]}