{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import our code \n",
    "import sys\n",
    "sys.path.append('D:/GitHub/test_stereopy_3D_browser')\n",
    "from stereopy_3D_browser import launch,endServer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 90411 × 30254\n",
       "    obs: 'ctype_user', 'slice', 'seurat_clusters', 'celltype'\n",
       "    uns: 'ccc_data'\n",
       "    obsm: 'spatial', 'spatial_regis'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# import annconda and load input data\n",
    "import anndata as ad\n",
    "adata = ad.read_h5ad(\"D:/GitHub/test_stereopy_3D_browser/examples/ccc.h5ad\")\n",
    "adata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "63632_48    ventricular-specific CM\n",
       "71109_47    ventricular-specific CM\n",
       "71222_47    ventricular-specific CM\n",
       "71529_47    ventricular-specific CM\n",
       "57013_49    ventricular-specific CM\n",
       "                     ...           \n",
       "77057_56         atrial-specific CM\n",
       "77099_56         atrial-specific CM\n",
       "77189_56         atrial-specific CM\n",
       "55382_55         atrial-specific CM\n",
       "55676_55         atrial-specific CM\n",
       "Name: celltype, Length: 90411, dtype: category\n",
       "Categories (6, object): ['atrial-specific CM', 'blood', 'endocardial/endothelial (EC)', 'epicardial (EP)', 'fibro-mesenchymal (FM)', 'ventricular-specific CM']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets see the annotation\n",
    "adata.obs['celltype']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4.10499635, 3.63142948, 2.32      ],\n",
       "       [4.12315354, 3.5931577 , 2.3       ],\n",
       "       [4.1188201 , 3.60296903, 2.3       ],\n",
       "       ...,\n",
       "       [3.64321558, 3.50162579, 2.48      ],\n",
       "       [3.63791952, 3.46330735, 2.46      ],\n",
       "       [3.63051298, 3.47297659, 2.46      ]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets see the 3D coordinate\n",
    "adata.obsm['spatial_regis']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'celltype_key': 'celltype',\n",
       " 'data':                         celltype1                     celltype2  ligand  \\\n",
       " 0                 epicardial (EP)  endocardial/endothelial (EC)  COL1A2   \n",
       " 1                 epicardial (EP)  endocardial/endothelial (EC)  COL1A1   \n",
       " 2    endocardial/endothelial (EC)  endocardial/endothelial (EC)  COL4A2   \n",
       " 3                 epicardial (EP)  endocardial/endothelial (EC)     APP   \n",
       " 4          fibro-mesenchymal (FM)  endocardial/endothelial (EC)     APP   \n",
       " ..                            ...                           ...     ...   \n",
       " 253        fibro-mesenchymal (FM)               epicardial (EP)     VIM   \n",
       " 254        fibro-mesenchymal (FM)        fibro-mesenchymal (FM)     VIM   \n",
       " 255        fibro-mesenchymal (FM)       ventricular-specific CM     VIM   \n",
       " 256       ventricular-specific CM            atrial-specific CM     VIM   \n",
       " 257       ventricular-specific CM               epicardial (EP)     VIM   \n",
       " \n",
       "     receptor  \n",
       " 0       CD93  \n",
       " 1       CD93  \n",
       " 2       CD93  \n",
       " 3      APLP2  \n",
       " 4      APLP2  \n",
       " ..       ...  \n",
       " 253     CD44  \n",
       " 254     CD44  \n",
       " 255     CD44  \n",
       " 256     CD44  \n",
       " 257     CD44  \n",
       " \n",
       " [258 rows x 4 columns]}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets see the CCC data\n",
    "adata.uns['ccc_data']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current front-dir is D:\\GitHub\\test_stereopy_3D_browser/vt3d_browser\n",
      "Server staring now ...\n",
      "Call endServer(\"127.0.0.1\",7654) to end this server\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"1600\"\n",
       "            height=\"1000\"\n",
       "            src=\"http://127.0.0.1:7654/\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "            \n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x1ebe828e220>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [12/Jun/2023 16:46:43] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:43] \"GET /manifest.js?771d4762c4d84c7416b9 HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:43] \"GET /vendor.js?68206e36d03a47277cba HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:43] \"GET /index.js?e502fb3b535a906ba2e0 HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:44] \"GET /summary.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:45] \"GET /Anno/celltype.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:48] \"GET /ccc_dict.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:54] \"GET /CCC/fibro-mesenchymal__FM_/APP.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:46:54] \"GET /CCC/endocardial_endothelial__EC_/RPSA.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:47:18] \"GET /Anno/celltype.json HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "# lets start the browser\n",
    "# now lets launch the browser  \n",
    "launch(adata,cluster_label=['celltype'],\n",
    "                    spatial_label='spatial_regis',\n",
    "                    ccc_key='ccc_data',\n",
    "                    port=7654)"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "[encoded data, 225332 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Here is the screenshot of above cell\n",
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"500\"\n",
       "            height=\"50\"\n",
       "            src=\"http://127.0.0.1:7654/endnow\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "            \n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x1d09de52820>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Server terminate ...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [12/Jun/2023 16:44:52] \"GET /endnow HTTP/1.1\" 404 -\n"
     ]
    }
   ],
   "source": [
    "endServer(\"127.0.0.1\",7654)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "stereopy1",
   "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.8.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
