{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":51294,"databundleVersionId":6923401,"sourceType":"competition"},{"sourceId":6822004,"sourceType":"datasetVersion","datasetId":3719560}],"dockerImageVersionId":30579,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"https://www.kaggle.com/code/alexandervc/dna-language-models/notebook","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"https://www.kaggle.com/code/alexandervc/ribonanza-1-eda?scriptVersionId=142749227","metadata":{}},{"cell_type":"markdown","source":"https://www.kaggle.com/code/alexandervc/ribonanza-1-eda/notebook?scriptVersionId=144103296","metadata":{}},{"cell_type":"code","source":"import warnings\nwarnings.simplefilter('ignore')\n\nimport pandas as pd\npd.set_option('display.max_columns', 30)","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:33:38.826477Z","iopub.execute_input":"2023-11-17T11:33:38.826953Z","iopub.status.idle":"2023-11-17T11:33:39.305446Z","shell.execute_reply.started":"2023-11-17T11:33:38.826915Z","shell.execute_reply":"2023-11-17T11:33:39.304122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/stanford-ribonanza-rna-folding/sample_submission.csv')\nsample_submission.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:33:39.307822Z","iopub.execute_input":"2023-11-17T11:33:39.308354Z","iopub.status.idle":"2023-11-17T11:35:35.206297Z","shell.execute_reply.started":"2023-11-17T11:33:39.308319Z","shell.execute_reply":"2023-11-17T11:35:35.204921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_parquet('/kaggle/input/stanford-ribonanza-rna-folding-converted/test_sequences.parquet')\ntest.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:35:35.207900Z","iopub.execute_input":"2023-11-17T11:35:35.208323Z","iopub.status.idle":"2023-11-17T11:35:40.390467Z","shell.execute_reply.started":"2023-11-17T11:35:35.208287Z","shell.execute_reply":"2023-11-17T11:35:40.389281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_parquet('/kaggle/input/stanford-ribonanza-rna-folding-converted/train_data.parquet')\ntrain","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:35:40.393607Z","iopub.execute_input":"2023-11-17T11:35:40.394028Z","iopub.status.idle":"2023-11-17T11:36:12.195483Z","shell.execute_reply.started":"2023-11-17T11:35:40.393991Z","shell.execute_reply":"2023-11-17T11:36:12.191102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.experiment_type.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:12.202632Z","iopub.execute_input":"2023-11-17T11:36:12.204283Z","iopub.status.idle":"2023-11-17T11:36:12.703742Z","shell.execute_reply.started":"2023-11-17T11:36:12.204118Z","shell.execute_reply":"2023-11-17T11:36:12.699573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(set(train.sequence))","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:12.710479Z","iopub.execute_input":"2023-11-17T11:36:12.711262Z","iopub.status.idle":"2023-11-17T11:36:14.441000Z","shell.execute_reply.started":"2023-11-17T11:36:12.711212Z","shell.execute_reply":"2023-11-17T11:36:14.439452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.SN_filter.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:14.443047Z","iopub.execute_input":"2023-11-17T11:36:14.443548Z","iopub.status.idle":"2023-11-17T11:36:14.484215Z","shell.execute_reply.started":"2023-11-17T11:36:14.443502Z","shell.execute_reply":"2023-11-17T11:36:14.482663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nSN_filter_1 = train.SN_filter == 1\nexperiment_type_2A3_MaP = train.experiment_type == '2A3_MaP'\n\ny = train[SN_filter_1 & experiment_type_2A3_MaP].iloc[:, 33:137].quantile(0.4, axis=0)\ny = y.round(3)\nprint('2A3_MaP')\nprint(f'Y.values:\\n\\n{y.values}')\n\nplt.figure(figsize=(20, 4))\nplt.plot(y.values, '*-', color='deeppink')\nplt.title('2A3', fontsize=20)\n\nplt.show()\nprint(80 * '=')\n\nexperiment_type_DMS_MaP = train.experiment_type == 'DMS_MaP'\n\ny = train[SN_filter_1 & experiment_type_DMS_MaP].iloc[:, 33:137].quantile(0.4, axis=0)\ny = y.round(3)\nprint('DMS_MaP')\nprint(f'Y.values:\\n\\n{y.values}')\n\nplt.figure(figsize=(20, 4))\nplt.plot(y.values, '*-', color='cyan')\nplt.title('DMS', fontsize=20)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:14.486299Z","iopub.execute_input":"2023-11-17T11:36:14.487248Z","iopub.status.idle":"2023-11-17T11:36:18.386172Z","shell.execute_reply.started":"2023-11-17T11:36:14.487202Z","shell.execute_reply":"2023-11-17T11:36:18.384592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sequence_lengths_test = [len(sequence) for sequence in test.sequence]\npd.Series(sequence_lengths_test).value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:18.388042Z","iopub.execute_input":"2023-11-17T11:36:18.388484Z","iopub.status.idle":"2023-11-17T11:36:19.656991Z","shell.execute_reply.started":"2023-11-17T11:36:18.388447Z","shell.execute_reply":"2023-11-17T11:36:19.655530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(sequence_lengths_test) - 1):\n    \n    if sequence_lengths_test[i] != sequence_lengths_test[i + 1]:\n        \n        print(f'I: {i}')\n        print(f'SEQUENCE_LENGTHS_TEST[I]: {sequence_lengths_test[i]}')\n        print(f'SEQUENCE_LENGTHS_TEST[I + 1]: {sequence_lengths_test[i + 1]}')\n        print(30 * '=')","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:19.661133Z","iopub.execute_input":"2023-11-17T11:36:19.661554Z","iopub.status.idle":"2023-11-17T11:36:20.069580Z","shell.execute_reply.started":"2023-11-17T11:36:19.661517Z","shell.execute_reply":"2023-11-17T11:36:20.067992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\nreactivity_0001_0177 = [f'reactivity_{i:04d}' for i in range(1, 178)]\nprint(f'reactivity_0001_0177[:2]: {reactivity_0001_0177[:2]}')\nprint(30 * '=')\n\ny = train[SN_filter_1 & experiment_type_2A3_MaP][reactivity_0001_0177].quantile(0.4, axis=0).fillna(0)\ny[y < 0] = 0\ny[y > 0.35] = 0.35\ny = np.round(y.values, 3)\n\nprint('2A3_MaP')\nprint(f'Y:\\n\\n{list(y)}')\n\nplt.figure(figsize=(20, 4))\nplt.plot(y, '*-', color='red')\nplt.title('2A3', fontsize=20)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:20.071187Z","iopub.execute_input":"2023-11-17T11:36:20.071610Z","iopub.status.idle":"2023-11-17T11:36:21.472755Z","shell.execute_reply.started":"2023-11-17T11:36:20.071578Z","shell.execute_reply":"2023-11-17T11:36:21.471381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_2A3_pred = np.zeros((335823, 177), dtype=np.float16)\nY_2A3_pred[:3, 25:28]","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:21.474760Z","iopub.execute_input":"2023-11-17T11:36:21.475286Z","iopub.status.idle":"2023-11-17T11:36:21.484353Z","shell.execute_reply.started":"2023-11-17T11:36:21.475244Z","shell.execute_reply":"2023-11-17T11:36:21.482995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_2A3_pred += y[np.newaxis, :]\nY_2A3_pred[:3, 25:28]","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:21.485908Z","iopub.execute_input":"2023-11-17T11:36:21.486239Z","iopub.status.idle":"2023-11-17T11:36:22.472764Z","shell.execute_reply.started":"2023-11-17T11:36:21.486211Z","shell.execute_reply":"2023-11-17T11:36:22.471431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train[SN_filter_1 & experiment_type_DMS_MaP][reactivity_0001_0177].quantile(0.4, axis=0).fillna(0)\ny[y < 0] = 0\ny[y > 0.35] = 0.35\ny = np.round(y.values, 3)\n\nprint('DMS_MaP')\nprint(f'Y:\\n\\n{list(y)}')\n\nplt.figure(figsize=(20, 4))\nplt.plot(y, '*-', color='lime')\nplt.title('DMS', fontsize=20)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:22.474579Z","iopub.execute_input":"2023-11-17T11:36:22.475083Z","iopub.status.idle":"2023-11-17T11:36:23.775192Z","shell.execute_reply.started":"2023-11-17T11:36:22.475013Z","shell.execute_reply":"2023-11-17T11:36:23.773937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_DMS_pred = np.zeros((335823, 177), dtype=np.float16)\nY_DMS_pred[:3, 25:28]","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:23.776650Z","iopub.execute_input":"2023-11-17T11:36:23.777111Z","iopub.status.idle":"2023-11-17T11:36:23.787708Z","shell.execute_reply.started":"2023-11-17T11:36:23.777049Z","shell.execute_reply":"2023-11-17T11:36:23.786216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_DMS_pred += y[np.newaxis, :]\nY_DMS_pred[:3, 25:28]","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:23.790293Z","iopub.execute_input":"2023-11-17T11:36:23.791169Z","iopub.status.idle":"2023-11-17T11:36:24.798330Z","shell.execute_reply.started":"2023-11-17T11:36:23.791118Z","shell.execute_reply":"2023-11-17T11:36:24.796692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"N = 269796671\n\nsubmit = pd.DataFrame(index=range(N))\nsubmit.index.name = 'id'\n\nsubmit['reactivity_DMS_MaP'] = np.zeros(N, dtype=np.float16)\nsubmit['reactivity_2A3_MaP'] = np.zeros(N, dtype=np.float16)\n\nLEN_RAVEL = len(Y_2A3_pred.ravel())\nsubmit['reactivity_DMS_MaP'].iloc[:LEN_RAVEL] = Y_DMS_pred.ravel()\nsubmit['reactivity_2A3_MaP'].iloc[:LEN_RAVEL] = Y_2A3_pred.ravel()\n\nsubmit.iloc[30:35, :]","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:24.800445Z","iopub.execute_input":"2023-11-17T11:36:24.801002Z","iopub.status.idle":"2023-11-17T11:36:25.920730Z","shell.execute_reply.started":"2023-11-17T11:36:24.800952Z","shell.execute_reply":"2023-11-17T11:36:25.919195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.to_csv('submission.csv', float_format='%.3f')","metadata":{"execution":{"iopub.status.busy":"2023-11-17T11:36:25.922596Z","iopub.execute_input":"2023-11-17T11:36:25.922988Z","iopub.status.idle":"2023-11-17T12:17:55.169432Z","shell.execute_reply.started":"2023-11-17T11:36:25.922957Z","shell.execute_reply":"2023-11-17T12:17:55.166668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.read_csv('/kaggle/working/submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-11-17T12:17:55.172565Z","iopub.execute_input":"2023-11-17T12:17:55.173779Z","iopub.status.idle":"2023-11-17T12:20:05.024699Z","shell.execute_reply.started":"2023-11-17T12:17:55.173735Z","shell.execute_reply":"2023-11-17T12:20:05.023182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}