{"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":"# What is about ?\n\nSimple script to load CITE-seq part of the Kaggle competition dataset\non Single Cell multimodal data: \nhttps://www.kaggle.com/competitions/open-problems-multimodal\n\n\nLook on some genes, correlations, expressions\n\n\n### Versions\n\n\n#### 1  transcription factor tcf7l2  with s100A4,6 , CD36 - no much correlation\n\nMotivated by:\n\nкак минимум одна некальциевая опция: \n\nэкспрессия s100a4 зависит от бета-катенина, This review focuses on our studies of the metastasis-inducing gene S100A4, which we identified as transcriptional target of β-catenin.\n\nhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC4931624/\n\nактивация cd36 повышает уровень бета-катенина\n\nAs shown in Figure 6A, compared with control cells, SNU-216 cells transfected with siCD36 exhibited a dramatic increase in both GSK-3β and p-β-catenin protein expression concurrently with a significant decrease in both p-Ser9-GSK-3β and β-catenin levels.\n\nhttps://www.aging-us.com/article/103985/text\n\n-----\n\nWhy CD36 and s100A4 are related: \n\nhttps://www.biostars.org/p/9549070/\n\nhttps://www.kaggle.com/datasets/alexandervc/research-project-01-around-multimodal-singlecell/discussion/370403?sort=recent-comments\n\n","metadata":{}},{"cell_type":"markdown","source":"# Preparations","metadata":{}},{"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 time\nt0start = time.time()\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":{"execution":{"iopub.status.busy":"2022-12-24T21:21:19.652956Z","iopub.execute_input":"2022-12-24T21:21:19.653370Z","iopub.status.idle":"2022-12-24T21:21:19.662936Z","shell.execute_reply.started":"2022-12-24T21:21:19.653339Z","shell.execute_reply":"2022-12-24T21:21:19.662042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#If you see a urllib warning running this cell, go to \"Settings\" on the right hand side, \n#and turn on internet. Note, you need to be phone verified.\n!pip install --quiet tables","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:21:20.441951Z","iopub.execute_input":"2022-12-24T21:21:20.442315Z","iopub.status.idle":"2022-12-24T21:21:31.367275Z","shell.execute_reply.started":"2022-12-24T21:21:20.442287Z","shell.execute_reply":"2022-12-24T21:21:31.365986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load data for targets -  140  CD (Cluster of differentiation) proteins \n\nhttps://en.wikipedia.org/wiki/Cluster_of_differentiation\n","metadata":{}},{"cell_type":"code","source":"%%time\ndf_y = pd.read_hdf('/kaggle/input/open-problems-multimodal/train_cite_targets.h5')\ndf_y","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:21:31.369339Z","iopub.execute_input":"2022-12-24T21:21:31.369748Z","iopub.status.idle":"2022-12-24T21:21:32.069558Z","shell.execute_reply.started":"2022-12-24T21:21:31.369708Z","shell.execute_reply":"2022-12-24T21:21:32.068625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load features - RNA expression data \n","metadata":{}},{"cell_type":"code","source":"%%time\ndf_rna = pd.read_hdf('/kaggle/input/open-problems-multimodal/train_cite_inputs.h5')\ndisplay(df_rna) \n","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:21:32.070732Z","iopub.execute_input":"2022-12-24T21:21:32.072062Z","iopub.status.idle":"2022-12-24T21:22:11.622830Z","shell.execute_reply.started":"2022-12-24T21:21:32.071996Z","shell.execute_reply":"2022-12-24T21:22:11.621303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Auxilliary meta data - not necessary for predictions","metadata":{}},{"cell_type":"code","source":"fn = '/kaggle/input/open-problems-multimodal/metadata.csv'\ndf_meta = pd.read_csv(fn, index_col = 0 )\ndf_meta","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:22:11.625207Z","iopub.execute_input":"2022-12-24T21:22:11.625540Z","iopub.status.idle":"2022-12-24T21:22:11.998563Z","shell.execute_reply.started":"2022-12-24T21:22:11.625514Z","shell.execute_reply":"2022-12-24T21:22:11.997622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Keep meta data only relevant for train part of the CITE-seq data \ndf_meta = pd.DataFrame(index = df_y.index ).join(df_meta, how = 'left' )\ndf_meta","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:22:11.999671Z","iopub.execute_input":"2022-12-24T21:22:11.999947Z","iopub.status.idle":"2022-12-24T21:22:12.090724Z","shell.execute_reply.started":"2022-12-24T21:22:11.999923Z","shell.execute_reply":"2022-12-24T21:22:12.089698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Selected correlations","metadata":{}},{"cell_type":"code","source":"list_genes_symbols = [t.split('_')[1] for t in df_rna.columns ]\nlist_genes_symbols[:3]","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:22:45.238211Z","iopub.execute_input":"2022-12-24T21:22:45.238568Z","iopub.status.idle":"2022-12-24T21:22:45.253452Z","shell.execute_reply.started":"2022-12-24T21:22:45.238539Z","shell.execute_reply":"2022-12-24T21:22:45.251842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'TCF7L2' in list_genes_symbols","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:23:37.688246Z","iopub.execute_input":"2022-12-24T21:23:37.688587Z","iopub.status.idle":"2022-12-24T21:23:37.696633Z","shell.execute_reply.started":"2022-12-24T21:23:37.688561Z","shell.execute_reply":"2022-12-24T21:23:37.695256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"I = list_genes_symbols.index( 'TCF7L2' )\nv1 = df_rna.iloc[:,I]\nl = []\nfor i in range(1000):\n    v2 = np.random.randn(len(v1))\n    c = np.corrcoef(v1,v2)[0,1]\n    l.append(c)\n    #print( c , v1.sum(), v2.sum() )\nnp.std(l),3*np.std(l), np.mean(l)    ","metadata":{"execution":{"iopub.status.busy":"2022-12-24T22:06:08.546810Z","iopub.execute_input":"2022-12-24T22:06:08.547243Z","iopub.status.idle":"2022-12-24T22:06:10.538513Z","shell.execute_reply.started":"2022-12-24T22:06:08.547209Z","shell.execute_reply":"2022-12-24T22:06:10.537540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"I = list_genes_symbols.index( 'TCF7L2' )\nv1 = df_rna.iloc[:,I]\nv2 = df_y['CD36']\nprint( np.corrcoef(v1,v2)[0,1], v1.sum(), v2.sum() )\n\nI = list_genes_symbols.index( 'TCF7L2' )\nv1 = df_rna.iloc[:,I]\nI = list_genes_symbols.index( 'S100A4' )\nv2 = df_rna.iloc[:,I]\nprint( np.corrcoef(v1,v2)[0,1], v1.sum(), v2.sum() )\n\nI = list_genes_symbols.index( 'TCF7L2' )\nv1 = df_rna.iloc[:,I]\nI = list_genes_symbols.index( 'S100A6' )\nv2 = df_rna.iloc[:,I]\nprint( np.corrcoef(v1,v2)[0,1], v1.sum(), v2.sum() )","metadata":{"execution":{"iopub.status.busy":"2022-12-24T22:04:02.366182Z","iopub.execute_input":"2022-12-24T22:04:02.366802Z","iopub.status.idle":"2022-12-24T22:04:02.382157Z","shell.execute_reply.started":"2022-12-24T22:04:02.366764Z","shell.execute_reply":"2022-12-24T22:04:02.380576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"I = list_genes_symbols.index( 'S100A4' )\nv1 = df_rna.iloc[:,I]\nv2 = df_y['CD36']\nprint( np.corrcoef(v1,v2)[0,1], v1.sum(), v2.sum() )\n","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:30:10.497246Z","iopub.execute_input":"2022-12-24T21:30:10.497583Z","iopub.status.idle":"2022-12-24T21:30:10.506092Z","shell.execute_reply.started":"2022-12-24T21:30:10.497559Z","shell.execute_reply":"2022-12-24T21:30:10.505163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2 = df_meta.copy()\nfor c in ['TCF7L2', 'S100A4',  'S100A6' , 'CD36' ]:\n    I = list_genes_symbols.index( c)\n    v1 = df_rna.iloc[:,I]\n    df2[c] = v1\n\nfor c in [ 'CD36' ]:\n    df2[c + '_protein'] = df_y[c]\n    \ndf2.groupby('cell_type').mean()","metadata":{"execution":{"iopub.status.busy":"2022-12-24T22:17:04.295198Z","iopub.execute_input":"2022-12-24T22:17:04.295545Z","iopub.status.idle":"2022-12-24T22:17:04.350748Z","shell.execute_reply.started":"2022-12-24T22:17:04.295518Z","shell.execute_reply":"2022-12-24T22:17:04.349220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t = time.time()-t0start\nprint('%.1f hours  = %.1f minutes = %.1f seconds passed total '%( t/3600,t/60, t ) )","metadata":{"execution":{"iopub.status.busy":"2022-12-24T21:31:44.178026Z","iopub.execute_input":"2022-12-24T21:31:44.178454Z","iopub.status.idle":"2022-12-24T21:31:44.186448Z","shell.execute_reply.started":"2022-12-24T21:31:44.178419Z","shell.execute_reply":"2022-12-24T21:31:44.184749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}