{"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":14875579,"sourceType":"competition"}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install biopython","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:09.364165Z","iopub.execute_input":"2026-01-24T12:47:09.364509Z","iopub.status.idle":"2026-01-24T12:47:16.537252Z","shell.execute_reply.started":"2026-01-24T12:47:09.364483Z","shell.execute_reply":"2026-01-24T12:47:16.536144Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nfrom Bio import SeqIO, Align\nfrom Bio.Align import PairwiseAligner","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:16.539086Z","iopub.execute_input":"2026-01-24T12:47:16.539410Z","iopub.status.idle":"2026-01-24T12:47:16.946916Z","shell.execute_reply.started":"2026-01-24T12:47:16.539381Z","shell.execute_reply":"2026-01-24T12:47:16.945880Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_GO = pd.read_csv(\"/kaggle/input/cafa-6-protein-function-prediction/Train/train_terms.tsv\",sep=\"\\t\") \ntrain_taxonomy = pd.read_csv(\"/kaggle/input/cafa-6-protein-function-prediction/Train/train_taxonomy.tsv\",sep=\"\\t\", names=[\"Train_EntryID\", \"OX\"]) \nseqs = SeqIO.parse(\"/kaggle/input/cafa-6-protein-function-prediction/Train/train_sequences.fasta\", \"fasta\")\n\nentries = []\n\nfor entry in seqs:\n\n    EntryID = entry.id.split('|')[1] \n    entries.append({\n        \"Train_EntryID\": EntryID,\n        \"sequence\": str(entry.seq),\n    })\n\nfasta_df = pd.DataFrame(entries)\ntrain_df = pd.merge(train_taxonomy, fasta_df, on=\"Train_EntryID\")\ntrain_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:16.951542Z","iopub.execute_input":"2026-01-24T12:47:16.951863Z","iopub.status.idle":"2026-01-24T12:47:18.371261Z","shell.execute_reply.started":"2026-01-24T12:47:16.951834Z","shell.execute_reply":"2026-01-24T12:47:18.370386Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"I skipped some prints here, but if you want step-by-step prits of the dataframes, you can check this notebook:\nhttps://www.kaggle.com/code/sofiyarachkevych/cafa6-protein-function-prediction-biopython-align\n\nLet's check these two protein sequences:","metadata":{}},{"cell_type":"code","source":"seq1 = 'MLKMSGWQRQSQNQSWNLRRECSRRKCIFIHHHT'\nseq2 = \"MLKMSGWQRQSQNNSRNLRRECSRRKCIFIHHHT\"\n\n#validating that these sequences exist in the train database:\nprint(\"seq1:\")\ndisplay(train_df[train_df.sequence == seq1])\nprint(\"seq2:\")\ndisplay(train_df[train_df.sequence == seq2])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:18.373282Z","iopub.execute_input":"2026-01-24T12:47:18.373678Z","iopub.status.idle":"2026-01-24T12:47:18.417212Z","shell.execute_reply.started":"2026-01-24T12:47:18.373652Z","shell.execute_reply":"2026-01-24T12:47:18.416479Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#aligning seq1 and seq1\n\naligner = PairwiseAligner(mismatch_score = -0.4, open_deletion_score = -1, open_insertion_score = -1, extend_insertion_score = -1, mode=\"local\")\n\ntarget, query = sorted((seq1, seq2), key=len)\nalignment = aligner.align(target, query)\nprint(alignment[0])\n\nprint(\"alignment_lenght:\", alignment[0].length)\nprint(\"seq1_lenght:\", len(seq1))\nprint(\"seq2_lenght:\", len(seq2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:18.418071Z","iopub.execute_input":"2026-01-24T12:47:18.418347Z","iopub.status.idle":"2026-01-24T12:47:18.427043Z","shell.execute_reply.started":"2026-01-24T12:47:18.418300Z","shell.execute_reply":"2026-01-24T12:47:18.426071Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"As you can see, these are quite homological sequences. One of two mistmaches, Q/N, is considered likely in BLOSUMs substitution matrices (BLOSUM80, BLOSUM62, BLOSUM45). Other said, a Q ↔ N substitution is conservative and well tolerated in protein evolution. In fact, it's a **DDIT3 upstream open reading frame protein** in \n***HUMAN (OX = 9606)*** and ***MOUSE (OX = 10090)***. One can expect that in such case, the GO terms would be also quite similar. Let's check if this is the case:","metadata":{}},{"cell_type":"markdown","source":"### CAPA6 Database","metadata":{}},{"cell_type":"code","source":"ID_1 = train_df[train_df.sequence == seq1].Train_EntryID.item()\nset1 = set(train_GO[train_GO.EntryID == ID_1].term)\nprint(\"seq1 GO terms:\", set1)\nprint(\"Amount of seq1 GO terms:\", len(set1))\nprint()\nID_2 = train_df[train_df.sequence == seq2].Train_EntryID.item()\nset2 = set(train_GO[train_GO.EntryID == ID_2].term)\nprint(\"seq2 GO terms:\", set2)\nprint(\"Amount of seq2 GO terms:\", len(set2))\nprint()\nprint(\"GO terms in both seq1 and seq2:\", set1 & set2)\nprint(\"Amount of GO terms in both seq1 and seq2:\", len(set1 & set2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:18.427941Z","iopub.execute_input":"2026-01-24T12:47:18.428473Z","iopub.status.idle":"2026-01-24T12:47:18.551780Z","shell.execute_reply.started":"2026-01-24T12:47:18.428440Z","shell.execute_reply":"2026-01-24T12:47:18.551013Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"It's quite sad, that for such high homological proteins not even half of GO terms are similar (1 vs 3)... So I decided to check NCBI Database.","metadata":{}},{"cell_type":"markdown","source":"### NCBI Database","metadata":{}},{"cell_type":"markdown","source":"I copy-paste GO Terms from the NCBI. Here are the links: <br>\nseq1: https://www.ncbi.nlm.nih.gov/protein/P0DPQ6 <br>\nseq2: https://www.ncbi.nlm.nih.gov/protein/A0A2R8VHR8 <br>","metadata":{"execution":{"iopub.status.busy":"2026-01-08T15:05:39.740261Z","iopub.execute_input":"2026-01-08T15:05:39.740565Z","iopub.status.idle":"2026-01-08T15:05:39.749715Z","shell.execute_reply.started":"2026-01-08T15:05:39.740542Z","shell.execute_reply":"2026-01-08T15:05:39.747661Z"}}},{"cell_type":"code","source":"n_set1 = set(\"\"\"\nGO:0005737, GO:0005770, GO:0005634,\n            GO:0003677, GO:0003700, GO:0060840, GO:0070509, GO:0002086,\n            GO:0030968, GO:0006983, GO:0010467, GO:0070059, GO:0045599,\n            GO:0036119, GO:0009611, GO:0007605, GO:1904738, GO:1990874\n\"\"\".replace(\" \", \"\").replace(\"\\n\", \"\").split(\",\")) - {\"\"}\nprint(\"Amount of seq1 GO terms:\", len(n_set1))\n\nn_set2 = set(\"\"\"\n GO:0005770, GO:0005634, GO:0003677,\n            GO:0003700, GO:0060840, GO:0070509, GO:0045454, GO:0002086,\n            GO:0030968, GO:0006983, GO:0010467, GO:0070059, GO:0045599,\n            GO:0006355, GO:0006357, GO:0061771, GO:0036119, GO:0009611,\n            GO:0007605, GO:1904738, GO:1990874\n\"\"\".replace(\" \", \"\").replace(\"\\n\", \"\").split(\",\")) - {\"\"}\nprint(\"Amount of seq2 GO terms:\", len(n_set2))\nprint()\nprint()\n\nncbi = n_set1 & n_set2\nprint(\"GO terms in both seq1 and seq2:\", ncbi)\nprint()\nprint(\"Amount of GO terms in both seq1 and seq2:\", len(ncbi))\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-24T12:47:46.490891Z","iopub.execute_input":"2026-01-24T12:47:46.491379Z","iopub.status.idle":"2026-01-24T12:47:46.498185Z","shell.execute_reply.started":"2026-01-24T12:47:46.491342Z","shell.execute_reply":"2026-01-24T12:47:46.497010Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"It is reasonable to expect that even highly homologous proteins across different organisms will show minor functional differences. Nevertheless, the majority of their functions should overlap.","metadata":{}},{"cell_type":"markdown","source":"-----------------------------","metadata":{}}]}