{"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":"# **I am glad to be with you at the competition, my friends**","metadata":{}},{"cell_type":"markdown","source":"  ....","metadata":{}},{"cell_type":"markdown","source":"**1.(file: go-basic.obo )**\n\nid,name,namespace,def,synonym,is_a\n\nid=(GO term ID ) :example (GO:0000001)\n\nname=protein name :example (mitochondrion inheritance)\n\nnamespace={biological_process,molecular_function,cellular_component}\n\ndef=Definition : example(The distribution of mitochondria)\n\nsynonym=same application as another : example(mitochondrial inheritance)\n\nis_a=pointer to others id : example( ['GO:0048308', 'GO:0048311'] )**\n\n\n**2.(file: train_sequences.fasta)**\n\nid,Description,Sequence\n\nid=(UniProt accession ID )\n\nDescription=(Description )\n\nSequence=(protein Sequence)\n\n**3.(file: testsuperset.fasta)**\n\nid,Description,Sequence\n\nid=(UniProt accession ID )\n\n*# Description=(Taxon ID*) \n\nSequence=(protein Sequence)\n\n\n\n**4.(file: train_taxonomy.tsv)**\n\nEntryID,taxonomyID\n\nEntryID=(UniProt accession ID )\n\n*# taxonomyID=(Taxon ID )*\n\n\n**5.(file: train_terms.tsv)**\n\nEntryID,term,aspect\n\nEntryID=(UniProt accession ID )\n\nterm=GO term ID\n\naspect=ontology the term appears {BPO,CCO,MFO}={biological_process,molecular_function,cellular_component}\n\n\n**6.(file: testsuperset-taxon-list.tsv)**\n\nID,Species\n\nID=taxon IDs\n\nSpecies=The species is the principle natural taxonomic unit : example (homo sapiens)","metadata":{}},{"cell_type":"code","source":"!pip install obonet\n!pip install pyvis -q\n!pip install fastaparser","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:27:57.524541Z","iopub.execute_input":"2023-04-26T00:27:57.524959Z","iopub.status.idle":"2023-04-26T00:28:32.512411Z","shell.execute_reply.started":"2023-04-26T00:27:57.524925Z","shell.execute_reply":"2023-04-26T00:28:32.510763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import obonet\nimport pandas as pd\nimport networkx\nimport fastaparser\nimport os.path\nfrom pyvis.network import Network","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:28:53.414799Z","iopub.execute_input":"2023-04-26T00:28:53.415263Z","iopub.status.idle":"2023-04-26T00:28:53.422921Z","shell.execute_reply.started":"2023-04-26T00:28:53.415217Z","shell.execute_reply":"2023-04-26T00:28:53.42142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"url_go = \"/kaggle/input/cafa-5-protein-function-prediction/Train/go-basic.obo\"\nurl_fasta_train=\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_sequences.fasta\"\nurl_go_basic_csv=\"/kaggle/input/datacafa/go-basic.csv\"\nurl_train_term =\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_terms.tsv\"\nurl_train_taxonomy =\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_taxonomy.tsv\"\nurl_ia =\"/kaggle/input/cafa-5-protein-function-prediction/IA.txt\"\nurl_fasta_test=\"/kaggle/input/cafa-5-protein-function-prediction/Test (Targets)/testsuperset.fasta\"\nurl_testsuperset_taxon_list =\"/kaggle/input/cafa-5-protein-function-prediction/Test (Targets)/testsuperset-taxon-list.tsv\"","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:28:56.086344Z","iopub.execute_input":"2023-04-26T00:28:56.086776Z","iopub.status.idle":"2023-04-26T00:28:56.092983Z","shell.execute_reply.started":"2023-04-26T00:28:56.086731Z","shell.execute_reply":"2023-04-26T00:28:56.091602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_nodes(graph, term, radius=1):\n    ng_graph = networkx.ego_graph(graph, term, radius=radius)\n    for n in ng_graph.nodes(data=True):\n        if( n[0]!=term):\n           n[1][\"label\"] = n[0] + \" \" +n[1][\"name\"]\n    nt = Network(directed=True, notebook=True,cdn_resources='in_line')#, cdn_resources=\"remote\")\n    nt.from_nx(ng_graph)\n    return nt.show(\"nodes.html\")","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:28:58.353649Z","iopub.execute_input":"2023-04-26T00:28:58.354918Z","iopub.status.idle":"2023-04-26T00:28:58.363836Z","shell.execute_reply.started":"2023-04-26T00:28:58.35486Z","shell.execute_reply":"2023-04-26T00:28:58.362343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"graph = obonet.read_obo(url_go)\nterm=\"GO:0006139\"\nplot_nodes(graph, term, radius=1)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:29:12.094212Z","iopub.execute_input":"2023-04-26T00:29:12.094737Z","iopub.status.idle":"2023-04-26T00:29:21.261565Z","shell.execute_reply.started":"2023-04-26T00:29:12.09469Z","shell.execute_reply":"2023-04-26T00:29:21.260402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def print_fasta(url_f):\n    with open(url_f) as fasta_file:\n            parser = fastaparser.Reader(fasta_file)\n            seq=parser.__next__()\n            print('ID:', seq.id)\n            print('Description:', seq.description)\n            print('Sequence:', seq.sequence_as_string())","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:29:27.21443Z","iopub.execute_input":"2023-04-26T00:29:27.214855Z","iopub.status.idle":"2023-04-26T00:29:27.221953Z","shell.execute_reply.started":"2023-04-26T00:29:27.214816Z","shell.execute_reply":"2023-04-26T00:29:27.220164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_fasta(url_fasta_train)\nprint_fasta(url_fasta_test)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:29:30.27405Z","iopub.execute_input":"2023-04-26T00:29:30.274488Z","iopub.status.idle":"2023-04-26T00:29:30.286455Z","shell.execute_reply.started":"2023-04-26T00:29:30.274451Z","shell.execute_reply":"2023-04-26T00:29:30.284974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_term =pd.read_csv(url_train_term,sep=\"\\t\",usecols=[\"EntryID\",\"term\",\"aspect\"]).drop_duplicates()\ndf_train_taxonomy =pd.read_csv(url_train_taxonomy,sep=\"\\t\",usecols=[\"EntryID\",\"taxonomyID\"]).drop_duplicates()\ndf_testsuperset_taxon_list=pd.read_csv(url_testsuperset_taxon_list, sep='\\t', encoding= 'unicode_escape').drop_duplicates()\ndf_ia = pd.read_csv(url_ia, header=None,  names=[\"EntryID\", \"weight\"] , sep='\\t', lineterminator='\\n').drop_duplicates()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:29:36.341388Z","iopub.execute_input":"2023-04-26T00:29:36.341931Z","iopub.status.idle":"2023-04-26T00:29:41.303763Z","shell.execute_reply.started":"2023-04-26T00:29:36.341882Z","shell.execute_reply":"2023-04-26T00:29:41.302197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('train_terms.tsv:\\n', df_train_term)\nprint()\nprint('Biological process terms used:',len(df_train_term[df_train_term.aspect=='BPO'].term.unique()))\nprint('Molecular function terms used:',len(df_train_term[df_train_term.aspect=='MFO'].term.unique()))\nprint('Cellular component terms used:',len(df_train_term[df_train_term.aspect=='CCO'].term.unique()))\nprint()\nprint('train_taxonomy.tsv:\\n' ,df_train_taxonomy)\nprint()\nprint('testsuperset-taxon-list.tsv:\\n' ,df_testsuperset_taxon_list)\nprint()\nprint('IA.txt:\\n' ,df_ia)\nprint()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:29:44.526215Z","iopub.execute_input":"2023-04-26T00:29:44.526651Z","iopub.status.idle":"2023-04-26T00:29:46.416479Z","shell.execute_reply.started":"2023-04-26T00:29:44.526611Z","shell.execute_reply":"2023-04-26T00:29:46.415156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/cafa-5-submission/submission.tsv',\n    sep='\\t', header=None)\n\nsubmission.to_csv('submission.tsv',\n    sep='\\t', header=False, index=False)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T00:44:49.46467Z","iopub.execute_input":"2023-04-26T00:44:49.465103Z","iopub.status.idle":"2023-04-26T00:44:50.198122Z","shell.execute_reply.started":"2023-04-26T00:44:49.465064Z","shell.execute_reply":"2023-04-26T00:44:50.19669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}