{"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"}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# **CAFA6 Data Structures**","metadata":{}},{"cell_type":"code","source":"!pip install pandas biopython obonet","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:38.534856Z","iopub.execute_input":"2025-10-16T12:06:38.535040Z","iopub.status.idle":"2025-10-16T12:06:45.595077Z","shell.execute_reply.started":"2025-10-16T12:06:38.535023Z","shell.execute_reply":"2025-10-16T12:06:45.593900Z"},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:45.597373Z","iopub.execute_input":"2025-10-16T12:06:45.597664Z","iopub.status.idle":"2025-10-16T12:06:45.913003Z","shell.execute_reply.started":"2025-10-16T12:06:45.597637Z","shell.execute_reply":"2025-10-16T12:06:45.912343Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **train: go-basic**","metadata":{}},{"cell_type":"code","source":"import obonet\n\ngo_graph = obonet.read_obo('/kaggle/input/cafa-6-protein-function-prediction/Train/go-basic.obo')\n\nprint(f\"Total number of GO terms (nodes): **{len(go_graph.nodes)}**\")\nprint(\"---\")\n\n# Example: Root GO term (biological_process)\nexample_go_id = 'GO:0008150' \n\nif example_go_id in go_graph:\n    # Get all node attributes as a dictionary\n    term_data = go_graph.nodes[example_go_id]\n    \n    print(f\"🔬 Details for GO Term ID: {example_go_id}\")\n    print(f\"  - Name: {term_data.get('name', 'N/A')}\")\n\n    definition = term_data.get('def', 'N/A')\n    print(f\"  - Definition: {definition[:60]}...\")\n    \n    # Print the entire dictionary (if you want to see all attributes)\n    print(\"\\n--- All Node Attributes ---\")\n    print(term_data)\n    \nelse:\n    print(f\"Term ID **{example_go_id}** not found in the graph.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:09:49.539400Z","iopub.execute_input":"2025-10-16T12:09:49.539746Z","iopub.status.idle":"2025-10-16T12:09:55.321096Z","shell.execute_reply.started":"2025-10-16T12:09:49.539722Z","shell.execute_reply":"2025-10-16T12:09:55.320089Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **train: EntryID, sequences**","metadata":{}},{"cell_type":"code","source":"from Bio import SeqIO\n\nsequences = list(SeqIO.parse('/kaggle/input/cafa-6-protein-function-prediction/Train/train_sequences.fasta', 'fasta'))\nprint('n_sequences:',len(sequences))\n\nif sequences:\n    first_record = sequences[0]\n    print(f\"EntryID: {first_record.id}\")\n    print(f\"Length: {len(first_record.seq)}\")\n    print(f\"First characters of the sequence: {first_record.seq}\")\nelse:\n    print(\"\\nNo sequence records found in 'train_sequences.fasta'.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:52.483790Z","iopub.execute_input":"2025-10-16T12:06:52.484342Z","iopub.status.idle":"2025-10-16T12:06:54.182070Z","shell.execute_reply.started":"2025-10-16T12:06:52.484299Z","shell.execute_reply":"2025-10-16T12:06:54.181130Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **test: EntryID, sequences**","metadata":{}},{"cell_type":"code","source":"tsequences = list(SeqIO.parse('/kaggle/input/cafa-6-protein-function-prediction/Test/testsuperset.fasta', 'fasta'))\nprint('n_sequences:',len(sequences))\n\nif tsequences:\n    first_record = tsequences[0]\n    print(f\"EntryID: {first_record.id}\")\n    print(f\"Length: {len(first_record.seq)}\")\n    print(f\"First characters of the sequence: {first_record.seq}\")\nelse:\n    print(\"\\nNo sequence records found in 'train_sequences.fasta'.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:54.183081Z","iopub.execute_input":"2025-10-16T12:06:54.183404Z","iopub.status.idle":"2025-10-16T12:06:56.971066Z","shell.execute_reply.started":"2025-10-16T12:06:54.183378Z","shell.execute_reply":"2025-10-16T12:06:56.969990Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **train: EntryID,GoID,aspect**","metadata":{}},{"cell_type":"code","source":"df_terms = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/Train/train_terms.tsv', sep='\\t')\nprint(df_terms[0:10])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:56.973006Z","iopub.execute_input":"2025-10-16T12:06:56.973249Z","iopub.status.idle":"2025-10-16T12:06:57.360127Z","shell.execute_reply.started":"2025-10-16T12:06:56.973229Z","shell.execute_reply":"2025-10-16T12:06:57.359416Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **train: EntryID, SpeciesID**","metadata":{}},{"cell_type":"code","source":"df_taxonomy = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/Train/train_taxonomy.tsv',header=None, sep='\\t')\nprint(df_taxonomy[0:10])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:57.361039Z","iopub.execute_input":"2025-10-16T12:06:57.361277Z","iopub.status.idle":"2025-10-16T12:06:57.420643Z","shell.execute_reply.started":"2025-10-16T12:06:57.361258Z","shell.execute_reply":"2025-10-16T12:06:57.419626Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **test: SpeciesID,Species**","metadata":{}},{"cell_type":"code","source":"df_ttaxonomy = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/Test/testsuperset-taxon-list.tsv',header=None, sep='\\t')\nprint(df_ttaxonomy[0:10])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:57.421483Z","iopub.execute_input":"2025-10-16T12:06:57.421777Z","iopub.status.idle":"2025-10-16T12:06:57.450595Z","shell.execute_reply.started":"2025-10-16T12:06:57.421752Z","shell.execute_reply":"2025-10-16T12:06:57.449770Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **IA: GoID,weights**","metadata":{}},{"cell_type":"code","source":"df_IA = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/IA.tsv',header=None, sep='\\t')\nprint(df_IA[0:10])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-16T12:06:57.451340Z","iopub.execute_input":"2025-10-16T12:06:57.451617Z","iopub.status.idle":"2025-10-16T12:06:57.492854Z","shell.execute_reply.started":"2025-10-16T12:06:57.451594Z","shell.execute_reply":"2025-10-16T12:06:57.491798Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## **submission: EntryID,GoID,score**","metadata":{}},{"cell_type":"code","source":"df_submit = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/sample_submission.tsv',\n                        header=None, sep='\\t', on_bad_lines='skip')\nprint(df_submit[0:10])","metadata":{"execution":{"iopub.status.busy":"2025-10-16T12:06:57.493876Z","iopub.execute_input":"2025-10-16T12:06:57.494585Z","iopub.status.idle":"2025-10-16T12:06:57.516271Z","shell.execute_reply.started":"2025-10-16T12:06:57.494562Z","shell.execute_reply":"2025-10-16T12:06:57.515452Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}}]}