{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":116062,"databundleVersionId":14084779,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":13482672,"sourceType":"datasetVersion","datasetId":8559888},{"sourceId":13502493,"sourceType":"datasetVersion","datasetId":8572953},{"sourceId":269339911,"sourceType":"kernelVersion"},{"sourceId":270571028,"sourceType":"kernelVersion"}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:01:32.396963Z","iopub.execute_input":"2025-10-29T18:01:32.399086Z","iopub.status.idle":"2025-10-29T18:01:32.412818Z","shell.execute_reply.started":"2025-10-29T18:01:32.398995Z","shell.execute_reply":"2025-10-29T18:01:32.411495Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class config:\n    score_threshold = 0.04\n    max_num_go_per_protein = 1800","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:01:33.110431Z","iopub.execute_input":"2025-10-29T18:01:33.111625Z","iopub.status.idle":"2025-10-29T18:01:33.116542Z","shell.execute_reply.started":"2025-10-29T18:01:33.111574Z","shell.execute_reply":"2025-10-29T18:01:33.115432Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### ⏳ Load Data","metadata":{}},{"cell_type":"code","source":"def load_submission(path):\n    df = pd.read_csv(path, sep='\\t', header=None)\n    df['pred_key'] = df[0].astype(str) + '_' + df[1].astype(str)\n    return df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:01:34.810232Z","iopub.execute_input":"2025-10-29T18:01:34.810576Z","iopub.status.idle":"2025-10-29T18:01:34.816869Z","shell.execute_reply.started":"2025-10-29T18:01:34.810560Z","shell.execute_reply":"2025-10-29T18:01:34.815887Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(f\"[1/5] Loading Data ...\")\nA = load_submission('/kaggle/input/gaf-submission/submission.tsv')  # LB Score: 0.269\nB = load_submission('/kaggle/input/merge-of-2submission-lb-0-25/submission.tsv')  # LB Score: 0.250\n\nprint(f\"[2/5] Filtering B ...\")\nA_idx = A.set_index('pred_key')\nB_idx = B.set_index('pred_key')\n# Keep only rows in B where pred_key is not in A\nB_filtered = B[~B['pred_key'].isin(A['pred_key'])]\n\nprint(f\"[3/5] Merging ..\")\nsubmission = pd.concat([A, B_filtered], ignore_index=True)\n\nprint(f\"[4/5] Finalizing format ..\")\nsubmission = submission.reset_index(drop=True)[[0, 1, 2]]\n\nprint(f\"[5/5] Submission shape: {submission.shape}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:01:36.453086Z","iopub.execute_input":"2025-10-29T18:01:36.453474Z","iopub.status.idle":"2025-10-29T18:03:25.600540Z","shell.execute_reply.started":"2025-10-29T18:01:36.453452Z","shell.execute_reply":"2025-10-29T18:03:25.598262Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### 🧹 Post-Processing","metadata":{}},{"cell_type":"code","source":"# Handle very low scores and scores > 1\nsubmission.columns = ['ProteinID', 'GO_Term', 'Score']\nsubmission = submission[submission['Score'] >= config.score_threshold]\nsubmission['Score'] = submission['Score'].clip(upper=1.0)\nsubmission.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:03:25.602168Z","iopub.execute_input":"2025-10-29T18:03:25.602487Z","iopub.status.idle":"2025-10-29T18:03:27.228168Z","shell.execute_reply.started":"2025-10-29T18:03:25.602468Z","shell.execute_reply":"2025-10-29T18:03:27.226403Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# # Keep only 1800 GO per Protein\n# submission = (\n#     submission.sort_values(['ProteinID', 'Score'], ascending=[True, False])\n#     .groupby('ProteinID', group_keys=False)\n#     .head(config.max_num_go_per_protein)\n# )\n# submission.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T17:41:06.361504Z","iopub.execute_input":"2025-10-29T17:41:06.362685Z","iopub.status.idle":"2025-10-29T17:41:20.525976Z","shell.execute_reply.started":"2025-10-29T17:41:06.362625Z","shell.execute_reply":"2025-10-29T17:41:20.524479Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### 🔗 Merge ","metadata":{}},{"cell_type":"code","source":"# GT data collected using QuickGO API\nprotein_go_annotations = pd.read_csv('/kaggle/input/protein-go-annotations-taxonomy/protein_go_annotations.csv')\nprotein_go_annotations = protein_go_annotations[['ProteinID', 'GO_Term']]\nprotein_go_annotations['Score'] = round(1.0, 3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:05:15.351195Z","iopub.execute_input":"2025-10-29T18:05:15.351625Z","iopub.status.idle":"2025-10-29T18:05:15.814617Z","shell.execute_reply.started":"2025-10-29T18:05:15.351569Z","shell.execute_reply":"2025-10-29T18:05:15.813266Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(f'[⏳] Combining Submissions ...')\ncombined = pd.concat([submission, protein_go_annotations], ignore_index=True)\n\n# Drop duplicates,\n# Keep the ground truth score (1.0) if overlap\ncombined.sort_values(by='Score', ascending=False, inplace=True)\nfinal_submission = combined.drop_duplicates(subset=['ProteinID', 'GO_Term'], keep='first').reset_index(drop=True)\nfinal_submission.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:05:17.728220Z","iopub.execute_input":"2025-10-29T18:05:17.728931Z","iopub.status.idle":"2025-10-29T18:06:04.745222Z","shell.execute_reply.started":"2025-10-29T18:05:17.728911Z","shell.execute_reply":"2025-10-29T18:06:04.743886Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### 📤 Submit","metadata":{}},{"cell_type":"code","source":"print(f'[⏳] Saving Submission ...')\nfinal_submission.to_csv('submission.tsv',sep='\\t', index=False, header=None)\nprint(f\"[+] Done.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T18:06:08.397691Z","iopub.execute_input":"2025-10-29T18:06:08.397948Z","iopub.status.idle":"2025-10-29T18:07:11.535753Z","shell.execute_reply.started":"2025-10-29T18:06:08.397934Z","shell.execute_reply":"2025-10-29T18:07:11.534190Z"}},"outputs":[],"execution_count":null}]}