{"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":"# CAFA 5 Mitochondria-related Functions","metadata":{}},{"cell_type":"code","source":"!pip install obonet","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:05.759493Z","iopub.execute_input":"2023-04-27T14:02:05.7599Z","iopub.status.idle":"2023-04-27T14:02:17.353093Z","shell.execute_reply.started":"2023-04-27T14:02:05.759867Z","shell.execute_reply":"2023-04-27T14:02:17.352011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport obonet\nimport numpy as np\nimport pandas as pd\nfrom Bio import SeqIO\nimport networkx as nx\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:17.35609Z","iopub.execute_input":"2023-04-27T14:02:17.356502Z","iopub.status.idle":"2023-04-27T14:02:17.363799Z","shell.execute_reply.started":"2023-04-27T14:02:17.356459Z","shell.execute_reply":"2023-04-27T14:02:17.362582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Assigning function to any specific protein can be made difficult due to the multiple functions many proteins have, along with their ability to interact with multiple partners. ","metadata":{}},{"cell_type":"code","source":"graph = obonet.read_obo('/kaggle/input/cafa-5-protein-function-prediction/Train/go-basic.obo')\ndf = pd.DataFrame(graph.nodes(data=True), columns=['id','data'])\ndisplay(df[0:3])\nprint(df.iloc[0,1])","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:17.365184Z","iopub.execute_input":"2023-04-27T14:02:17.365547Z","iopub.status.idle":"2023-04-27T14:02:26.146479Z","shell.execute_reply.started":"2023-04-27T14:02:17.36551Z","shell.execute_reply":"2023-04-27T14:02:26.145345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df.iloc[0,1].keys())","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:26.148347Z","iopub.execute_input":"2023-04-27T14:02:26.149198Z","iopub.status.idle":"2023-04-27T14:02:26.15568Z","shell.execute_reply.started":"2023-04-27T14:02:26.149159Z","shell.execute_reply":"2023-04-27T14:02:26.154458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2=pd.DataFrame(columns=['id','name','namespace','def','synonym','is_a'],index=range(len(df)))\n\nfor i in range(len(df)):\n    df2.iloc[i,0]=df.iloc[i,0]\n    df2.iloc[i,1]=df.iloc[i,1].get('name','N')\n    df2.iloc[i,2]=df.iloc[i,1].get('namespace','N')\n    df2.iloc[i,3]=df.iloc[i,1].get('def','N')\n    df2.iloc[i,4]=df.iloc[i,1].get('synonym','N')\n    df2.iloc[i,5]=df.iloc[i,1].get('is_a','N')\n\ndisplay(df2)","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:26.159835Z","iopub.execute_input":"2023-04-27T14:02:26.160374Z","iopub.status.idle":"2023-04-27T14:02:51.944361Z","shell.execute_reply.started":"2023-04-27T14:02:26.160336Z","shell.execute_reply":"2023-04-27T14:02:51.943102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#GO:id vs def\nfor i in range(5):\n    #print(df2.iloc[i,0])\n    print(df2.iloc[i,3])\n    print()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:51.946064Z","iopub.execute_input":"2023-04-27T14:02:51.946581Z","iopub.status.idle":"2023-04-27T14:02:51.954292Z","shell.execute_reply.started":"2023-04-27T14:02:51.946532Z","shell.execute_reply":"2023-04-27T14:02:51.953009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The Gene Ontology (GO) is a concept hierarchy that describes the biological function of genes and gene products at different levels of abstraction (Ashburner et al., 2000). It is a good model to describe the multi-faceted nature of protein function.","metadata":{}},{"cell_type":"markdown","source":"The list of predictions contains a list of pairs between protein targets and GO terms, followed by the probabilistic estimate of the relationship (one association per line). ","metadata":{}},{"cell_type":"code","source":"submit=pd.read_csv('/kaggle/input/cafa-5-protein-function-prediction/sample_submission.tsv', delimiter='\\t', header=None)\ndisplay(submit)\nids=submit.iloc[:,0].unique().tolist()\nprint(ids[0:5])\ngos=submit.iloc[:,1].unique().tolist()\nprint(gos)","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:51.95614Z","iopub.execute_input":"2023-04-27T14:02:51.956642Z","iopub.status.idle":"2023-04-27T14:02:52.206927Z","shell.execute_reply.started":"2023-04-27T14:02:51.956593Z","shell.execute_reply":"2023-04-27T14:02:52.20568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eids=submit.iloc[:,0].unique().tolist()\nprint(len(eids))","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:09:56.475376Z","iopub.execute_input":"2023-04-27T14:09:56.475804Z","iopub.status.idle":"2023-04-27T14:09:56.523168Z","shell.execute_reply.started":"2023-04-27T14:09:56.475766Z","shell.execute_reply":"2023-04-27T14:09:56.521756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Only EntryIDs related to 'GO:0000001' and 'GO:0000002' are subject to submission.","metadata":{}},{"cell_type":"code","source":"print(df2.iloc[0:2,1])\n# both functions are related to mitochondria.","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:52.208343Z","iopub.execute_input":"2023-04-27T14:02:52.208777Z","iopub.status.idle":"2023-04-27T14:02:52.215107Z","shell.execute_reply.started":"2023-04-27T14:02:52.208741Z","shell.execute_reply":"2023-04-27T14:02:52.214221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#select mitochondria related functions\niss=[]\ngos=[]\nfor i in range(len(df2)):\n    if 'mitochond' in df2.iloc[i,1]:\n        gos+=[df2.iloc[i,0]]\n        iss+=[i]\nprint(len(gos))","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:52.216472Z","iopub.execute_input":"2023-04-27T14:02:52.2168Z","iopub.status.idle":"2023-04-27T14:02:53.519635Z","shell.execute_reply.started":"2023-04-27T14:02:52.216768Z","shell.execute_reply":"2023-04-27T14:02:53.518569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df3=df2.iloc[iss][['id','is_a']]\ndf4 = df3.explode('is_a').reset_index(drop=True)\ndisplay(df4)","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:02:53.521275Z","iopub.execute_input":"2023-04-27T14:02:53.521686Z","iopub.status.idle":"2023-04-27T14:02:53.544745Z","shell.execute_reply.started":"2023-04-27T14:02:53.52165Z","shell.execute_reply":"2023-04-27T14:02:53.543554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"nx.DiGraph() is one of the classes representing directed graphs in the Python library NetworkX.\n\nA directed graph consists of a set of nodes (vertices) and edges (edges), and is called a directed graph if the edges are directed, that is, if the edges have a direction.\n","metadata":{}},{"cell_type":"code","source":"G = nx.DiGraph()\nfor _, row in df4.iterrows():\n    G.add_edge(row['is_a'], row['id'])\n\nplt.figure(figsize=(12,40))\nnx.draw_circular(G, with_labels=True, font_size=6)\nplt.title('mutual relations among mitochondria related functions', size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-27T14:07:18.833611Z","iopub.execute_input":"2023-04-27T14:07:18.834042Z","iopub.status.idle":"2023-04-27T14:07:26.2912Z","shell.execute_reply.started":"2023-04-27T14:07:18.834002Z","shell.execute_reply":"2023-04-27T14:07:26.290239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}