{"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":"code","source":"import pandas as pd\nfrom Bio import SeqIO\nsequences = SeqIO.parse('/kaggle/input/cafa-5-protein-function-prediction/Train/train_sequences.fasta', \"fasta\")\nexample_sequence = next(iter(sequences))\nprint(\"Sequence example:\\n\\n\", example_sequence)\n\nsequence_df = pd.DataFrame([{\"id\": s.id, \"seq\": str(s.seq)} for s in sequences])\nsequence_df = sequence_df.set_index('id')\nsequence_df","metadata":{"execution":{"iopub.status.busy":"2023-06-18T15:58:30.994293Z","iopub.execute_input":"2023-06-18T15:58:30.994634Z","iopub.status.idle":"2023-06-18T15:58:33.747718Z","shell.execute_reply.started":"2023-06-18T15:58:30.994603Z","shell.execute_reply":"2023-06-18T15:58:33.746497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_terms_df = pd.read_csv('/kaggle/input/cafa-5-protein-function-prediction/Train/train_terms.tsv', sep=\"\\t\")\ntrain_terms_df = train_terms_df.rename(columns={\"EntryID\": \"id\"})\ntrain_terms_grouped_df = train_terms_df.groupby(\"id\").aggregate(lambda tdf: tdf.unique().tolist())[['term']]\n\nprint('Terms for example sequence:', train_terms_grouped_df.loc[example_sequence.id])\n\ntrain_terms_grouped_df","metadata":{"execution":{"iopub.status.busy":"2023-06-18T15:58:33.749267Z","iopub.execute_input":"2023-06-18T15:58:33.749616Z","iopub.status.idle":"2023-06-18T15:58:59.002013Z","shell.execute_reply.started":"2023-06-18T15:58:33.749587Z","shell.execute_reply":"2023-06-18T15:58:59.00061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = sequence_df.join(train_terms_grouped_df)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2023-06-18T15:58:59.00395Z","iopub.execute_input":"2023-06-18T15:58:59.004503Z","iopub.status.idle":"2023-06-18T15:58:59.176315Z","shell.execute_reply.started":"2023-06-18T15:58:59.004457Z","shell.execute_reply":"2023-06-18T15:58:59.175198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.to_csv('train_data.csv')","metadata":{"execution":{"iopub.status.busy":"2023-06-18T15:58:59.179004Z","iopub.execute_input":"2023-06-18T15:58:59.179343Z","iopub.status.idle":"2023-06-18T15:59:07.38561Z","shell.execute_reply.started":"2023-06-18T15:58:59.179315Z","shell.execute_reply":"2023-06-18T15:59:07.384374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!head -10 train_data.csv","metadata":{"execution":{"iopub.status.busy":"2023-06-18T15:59:07.387154Z","iopub.execute_input":"2023-06-18T15:59:07.387529Z","iopub.status.idle":"2023-06-18T15:59:08.508045Z","shell.execute_reply.started":"2023-06-18T15:59:07.387497Z","shell.execute_reply":"2023-06-18T15:59:08.506688Z"},"trusted":true},"execution_count":null,"outputs":[]}]}