{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.12.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":116062,"databundleVersionId":14875579,"sourceType":"competition"},{"sourceId":14187577,"sourceType":"datasetVersion","datasetId":9045748},{"sourceId":287175447,"sourceType":"kernelVersion"}],"dockerImageVersionId":31234,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"papermill":{"default_parameters":{},"duration":267.822373,"end_time":"2025-12-29T09:05:39.800881","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2025-12-29T09:01:11.978508","version":"2.6.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"13de1a8f9e4d4b88a03d1d002ed41477":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"209785c48b7e4a84807fd1554ec2309f":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"2a962171e6464ab0ae05f743f9c7e03c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_f20d564304c34bec90a9719c0b465ed5","max":3863,"min":0,"orientation":"horizontal","style":"IPY_MODEL_970d3f0f14da4cae882db5980d955e89","tabbable":null,"tooltip":null,"value":3863}},"2f68cf11c9f548ad8b07e23f89cae500":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"3c09cf1a9c2c43f3845fc05242c0d058":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"4283602680624cd6ae6daa45e0505a48":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_a499010d6521421d83388bd2c6445d1b","IPY_MODEL_2a962171e6464ab0ae05f743f9c7e03c","IPY_MODEL_7d032cd13ae0413393b266b0e2ecd03c"],"layout":"IPY_MODEL_7e6aee1aa4a64dbab9e38bbd103cde4b","tabbable":null,"tooltip":null}},"48a574bd78e5481cb9b921c52a0d5d0e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4954c6eebfd54d56a0759a275a7863fc":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"5c539a73099a42e392064ba76cd4a302":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"64df3017176e40349b0827a2a2c74e28":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"678024ae5e6948a89b53b4e3023025b2":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"75f28d2503754af4997b25fa3effedb9":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_d7f31cd4f542437399dbb3d756ebce4b","IPY_MODEL_c5e542d7a0ed468a82991ad09a98c48c","IPY_MODEL_fdc6e4d9a43c4ea0b9f1480498c03a83"],"layout":"IPY_MODEL_48a574bd78e5481cb9b921c52a0d5d0e","tabbable":null,"tooltip":null}},"773ada616bd3452c87fff57dc2ef375a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7d032cd13ae0413393b266b0e2ecd03c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_82470072f8ac42889af8ca4074631103","placeholder":"​","style":"IPY_MODEL_3c09cf1a9c2c43f3845fc05242c0d058","tabbable":null,"tooltip":null,"value":" 3863/3863 [00:00&lt;00:00, 33860.59it/s]"}},"7e6aee1aa4a64dbab9e38bbd103cde4b":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"82470072f8ac42889af8ca4074631103":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"970d3f0f14da4cae882db5980d955e89":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"a499010d6521421d83388bd2c6445d1b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_209785c48b7e4a84807fd1554ec2309f","placeholder":"​","style":"IPY_MODEL_678024ae5e6948a89b53b4e3023025b2","tabbable":null,"tooltip":null,"value":"Propagating Negatives: 100%"}},"c5e542d7a0ed468a82991ad09a98c48c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_773ada616bd3452c87fff57dc2ef375a","max":3862,"min":0,"orientation":"horizontal","style":"IPY_MODEL_13de1a8f9e4d4b88a03d1d002ed41477","tabbable":null,"tooltip":null,"value":3862}},"d7f31cd4f542437399dbb3d756ebce4b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_2f68cf11c9f548ad8b07e23f89cae500","placeholder":"​","style":"IPY_MODEL_4954c6eebfd54d56a0759a275a7863fc","tabbable":null,"tooltip":null,"value":"Propagating Negatives: 100%"}},"f20d564304c34bec90a9719c0b465ed5":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"fdc6e4d9a43c4ea0b9f1480498c03a83":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_64df3017176e40349b0827a2a2c74e28","placeholder":"​","style":"IPY_MODEL_5c539a73099a42e392064ba76cd4a302","tabbable":null,"tooltip":null,"value":" 3862/3862 [00:00&lt;00:00, 39850.72it/s]"}}},"version_major":2,"version_minor":0}}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport gc\nimport pandas as pd\nimport numpy as np\nfrom collections import defaultdict\nfrom tqdm.auto import tqdm","metadata":{"execution":{"iopub.status.busy":"2026-01-05T19:59:41.251701Z","iopub.execute_input":"2026-01-05T19:59:41.252357Z","iopub.status.idle":"2026-01-05T19:59:42.865696Z","shell.execute_reply.started":"2026-01-05T19:59:41.252322Z","shell.execute_reply":"2026-01-05T19:59:42.864527Z"},"papermill":{"duration":2.464365,"end_time":"2025-12-29T09:01:19.303468","exception":false,"start_time":"2025-12-29T09:01:16.839103","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ==========================================\n# 1. OPTIMIZED OBO PARSER\n# ==========================================\ndef parse_obo_parents(go_obo_path):\n    print(f\"[1/5] Parsing OBO Ontology...\")\n    term_parents = defaultdict(set)\n    roots = set(['GO:0003674', 'GO:0008150', 'GO:0005575'])\n    \n    with open(go_obo_path, \"r\") as f:\n        cur_id = None\n        for line in f:\n            line = line.strip()\n            if line == \"[Term]\":\n                cur_id = None\n            elif line.startswith(\"id: \"):\n                cur_id = line.split(\"id: \")[1].strip()\n            elif line.startswith(\"is_a: \"):\n                pid = line.split()[1].strip()\n                if cur_id: term_parents[cur_id].add(pid)\n            elif line.startswith(\"relationship: part_of \"):\n                parts = line.split()\n                if len(parts) >= 3:\n                    pid = parts[2].strip()\n                    if cur_id: term_parents[cur_id].add(pid)\n    return term_parents, roots\n\ndef get_ancestors_map(term_parents):\n    print(\"[1/5] Building Ancestor Map...\")\n    ancestors = {}\n    def get_all_ancestors(term):\n        if term in ancestors: return ancestors[term]\n        parents = term_parents.get(term, set())\n        all_anc = set(parents)\n        for p in parents:\n            all_anc |= get_all_ancestors(p)\n        ancestors[term] = all_anc\n        return all_anc\n    \n    for term in tqdm(list(term_parents.keys())):\n        get_all_ancestors(term)\n    return ancestors","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-05T19:59:42.867633Z","iopub.execute_input":"2026-01-05T19:59:42.868145Z","iopub.status.idle":"2026-01-05T19:59:42.879881Z","shell.execute_reply.started":"2026-01-05T19:59:42.868111Z","shell.execute_reply":"2026-01-05T19:59:42.878377Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ==========================================\n# 2. LOGIC: PROPAGATION + NORMALIZATION\n# ==========================================\ndef process_predictions(df, ancestors_map, roots):\n    print(\"[3/5] Processing Predictions (Propagate + Normalize)...\")\n    \n    # 1. Convert to Dict Structure for fast access\n    # { protein_id: { go_term: score } }\n    data_map = defaultdict(dict)\n    values = df.values # protein, term, score\n    \n    for pid, term, score in tqdm(values, desc=\"Grouping\"):\n        data_map[pid][term] = float(score)\n    \n    new_rows = []\n    \n    # 2. Iterate Per Protein\n    for pid, terms_dict in tqdm(data_map.items(), desc=\"Optimizing\"):\n        final_scores = terms_dict.copy()\n        \n        # --- A. POSITIVE PROPAGATION ---\n        # Ensure Parent >= Child\n        # Sort terms to process leaves first (optional but helps)\n        current_terms = list(terms_dict.keys())\n        for term in current_terms:\n            s = terms_dict[term]\n            if term in ancestors_map:\n                for anc in ancestors_map[term]:\n                    final_scores[anc] = max(final_scores.get(anc, 0.0), s)\n        \n        # --- B. FORCE ROOTS ---\n        # If we have any prediction, the roots must be 1.0\n        if len(final_scores) > 0:\n            for r in roots:\n                final_scores[r] = 1.0\n        \n        # --- C. RANK NORMALIZATION (The Boost) ---\n        # Find the max score for this protein (excluding roots usually 1.0)\n        # We want to boost the best \"non-root\" prediction to a high confidence\n        # to ensure it survives thresholding.\n        \n        max_val = 0.0\n        for t, s in final_scores.items():\n            if t not in roots:\n                max_val = max(max_val, s)\n        \n        # If the best prediction is weak (e.g., 0.3), scale everything up\n        # Target: Make the max score at least 0.95\n        if max_val > 0 and max_val < 0.95:\n            scale_factor = 0.95 / max_val\n            for t in final_scores:\n                if t not in roots: # Don't scale roots > 1.0\n                    final_scores[t] = min(1.0, final_scores[t] * scale_factor)\n\n        # Collect\n        for go_term, score in final_scores.items():\n            # Optimization: Drop extremely low scores to reduce file size\n            if score >= 0.001:\n                new_rows.append((pid, go_term, score))\n                \n    return pd.DataFrame(new_rows, columns=['protein_id', 'go_term', 'score'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-05T19:59:42.881044Z","iopub.execute_input":"2026-01-05T19:59:42.881324Z","iopub.status.idle":"2026-01-05T19:59:42.904327Z","shell.execute_reply.started":"2026-01-05T19:59:42.881300Z","shell.execute_reply":"2026-01-05T19:59:42.903415Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ==========================================\n# 3. MAIN PIPELINE\n# ==========================================\n\n# Paths\nOBO_PATH = \"/kaggle/input/cafa-6-protein-function-prediction/Train/go-basic.obo\"\nSUBMISSION_INPUT = '/kaggle/input/goa-negative-propagation/submission.tsv'\nSUBMISSION_OUTPUT = 'submission.tsv'\n\n# 1. Load Ontology\nterm_parents, roots = parse_obo_parents(OBO_PATH)\nancestors_map = get_ancestors_map(term_parents)\n\n# 2. Load Submission\nprint(f\"[2/5] Loading submission...\")\n# If OOM occurs, add nrows=10_000_000 or use chunks\nsubmission = pd.read_csv(SUBMISSION_INPUT, sep='\\t', header=None, names=['protein_id', 'go_term', 'score', 'key'])\nsubmission = submission[['protein_id', 'go_term', 'score']]\n\n# 3. Process\nfinal_df = process_predictions(submission, ancestors_map, roots)\n\n# 4. Save\nprint(f\"[4/5] Saving {len(final_df)} rows...\")\n# Sorting ensures deterministic file for hashing/checks\nfinal_df.sort_values(['protein_id', 'score'], ascending=[True, False], inplace=True)\nfinal_df.to_csv(SUBMISSION_OUTPUT, sep='\\t', index=False, header=False)\n\nprint(f\"[✅] Done. Saved to {SUBMISSION_OUTPUT}\")\nprint(final_df.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-05T19:59:42.905880Z","iopub.execute_input":"2026-01-05T19:59:42.906227Z","iopub.status.idle":"2026-01-05T20:08:53.361074Z","shell.execute_reply.started":"2026-01-05T19:59:42.906194Z","shell.execute_reply":"2026-01-05T20:08:53.359608Z"}},"outputs":[],"execution_count":null}]}