{"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\nPrecalculated mutual information for CD proteins  and RNA, loaded and saved in more suitable format.\n\nResults stored to: https://www.kaggle.com/datasets/alexandervc/research-project-01-around-multimodal-singlecell?select=FeatureImportancesFormatOneFileAllCD\n\nCalculation of the mutual information was done by Andrei Lange using package \nhttps://github.com/jundongl/scikit-feature,\nhttps://jundongl.github.io/scikit-feature/\n\n\nSome analysis is also done.\n\nData in file #fn = '/kaggle/input/nips22-mutual-information/22050x140_round001_mutual_CD.csv'\nseems a bit strange - the order of top related rna seems to be almost the same for all CDs that is strange. \nAlso that data are less consitent with LGB importances. \nWe do not plan to use it further.\n\n","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 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":"2023-01-25T21:50:45.413403Z","iopub.execute_input":"2023-01-25T21:50:45.413846Z","iopub.status.idle":"2023-01-25T21:50:45.479909Z","shell.execute_reply.started":"2023-01-25T21:50:45.413809Z","shell.execute_reply":"2023-01-25T21:50:45.478677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fn = '/kaggle/input/nips22-mutual-information/22050x140_round01_mutual_CD.csv'\n#fn = '/kaggle/input/nips22-mutual-information/22050x140_round001_mutual_CD.csv'","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:31:11.649069Z","iopub.execute_input":"2023-01-25T22:31:11.649533Z","iopub.status.idle":"2023-01-25T22:31:11.655229Z","shell.execute_reply.started":"2023-01-25T22:31:11.649496Z","shell.execute_reply":"2023-01-25T22:31:11.653816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ndf = pd.read_csv(fn, index_col = 0)\ndf","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:31:15.093731Z","iopub.execute_input":"2023-01-25T22:31:15.094706Z","iopub.status.idle":"2023-01-25T22:31:18.293778Z","shell.execute_reply.started":"2023-01-25T22:31:15.094652Z","shell.execute_reply":"2023-01-25T22:31:18.292373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(20)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:31:18.295517Z","iopub.execute_input":"2023-01-25T22:31:18.295847Z","iopub.status.idle":"2023-01-25T22:31:18.333947Z","shell.execute_reply.started":"2023-01-25T22:31:18.295817Z","shell.execute_reply":"2023-01-25T22:31:18.332723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nfilename_rna_data = '/kaggle/input/open-problems-multimodal/train_cite_inputs.h5'\ndf_rna = pd.read_hdf(filename_rna_data)\ndisplay(df_rna) ","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:03:44.901555Z","iopub.execute_input":"2023-01-25T22:03:44.901955Z","iopub.status.idle":"2023-01-25T22:04:40.265378Z","shell.execute_reply.started":"2023-01-25T22:03:44.901924Z","shell.execute_reply":"2023-01-25T22:04:40.264077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nimport time\nt0 = time.time()\n\ndf_res = pd.DataFrame(index = df_rna.columns)\n\nfor i0,col in enumerate(df.columns):\n    if (i0%20==0):\n        print(i0, col)\n    sr = df[col]\n    l1 = []; l2 = []\n    for i in range(len(sr)):\n        t = sr.iat[i]\n        s1 =  t.replace(\"('\",\"\").replace(\")\",\"\").split(',')[0].replace(\"'\",\"\")\n        s2 =  float( t.replace(\"('\",\"\").replace(\")\",\"\").split(',')[1] )\n        l1.append(s1); l2.append(s2)\n    sr2 = pd.Series(index = l1, data = l2)\n    sr2.name = col\n    df_res = df_res.join(sr2)\n    #break\ndf_res","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:31:32.839893Z","iopub.execute_input":"2023-01-25T22:31:32.840395Z","iopub.status.idle":"2023-01-25T22:31:51.943745Z","shell.execute_reply.started":"2023-01-25T22:31:32.840355Z","shell.execute_reply":"2023-01-25T22:31:51.942386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Save Results","metadata":{}},{"cell_type":"code","source":"%%time\nif fn == '/kaggle/input/nips22-mutual-information/22050x140_round01_mutual_CD.csv':\n    fn4save = 'NIPS22_importances_univariable_MutualInfSkfeatureRound01.csv'\nelif fn == '/kaggle/input/nips22-mutual-information/22050x140_round001_mutual_CD.csv':\n    fn4save = 'NIPS22_importances_univariable_MutualInfSkfeatureRound001.csv'\nprint(fn4save)\ndisplay(df_res.info())\ndf_res.to_csv(fn4save)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:34:41.720717Z","iopub.execute_input":"2023-01-25T22:34:41.721171Z","iopub.status.idle":"2023-01-25T22:34:46.605555Z","shell.execute_reply.started":"2023-01-25T22:34:41.721132Z","shell.execute_reply":"2023-01-25T22:34:46.604378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analysis","metadata":{}},{"cell_type":"code","source":"d = df_res.describe()\nd","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:33:45.954894Z","iopub.execute_input":"2023-01-25T22:33:45.955429Z","iopub.status.idle":"2023-01-25T22:33:46.467152Z","shell.execute_reply.started":"2023-01-25T22:33:45.955390Z","shell.execute_reply":"2023-01-25T22:33:46.465722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.hist(d.T['max'], bins = 20)\nplt.grid()\nplt.title('Top Mutual Info for All CD')\nplt.show()\nd.T['max'].describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:33:47.585638Z","iopub.execute_input":"2023-01-25T22:33:47.586036Z","iopub.status.idle":"2023-01-25T22:33:47.849506Z","shell.execute_reply.started":"2023-01-25T22:33:47.586005Z","shell.execute_reply":"2023-01-25T22:33:47.848599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"l = []\nfor col in d.T['max'].sort_values(ascending = False).index:\n    sr = df_res[col]\n    sr = sr.sort_values(ascending = False)\n    print(col, sr.index[0], sr.iat[0],'   ', sr.index[1], sr.iat[1],'   ', sr.index[2], sr.iat[2])\n    l.append(sr.index[0])\nprint()\npd.Series(l).value_counts().head(50)    ","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:33:51.270347Z","iopub.execute_input":"2023-01-25T22:33:51.271573Z","iopub.status.idle":"2023-01-25T22:33:51.802997Z","shell.execute_reply.started":"2023-01-25T22:33:51.271531Z","shell.execute_reply":"2023-01-25T22:33:51.801824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d.T['max'].sort_values(ascending = False).head(50)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:34:06.242966Z","iopub.execute_input":"2023-01-25T22:34:06.243550Z","iopub.status.idle":"2023-01-25T22:34:06.255129Z","shell.execute_reply.started":"2023-01-25T22:34:06.243503Z","shell.execute_reply":"2023-01-25T22:34:06.253863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nsns.clustermap(df_res.corr() )","metadata":{"execution":{"iopub.status.busy":"2023-01-25T22:34:08.803540Z","iopub.execute_input":"2023-01-25T22:34:08.804473Z","iopub.status.idle":"2023-01-25T22:34:11.100585Z","shell.execute_reply.started":"2023-01-25T22:34:08.804433Z","shell.execute_reply":"2023-01-25T22:34:11.099031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}