{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-06T02:27:05.872753Z","iopub.execute_input":"2022-11-06T02:27:05.873303Z","iopub.status.idle":"2022-11-06T02:27:05.888755Z","shell.execute_reply.started":"2022-11-06T02:27:05.873264Z","shell.execute_reply":"2022-11-06T02:27:05.887557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib.colors import ListedColormap, LinearSegmentedColormap\nfrom matplotlib.offsetbox import AnnotationBbox, OffsetImage\nfrom sklearn.decomposition import TruncatedSVD\nfrom matplotlib.patches import Rectangle\nimport matplotlib.patches as patches\nimport matplotlib.pyplot as plt\nfrom tqdm import tqdm\nimport seaborn as sns\nimport pandas as pd\nimport numpy as np\nimport itertools\nimport warnings\nimport os\nimport gc\n!pip install scanpy\nimport scanpy as sc\nimport anndata\nimport time\nt0start = time.time()\nimport sys","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:27:05.891291Z","iopub.execute_input":"2022-11-06T02:27:05.891825Z","iopub.status.idle":"2022-11-06T02:27:18.019659Z","shell.execute_reply.started":"2022-11-06T02:27:05.891791Z","shell.execute_reply":"2022-11-06T02:27:18.018236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#The following notebook is further exploration of association of RNA and protein markers. I looked at a few different lineage markers\n#and made some plots to see if there was and association. I found the CD33 protein and CD3 RNA had a better degree of correlation of the markers\n#tested and showed this on a SNS matrix plot. \n#I also looked at trajectory of markers in the .h5 dataset provided with the leiden algorthim.\n#My reasoning was that the better understaing of markers expressed may help with associations\n\n","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:27:18.021736Z","iopub.execute_input":"2022-11-06T02:27:18.022159Z","iopub.status.idle":"2022-11-06T02:27:18.029961Z","shell.execute_reply.started":"2022-11-06T02:27:18.022102Z","shell.execute_reply":"2022-11-06T02:27:18.026924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MAIN_DIRECT = '../input/open-problems-multimodal'\nmeta_data_path = os.path.join(MAIN_DIRECT + '/metadata.csv')\neval_data_path  = os.path.join(MAIN_DIRECT + '/evaluation_ids.csv')\nsubmission_path = os.path.join(MAIN_DIRECT + '/sample_submission.csv')\n\ntest_cite_path = os.path.join(MAIN_DIRECT + '/test_cite_inputs.h5')\ntest_cite_path_day2 = os.path.join(MAIN_DIRECT + '/test_cite_inputs_day_2_donor_27678.h5')\ntest_multi_path = os.path.join(MAIN_DIRECT + '/test_multi_inputs.h5')\n\n\ntrain_cite_path = os.path.join(MAIN_DIRECT + '/train_cite_inputs.h5')\ntrain_cite_target_path = os.path.join(MAIN_DIRECT + '/train_cite_targets.h5')\ntrain_multi_path = os.path.join(MAIN_DIRECT + '/train_multi_inputs.h5')\ntrain_multi_target_path = os.path.join(MAIN_DIRECT + '/train_multi_targets.h5')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:27:18.031814Z","iopub.execute_input":"2022-11-06T02:27:18.032250Z","iopub.status.idle":"2022-11-06T02:27:18.048690Z","shell.execute_reply.started":"2022-11-06T02:27:18.032204Z","shell.execute_reply":"2022-11-06T02:27:18.047233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf_cite_train_x = pd.read_hdf(train_cite_path)\ndf_cite_train_y = pd.read_hdf(train_cite_target_path)\n\nif 0:\n    df_cite_test_x = pd.read_hdf(test_cite_path)\n    display( df_cite_test_x.head() )","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:27:18.052897Z","iopub.execute_input":"2022-11-06T02:27:18.053407Z","iopub.status.idle":"2022-11-06T02:28:51.763901Z","shell.execute_reply.started":"2022-11-06T02:27:18.053367Z","shell.execute_reply":"2022-11-06T02:28:51.762016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#There was a notebook that did help with getting the data in the following table below so I could \n# make my plots and inputed my genes of interest (from lineage markers). I did not note the notebook, \n#but would like to give them credit.\n# (please let me know so I can aknowledge you- Thanks!)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:51.765636Z","iopub.execute_input":"2022-11-06T02:28:51.766068Z","iopub.status.idle":"2022-11-06T02:28:51.772264Z","shell.execute_reply.started":"2022-11-06T02:28:51.766027Z","shell.execute_reply":"2022-11-06T02:28:51.771026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nlist_genes_names = [t.split('_')[1] for t in df_cite_train_x.columns ]\nprint(len(list_genes_names), list_genes_names[:10])\nlist_genes_ids = [t.split('_')[0] for t in df_cite_train_x.columns ]\nprint(len(list_genes_ids), list_genes_ids[:10])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:51.773997Z","iopub.execute_input":"2022-11-06T02:28:51.774684Z","iopub.status.idle":"2022-11-06T02:28:51.812633Z","shell.execute_reply.started":"2022-11-06T02:28:51.774637Z","shell.execute_reply":"2022-11-06T02:28:51.811034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'ENSG00000066044' in list_genes_ids","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:51.814821Z","iopub.execute_input":"2022-11-06T02:28:51.815436Z","iopub.status.idle":"2022-11-06T02:28:51.827511Z","shell.execute_reply.started":"2022-11-06T02:28:51.815387Z","shell.execute_reply":"2022-11-06T02:28:51.826088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_new = pd.DataFrame()\ndf_new['CD33_protein'] = df_cite_train_y['CD33']\n\nlist_ids = ['ENSG00000131043', 'ENSG00000115977', 'ENSG00000127837', 'ENSG00000281376', 'ENSG00000121410', 'ENSG00000129673', 'ENSG00000205002', 'ENSG00000124608', 'ENSG00000183044']\nlist_names = ['CD33', 'CD3', 'CD56', 'CD14', 'CD86', 'CD19', 'CD11c', 'CD45RA', 'CD16']\nfor i,id1 in enumerate(list_ids): \n    gene_name1 = list_names[i]\n    IX = list_genes_ids.index(id1)\n    print(IX, list_genes_ids[IX], list_genes_names[IX], df_cite_train_x.columns[IX] )\n    v =  df_cite_train_x.iloc[:, IX]\n    df_new[gene_name1 + '_RNA'] = v\n\n\ndisplay(df_new)\ndisplay(df_new.describe() )\ndisplay(df_new.corr() )","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:51.829950Z","iopub.execute_input":"2022-11-06T02:28:51.830803Z","iopub.status.idle":"2022-11-06T02:28:52.083141Z","shell.execute_reply.started":"2022-11-06T02:28:51.830757Z","shell.execute_reply":"2022-11-06T02:28:52.081582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_new.corr(method = 'spearman')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:52.084762Z","iopub.execute_input":"2022-11-06T02:28:52.085126Z","iopub.status.idle":"2022-11-06T02:28:52.177766Z","shell.execute_reply.started":"2022-11-06T02:28:52.085082Z","shell.execute_reply":"2022-11-06T02:28:52.176739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_new.corr(method = 'kendall')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:52.179218Z","iopub.execute_input":"2022-11-06T02:28:52.179796Z","iopub.status.idle":"2022-11-06T02:28:52.747444Z","shell.execute_reply.started":"2022-11-06T02:28:52.179760Z","shell.execute_reply":"2022-11-06T02:28:52.746212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(df_new['CD56_RNA'],df_new['CD33_RNA'])\n","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:52.749005Z","iopub.execute_input":"2022-11-06T02:28:52.749421Z","iopub.status.idle":"2022-11-06T02:28:53.785029Z","shell.execute_reply.started":"2022-11-06T02:28:52.749384Z","shell.execute_reply":"2022-11-06T02:28:53.783698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(df_new['CD33_RNA'],df_new['CD3_RNA'])\n","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:53.790578Z","iopub.execute_input":"2022-11-06T02:28:53.790992Z","iopub.status.idle":"2022-11-06T02:28:54.807039Z","shell.execute_reply.started":"2022-11-06T02:28:53.790958Z","shell.execute_reply":"2022-11-06T02:28:54.805880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Note this plot looks significantly different to the others\nplt.scatter(df_new['CD33_protein'],df_new['CD3_RNA'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:54.808837Z","iopub.execute_input":"2022-11-06T02:28:54.809259Z","iopub.status.idle":"2022-11-06T02:28:55.834074Z","shell.execute_reply.started":"2022-11-06T02:28:54.809206Z","shell.execute_reply":"2022-11-06T02:28:55.832883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(df_new['CD14_RNA'],df_new['CD3_RNA'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:55.835785Z","iopub.execute_input":"2022-11-06T02:28:55.836785Z","iopub.status.idle":"2022-11-06T02:28:56.844558Z","shell.execute_reply.started":"2022-11-06T02:28:55.836745Z","shell.execute_reply":"2022-11-06T02:28:56.843447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(df_new['CD14_RNA'],df_new['CD56_RNA'])\n","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:56.846527Z","iopub.execute_input":"2022-11-06T02:28:56.846912Z","iopub.status.idle":"2022-11-06T02:28:57.859586Z","shell.execute_reply.started":"2022-11-06T02:28:56.846878Z","shell.execute_reply":"2022-11-06T02:28:57.858321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nplt.scatter(df_new['CD33_protein'],df_new['CD14_RNA'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:57.861282Z","iopub.execute_input":"2022-11-06T02:28:57.862662Z","iopub.status.idle":"2022-11-06T02:28:58.877731Z","shell.execute_reply.started":"2022-11-06T02:28:57.862609Z","shell.execute_reply":"2022-11-06T02:28:58.876217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport seaborn as sns\nimport matplotlib.pyplot as plt\ncorr = df_new.corr()\nsns.heatmap(corr, \n            xticklabels=corr.columns.values,\n            yticklabels=corr.columns.values)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:58.878945Z","iopub.execute_input":"2022-11-06T02:28:58.879437Z","iopub.status.idle":"2022-11-06T02:28:59.430246Z","shell.execute_reply.started":"2022-11-06T02:28:58.879401Z","shell.execute_reply":"2022-11-06T02:28:59.429293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\n\nwarnings.simplefilter(\"ignore\", category=UserWarning)\nwarnings.simplefilter(\"ignore\", category=FutureWarning)\nwarnings.simplefilter(\"ignore\", category=DeprecationWarning)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:59.431643Z","iopub.execute_input":"2022-11-06T02:28:59.432268Z","iopub.status.idle":"2022-11-06T02:28:59.437937Z","shell.execute_reply.started":"2022-11-06T02:28:59.432230Z","shell.execute_reply":"2022-11-06T02:28:59.436710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafile = \"data/5k_pbmc_protein_v3_nextgem_filtered_feature_bc_matrix.h5\"","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:59.439491Z","iopub.execute_input":"2022-11-06T02:28:59.439877Z","iopub.status.idle":"2022-11-06T02:28:59.451005Z","shell.execute_reply.started":"2022-11-06T02:28:59.439841Z","shell.execute_reply":"2022-11-06T02:28:59.449885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install scanpy","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:28:59.452743Z","iopub.execute_input":"2022-11-06T02:28:59.453443Z","iopub.status.idle":"2022-11-06T02:29:11.578961Z","shell.execute_reply.started":"2022-11-06T02:28:59.453404Z","shell.execute_reply":"2022-11-06T02:29:11.577590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import h5py    \nimport numpy as np    \n","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:11.580626Z","iopub.execute_input":"2022-11-06T02:29:11.581159Z","iopub.status.idle":"2022-11-06T02:29:11.589470Z","shell.execute_reply.started":"2022-11-06T02:29:11.581083Z","shell.execute_reply":"2022-11-06T02:29:11.587544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install -q tables ","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:11.591342Z","iopub.execute_input":"2022-11-06T02:29:11.591835Z","iopub.status.idle":"2022-11-06T02:29:23.184066Z","shell.execute_reply.started":"2022-11-06T02:29:11.591801Z","shell.execute_reply":"2022-11-06T02:29:23.182064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafile = \"../input/open-problems-multimodal/train_multi_targets.h5\"","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:23.186688Z","iopub.execute_input":"2022-11-06T02:29:23.187281Z","iopub.status.idle":"2022-11-06T02:29:23.194673Z","shell.execute_reply.started":"2022-11-06T02:29:23.187223Z","shell.execute_reply":"2022-11-06T02:29:23.193666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" !mkdir -p data\n!wget http://cf.10xgenomics.com/samples/cell-exp/3.1.0/5k_pbmc_protein_v3_nextgem/5k_pbmc_protein_v3_nextgem_filtered_feature_bc_matrix.h5 -O data/5k_pbmc_protein_v3_nextgem_filtered_feature_bc_matrix.h5","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:23.197068Z","iopub.execute_input":"2022-11-06T02:29:23.197610Z","iopub.status.idle":"2022-11-06T02:29:25.980534Z","shell.execute_reply.started":"2022-11-06T02:29:23.197560Z","shell.execute_reply":"2022-11-06T02:29:25.979384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Thanks to Proteins/RNA Leidenalg & Scanpy-MARÍLIA PRATA notebook to help load the h5 datafile!","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:25.982030Z","iopub.execute_input":"2022-11-06T02:29:25.982465Z","iopub.status.idle":"2022-11-06T02:29:25.988894Z","shell.execute_reply.started":"2022-11-06T02:29:25.982425Z","shell.execute_reply":"2022-11-06T02:29:25.988035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datafile = \"data/5k_pbmc_protein_v3_nextgem_filtered_feature_bc_matrix.h5\"","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:25.989980Z","iopub.execute_input":"2022-11-06T02:29:25.990325Z","iopub.status.idle":"2022-11-06T02:29:26.005262Z","shell.execute_reply.started":"2022-11-06T02:29:25.990293Z","shell.execute_reply":"2022-11-06T02:29:26.004079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adata = sc.read_10x_h5(datafile, gex_only=False)\nadata.var_names_make_unique()\nadata.layers[\"counts\"] = adata.X.copy()\nsc.pp.filter_genes(adata, min_counts=1)\nadata","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:26.007291Z","iopub.execute_input":"2022-11-06T02:29:26.007667Z","iopub.status.idle":"2022-11-06T02:29:27.169985Z","shell.execute_reply.started":"2022-11-06T02:29:26.007635Z","shell.execute_reply":"2022-11-06T02:29:27.168570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.filter_cells(adata, min_genes=200)\nsc.pp.filter_genes(adata, min_cells=3)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:27.172266Z","iopub.execute_input":"2022-11-06T02:29:27.172816Z","iopub.status.idle":"2022-11-06T02:29:27.906877Z","shell.execute_reply.started":"2022-11-06T02:29:27.172766Z","shell.execute_reply":"2022-11-06T02:29:27.905618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adata.var['mt'] = adata.var_names.str.startswith('MT-')  # annotate the group of mitochondrial genes as 'mt'\nsc.pp.calculate_qc_metrics(adata, qc_vars=['mt'], percent_top=None, log1p=False, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:27.908308Z","iopub.execute_input":"2022-11-06T02:29:27.908656Z","iopub.status.idle":"2022-11-06T02:29:28.272797Z","shell.execute_reply.started":"2022-11-06T02:29:27.908625Z","shell.execute_reply":"2022-11-06T02:29:28.271601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adata = adata[adata.obs.n_genes_by_counts < 2500, :]\nadata = adata[adata.obs.pct_counts_mt < 5, :]","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:28.274537Z","iopub.execute_input":"2022-11-06T02:29:28.275052Z","iopub.status.idle":"2022-11-06T02:29:28.295672Z","shell.execute_reply.started":"2022-11-06T02:29:28.275002Z","shell.execute_reply":"2022-11-06T02:29:28.294595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.normalize_total(adata, target_sum=1e4)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:28.298339Z","iopub.execute_input":"2022-11-06T02:29:28.298891Z","iopub.status.idle":"2022-11-06T02:29:28.371192Z","shell.execute_reply.started":"2022-11-06T02:29:28.298840Z","shell.execute_reply":"2022-11-06T02:29:28.369870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.log1p(adata)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:28.373331Z","iopub.execute_input":"2022-11-06T02:29:28.374494Z","iopub.status.idle":"2022-11-06T02:29:28.437917Z","shell.execute_reply.started":"2022-11-06T02:29:28.374445Z","shell.execute_reply":"2022-11-06T02:29:28.436839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:28.439788Z","iopub.execute_input":"2022-11-06T02:29:28.440711Z","iopub.status.idle":"2022-11-06T02:29:30.134232Z","shell.execute_reply.started":"2022-11-06T02:29:28.440655Z","shell.execute_reply":"2022-11-06T02:29:30.132894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adata.raw = adata","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:30.136124Z","iopub.execute_input":"2022-11-06T02:29:30.137002Z","iopub.status.idle":"2022-11-06T02:29:30.152233Z","shell.execute_reply.started":"2022-11-06T02:29:30.136964Z","shell.execute_reply":"2022-11-06T02:29:30.151248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"adata = adata[:, adata.var.highly_variable]","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:30.153499Z","iopub.execute_input":"2022-11-06T02:29:30.154386Z","iopub.status.idle":"2022-11-06T02:29:30.172014Z","shell.execute_reply.started":"2022-11-06T02:29:30.154345Z","shell.execute_reply":"2022-11-06T02:29:30.170780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.regress_out(adata, ['total_counts', 'pct_counts_mt'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:30.179942Z","iopub.execute_input":"2022-11-06T02:29:30.181073Z","iopub.status.idle":"2022-11-06T02:29:39.710532Z","shell.execute_reply.started":"2022-11-06T02:29:30.181027Z","shell.execute_reply":"2022-11-06T02:29:39.709206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.scale(adata, max_value=10)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:39.712310Z","iopub.execute_input":"2022-11-06T02:29:39.712805Z","iopub.status.idle":"2022-11-06T02:29:39.754835Z","shell.execute_reply.started":"2022-11-06T02:29:39.712757Z","shell.execute_reply":"2022-11-06T02:29:39.753684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.pca(adata, svd_solver='arpack')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:39.756509Z","iopub.execute_input":"2022-11-06T02:29:39.756849Z","iopub.status.idle":"2022-11-06T02:29:40.591975Z","shell.execute_reply.started":"2022-11-06T02:29:39.756818Z","shell.execute_reply":"2022-11-06T02:29:40.589883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pp.neighbors(adata, n_neighbors=10, n_pcs=40)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:40.594542Z","iopub.execute_input":"2022-11-06T02:29:40.595416Z","iopub.status.idle":"2022-11-06T02:29:40.816859Z","shell.execute_reply.started":"2022-11-06T02:29:40.595352Z","shell.execute_reply":"2022-11-06T02:29:40.815417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip3 install leidenalg\n!pip install louvain","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.leiden(adata)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:40.818497Z","iopub.execute_input":"2022-11-06T02:29:40.818868Z","iopub.status.idle":"2022-11-06T02:29:40.935172Z","shell.execute_reply.started":"2022-11-06T02:29:40.818833Z","shell.execute_reply":"2022-11-06T02:29:40.933784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.umap(adata)\n","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:40.937544Z","iopub.execute_input":"2022-11-06T02:29:40.938071Z","iopub.status.idle":"2022-11-06T02:29:44.749065Z","shell.execute_reply.started":"2022-11-06T02:29:40.938021Z","shell.execute_reply":"2022-11-06T02:29:44.747706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.umap(adata, color=['PTPRC', 'CD3E', 'CD4', 'CD8A', 'CD14', 'PPBP', 'NKG7', 'CD79A'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:44.751046Z","iopub.execute_input":"2022-11-06T02:29:44.752459Z","iopub.status.idle":"2022-11-06T02:29:46.553336Z","shell.execute_reply.started":"2022-11-06T02:29:44.752402Z","shell.execute_reply":"2022-11-06T02:29:46.550379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.leiden(adata, key_added = \"leiden_1.0\") # default resolution in 1.0\nsc.tl.leiden(adata, resolution = 0.6, key_added = \"leiden_0.6\")\nsc.tl.leiden(adata, resolution = 0.4, key_added = \"leiden_0.4\")\nsc.tl.leiden(adata, resolution = 1.4, key_added = \"leiden_1.4\")","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:46.555379Z","iopub.execute_input":"2022-11-06T02:29:46.555797Z","iopub.status.idle":"2022-11-06T02:29:47.033689Z","shell.execute_reply.started":"2022-11-06T02:29:46.555757Z","shell.execute_reply":"2022-11-06T02:29:47.032305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.umap(adata, color=['leiden_0.4', 'leiden_0.6', 'leiden_1.0','leiden_1.4'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:47.035193Z","iopub.execute_input":"2022-11-06T02:29:47.035547Z","iopub.status.idle":"2022-11-06T02:29:48.454432Z","shell.execute_reply.started":"2022-11-06T02:29:47.035514Z","shell.execute_reply":"2022-11-06T02:29:48.453130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.paga(adata)\nsc.pl.paga(adata, plot=False)  # remove `plot=False` if you want to see the coarse-grained graph\nsc.tl.umap(adata, init_pos='paga')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:48.456622Z","iopub.execute_input":"2022-11-06T02:29:48.457067Z","iopub.status.idle":"2022-11-06T02:29:52.128687Z","shell.execute_reply.started":"2022-11-06T02:29:48.457028Z","shell.execute_reply":"2022-11-06T02:29:52.127608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install fa2","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:29:52.130260Z","iopub.execute_input":"2022-11-06T02:29:52.131255Z","iopub.status.idle":"2022-11-06T02:30:03.684033Z","shell.execute_reply.started":"2022-11-06T02:29:52.131210Z","shell.execute_reply":"2022-11-06T02:30:03.682474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport scanpy as sc\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:03.686487Z","iopub.execute_input":"2022-11-06T02:30:03.687059Z","iopub.status.idle":"2022-11-06T02:30:03.694619Z","shell.execute_reply.started":"2022-11-06T02:30:03.686999Z","shell.execute_reply":"2022-11-06T02:30:03.693647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.dendrogram(adata, groupby = \"leiden_0.6\")\nsc.pl.dendrogram(adata, groupby = \"leiden_0.6\")\n\ngenes  = [\"CD3E\", \"CD4\", \"CD8A\", \"GNLY\",\"NKG7\", \"MS4A1\", \"CD38\", \"CD19\", \"FCGR3A\",\"CD14\",\"LYZ\",\"CST3\",\"MS4A7\",\"FCGR1A\", \"PPBP\", \"IL7R\",\"FOXP3\"]\nsc.pl.dotplot(adata, genes, groupby='leiden_0.6', dendrogram=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:27.149402Z","iopub.execute_input":"2022-11-06T02:30:27.149866Z","iopub.status.idle":"2022-11-06T02:30:28.140847Z","shell.execute_reply.started":"2022-11-06T02:30:27.149822Z","shell.execute_reply":"2022-11-06T02:30:28.139833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.leiden(adata, key_added='clusters', resolution=0.6)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:28.142683Z","iopub.execute_input":"2022-11-06T02:30:28.143468Z","iopub.status.idle":"2022-11-06T02:30:28.252442Z","shell.execute_reply.started":"2022-11-06T02:30:28.143428Z","shell.execute_reply":"2022-11-06T02:30:28.251341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.umap(adata, color='clusters', add_outline=True, legend_loc='on data',\n               legend_fontsize=12, legend_fontoutline=2,frameon=False,\n               title='clustering of cells', palette='Set1')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:28.254327Z","iopub.execute_input":"2022-11-06T02:30:28.254761Z","iopub.status.idle":"2022-11-06T02:30:28.562959Z","shell.execute_reply.started":"2022-11-06T02:30:28.254723Z","shell.execute_reply":"2022-11-06T02:30:28.561587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"marker_genes_dict = {\n    'B-cell': ['CD79A', 'MS4A1', 'CD38'],\n    'Dendritic': ['FCER1A', 'CST3'],\n    'Monocytes': ['CD14'],\n    'NK': ['GNLY', 'NKG7', 'FCGR3A'],\n    'CD8 T cell': ['CD8A'],\n    'CD4 T cell': ['CD4'],\n    'T-cell': ['CD3D'],\n   \n}","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:28.565089Z","iopub.execute_input":"2022-11-06T02:30:28.565512Z","iopub.status.idle":"2022-11-06T02:30:28.572480Z","shell.execute_reply.started":"2022-11-06T02:30:28.565474Z","shell.execute_reply":"2022-11-06T02:30:28.571035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.dotplot(adata, marker_genes_dict, 'clusters', dendrogram=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:28.574391Z","iopub.execute_input":"2022-11-06T02:30:28.574813Z","iopub.status.idle":"2022-11-06T02:30:29.274632Z","shell.execute_reply.started":"2022-11-06T02:30:28.574768Z","shell.execute_reply":"2022-11-06T02:30:29.273710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.tl.paga(adata, groups='leiden')","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:29.276406Z","iopub.execute_input":"2022-11-06T02:30:29.277078Z","iopub.status.idle":"2022-11-06T02:30:29.352592Z","shell.execute_reply.started":"2022-11-06T02:30:29.277038Z","shell.execute_reply":"2022-11-06T02:30:29.351683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#CD34 is a marker of stem cells- absent/minor expression of this marker\nsc.pl.paga(adata, color=['leiden', 'CD34'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:29.354253Z","iopub.execute_input":"2022-11-06T02:30:29.354857Z","iopub.status.idle":"2022-11-06T02:30:29.945484Z","shell.execute_reply.started":"2022-11-06T02:30:29.354819Z","shell.execute_reply":"2022-11-06T02:30:29.944293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#MKP markers, ITGA2B expressed early at points 0, 1 and PLEK later at 4,5 and increasd expression at 6\nsc.pl.paga(adata, color=['ITGA2B', 'PLEK'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:29.946989Z","iopub.execute_input":"2022-11-06T02:30:29.947369Z","iopub.status.idle":"2022-11-06T02:30:31.578850Z","shell.execute_reply.started":"2022-11-06T02:30:29.947333Z","shell.execute_reply":"2022-11-06T02:30:31.577582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#NeuP Markers expressed at stages 3, 4 and 5\nsc.pl.paga(adata, color=['CSTA', 'LYZ'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:31.580604Z","iopub.execute_input":"2022-11-06T02:30:31.580979Z","iopub.status.idle":"2022-11-06T02:30:32.317602Z","shell.execute_reply.started":"2022-11-06T02:30:31.580947Z","shell.execute_reply":"2022-11-06T02:30:32.316279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#MoP\nsc.pl.paga(adata, color=['SCT', 'LGMN'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:32.319228Z","iopub.execute_input":"2022-11-06T02:30:32.319593Z","iopub.status.idle":"2022-11-06T02:30:33.031893Z","shell.execute_reply.started":"2022-11-06T02:30:32.319561Z","shell.execute_reply":"2022-11-06T02:30:33.030465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#ERyP\nsc.pl.paga(adata, color=['HBB', 'LMNA'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:33.033654Z","iopub.execute_input":"2022-11-06T02:30:33.034050Z","iopub.status.idle":"2022-11-06T02:30:33.760576Z","shell.execute_reply.started":"2022-11-06T02:30:33.034013Z","shell.execute_reply":"2022-11-06T02:30:33.759404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#BP \nsc.pl.paga(adata, color=['DNTT', 'CD79A'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:33.762265Z","iopub.execute_input":"2022-11-06T02:30:33.763242Z","iopub.status.idle":"2022-11-06T02:30:34.493722Z","shell.execute_reply.started":"2022-11-06T02:30:33.763191Z","shell.execute_reply":"2022-11-06T02:30:34.492416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.paga(adata, color=['CD14', 'FCGR3A'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:34.495723Z","iopub.execute_input":"2022-11-06T02:30:34.496098Z","iopub.status.idle":"2022-11-06T02:30:35.226782Z","shell.execute_reply.started":"2022-11-06T02:30:34.496064Z","shell.execute_reply":"2022-11-06T02:30:35.225336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.paga(adata, color=['CD3E', 'CD4'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:35.228287Z","iopub.execute_input":"2022-11-06T02:30:35.228673Z","iopub.status.idle":"2022-11-06T02:30:35.950496Z","shell.execute_reply.started":"2022-11-06T02:30:35.228638Z","shell.execute_reply":"2022-11-06T02:30:35.949330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.paga(adata, color=['CD8A', 'NKG7'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:35.951860Z","iopub.execute_input":"2022-11-06T02:30:35.952302Z","iopub.status.idle":"2022-11-06T02:30:36.668060Z","shell.execute_reply.started":"2022-11-06T02:30:35.952228Z","shell.execute_reply":"2022-11-06T02:30:36.666673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sc.pl.paga(adata, color=['CD38', 'MS4A1'])","metadata":{"execution":{"iopub.status.busy":"2022-11-06T02:30:36.670357Z","iopub.execute_input":"2022-11-06T02:30:36.670765Z","iopub.status.idle":"2022-11-06T02:30:37.416870Z","shell.execute_reply.started":"2022-11-06T02:30:36.670724Z","shell.execute_reply":"2022-11-06T02:30:37.415422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#The following trajectory maps show the expression of markers during a trajectory. There is little expression of the HSC (stem cell) marker CD34,\n#however the developing lymphocytes marker DNTT is expressed at point 0,  MKP marker ITGA2B is expressed at point 1 followed by, EryP marker LMNA, then NeuP markers \n#and the classical monocytic CD14 marker at 3,4,5 then followed by\n#CD8 and NK cell expression at point 6. B cell markers CD79a and MS4A1 are on at 7 and 9 away from the other populations.\n#The development of markers does make logical sense along this trajectory with more of the 'progenitor' type\n#cell markers being expressed 0,1,2 and as they become more differentiated into specific lineages like Cd14 monocytes\n#or CD8 T cells then there are at nodes 3,4,5 and 7 and 9 for the B cells expressing CD79a and MS4A1.\n","metadata":{},"execution_count":null,"outputs":[]}]}