{"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,"sourceType":"competition"},{"sourceId":13482672,"sourceType":"datasetVersion","datasetId":8559888}],"dockerImageVersionId":31192,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os, gc\nfrom collections import defaultdict\nimport pandas as pd\nfrom tqdm.auto import tqdm\nimport numpy as np\nfrom collections import Counter\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-11-13T14:37:14.213864Z","iopub.execute_input":"2025-11-13T14:37:14.214099Z","iopub.status.idle":"2025-11-13T14:37:16.244692Z","shell.execute_reply.started":"2025-11-13T14:37:14.214076Z","shell.execute_reply":"2025-11-13T14:37:16.243691Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Utils\ndef parse_obo(go_obo_path):\n    parents = defaultdict(set)\n    children = defaultdict(set)\n    \n    if not os.path.exists(go_obo_path): \n        return parents, children\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: \n                    parents[cur_id].add(pid)\n                    children[pid].add(cur_id)\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: \n                        parents[cur_id].add(pid)\n                        children[pid].add(cur_id)\n    print(f\"[io] Parsed OBO: {len(parents)} nodes with parents\")\n    return parents, children","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T14:37:16.245551Z","iopub.execute_input":"2025-11-13T14:37:16.245924Z","iopub.status.idle":"2025-11-13T14:37:16.253012Z","shell.execute_reply.started":"2025-11-13T14:37:16.245904Z","shell.execute_reply":"2025-11-13T14:37:16.252239Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"children_to_parent, parent_to_children = parse_obo('/kaggle/input/cafa-6-protein-function-prediction/Train/go-basic.obo')\ntrain_taxonomy = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/Train/train_taxonomy.tsv', sep='\\t', header=None)\ntrain_taxonomy.columns = ['uniprot', 'taxonomy']\ntrain_terms = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/Train/train_terms.tsv', sep='\\t')\nIA = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/IA.tsv', sep='\\t', header=None)\nIA.columns = ['GO', 'weight']\nCounter(train_taxonomy.taxonomy)\nCounter(train_terms.term)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T14:37:16.254222Z","iopub.execute_input":"2025-11-13T14:37:16.254432Z","iopub.status.idle":"2025-11-13T14:37:17.452424Z","shell.execute_reply.started":"2025-11-13T14:37:16.254411Z","shell.execute_reply":"2025-11-13T14:37:17.451103Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(children_to_parent['GO:0000785'])\ntrain_terms[train_terms['EntryID'] == 'A0JNW5']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-13T14:45:33.261035Z","iopub.execute_input":"2025-11-13T14:45:33.261313Z","iopub.status.idle":"2025-11-13T14:45:33.298144Z","shell.execute_reply.started":"2025-11-13T14:45:33.261293Z","shell.execute_reply":"2025-11-13T14:45:33.297184Z"}},"outputs":[],"execution_count":null}]}