{"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":"# **Working with the Taxonomy Information**","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-27T20:10:55.079076Z","iopub.execute_input":"2023-04-27T20:10:55.08024Z","iopub.status.idle":"2023-04-27T20:11:06.930755Z","shell.execute_reply.started":"2023-04-27T20:10:55.080194Z","shell.execute_reply":"2023-04-27T20:11:06.929316Z"}}},{"cell_type":"code","source":"!pip install taxoniq\nimport numpy as np \nimport pandas as pd \nimport os\nfrom Bio import SeqIO\n# a python package for taxonomy\nimport taxoniq","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:37:51.972644Z","iopub.execute_input":"2023-04-28T19:37:51.973539Z","iopub.status.idle":"2023-04-28T19:38:08.636737Z","shell.execute_reply.started":"2023-04-28T19:37:51.973488Z","shell.execute_reply":"2023-04-28T19:38:08.635323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Define a LCA function hopefully useful","metadata":{}},{"cell_type":"code","source":"# find the LCA of two species using taxoniq\ndef lca(t0, t1):\n    parents_t0 = set()\n    t = t0\n    while t != taxoniq.Taxon(1):\n        parents_t0.add(t.tax_id)\n        t = t.parent\n    parents_t0.add(t.tax_id)\n    t = t1\n    while t != taxoniq.Taxon(1):\n        if t.tax_id in parents_t0:\n            return t\n        t = t.parent","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:08.639382Z","iopub.execute_input":"2023-04-28T19:38:08.639745Z","iopub.status.idle":"2023-04-28T19:38:08.647528Z","shell.execute_reply.started":"2023-04-28T19:38:08.639707Z","shell.execute_reply":"2023-04-28T19:38:08.646224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load the training and test taxonomy information","metadata":{}},{"cell_type":"code","source":"train_taxonomy = pd.read_csv(\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_taxonomy.tsv\",sep=\"\\t\")\ntest_taxonomy_id_list = pd.read_csv(\"/kaggle/input/cafa-5-protein-function-prediction/Test (Targets)/testsuperset-taxon-list.tsv\",sep=\"\\t\", encoding = 'unicode_escape')\n\nfn = '/kaggle/input/cafa-5-protein-function-prediction/Test (Targets)/testsuperset.fasta'\nsequences = SeqIO.parse(fn, \"fasta\")\ndict_id_species = {}\nset_test_taxonomy_id = set()\nfor m in sequences:\n    dict_id_species[m.id] = int(m.description.split('\\t')[1])\n    set_test_taxonomy_id.add(int(m.description.split('\\t')[1]))\n\n# check whether all test species are in the training set\nvec_counts_taxonomyid = train_taxonomy['taxonomyID'].value_counts()\ncounts_taxonomyid = train_taxonomy['taxonomyID'].value_counts().to_dict()\nset_train_taxonomy_id = set(counts_taxonomyid.keys())\nclass bcolors:\n    HEADER = '\\033[95m'\n    OKBLUE = '\\033[94m'\n    OKCYAN = '\\033[96m'\n    OKGREEN = '\\033[92m'\n    WARNING = '\\033[93m'\n    FAIL = '\\033[91m'\n    ENDC = '\\033[0m'\n    BOLD = '\\033[1m'\n    UNDERLINE = '\\033[4m'\nfor taxonomy_id in set_test_taxonomy_id:\n    if taxonomy_id in counts_taxonomyid:\n        print(\"taxonomy_id:\", taxonomy_id, \", scientific name:\", taxoniq.Taxon(taxonomy_id).scientific_name, \", counts\", counts_taxonomyid[taxonomy_id])\n    else:\n        print(\"taxonomy_id:\", taxonomy_id, \", scientific name:\", taxoniq.Taxon(taxonomy_id).scientific_name, \",\", bcolors.WARNING, \"not found\", bcolors.ENDC)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:08.649039Z","iopub.execute_input":"2023-04-28T19:38:08.649396Z","iopub.status.idle":"2023-04-28T19:38:11.125082Z","shell.execute_reply.started":"2023-04-28T19:38:08.649361Z","shell.execute_reply":"2023-04-28T19:38:11.123838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# find LCA of two species","metadata":{}},{"cell_type":"code","source":"# find LCA of two species\nspecies = vec_counts_taxonomyid.keys()\ns_lca = lca(taxoniq.Taxon(species[0]), taxoniq.Taxon(species[1]))\nprint(\"LCA of\\n\", taxoniq.Taxon(species[0]).tax_id, taxoniq.Taxon(species[0]).scientific_name, \"\\n\",\n      taxoniq.Taxon(species[1]).tax_id, taxoniq.Taxon(species[1]).scientific_name, \"\\n\",\n      \"is\\n\",\n      s_lca.tax_id, s_lca.scientific_name)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.128727Z","iopub.execute_input":"2023-04-28T19:38:11.129127Z","iopub.status.idle":"2023-04-28T19:38:11.137004Z","shell.execute_reply.started":"2023-04-28T19:38:11.12909Z","shell.execute_reply":"2023-04-28T19:38:11.135643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ranks = set()\nfor rank in taxoniq.Rank:\n    ranks.add(rank)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.13825Z","iopub.execute_input":"2023-04-28T19:38:11.13855Z","iopub.status.idle":"2023-04-28T19:38:11.148643Z","shell.execute_reply.started":"2023-04-28T19:38:11.13852Z","shell.execute_reply":"2023-04-28T19:38:11.147598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tax = taxoniq.Taxon(9606)\nprint(tax.scientific_name, \",\", tax.rank)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.150558Z","iopub.execute_input":"2023-04-28T19:38:11.151047Z","iopub.status.idle":"2023-04-28T19:38:11.159938Z","shell.execute_reply.started":"2023-04-28T19:38:11.151002Z","shell.execute_reply":"2023-04-28T19:38:11.15918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(set_train_taxonomy_id), len(set_test_taxonomy_id)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.16131Z","iopub.execute_input":"2023-04-28T19:38:11.16171Z","iopub.status.idle":"2023-04-28T19:38:11.17239Z","shell.execute_reply.started":"2023-04-28T19:38:11.16168Z","shell.execute_reply":"2023-04-28T19:38:11.171632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_ranks = set()\ncount_not_found = 0\nlist_not_found = []\nfor taxid in set_train_taxonomy_id:\n    try:\n        tax = taxoniq.Taxon(taxid)\n        print(taxid, tax.scientific_name, \",\", tax.rank)\n        unique_ranks.add(tax.rank)\n    except:\n        count_not_found += 1\n        list_not_found.append(taxid)\n        print(taxid, bcolors.WARNING, \"not found\", bcolors.ENDC)\nprint(\"\\nIn total\", count_not_found, \"species not found\")\nprint(list_not_found)\nprint()\nfor taxid in set_test_taxonomy_id:\n    tax = taxoniq.Taxon(taxid)\n    unique_ranks.add(tax.rank)\n    print(taxid, tax.scientific_name, \",\", tax.rank)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.173264Z","iopub.execute_input":"2023-04-28T19:38:11.17354Z","iopub.status.idle":"2023-04-28T19:38:11.320101Z","shell.execute_reply.started":"2023-04-28T19:38:11.173512Z","shell.execute_reply":"2023-04-28T19:38:11.318755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_ranks","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.321873Z","iopub.execute_input":"2023-04-28T19:38:11.32253Z","iopub.status.idle":"2023-04-28T19:38:11.330426Z","shell.execute_reply.started":"2023-04-28T19:38:11.322486Z","shell.execute_reply":"2023-04-28T19:38:11.329192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for tax in taxoniq.Taxon(39947).lineage:\n    print(tax.scientific_name)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.335512Z","iopub.execute_input":"2023-04-28T19:38:11.335909Z","iopub.status.idle":"2023-04-28T19:38:11.343311Z","shell.execute_reply.started":"2023-04-28T19:38:11.335871Z","shell.execute_reply":"2023-04-28T19:38:11.342062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_tax = []\nfor tax in taxoniq.Taxon(1).child_nodes:\n    list_tax = list_tax + tax.child_nodes\n    print(tax.scientific_name)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.344794Z","iopub.execute_input":"2023-04-28T19:38:11.345164Z","iopub.status.idle":"2023-04-28T19:38:11.418661Z","shell.execute_reply.started":"2023-04-28T19:38:11.345113Z","shell.execute_reply":"2023-04-28T19:38:11.417685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for tax in list_tax:\n    print(tax.scientific_name)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.41998Z","iopub.execute_input":"2023-04-28T19:38:11.420394Z","iopub.status.idle":"2023-04-28T19:38:11.42645Z","shell.execute_reply.started":"2023-04-28T19:38:11.420361Z","shell.execute_reply":"2023-04-28T19:38:11.425331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(taxoniq.Taxon(131567).scientific_name)\ntaxoniq.Taxon(131567).child_nodes","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.427954Z","iopub.execute_input":"2023-04-28T19:38:11.428394Z","iopub.status.idle":"2023-04-28T19:38:11.440273Z","shell.execute_reply.started":"2023-04-28T19:38:11.42836Z","shell.execute_reply":"2023-04-28T19:38:11.439059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for tax in taxoniq.Taxon(367110).lineage:\n    print(tax.scientific_name)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.441409Z","iopub.execute_input":"2023-04-28T19:38:11.441707Z","iopub.status.idle":"2023-04-28T19:38:11.449296Z","shell.execute_reply.started":"2023-04-28T19:38:11.441677Z","shell.execute_reply":"2023-04-28T19:38:11.448007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(taxoniq.Taxon(2759).scientific_name)\nfor tax in taxoniq.Taxon(2759).child_nodes:\n    print(tax.scientific_name)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.450703Z","iopub.execute_input":"2023-04-28T19:38:11.451018Z","iopub.status.idle":"2023-04-28T19:38:11.458768Z","shell.execute_reply.started":"2023-04-28T19:38:11.450988Z","shell.execute_reply":"2023-04-28T19:38:11.457987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(taxoniq.Taxon(33154).scientific_name)\nprint()\nfor tax in taxoniq.Taxon(33154).child_nodes:\n    print(tax.scientific_name)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.459977Z","iopub.execute_input":"2023-04-28T19:38:11.460405Z","iopub.status.idle":"2023-04-28T19:38:11.467709Z","shell.execute_reply.started":"2023-04-28T19:38:11.460371Z","shell.execute_reply":"2023-04-28T19:38:11.466774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"taxoniq.Taxon(9606).lineage","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.468605Z","iopub.execute_input":"2023-04-28T19:38:11.468896Z","iopub.status.idle":"2023-04-28T19:38:11.480854Z","shell.execute_reply.started":"2023-04-28T19:38:11.468865Z","shell.execute_reply":"2023-04-28T19:38:11.480102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for taxid in set_test_taxonomy_id:\n    tax = taxoniq.Taxon(taxid)\n    unique_ranks.add(tax.rank)\n    print(taxid, tax.scientific_name, \",\", tax.rank)\n    for tax_1 in tax.lineage:\n        print(tax_1.scientific_name, end=\", \")\n    print()\n    print()","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.481656Z","iopub.execute_input":"2023-04-28T19:38:11.481948Z","iopub.status.idle":"2023-04-28T19:38:11.529294Z","shell.execute_reply.started":"2023-04-28T19:38:11.481919Z","shell.execute_reply":"2023-04-28T19:38:11.528197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for taxid in set_test_taxonomy_id:\n    tax = taxoniq.Taxon(taxid)\n    print(taxid, tax.scientific_name)\n    if taxoniq.Taxon(2) in tax.lineage:\n        print(taxoniq.Taxon(2).scientific_name)\n    elif taxoniq.Taxon(2157) in tax.lineage:\n        print(taxoniq.Taxon(2157).scientific_name)\n    elif taxoniq.Taxon(2759) in tax.lineage:\n        print(taxoniq.Taxon(2759).scientific_name)\n        for tax_1 in taxoniq.Taxon(2759).child_nodes:\n            if tax_1 in tax.lineage:\n                print(\"--\", tax_1.scientific_name)\n    else:\n        print(\"not of these\")\n    print()\n    #unique_ranks.add(tax.rank)\n    #print(taxid, tax.scientific_name, \",\", tax.rank)\n    #for tax_1 in tax.lineage:\n    #    print(tax_1.scientific_name, end=\", \")\n    #print()\n    #print()","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.53066Z","iopub.execute_input":"2023-04-28T19:38:11.531092Z","iopub.status.idle":"2023-04-28T19:38:11.76286Z","shell.execute_reply.started":"2023-04-28T19:38:11.531036Z","shell.execute_reply":"2023-04-28T19:38:11.761499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"taxoniq.Taxon(131567).child_nodes","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.764188Z","iopub.execute_input":"2023-04-28T19:38:11.764531Z","iopub.status.idle":"2023-04-28T19:38:11.771628Z","shell.execute_reply.started":"2023-04-28T19:38:11.764496Z","shell.execute_reply":"2023-04-28T19:38:11.770544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"taxoniq.Taxon(2759).scientific_name","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.772754Z","iopub.execute_input":"2023-04-28T19:38:11.773111Z","iopub.status.idle":"2023-04-28T19:38:11.784267Z","shell.execute_reply.started":"2023-04-28T19:38:11.773049Z","shell.execute_reply":"2023-04-28T19:38:11.783015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(set_test_taxonomy_id)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.785504Z","iopub.execute_input":"2023-04-28T19:38:11.785823Z","iopub.status.idle":"2023-04-28T19:38:11.796776Z","shell.execute_reply.started":"2023-04-28T19:38:11.78579Z","shell.execute_reply":"2023-04-28T19:38:11.795536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for taxid in set_train_taxonomy_id:\n    taxid","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.798254Z","iopub.execute_input":"2023-04-28T19:38:11.798752Z","iopub.status.idle":"2023-04-28T19:38:11.807678Z","shell.execute_reply.started":"2023-04-28T19:38:11.798704Z","shell.execute_reply":"2023-04-28T19:38:11.806574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n        ","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:40:59.492546Z","iopub.execute_input":"2023-04-28T19:40:59.493898Z","iopub.status.idle":"2023-04-28T19:40:59.501644Z","shell.execute_reply.started":"2023-04-28T19:40:59.493848Z","shell.execute_reply":"2023-04-28T19:40:59.500226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"set_taxid_embed = set()\ncount = 0\nfor taxid_1 in set_train_taxonomy_id:\n    print(f\"Progress: {count}/{len(set_train_taxonomy_id)}\", end=\"\\r\")\n    count+=1\n    if taxid_1 == 1289469:\n        taxid_1 = 213633\n    for taxid_2 in set_train_taxonomy_id:\n        if taxid_2 == 1289469:\n            taxid_2 = 213633\n        if (taxid_1 == taxid_2):\n            continue\n        lineage1 = taxoniq.Taxon(taxid_1).lineage\n        lineage2 = taxoniq.Taxon(taxid_2).lineage\n        for i in range(min(len(lineage1), len(lineage2), 5)):\n            if (lineage1[::-1][i] != lineage2[::-1][i]):\n                set_taxid_embed.add(lineage1[::-1][i].tax_id)\n                set_taxid_embed.add(lineage2[::-1][i].tax_id)\n                break\n        \n        \n        ","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:34:03.619755Z","iopub.status.idle":"2023-04-28T19:34:03.622446Z","shell.execute_reply.started":"2023-04-28T19:34:03.622212Z","shell.execute_reply":"2023-04-28T19:34:03.622238Z"}}},{"cell_type":"code","source":"len(set_taxid_embed)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:38:11.820325Z","iopub.status.idle":"2023-04-28T19:38:11.820757Z","shell.execute_reply.started":"2023-04-28T19:38:11.820555Z","shell.execute_reply":"2023-04-28T19:38:11.820578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"taxoniq.Taxon(1798711).scientific_name","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:10:55.072818Z","iopub.execute_input":"2023-04-28T20:10:55.073657Z","iopub.status.idle":"2023-04-28T20:10:55.080955Z","shell.execute_reply.started":"2023-04-28T20:10:55.073612Z","shell.execute_reply":"2023-04-28T20:10:55.079621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"set_taxid_embed_2 = set()\ncount = 0\nfor taxid_1 in set_train_taxonomy_id:\n    print(f\"Progress: {count}/{len(set_train_taxonomy_id)}\", end=\"\\r\")\n    count+=1\n    if taxid_1 == 1289469:\n        taxid_1 = 213633\n    for taxid_2 in set_train_taxonomy_id:\n        if taxid_2 == 1289469:\n            taxid_2 = 213633\n        if (taxid_1 == taxid_2):\n            continue\n        lineage1 = taxoniq.Taxon(taxid_1).lineage\n        lineage2 = taxoniq.Taxon(taxid_2).lineage\n        for i in range(min(len(lineage1), len(lineage2), 5)):\n            if (lineage1[::-1][i].tax_id == 10239 or lineage2[::-1][i].tax_id == 10239 or lineage1[::-1][i] != lineage2[::-1][i]):\n                set_taxid_embed_2.add(lineage1[::-1][i].tax_id)\n                set_taxid_embed_2.add(lineage2[::-1][i].tax_id)\n                break","metadata":{"execution":{"iopub.status.busy":"2023-04-28T19:41:11.537449Z","iopub.execute_input":"2023-04-28T19:41:11.537838Z","iopub.status.idle":"2023-04-28T20:08:59.254756Z","shell.execute_reply.started":"2023-04-28T19:41:11.537805Z","shell.execute_reply":"2023-04-28T20:08:59.253703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"set_taxid_embed_2\nfor tax in set_taxid_embed_2:\n    print(taxoniq.Taxon(tax).rank)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:11:43.46802Z","iopub.execute_input":"2023-04-28T20:11:43.468695Z","iopub.status.idle":"2023-04-28T20:11:43.477847Z","shell.execute_reply.started":"2023-04-28T20:11:43.468618Z","shell.execute_reply":"2023-04-28T20:11:43.476557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list(set_taxid_embed_2)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:12:18.634482Z","iopub.execute_input":"2023-04-28T20:12:18.635615Z","iopub.status.idle":"2023-04-28T20:12:18.644156Z","shell.execute_reply.started":"2023-04-28T20:12:18.635558Z","shell.execute_reply":"2023-04-28T20:12:18.642938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_taxid_embed = list(set_taxid_embed_2)\n\ncount = 0\ntrain_taxid = []\ntrain_embedding = []\nfor taxid_1 in set_train_taxonomy_id:\n    print(f\"Progress: {count}/{len(set_train_taxonomy_id)}\", end=\"\\r\")\n    count+=1\n    train_taxid.append(taxid_1)\n    train_embedding.append([0]*len(list_taxid_embed))\n\n    if taxid_1 == 1289469:\n        #taxid_1 = 213633\n        lineage1 = taxoniq.Taxon(213633).lineage\n    else:\n        lineage1 = taxoniq.Taxon(taxid_1).lineage\n    set_lineage1 = set()\n    for taxid_lineage in lineage1:\n        set_lineage1.add(taxid_lineage.tax_id)\n    for idx, taxid_embed in enumerate(list_taxid_embed):\n        if taxid_embed in set_lineage1:\n            train_embedding[-1][idx] = 1\n\ntrain_taxid = np.array(train_taxid)\ntrain_embedding = np.array(train_embedding)\n\ncount = 0\ntest_taxid = []\ntest_embedding = []\n\nfor taxid_1 in set_test_taxonomy_id:\n    print(f\"Progress: {count}/{len(set_test_taxonomy_id)}\", end=\"\\r\")\n    count+=1\n    test_taxid.append(taxid_1)\n    test_embedding.append([0]*len(list_taxid_embed))\n\n    if taxid_1 == 1289469:\n        #taxid_1 = 213633\n        lineage1 = taxoniq.Taxon(213633).lineage\n    else:\n        lineage1 = taxoniq.Taxon(taxid_1).lineage\n    set_lineage1 = set()\n    for taxid_lineage in lineage1:\n        set_lineage1.add(taxid_lineage.tax_id)\n    for idx, taxid_embed in enumerate(list_taxid_embed):\n        if taxid_embed in set_lineage1:\n            test_embedding[-1][idx] = 1\ntest_taxid = np.array(test_taxid)\ntest_embedding = np.array(test_embedding)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:38:23.198383Z","iopub.execute_input":"2023-04-28T20:38:23.198794Z","iopub.status.idle":"2023-04-28T20:38:23.621578Z","shell.execute_reply.started":"2023-04-28T20:38:23.198755Z","shell.execute_reply":"2023-04-28T20:38:23.620537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.save(\"train_taxid.npy\", train_taxid)\nnp.save(\"train_tax_embedding.npy\", train_embedding)\nnp.save(\"test_taxid.npy\", test_taxid)\nnp.save(\"test_tax_embedding.npy\", test_embedding)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:43:24.513829Z","iopub.execute_input":"2023-04-28T20:43:24.514221Z","iopub.status.idle":"2023-04-28T20:43:24.523484Z","shell.execute_reply.started":"2023-04-28T20:43:24.514188Z","shell.execute_reply":"2023-04-28T20:43:24.522508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:26:28.929501Z","iopub.execute_input":"2023-04-28T20:26:28.93045Z","iopub.status.idle":"2023-04-28T20:26:28.935797Z","shell.execute_reply.started":"2023-04-28T20:26:28.930391Z","shell.execute_reply":"2023-04-28T20:26:28.934566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:28:56.857018Z","iopub.execute_input":"2023-04-28T20:28:56.857451Z","iopub.status.idle":"2023-04-28T20:28:57.069272Z","shell.execute_reply.started":"2023-04-28T20:28:56.857415Z","shell.execute_reply":"2023-04-28T20:28:57.067976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-04-28T20:30:39.827982Z","iopub.execute_input":"2023-04-28T20:30:39.828402Z","iopub.status.idle":"2023-04-28T20:30:39.873108Z","shell.execute_reply.started":"2023-04-28T20:30:39.828363Z","shell.execute_reply":"2023-04-28T20:30:39.871804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}