{
 "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 = 15295 × 13668\n",
       "    obs: 'slice_ID', 'raw_x', 'raw_y', 'new_x', 'new_y', 'new_z', 'annotation', 'batch', 'dpt_pseudotime'\n",
       "    uns: 'annotation_sizes', 'diffmap_evals', 'iroot', 'mesh', 'neighbors', 'paga', 'pca'\n",
       "    obsm: 'X_diffmap', 'X_pca', 'X_umap', 'spatial', 'spatial_elas', 'spatial_rigid'\n",
       "    varm: 'PCs'\n",
       "    layers: 'raw_counts'\n",
       "    obsp: 'connectivities', 'distances'"
      ]
     },
     "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/mesh_paga.h5ad\")\n",
    "adata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "E14-16h_a_S01_20500x62780-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0          CNS\n",
       "E14-16h_a_S01_20500x62800-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0          CNS\n",
       "E14-16h_a_S01_20500x62820-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0    epidermis\n",
       "E14-16h_a_S01_20500x62840-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0          CNS\n",
       "E14-16h_a_S01_20500x62860-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0          CNS\n",
       "                                                               ...    \n",
       "E14-16h_a_S10_43200x77920-9-1                                epidermis\n",
       "E14-16h_a_S10_43200x77940-9-1                                epidermis\n",
       "E14-16h_a_S10_43200x77960-9-1                                  carcass\n",
       "E14-16h_a_S10_43200x77980-9-1                                epidermis\n",
       "E14-16h_a_S10_43200x78000-9-1                                  carcass\n",
       "Name: annotation, Length: 15295, dtype: category\n",
       "Categories (10, object): ['CNS', 'amnioserosa', 'carcass', 'epidermis', ..., 'midgut', 'muscle', 'salivary gland', 'trachea']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets see the annotation info\n",
    "adata.obs['annotation']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-11.17012448,  -8.07053942,   0.        ],\n",
       "       [-11.17012448,  -7.07053942,   0.        ],\n",
       "       [-11.17012448,  -6.07053942,   0.        ],\n",
       "       ...,\n",
       "       [ -2.55247845,  19.90225468,   6.3       ],\n",
       "       [ -1.98124136,  20.72303979,   6.3       ],\n",
       "       [ -1.41000427,  21.54382489,   6.3       ]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets see the 3D spatial coordidate\n",
    "adata.obsm['spatial_rigid']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'connectivities': <10x10 sparse matrix of type '<class 'numpy.float64'>'\n",
       " \twith 86 stored elements in Compressed Sparse Row format>,\n",
       " 'connectivities_tree': <10x10 sparse matrix of type '<class 'numpy.float64'>'\n",
       " \twith 9 stored elements in Compressed Sparse Row format>,\n",
       " 'groups': 'annotation'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lets see the paga data\n",
    "adata.uns['paga']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "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 0x22d6eea6790>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [12/Jun/2023 16:14:06] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:14:06] \"GET /manifest.js?771d4762c4d84c7416b9 HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:14:06] \"GET /vendor.js?68206e36d03a47277cba HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:14:06] \"GET /index.js?e502fb3b535a906ba2e0 HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:14:06] \"GET /summary.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:14:07] \"GET /Anno/annotation.json HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:14:19] \"GET /paga.json HTTP/1.1\" 200 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Server terminate ...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [12/Jun/2023 16:15:25] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [12/Jun/2023 16:15:25] \"GET /endnow HTTP/1.1\" 404 -\n"
     ]
    }
   ],
   "source": [
    "# now lets launch the browser  \n",
    "launch(adata,cluster_label=['annotation'],\n",
    "             spatial_label='spatial',\n",
    "             paga_key='paga',\n",
    "             port=7654)"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "[encoded data, 107800 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Here is the screenshot of above cell\n",
    "![image.png](attachment:image.png)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "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 0x22d6eea6d00>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#now end the web server\n",
    "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
}
