{"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":"# Summary\n\nFocusing only on gene_id, submit the average value of gene_id.\n\nIn this case, cell_id is not used.","metadata":{}},{"cell_type":"markdown","source":"# Data preparation\n\nI referred to [@peterholderrieth](https://www.kaggle.com/peterholderrieth)'s notebook. (https://www.kaggle.com/code/peterholderrieth/getting-started-data-loading)","metadata":{}},{"cell_type":"code","source":"!pip install --quiet tables","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:13.431506Z","iopub.execute_input":"2022-08-16T14:30:13.432376Z","iopub.status.idle":"2022-08-16T14:30:28.740086Z","shell.execute_reply.started":"2022-08-16T14:30:13.432228Z","shell.execute_reply":"2022-08-16T14:30:28.738508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:28.744161Z","iopub.execute_input":"2022-08-16T14:30:28.744565Z","iopub.status.idle":"2022-08-16T14:30:28.753117Z","shell.execute_reply.started":"2022-08-16T14:30:28.744530Z","shell.execute_reply":"2022-08-16T14:30:28.751989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir(\"/kaggle/input/open-problems-multimodal/\")","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:28.755807Z","iopub.execute_input":"2022-08-16T14:30:28.757021Z","iopub.status.idle":"2022-08-16T14:30:28.770043Z","shell.execute_reply.started":"2022-08-16T14:30:28.756968Z","shell.execute_reply":"2022-08-16T14:30:28.768830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = \"/kaggle/input/open-problems-multimodal/\"\n\nSUBMISSON = os.path.join(DATA_DIR,\"sample_submission.csv\")\n\nEVALUATION_IDS = os.path.join(DATA_DIR,\"evaluation_ids.csv\")\n\nFP_CELL_METADATA = os.path.join(DATA_DIR,\"metadata.csv\")\n\nFP_CITE_TRAIN_INPUTS = os.path.join(DATA_DIR,\"train_cite_inputs.h5\")\nFP_CITE_TRAIN_TARGETS = os.path.join(DATA_DIR,\"train_cite_targets.h5\")\nFP_CITE_TEST_INPUTS = os.path.join(DATA_DIR,\"test_cite_inputs.h5\")\n\nFP_MULTIOME_TRAIN_INPUTS = os.path.join(DATA_DIR,\"train_multi_inputs.h5\")\nFP_MULTIOME_TRAIN_TARGETS = os.path.join(DATA_DIR,\"train_multi_targets.h5\")\nFP_MULTIOME_TEST_INPUTS = os.path.join(DATA_DIR,\"test_multi_inputs.h5\")\n\nFP_SUBMISSION = os.path.join(DATA_DIR,\"sample_submission.csv\")\nFP_EVALUATION_IDS = os.path.join(DATA_DIR,\"evaluation_ids.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-16T14:30:28.773401Z","iopub.execute_input":"2022-08-16T14:30:28.773750Z","iopub.status.idle":"2022-08-16T14:30:28.781406Z","shell.execute_reply.started":"2022-08-16T14:30:28.773719Z","shell.execute_reply":"2022-08-16T14:30:28.780560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Citeseq","metadata":{"execution":{"iopub.status.busy":"2022-08-11T21:31:40.539251Z","iopub.execute_input":"2022-08-11T21:31:40.540195Z","iopub.status.idle":"2022-08-11T21:31:40.544877Z","shell.execute_reply.started":"2022-08-11T21:31:40.540149Z","shell.execute_reply":"2022-08-11T21:31:40.543637Z"}}},{"cell_type":"code","source":"df_cite_train_y = pd.read_hdf('../input/open-problems-multimodal/train_cite_targets.h5')\ndf_cite_train_y.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:28.782733Z","iopub.execute_input":"2022-08-16T14:30:28.783621Z","iopub.status.idle":"2022-08-16T14:30:29.643247Z","shell.execute_reply.started":"2022-08-16T14:30:28.783587Z","shell.execute_reply":"2022-08-16T14:30:29.642154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_gene_id_mean = df_cite_train_y.mean()\ncite_gene_id_mean","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:29.644497Z","iopub.execute_input":"2022-08-16T14:30:29.644797Z","iopub.status.idle":"2022-08-16T14:30:29.680976Z","shell.execute_reply.started":"2022-08-16T14:30:29.644772Z","shell.execute_reply":"2022-08-16T14:30:29.679593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Multiome","metadata":{}},{"cell_type":"code","source":"START = int(1e4)\nSTOP = START+10000","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:29.682755Z","iopub.execute_input":"2022-08-16T14:30:29.683307Z","iopub.status.idle":"2022-08-16T14:30:29.688705Z","shell.execute_reply.started":"2022-08-16T14:30:29.683270Z","shell.execute_reply":"2022-08-16T14:30:29.687461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_multi_train_y = pd.read_hdf(FP_MULTIOME_TRAIN_TARGETS, start=START, stop=STOP)\ndf_multi_train_y.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:29.690792Z","iopub.execute_input":"2022-08-16T14:30:29.691399Z","iopub.status.idle":"2022-08-16T14:30:38.176287Z","shell.execute_reply.started":"2022-08-16T14:30:29.691356Z","shell.execute_reply":"2022-08-16T14:30:38.175159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multi_gene_id_mean = df_multi_train_y.mean()\nmulti_gene_id_mean","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:38.177896Z","iopub.execute_input":"2022-08-16T14:30:38.178349Z","iopub.status.idle":"2022-08-16T14:30:38.762516Z","shell.execute_reply.started":"2022-08-16T14:30:38.178308Z","shell.execute_reply":"2022-08-16T14:30:38.761356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Convert gene_id to int (to save memory)","metadata":{}},{"cell_type":"code","source":"cite_gene_id_mean.index","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:38.766760Z","iopub.execute_input":"2022-08-16T14:30:38.767096Z","iopub.status.idle":"2022-08-16T14:30:38.774239Z","shell.execute_reply.started":"2022-08-16T14:30:38.767067Z","shell.execute_reply":"2022-08-16T14:30:38.773243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multi_gene_id_mean.index","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:38.775509Z","iopub.execute_input":"2022-08-16T14:30:38.776292Z","iopub.status.idle":"2022-08-16T14:30:38.789124Z","shell.execute_reply.started":"2022-08-16T14:30:38.776259Z","shell.execute_reply":"2022-08-16T14:30:38.788029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_ = list(cite_gene_id_mean.index) + list(multi_gene_id_mean.index)\ngene_id = pd.DataFrame(_, columns=['gene_id'])\ngene_id","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:38.790437Z","iopub.execute_input":"2022-08-16T14:30:38.790772Z","iopub.status.idle":"2022-08-16T14:30:38.811084Z","shell.execute_reply.started":"2022-08-16T14:30:38.790743Z","shell.execute_reply":"2022-08-16T14:30:38.809615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gene_id['gene_id_int'] = gene_id['gene_id'].apply(lambda x: int(x.replace('-', '').replace('.', '')[-8:],34)).astype(int)\ngene_id['gene_id_int'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:38.812697Z","iopub.execute_input":"2022-08-16T14:30:38.813082Z","iopub.status.idle":"2022-08-16T14:30:38.850458Z","shell.execute_reply.started":"2022-08-16T14:30:38.813050Z","shell.execute_reply":"2022-08-16T14:30:38.849370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Create submit file","metadata":{}},{"cell_type":"code","source":"df_sample_submission = pd.read_csv(SUBMISSON, usecols=['row_id'])\ndf_sample_submission.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:38.852040Z","iopub.execute_input":"2022-08-16T14:30:38.852684Z","iopub.status.idle":"2022-08-16T14:30:53.593150Z","shell.execute_reply.started":"2022-08-16T14:30:38.852641Z","shell.execute_reply":"2022-08-16T14:30:53.592026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_evaluation = pd.read_csv(EVALUATION_IDS, usecols=['row_id', 'gene_id'])\ndf_evaluation['gene_id_int'] = df_evaluation['gene_id'].apply(lambda x: int(x.replace('-', '').replace('.', '')[-8:],34)).astype(int)\ndf_evaluation.drop(['gene_id'], axis=1, inplace=True)\ndf_evaluation.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:30:53.594654Z","iopub.execute_input":"2022-08-16T14:30:53.595088Z","iopub.status.idle":"2022-08-16T14:32:52.404130Z","shell.execute_reply.started":"2022-08-16T14:30:53.595057Z","shell.execute_reply":"2022-08-16T14:32:52.402984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample_submission = df_sample_submission.merge(df_evaluation, how='left', on='row_id')\ndf_sample_submission.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:32:52.405701Z","iopub.execute_input":"2022-08-16T14:32:52.406488Z","iopub.status.idle":"2022-08-16T14:33:37.396668Z","shell.execute_reply.started":"2022-08-16T14:32:52.406451Z","shell.execute_reply":"2022-08-16T14:33:37.395470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_gene_id_mean = pd.DataFrame(cite_gene_id_mean, columns=['target']).reset_index()\ncite_gene_id_mean['gene_id_int'] = cite_gene_id_mean['gene_id'].apply(lambda x: int(x.replace('-', '').replace('.', '')[-8:],34)).astype(int)\ncite_gene_id_mean.drop(['gene_id'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:33:37.398082Z","iopub.execute_input":"2022-08-16T14:33:37.398407Z","iopub.status.idle":"2022-08-16T14:33:37.408696Z","shell.execute_reply.started":"2022-08-16T14:33:37.398378Z","shell.execute_reply":"2022-08-16T14:33:37.407675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multi_gene_id_mean = pd.DataFrame(multi_gene_id_mean, columns=['target']).reset_index()\nmulti_gene_id_mean['gene_id_int'] = multi_gene_id_mean['gene_id'].apply(lambda x: int(x.replace('-', '').replace('.', '')[-8:],34)).astype(int)\nmulti_gene_id_mean.drop(['gene_id'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:33:37.409997Z","iopub.execute_input":"2022-08-16T14:33:37.410885Z","iopub.status.idle":"2022-08-16T14:33:37.449227Z","shell.execute_reply.started":"2022-08-16T14:33:37.410852Z","shell.execute_reply":"2022-08-16T14:33:37.448146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_multi_gene_id_mean = pd.concat([cite_gene_id_mean, multi_gene_id_mean])\ncite_multi_gene_id_mean.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:33:37.450674Z","iopub.execute_input":"2022-08-16T14:33:37.451189Z","iopub.status.idle":"2022-08-16T14:33:37.467173Z","shell.execute_reply.started":"2022-08-16T14:33:37.451157Z","shell.execute_reply":"2022-08-16T14:33:37.465838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample_submission = df_sample_submission.merge(cite_multi_gene_id_mean, how='left', on='gene_id_int')\ndf_sample_submission.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:33:37.468733Z","iopub.execute_input":"2022-08-16T14:33:37.469117Z","iopub.status.idle":"2022-08-16T14:33:48.998838Z","shell.execute_reply.started":"2022-08-16T14:33:37.469080Z","shell.execute_reply":"2022-08-16T14:33:48.997646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample_submission[['row_id', 'target']].to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-16T14:33:49.000504Z","iopub.execute_input":"2022-08-16T14:33:49.001411Z","iopub.status.idle":"2022-08-16T14:35:47.365292Z","shell.execute_reply.started":"2022-08-16T14:33:49.001365Z","shell.execute_reply":"2022-08-16T14:35:47.364143Z"},"trusted":true},"execution_count":null,"outputs":[]}]}