{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# NAIVE\nNaive is an official baseline of CAFA. For a given Pj, the score that Pj is associated with Gi is defined as the relative frequency of Gi in D.","metadata":{}},{"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)\nfrom Bio import SeqIO\nfrom tqdm import tqdm\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","execution":{"iopub.status.busy":"2023-04-23T14:21:08.087119Z","iopub.execute_input":"2023-04-23T14:21:08.08753Z","iopub.status.idle":"2023-04-23T14:21:08.10113Z","shell.execute_reply.started":"2023-04-23T14:21:08.087493Z","shell.execute_reply":"2023-04-23T14:21:08.100061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def GetDfFromFasta(fastaPath):    \n    input_file = fastaPath\n    fasta_sequences = SeqIO.parse(open(input_file),'fasta')\n    nameList = [] \n    sequenceList = []\n    for fasta in fasta_sequences:\n        name, sequence = fasta.id, str(fasta.seq)\n        nameList.append(name)\n        sequenceList.append(sequence)\n        \n    return pd.DataFrame(list(zip(nameList, sequenceList)), columns={\"Id\",\"seq\"})","metadata":{"execution":{"iopub.status.busy":"2023-04-23T14:21:08.103461Z","iopub.execute_input":"2023-04-23T14:21:08.10495Z","iopub.status.idle":"2023-04-23T14:21:08.114212Z","shell.execute_reply.started":"2023-04-23T14:21:08.104911Z","shell.execute_reply":"2023-04-23T14:21:08.112788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainTerms = pd.read_csv(\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_terms.tsv\",sep=\"\\t\")\nfreqCount = dict(trainTerms['term'].value_counts())\nmaxCount = len(trainTerms)\nfreqCount = {k:(v/maxCount) for k, v in freqCount.items()}","metadata":{"execution":{"iopub.status.busy":"2023-04-23T14:21:08.11588Z","iopub.execute_input":"2023-04-23T14:21:08.116291Z","iopub.status.idle":"2023-04-23T14:21:10.895041Z","shell.execute_reply.started":"2023-04-23T14:21:08.116256Z","shell.execute_reply":"2023-04-23T14:21:10.893688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = GetDfFromFasta(\"/kaggle/input/cafa-5-protein-function-prediction/Test (Targets)/testsuperset.fasta\")\n\nseqId = []\ngoTerm = [] \nconfidence = [] \n# Add only first 10 most frequent GO terms?!\n# Also how is relative frequency related to node/branch level\nfreqTop  = list(freqCount.items())[0:5]\nfor indx, row in tqdm(submission.iterrows(),total = submission.shape[0], position=0):\n    for gofq in freqTop:\n        seqId.append(row['seq'])\n        goTerm.append(gofq[0])\n        confidence.append(gofq[1])\n        \nfinalSubmission = pd.DataFrame(list(zip(seqId,goTerm,confidence)))\n#submission[\"confidence\"] = submission[\"confidence\"]/max(submission[\"confidence\"])\nfinalSubmission.to_csv(\"submission.tsv\",header=False, index=False, sep=\"\\t\")","metadata":{"execution":{"iopub.status.busy":"2023-04-23T14:21:10.89734Z","iopub.execute_input":"2023-04-23T14:21:10.89771Z","iopub.status.idle":"2023-04-23T14:21:31.657258Z","shell.execute_reply.started":"2023-04-23T14:21:10.897677Z","shell.execute_reply":"2023-04-23T14:21:31.655397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"finalSubmission","metadata":{"execution":{"iopub.status.busy":"2023-04-23T14:21:31.659027Z","iopub.execute_input":"2023-04-23T14:21:31.659363Z","iopub.status.idle":"2023-04-23T14:21:31.676363Z","shell.execute_reply.started":"2023-04-23T14:21:31.659332Z","shell.execute_reply":"2023-04-23T14:21:31.67509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row","metadata":{"execution":{"iopub.status.busy":"2023-04-23T14:21:31.678202Z","iopub.execute_input":"2023-04-23T14:21:31.678616Z","iopub.status.idle":"2023-04-23T14:21:31.69272Z","shell.execute_reply.started":"2023-04-23T14:21:31.678553Z","shell.execute_reply":"2023-04-23T14:21:31.691524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}