{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":116062,"databundleVersionId":14084779,"sourceType":"competition"},{"sourceId":5549164,"sourceType":"datasetVersion","datasetId":3197305},{"sourceId":5792099,"sourceType":"datasetVersion","datasetId":3327296},{"sourceId":6247561,"sourceType":"datasetVersion","datasetId":3590060}],"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-11-24T05:05:39.249367Z","iopub.execute_input":"2025-11-24T05:05:39.249610Z","iopub.status.idle":"2025-11-24T05:05:40.756114Z","shell.execute_reply.started":"2025-11-24T05:05:39.249585Z","shell.execute_reply":"2025-11-24T05:05:40.755333Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install Bio","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-24T05:06:18.967976Z","iopub.execute_input":"2025-11-24T05:06:18.968675Z","iopub.status.idle":"2025-11-24T05:06:24.849836Z","shell.execute_reply.started":"2025-11-24T05:06:18.968645Z","shell.execute_reply":"2025-11-24T05:06:24.849099Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom Bio import SeqIO\nfrom tqdm import tqdm","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-24T05:06:41.441085Z","iopub.execute_input":"2025-11-24T05:06:41.441633Z","iopub.status.idle":"2025-11-24T05:06:41.576423Z","shell.execute_reply.started":"2025-11-24T05:06:41.441602Z","shell.execute_reply":"2025-11-24T05:06:41.575900Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def read_fasta(fastaPath):    \n    fasta_sequences = SeqIO.parse(open(fastaPath), 'fasta')\n    ids = []\n    sequences = []\n    for fasta in fasta_sequences:\n        ids.append(fasta.id)\n        sequences.append(str(fasta.seq))\n    return pd.DataFrame({'Id': ids, 'Sequence': sequences})\n\ndef get_top_go_terms(data, num_terms):\n    term_counts = data['term'].value_counts()\n    freq_counts = term_counts / len(data)\n    freq_top = freq_counts.nlargest(num_terms)\n    return freq_top","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-24T05:06:44.491222Z","iopub.execute_input":"2025-11-24T05:06:44.491947Z","iopub.status.idle":"2025-11-24T05:06:44.497892Z","shell.execute_reply.started":"2025-11-24T05:06:44.491924Z","shell.execute_reply":"2025-11-24T05:06:44.496949Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_terms = pd.read_csv('/kaggle/input/cafa-6-protein-function-prediction/Train/train_terms.tsv', sep='\\t')\ntop_terms = get_top_go_terms(train_terms, 10)\n\ntest_data = read_fasta('/kaggle/input/cafa-6-protein-function-prediction/Test/testsuperset.fasta')\n\nresults = []\nfor index, row in tqdm(test_data.iterrows(), total=test_data.shape[0], position=0):\n    for term, freq in top_terms.items():\n        results.append((row['Id'], term, freq))\n\nfinal_results = pd.DataFrame(results, columns=['Id', 'GO term', 'Confidence'])\nfinal_results.to_csv('submission.tsv', sep='\\t', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-24T05:08:32.097761Z","iopub.execute_input":"2025-11-24T05:08:32.098468Z","iopub.status.idle":"2025-11-24T05:08:51.448024Z","shell.execute_reply.started":"2025-11-24T05:08:32.098443Z","shell.execute_reply":"2025-11-24T05:08:51.446999Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}