{
    "cells": [
        {
            "cell_type": "code",
            "execution_count": 1,
            "metadata": {},
            "outputs": [],
            "source": [
                "import anndata as ad\n",
                "import ACTIONet as anet"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 2,
            "metadata": {},
            "outputs": [],
            "source": [
                "%load_ext autoreload\n",
                "%autoreload 2\n",
                "%aimport ACTIONet"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 3,
            "metadata": {},
            "outputs": [],
            "source": [
                "adata = ad.read_h5ad(\"../data/pfc5k_ACTIONet_v2_python.h5ad\")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 4,
            "metadata": {},
            "outputs": [
                {
                    "data": {
                        "text/plain": [
                            "<AxesSubplot:title={'center':'__annotations__'}, xlabel='actionet2d1', ylabel='actionet2d2'>"
                        ]
                    },
                    "execution_count": 4,
                    "metadata": {},
                    "output_type": "execute_result"
                },
                {
                    "data": {
                        "image/png": "[encoded data, 45060 characters]",
                        "text/plain": [
                            "<Figure size 432x288 with 1 Axes>"
                        ]
                    },
                    "metadata": {},
                    "output_type": "display_data"
                }
            ],
            "source": [
                "anet.pl.plot_ACTIONet(adata, \"Celltype\")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 5,
            "metadata": {},
            "outputs": [],
            "source": [
                "import numpy as np\n",
                "\n",
                "from random import sample\n",
                "l = adata.obs[\"Celltype\"].copy()\n",
                "perm = sample(list(np.arange(adata.shape[0])), 3000)\n",
                "l[perm] = None"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 6,
            "metadata": {},
            "outputs": [
                {
                    "data": {
                        "text/plain": [
                            "<AxesSubplot:title={'center':'__annotations__'}, xlabel='actionet2d1', ylabel='actionet2d2'>"
                        ]
                    },
                    "execution_count": 6,
                    "metadata": {},
                    "output_type": "execute_result"
                },
                {
                    "data": {
                        "image/png": "[encoded data, 54104 characters]",
                        "text/plain": [
                            "<Figure size 432x288 with 1 Axes>"
                        ]
                    },
                    "metadata": {},
                    "output_type": "display_data"
                }
            ],
            "source": [
                "anet.pl.plot_ACTIONet(adata, l)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 7,
            "metadata": {},
            "outputs": [],
            "source": [
                "l2 = anet.po.cells.infer_missing_labels(adata, initial_labels=l, return_raw=True)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 8,
            "metadata": {},
            "outputs": [
                {
                    "data": {
                        "text/plain": [
                            "<AxesSubplot:title={'center':'__annotations__'}, xlabel='actionet2d1', ylabel='actionet2d2'>"
                        ]
                    },
                    "execution_count": 8,
                    "metadata": {},
                    "output_type": "execute_result"
                },
                {
                    "data": {
                        "image/png": "[encoded data, 44764 characters]",
                        "text/plain": [
                            "<Figure size 432x288 with 1 Axes>"
                        ]
                    },
                    "metadata": {},
                    "output_type": "display_data"
                }
            ],
            "source": [
                "anet.pl.plot_ACTIONet(adata, l2)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 9,
            "metadata": {},
            "outputs": [],
            "source": [
                "l3 = anet.po.cells.correct_labels(adata, initial_labels=\"Celltype\", return_raw=True)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 10,
            "metadata": {},
            "outputs": [
                {
                    "data": {
                        "text/plain": [
                            "<AxesSubplot:title={'center':'__annotations__'}, xlabel='actionet2d1', ylabel='actionet2d2'>"
                        ]
                    },
                    "execution_count": 10,
                    "metadata": {},
                    "output_type": "execute_result"
                },
                {
                    "data": {
                        "image/png": "[encoded data, 44236 characters]",
                        "text/plain": [
                            "<Figure size 432x288 with 1 Axes>"
                        ]
                    },
                    "metadata": {},
                    "output_type": "display_data"
                }
            ],
            "source": [
                "anet.pl.plot_ACTIONet(adata, l3)"
            ]
        }
    ],
    "metadata": {
        "interpreter": {
            "hash": "e6b19d727065d69898d5719ef57bdd3f52a377d995ad1aaa3251e7a9df51309b"
        },
        "kernelspec": {
            "display_name": "Python 3.8.8 64-bit",
            "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.3"
        },
        "orig_nbformat": 4
    },
    "nbformat": 4,
    "nbformat_minor": 2
}
