{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install TCT\n",
    "\n",
    "from TCT import name_resolver\n",
    "from TCT import translator_metakg\n",
    "from TCT import translator_kpinfo\n",
    "from TCT import TCT\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_translator_resources():\n",
    "    \"\"\"\n",
    "    Load the necessary resources for the Translator.\n",
    "    \"\"\"\n",
    "    Translator_KP_info,APInames= translator_kpinfo.get_translator_kp_info()\n",
    "    metaKG = translator_metakg.get_KP_metadata(APInames) \n",
    "    #APInames,metaKG = translator_metakg.add_plover_API(APInames, metaKG)\n",
    "    return  APInames, metaKG, Translator_KP_info\n",
    "\n",
    "APInames, metaKG, Translator_KP_info= load_translator_resources()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "All_predicates = list(set(metaKG['Predicate']))\n",
    "All_categories = list((set(list(set(metaKG['Subject']))+list(set(metaKG['Object'])))))\n",
    "API_withMetaKG = list(set(metaKG['API']))\n",
    "\n",
    "    # generate a dictionary of API and its predicates\n",
    "API_predicates = {}\n",
    "for api in API_withMetaKG:\n",
    "    API_predicates[api] = list(set(metaKG[metaKG['API'] == api]['Predicate']))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "url = 'https://amlkg.systemsbiology.org:9990/AMLkg/meta_knowledge_graph'\n",
    "response = requests.get(url)\n",
    "data = response.json()\n",
    "for i in range(len(data[\"edges\"])):\n",
    "    APInames, metaKG = translator_metakg.add_new_API_for_query(APInames, metaKG, \"AMLKG\", \"https://amlkg.systemsbiology.org:9990/AMLkg/query\", data[\"edges\"][i]['predicate'], data[\"edges\"][i]['subject'], data[\"edges\"][i]['object'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "API_withMetaKG = list(set(metaKG['API']))\n",
    "for api in API_withMetaKG:\n",
    "    API_predicates[api] = list(set(metaKG[metaKG['API'] == api]['Predicate']))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 234780 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import networkx as nx\n",
    "selected_KGs = ['AMLKG']\n",
    "\n",
    "metaKG_sele = metaKG[metaKG['API'].isin(selected_KGs)]\n",
    "\n",
    "# build a multigraph to capture all edges (including duplicates) and their predicates\n",
    "G = nx.MultiGraph()\n",
    "for _, row in metaKG_sele.iterrows():\n",
    "        G.add_edge(row['Subject'], row['Object'], predicate=row['Predicate'])\n",
    "\n",
    "# layout and draw nodes + edges\n",
    "plt.figure(figsize=(12, 12))\n",
    "pos = nx.spring_layout(G, k=0.5, iterations=20)\n",
    "nx.draw(G, pos,\n",
    "                with_labels=True,\n",
    "                node_size=50,\n",
    "                font_size=12,\n",
    "                font_color='black',\n",
    "                node_color='blue',\n",
    "                edge_color='gray')\n",
    "\n",
    "# draw edge labels\n",
    "edge_labels = nx.get_edge_attributes(G, 'predicate')\n",
    "nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8)\n",
    "plt.title('Interaction Graph of Subjects and Objects in metaKG')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>API</th>\n",
       "      <th>Predicate</th>\n",
       "      <th>Subject</th>\n",
       "      <th>Object</th>\n",
       "      <th>URL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10576</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:expressed_in</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:Cell</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10577</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10578</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10579</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>biolink:PhenotypicFeature</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10580</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ChemicalEntity</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10581</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10582</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10583</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10584</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10585</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10586</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10587</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:EnvironmentalProcess</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10588</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:PhenotypicFeature</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10589</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10590</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10591</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10592</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10593</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ChemicalEntity</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10594</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10595</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10596</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10597</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:in_complex_with</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10598</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:in_complex_with</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10599</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>biolink:PhenotypicFeature</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10600</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:in_complex_with</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10601</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ChemicalEntity</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10602</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MicroRNA</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10603</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:in_complex_with</td>\n",
       "      <td>biolink:ChemicalEntity</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10604</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>biolink:PhenotypicFeature</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10605</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:PhenotypicFeature</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10606</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Drug</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10607</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10608</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:in_complex_with</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>biolink:MacromolecularComplex</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10609</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Noncoding_RNAProduct</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10610</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10611</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ChemicalEntity</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10612</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:ProteinFamily</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10613</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:EnvironmentalProcess</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10614</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:SmallMolecule</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10615</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MicroRNA</td>\n",
       "      <td>biolink:PhenotypicFeature</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10616</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:regulates</td>\n",
       "      <td>biolink:MicroRNA</td>\n",
       "      <td>biolink:Protein</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10617</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:associated_with_sensitivity_to</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:Drug</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10618</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:associated_with_resistance_to</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:Drug</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10619</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:GeneToDiseaseOrPhenotypicFeatureAssoci...</td>\n",
       "      <td>biolink:Gene</td>\n",
       "      <td>biolink:Disease</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10620</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:treats</td>\n",
       "      <td>biolink:Drug</td>\n",
       "      <td>biolink:Disease</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10621</th>\n",
       "      <td>AMLKG</td>\n",
       "      <td>biolink:subclass_of</td>\n",
       "      <td>biolink:Disease</td>\n",
       "      <td>biolink:Disease</td>\n",
       "      <td>https://amlkg.systemsbiology.org:9990/AMLkg/query</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         API                                          Predicate  \\\n",
       "10576  AMLKG                               biolink:expressed_in   \n",
       "10577  AMLKG                                  biolink:regulates   \n",
       "10578  AMLKG                                  biolink:regulates   \n",
       "10579  AMLKG                                  biolink:regulates   \n",
       "10580  AMLKG                                  biolink:regulates   \n",
       "10581  AMLKG                                  biolink:regulates   \n",
       "10582  AMLKG                                  biolink:regulates   \n",
       "10583  AMLKG                                  biolink:regulates   \n",
       "10584  AMLKG                                  biolink:regulates   \n",
       "10585  AMLKG                                  biolink:regulates   \n",
       "10586  AMLKG                                  biolink:regulates   \n",
       "10587  AMLKG                                  biolink:regulates   \n",
       "10588  AMLKG                                  biolink:regulates   \n",
       "10589  AMLKG                                  biolink:regulates   \n",
       "10590  AMLKG                                  biolink:regulates   \n",
       "10591  AMLKG                                  biolink:regulates   \n",
       "10592  AMLKG                                  biolink:regulates   \n",
       "10593  AMLKG                                  biolink:regulates   \n",
       "10594  AMLKG                                  biolink:regulates   \n",
       "10595  AMLKG                                  biolink:regulates   \n",
       "10596  AMLKG                                  biolink:regulates   \n",
       "10597  AMLKG                            biolink:in_complex_with   \n",
       "10598  AMLKG                            biolink:in_complex_with   \n",
       "10599  AMLKG                                  biolink:regulates   \n",
       "10600  AMLKG                            biolink:in_complex_with   \n",
       "10601  AMLKG                                  biolink:regulates   \n",
       "10602  AMLKG                                  biolink:regulates   \n",
       "10603  AMLKG                            biolink:in_complex_with   \n",
       "10604  AMLKG                                  biolink:regulates   \n",
       "10605  AMLKG                                  biolink:regulates   \n",
       "10606  AMLKG                                  biolink:regulates   \n",
       "10607  AMLKG                                  biolink:regulates   \n",
       "10608  AMLKG                            biolink:in_complex_with   \n",
       "10609  AMLKG                                  biolink:regulates   \n",
       "10610  AMLKG                                  biolink:regulates   \n",
       "10611  AMLKG                                  biolink:regulates   \n",
       "10612  AMLKG                                  biolink:regulates   \n",
       "10613  AMLKG                                  biolink:regulates   \n",
       "10614  AMLKG                                  biolink:regulates   \n",
       "10615  AMLKG                                  biolink:regulates   \n",
       "10616  AMLKG                                  biolink:regulates   \n",
       "10617  AMLKG             biolink:associated_with_sensitivity_to   \n",
       "10618  AMLKG              biolink:associated_with_resistance_to   \n",
       "10619  AMLKG  biolink:GeneToDiseaseOrPhenotypicFeatureAssoci...   \n",
       "10620  AMLKG                                     biolink:treats   \n",
       "10621  AMLKG                                biolink:subclass_of   \n",
       "\n",
       "                             Subject                         Object  \\\n",
       "10576                   biolink:Gene                   biolink:Cell   \n",
       "10577                   biolink:Gene                   biolink:Gene   \n",
       "10578  biolink:MacromolecularComplex                   biolink:Gene   \n",
       "10579  biolink:MacromolecularComplex      biolink:PhenotypicFeature   \n",
       "10580         biolink:ChemicalEntity                   biolink:Gene   \n",
       "10581                biolink:Protein                   biolink:Gene   \n",
       "10582                   biolink:Gene  biolink:MacromolecularComplex   \n",
       "10583          biolink:SmallMolecule                   biolink:Gene   \n",
       "10584          biolink:SmallMolecule          biolink:SmallMolecule   \n",
       "10585          biolink:SmallMolecule          biolink:ProteinFamily   \n",
       "10586          biolink:ProteinFamily                   biolink:Gene   \n",
       "10587   biolink:EnvironmentalProcess                   biolink:Gene   \n",
       "10588                   biolink:Gene      biolink:PhenotypicFeature   \n",
       "10589  biolink:MacromolecularComplex  biolink:MacromolecularComplex   \n",
       "10590                   biolink:Gene                biolink:Protein   \n",
       "10591          biolink:ProteinFamily          biolink:ProteinFamily   \n",
       "10592          biolink:ProteinFamily  biolink:MacromolecularComplex   \n",
       "10593         biolink:ChemicalEntity  biolink:MacromolecularComplex   \n",
       "10594          biolink:SmallMolecule  biolink:MacromolecularComplex   \n",
       "10595  biolink:MacromolecularComplex                biolink:Protein   \n",
       "10596  biolink:MacromolecularComplex          biolink:ProteinFamily   \n",
       "10597          biolink:ProteinFamily  biolink:MacromolecularComplex   \n",
       "10598  biolink:MacromolecularComplex  biolink:MacromolecularComplex   \n",
       "10599                biolink:Protein      biolink:PhenotypicFeature   \n",
       "10600          biolink:SmallMolecule  biolink:MacromolecularComplex   \n",
       "10601         biolink:ChemicalEntity          biolink:ProteinFamily   \n",
       "10602               biolink:MicroRNA                   biolink:Gene   \n",
       "10603         biolink:ChemicalEntity  biolink:MacromolecularComplex   \n",
       "10604          biolink:ProteinFamily      biolink:PhenotypicFeature   \n",
       "10605          biolink:SmallMolecule      biolink:PhenotypicFeature   \n",
       "10606                   biolink:Drug                   biolink:Gene   \n",
       "10607                biolink:Protein  biolink:MacromolecularComplex   \n",
       "10608                biolink:Protein  biolink:MacromolecularComplex   \n",
       "10609   biolink:Noncoding_RNAProduct                   biolink:Gene   \n",
       "10610                biolink:Protein          biolink:ProteinFamily   \n",
       "10611         biolink:ChemicalEntity                biolink:Protein   \n",
       "10612          biolink:ProteinFamily                biolink:Protein   \n",
       "10613   biolink:EnvironmentalProcess          biolink:SmallMolecule   \n",
       "10614          biolink:SmallMolecule                biolink:Protein   \n",
       "10615               biolink:MicroRNA      biolink:PhenotypicFeature   \n",
       "10616               biolink:MicroRNA                biolink:Protein   \n",
       "10617                   biolink:Gene                   biolink:Drug   \n",
       "10618                   biolink:Gene                   biolink:Drug   \n",
       "10619                   biolink:Gene                biolink:Disease   \n",
       "10620                   biolink:Drug                biolink:Disease   \n",
       "10621                biolink:Disease                biolink:Disease   \n",
       "\n",
       "                                                     URL  \n",
       "10576  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10577  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10578  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10579  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10580  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10581  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10582  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10583  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10584  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10585  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10586  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10587  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10588  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10589  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10590  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10591  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10592  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10593  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10594  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10595  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10596  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10597  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10598  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10599  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10600  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10601  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10602  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10603  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10604  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10605  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10606  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10607  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10608  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10609  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10610  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10611  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10612  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10613  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10614  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10615  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10616  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10617  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10618  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10619  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10620  https://amlkg.systemsbiology.org:9990/AMLkg/query  \n",
       "10621  https://amlkg.systemsbiology.org:9990/AMLkg/query  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metaKG_sele"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'AMLKG': 'https://amlkg.systemsbiology.org:9990/AMLkg/query', 'Clinical Trials KP - TRAPI 1.5.0': 'https://multiomics.transltr.io/ctkp/query/', 'Drug Approvals KP - TRAPI 1.5.0': 'https://multiomics.transltr.io/dakp/query/'}\n",
      "(46, 5)\n"
     ]
    }
   ],
   "source": [
    "# select a list of APIs to use and a list of predicates to use\n",
    "selected_APIlist = [\n",
    "    'AMLKG',\n",
    "    'Clinical Trials KP - TRAPI 1.5.0', \n",
    "    'Drug Approvals KP - TRAPI 1.5.0',\n",
    "]\n",
    "\n",
    "if len(selected_APIlist) == 0:\n",
    "    select_APIs = APInames\n",
    "else:\n",
    "    select_APIs = {k: APInames[k] for k in selected_APIlist if k in APInames}\n",
    "\n",
    "selected_metaKG = metaKG[metaKG['API'].isin(select_APIs.keys())]\n",
    "print(select_APIs)\n",
    "print(selected_metaKG.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MONDO:0018874\n",
      "AMLKG: Success!\n"
     ]
    }
   ],
   "source": [
    "input_node_id, result, result_parsed, result_ranked_by_primary_infores = TCT.Neiborhood_finder('AML',\n",
    "                                                                                            node2_categories = ['biolink:SmallMolecule', 'biolink:Drug', 'biolink:ChemicalEntity'],\n",
    "                                                                                            APInames = select_APIs,\n",
    "                                                                                            metaKG = selected_metaKG,\n",
    "                                                                                            API_predicates = API_predicates)     "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Text(0.5, 0, 'Pemigatinib'), Text(2.5, 0, 'Marqibo'), Text(4.5, 0, 'diarsenic trioxide'), Text(6.5, 0, 'DAUNOrubicin Hydrochloride Novaplus'), Text(8.5, 0, 'Quizartinib'), Text(10.5, 0, 'Gilteritinib'), Text(12.5, 0, 'Mitoxantrone'), Text(14.5, 0, 'Prednisone'), Text(16.5, 0, 'Venetoclax'), Text(18.5, 0, 'Daunorubicin'), Text(20.5, 0, 'Decitabine'), Text(22.5, 0, 'cytarabine / daunorubicin'), Text(24.5, 0, 'N-(Hydroxyethyl)doxorubicin hydrochloride'), Text(26.5, 0, 'Enasidenib'), Text(28.5, 0, 'Rituximab 10 MG/1 ML Intravenous Solution [RITUXAN]'), Text(30.5, 0, 'Ivosidenib'), Text(32.5, 0, 'Cyclophosphamide')]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 154684 characters]",
      "text/plain": [
       "<Figure size 1329x1050 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Text(0.5, 0, 'Pemigatinib'), Text(2.5, 0, 'Marqibo'), Text(4.5, 0, 'diarsenic trioxide'), Text(6.5, 0, 'DAUNOrubicin Hydrochloride Novaplus'), Text(8.5, 0, 'Quizartinib'), Text(10.5, 0, 'Gilteritinib'), Text(12.5, 0, 'Mitoxantrone'), Text(14.5, 0, 'Prednisone'), Text(16.5, 0, 'Venetoclax'), Text(18.5, 0, 'Daunorubicin'), Text(20.5, 0, 'Decitabine'), Text(22.5, 0, 'cytarabine / daunorubicin'), Text(24.5, 0, 'N-(Hydroxyethyl)doxorubicin hydrochloride'), Text(26.5, 0, 'Enasidenib'), Text(28.5, 0, 'Rituximab 10 MG/1 ML Intravenous Solution [RITUXAN]'), Text(30.5, 0, 'Ivosidenib'), Text(32.5, 0, 'Cyclophosphamide')]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 154136 characters]",
      "text/plain": [
       "<Figure size 1329x1050 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Pemigatinib</th>\n",
       "      <th>Midostaurin</th>\n",
       "      <th>Marqibo</th>\n",
       "      <th>Gemtuzumab</th>\n",
       "      <th>diarsenic trioxide</th>\n",
       "      <th>Cytarabine</th>\n",
       "      <th>DAUNOrubicin Hydrochloride Novaplus</th>\n",
       "      <th>Rituximab</th>\n",
       "      <th>Quizartinib</th>\n",
       "      <th>GLASDEGIB MALEATE</th>\n",
       "      <th>...</th>\n",
       "      <th>Olutasidenib</th>\n",
       "      <th>N-(Hydroxyethyl)doxorubicin hydrochloride</th>\n",
       "      <th>Idarubicin</th>\n",
       "      <th>Enasidenib</th>\n",
       "      <th>Glasdegib</th>\n",
       "      <th>Rituximab 10 MG/1 ML Intravenous Solution [RITUXAN]</th>\n",
       "      <th>Azacitidine</th>\n",
       "      <th>Ivosidenib</th>\n",
       "      <th>Tioguanine</th>\n",
       "      <th>Cyclophosphamide</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>biolink:treats</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 33 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Pemigatinib  Midostaurin  Marqibo  Gemtuzumab  \\\n",
       "biolink:treats            1            1        1           1   \n",
       "\n",
       "                diarsenic trioxide  Cytarabine  \\\n",
       "biolink:treats                   1           1   \n",
       "\n",
       "                DAUNOrubicin Hydrochloride Novaplus  Rituximab  Quizartinib  \\\n",
       "biolink:treats                                    1          1            1   \n",
       "\n",
       "                GLASDEGIB MALEATE  ...  Olutasidenib  \\\n",
       "biolink:treats                  1  ...             1   \n",
       "\n",
       "                N-(Hydroxyethyl)doxorubicin hydrochloride  Idarubicin  \\\n",
       "biolink:treats                                          1           1   \n",
       "\n",
       "                Enasidenib  Glasdegib  \\\n",
       "biolink:treats           1          1   \n",
       "\n",
       "                Rituximab 10 MG/1 ML Intravenous Solution [RITUXAN]  \\\n",
       "biolink:treats                                                  1     \n",
       "\n",
       "                Azacitidine  Ivosidenib  Tioguanine  Cyclophosphamide  \n",
       "biolink:treats            1           1           1                 1  \n",
       "\n",
       "[1 rows x 33 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Step 8: Visualize the results\n",
    "TCT.visulization_one_hop_ranking(result_ranked_by_primary_infores, result_parsed, \n",
    "                                num_of_nodes = 50, input_query = input_node_id, \n",
    "                                fontsize = 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MONDO:0018874\n",
      "NCBIGene:7157\n",
      "AMLKG: Success!\n",
      "'Automat-ehr-may-treat-kp(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'SPOKE KP for TRAPI 1.5' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'COHD TRAPI' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'imProving Agent for TRAPI 1.5' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Text Mined Cooccurrence API' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'MolePro' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-icees-kg(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-ehr-clinical-connections-kp(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-hmdb(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-ubergraph(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "Automat-hetionet(Trapi v1.5.0): Success!\n",
      "'Automat-reactome(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "Automat-monarchinitiative(Trapi v1.5.0): Success!\n",
      "'Knowledge Collaboratory API' generated an exception: argument of type 'NoneType' is not iterable\n",
      "Automat-ctd(Trapi v1.5.0): Success!\n",
      "Automat-drug-central(Trapi v1.5.0): Success!\n",
      "Automat-robokop(Trapi v1.5.0): Success!\n",
      "BioThings Explorer (BTE) TRAPI: Success!\n",
      "Service Provider TRAPI: Success!\n",
      "AMLKG: Success!\n",
      "'Automat-ehr-may-treat-kp(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-ehr-clinical-connections-kp(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'SPOKE KP for TRAPI 1.5' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'MolePro' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'imProving Agent for TRAPI 1.5' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-icees-kg(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-gtopdb(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-monarchinitiative(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Text Mined Cooccurrence API' generated an exception: argument of type 'NoneType' is not iterable\n",
      "'Automat-hmdb(Trapi v1.5.0)' generated an exception: argument of type 'NoneType' is not iterable\n",
      "Automat-pharos(Trapi v1.5.0): Success!\n",
      "Automat-hetionet(Trapi v1.5.0): Success!\n",
      "Automat-ctd(Trapi v1.5.0): Success!\n",
      "Automat-cam-kp(Trapi v1.5.0): Success!\n",
      "Automat-robokop(Trapi v1.5.0): Success!\n",
      "Service Provider TRAPI: Success!\n",
      "BioThings Explorer (BTE) TRAPI: Success!\n",
      "NodeNorm does not know about these identifiers: UNII:ET4JC4S66E,UNII:Y8DGL9885E,UNII:3D2KVS9K7P,UNII:OEN4982XNW,UNII:PVH8394DLN,UNII:FR89SC8CT4,UNII:Q805XO2F7C,UNII:E6349B696W,UNII:VS12X225PL,UNII:IZR558KO53,UNII:475247QF1Z,UNII:L4D9X59F34,UNII:O5V0F26RUW,UNII:RXG7T6RB8K,RXCUI:1791496,RXCUI:1736582,RXCUI:1722942,MESH:C059764,MESH:D000596,MESH:C081693,UMLS:DC0003818,UMLS:DC0012155,UMLS:DC0037549,UMLS:DC0041411,UNII:7EV65EAW6H,UMLS:C0596087,UMLS:C0002073,UMLS:C0062128,UMLS:C0597573,RXCUI:1433769,RXCUI:1795154,RXCUI:1662281,RXCUI:1362058,RXCUI:1860240,RXCUI:1807509,RXCUI:1665191,RXCUI:1362049,RXCUI:1656667,RXCUI:1362054,RXCUI:1723777,RXCUI:379454,RXCUI:1860464,RXCUI:1658260,RXCUI:1795608,RXCUI:1666799,RXCUI:1729198,RXCUI:1360104,RXCUI:1719287,RXCUI:900963\n",
      "CHEMBL.COMPOUND:CHEMBL1702181: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL591126: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL580421: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL1389794: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL1303948: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL1522984: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3979783: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3912203: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3894034: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3967624: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3966414: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3895110: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3983285: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3906706: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3937960: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3968623: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3980581: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3895513: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3949558: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3931174: no preferred name\n",
      "CHEMBL.COMPOUND:CHEMBL3895549: no preferred name\n",
      "NodeNorm does not know about these identifiers: ChEBI:CHEBI:94980,ChEBI:CHEBI:45307,ChEBI:CHEBI:91326,PUBCHEM:CID:216345,TTD.DRUG:D0T8EL,TTD.DRUG:D02CKH,CHEMBL.COMPOUND:CHEMBL297812,CHEMBL.COMPOUND:CHEMBL3545195,CHEMBL.COMPOUND:CHEMBL4297189,CHEMBL.COMPOUND:CHEMBL3545007,CHEBI:35224,CHEBI:16670,CHEBI:35222,CHEBI:16541,CHEBI:36355,CHEBI:39026,CHEBI:25212,CHEBI:4056,CHEBI:25512,CHEBI:23888,CHEBI:60151,CHEBI:62488,CHEBI:51451,CHEBI:183050,CHEBI:36080,CHEBI:36348,CHEBI:48706,CHEBI:59132,CHEBI:73647,CHEBI:38559,CHEBI:48705,CHEBI:50902,CHEBI:82665,CHEBI:37396,CHEBI:140399,CHEBI:77966,CHEBI:48432,CHEBI:38637,MESH:D000596,MESH:D053222,MESH:C104874,MESH:C110072,MESH:C066716,CHEMBL.COMPOUND:CHEMBL2108585,UMLS:C0011501,INCHIKEY:OJDPNQPVVVQHBS-WHSBFGAESA-N,INCHIKEY:DIVMTXBUDOMYFO-UHFFFAOYSA-N,INCHIKEY:LDOCNQIRVXHZQU-BVRKHOPBSA-N,INCHIKEY:HZTQINJSGAPBLS-ZITMISKDSA-N,INCHIKEY:HZTQINJSGAPBLS-FPHQXIGGSA-N,INCHIKEY:ONXUOCISKNKLEO-UHFFFAOYSA-N,INCHIKEY:AVCINXLMIYQZIG-ZQWAWDFXSA-N,INCHIKEY:NBPAQCMFLGCFBK-UHFFFAOYSA-N,UMLS:C0018282,UMLS:C0596087,UMLS:C0052418,CHEBI:140921,CHEBI:139492,CHEBI:38462,CHEBI:138180,CHEBI:138181,CHEBI:138157,MESH:C507277,MESH:C058575,MESH:D010436,MESH:C060751,MESH:C054569,MESH:D012471,MESH:D006150,MESH:D003839,MESH:C045346,MESH:D010977,MESH:D000809,MESH:C052507,MESH:D004745,MESH:C476718,MESH:C048677\n",
      "Number of possible paths:  788\n",
      "NodeNorm does not know about these identifiers: UMLS:C0596087,MESH:D000596\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/guangrong/.pyenv/versions/3.12.1/lib/python3.12/site-packages/TCT/TCT.py:1517: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.\n",
      "  ax.set_xticklabels(ax.get_xticklabels(), rotation=90, ha=\"center\", fontsize=fontsize)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 252704 characters]",
      "text/plain": [
       "<Figure size 1500x1500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "paths, input_node1_id, input_node2_id, result1, result2, result_parsed1, result_parsed2, result_ranked_by_primary_infores1, result_ranked_by_primary_infores2 = TCT.Path_finder('AML', \n",
    "                                                                                                                                                                                'TP53', \n",
    "                                                                                                                                                                                ['biolink:Drug', 'biolink:SmallMolecule', 'biolink:ChemicalEntity'], \n",
    "                                                                                                                                                                                APInames=APInames, \n",
    "                                                                                                                                                                                metaKG=metaKG, \n",
    "                                                                                                                                                                                API_predicates=API_predicates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>score</th>\n",
       "      <th>output_node</th>\n",
       "      <th>predictes1</th>\n",
       "      <th>predictes2</th>\n",
       "      <th>output_node_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Bortezomib</th>\n",
       "      <td>0.642857</td>\n",
       "      <td>CHEBI:52717</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Bortezomib</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tretinoin</th>\n",
       "      <td>0.489796</td>\n",
       "      <td>CHEBI:15367</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Tretinoin</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Azacitidine</th>\n",
       "      <td>0.428571</td>\n",
       "      <td>CHEBI:2038</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:inte...</td>\n",
       "      <td>Azacitidine</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sirolimus</th>\n",
       "      <td>0.367347</td>\n",
       "      <td>CHEBI:9168</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:regulates; biolink:se...</td>\n",
       "      <td>Sirolimus</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Decitabine</th>\n",
       "      <td>0.367347</td>\n",
       "      <td>CHEBI:50131</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Decitabine</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Topotecan</th>\n",
       "      <td>0.357143</td>\n",
       "      <td>CHEBI:63632</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Topotecan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cyclosporine</th>\n",
       "      <td>0.326531</td>\n",
       "      <td>CHEBI:4031</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:regulates; biolink:af...</td>\n",
       "      <td>Cyclosporine</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Venetoclax</th>\n",
       "      <td>0.306122</td>\n",
       "      <td>CHEBI:133021</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:interacts_with; bioli...</td>\n",
       "      <td>Venetoclax</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Vorinostat</th>\n",
       "      <td>0.306122</td>\n",
       "      <td>CHEBI:45716</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Vorinostat</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ascorbic acid</th>\n",
       "      <td>0.275510</td>\n",
       "      <td>CHEBI:22652</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Ascorbic acid</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Daunorubicin hydrochloride</th>\n",
       "      <td>0.275510</td>\n",
       "      <td>CHEBI:31456</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:interacts_with; biolink:affects; bioli...</td>\n",
       "      <td>Daunorubicin hydrochloride</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydroxyurea</th>\n",
       "      <td>0.244898</td>\n",
       "      <td>CHEBI:44423</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Hydroxyurea</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>imatinib methanesulfonate</th>\n",
       "      <td>0.244898</td>\n",
       "      <td>CHEBI:31690</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:occurs_together_in_literature_with; bi...</td>\n",
       "      <td>imatinib methanesulfonate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dexamethasone sodium phosphate</th>\n",
       "      <td>0.244898</td>\n",
       "      <td>CHEBI:4462</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:occurs_together_in_literature_with; bi...</td>\n",
       "      <td>dexamethasone sodium phosphate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Midostaurin</th>\n",
       "      <td>0.224490</td>\n",
       "      <td>CHEBI:63452</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:occu...</td>\n",
       "      <td>Midostaurin</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dasatinib</th>\n",
       "      <td>0.214286</td>\n",
       "      <td>CHEBI:49375</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:sensitivity_associate...</td>\n",
       "      <td>Dasatinib</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Acetaminophen</th>\n",
       "      <td>0.214286</td>\n",
       "      <td>CHEBI:46195</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:affe...</td>\n",
       "      <td>Acetaminophen</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metformin</th>\n",
       "      <td>0.214286</td>\n",
       "      <td>CHEBI:6801</td>\n",
       "      <td>biolink:has_adverse_event; biolink:treats_or_a...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:occu...</td>\n",
       "      <td>Metformin</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alvocidib</th>\n",
       "      <td>0.214286</td>\n",
       "      <td>CHEBI:47344</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:occu...</td>\n",
       "      <td>Alvocidib</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sorafenib</th>\n",
       "      <td>0.214286</td>\n",
       "      <td>CHEBI:50924</td>\n",
       "      <td>biolink:treats_or_applied_or_studied_to_treat;...</td>\n",
       "      <td>biolink:affects; biolink:affects; biolink:occu...</td>\n",
       "      <td>Sorafenib</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   score   output_node  \\\n",
       "Bortezomib                      0.642857   CHEBI:52717   \n",
       "Tretinoin                       0.489796   CHEBI:15367   \n",
       "Azacitidine                     0.428571    CHEBI:2038   \n",
       "Sirolimus                       0.367347    CHEBI:9168   \n",
       "Decitabine                      0.367347   CHEBI:50131   \n",
       "Topotecan                       0.357143   CHEBI:63632   \n",
       "Cyclosporine                    0.326531    CHEBI:4031   \n",
       "Venetoclax                      0.306122  CHEBI:133021   \n",
       "Vorinostat                      0.306122   CHEBI:45716   \n",
       "Ascorbic acid                   0.275510   CHEBI:22652   \n",
       "Daunorubicin hydrochloride      0.275510   CHEBI:31456   \n",
       "Hydroxyurea                     0.244898   CHEBI:44423   \n",
       "imatinib methanesulfonate       0.244898   CHEBI:31690   \n",
       "dexamethasone sodium phosphate  0.244898    CHEBI:4462   \n",
       "Midostaurin                     0.224490   CHEBI:63452   \n",
       "Dasatinib                       0.214286   CHEBI:49375   \n",
       "Acetaminophen                   0.214286   CHEBI:46195   \n",
       "Metformin                       0.214286    CHEBI:6801   \n",
       "Alvocidib                       0.214286   CHEBI:47344   \n",
       "Sorafenib                       0.214286   CHEBI:50924   \n",
       "\n",
       "                                                                       predictes1  \\\n",
       "Bortezomib                      biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Tretinoin                       biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Azacitidine                     biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Sirolimus                       biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Decitabine                      biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Topotecan                       biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Cyclosporine                    biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Venetoclax                      biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Vorinostat                      biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Ascorbic acid                   biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Daunorubicin hydrochloride      biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Hydroxyurea                     biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "imatinib methanesulfonate       biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "dexamethasone sodium phosphate  biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Midostaurin                     biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Dasatinib                       biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Acetaminophen                   biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Metformin                       biolink:has_adverse_event; biolink:treats_or_a...   \n",
       "Alvocidib                       biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "Sorafenib                       biolink:treats_or_applied_or_studied_to_treat;...   \n",
       "\n",
       "                                                                       predictes2  \\\n",
       "Bortezomib                      biolink:affects; biolink:affects; biolink:affe...   \n",
       "Tretinoin                       biolink:affects; biolink:affects; biolink:affe...   \n",
       "Azacitidine                     biolink:affects; biolink:affects; biolink:inte...   \n",
       "Sirolimus                       biolink:affects; biolink:regulates; biolink:se...   \n",
       "Decitabine                      biolink:affects; biolink:affects; biolink:affe...   \n",
       "Topotecan                       biolink:affects; biolink:affects; biolink:affe...   \n",
       "Cyclosporine                    biolink:affects; biolink:regulates; biolink:af...   \n",
       "Venetoclax                      biolink:affects; biolink:interacts_with; bioli...   \n",
       "Vorinostat                      biolink:affects; biolink:affects; biolink:affe...   \n",
       "Ascorbic acid                   biolink:affects; biolink:affects; biolink:affe...   \n",
       "Daunorubicin hydrochloride      biolink:interacts_with; biolink:affects; bioli...   \n",
       "Hydroxyurea                     biolink:affects; biolink:affects; biolink:affe...   \n",
       "imatinib methanesulfonate       biolink:occurs_together_in_literature_with; bi...   \n",
       "dexamethasone sodium phosphate  biolink:occurs_together_in_literature_with; bi...   \n",
       "Midostaurin                     biolink:affects; biolink:affects; biolink:occu...   \n",
       "Dasatinib                       biolink:affects; biolink:sensitivity_associate...   \n",
       "Acetaminophen                   biolink:affects; biolink:affects; biolink:affe...   \n",
       "Metformin                       biolink:affects; biolink:affects; biolink:occu...   \n",
       "Alvocidib                       biolink:affects; biolink:affects; biolink:occu...   \n",
       "Sorafenib                       biolink:affects; biolink:affects; biolink:occu...   \n",
       "\n",
       "                                              output_node_name  \n",
       "Bortezomib                                          Bortezomib  \n",
       "Tretinoin                                            Tretinoin  \n",
       "Azacitidine                                        Azacitidine  \n",
       "Sirolimus                                            Sirolimus  \n",
       "Decitabine                                          Decitabine  \n",
       "Topotecan                                            Topotecan  \n",
       "Cyclosporine                                      Cyclosporine  \n",
       "Venetoclax                                          Venetoclax  \n",
       "Vorinostat                                          Vorinostat  \n",
       "Ascorbic acid                                    Ascorbic acid  \n",
       "Daunorubicin hydrochloride          Daunorubicin hydrochloride  \n",
       "Hydroxyurea                                        Hydroxyurea  \n",
       "imatinib methanesulfonate            imatinib methanesulfonate  \n",
       "dexamethasone sodium phosphate  dexamethasone sodium phosphate  \n",
       "Midostaurin                                        Midostaurin  \n",
       "Dasatinib                                            Dasatinib  \n",
       "Acetaminophen                                    Acetaminophen  \n",
       "Metformin                                            Metformin  \n",
       "Alvocidib                                            Alvocidib  \n",
       "Sorafenib                                            Sorafenib  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paths.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2bf82c61628a4b4caa2b9a51c49f04b1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "CytoscapeWidget(cytoscape_layout={'name': 'cola', 'title': 'Path', 'nodeSpacing': 80, 'edgeLengthVal': 50}, cy…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forplot = TCT.visulize_path(input_node1_id, name_resolver.lookup('Azacitidine').curie, input_node2_id, result1, result2) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "3.12.1",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
