{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# hv-anndata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import holoviews as hv\n", "import panel as pn\n", "import scanpy as sc\n", "\n", "import hv_anndata\n", "from hv_anndata import A" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv_anndata.register()\n", "hv.extension(\"bokeh\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example workflow 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "adata = sc.datasets.paul15()\n", "sc.pp.pca(adata)\n", "sc.pp.neighbors(adata)\n", "sc.tl.umap(adata)\n", "adata" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Simple HoloViews/Bokeh scatter of UMAP results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(\n", " hv\n", " .Scatter(\n", " adata, A.obsm[\"X_umap\"][0], [A.obsm[\"X_umap\"][1], A.obs[\"paul15_clusters\"]]\n", " )\n", " .opts(\n", " color=A.obs[\"paul15_clusters\"],\n", " cmap=\"Category20\",\n", " legend_position=\"left\",\n", " frame_width=500,\n", " height=500,\n", " alpha=0.5,\n", " tools=[\"hover\"],\n", " )\n", " .hist()\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### `ManifoldMap` App to explore all dimensionality reduction results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv_anndata.ManifoldMap(\n", " adata=adata, datashade=False, reduction=\"X_umap\", show_labels=True\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Holoviews/Bokeh Dotmap plot " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### `ManifoldMap` App to explore all dimensionality reduction results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv_anndata.ManifoldMap(\n", " adata=adata, datashade=False, reduction=\"X_umap\", show_labels=True\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Holoviews/Bokeh Dotmap widget" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Required for the GeneSelector to render properly\n", "pn.extension(\"jsoneditor\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "marker_genes = {\n", " \"Erythroids\": [\"Gata1\", \"Klf1\", \"Epor\", \"Gypa\", \"Hba-a2\"],\n", " # \"Neutrophils\": [\"Elane\", \"Cebpe\", \"Ctsg\", \"Mpo\", \"Gfi1\"],\n", " \"Monocytes\": [\"Irf8\", \"Csf1r\", \"Ctsg\", \"Mpo\"],\n", " \"Megakaryocytes\": [\"Itga2b\", \"Pbx1\", \"Sdpr\", \"Vwf\"],\n", " \"Basophils\": [\"Mcpt8\", \"Prss34\"],\n", " \"Mast cells\": [\"Cma1\", \"Gzmb\"],\n", "}\n", "hv_anndata.Dotmap(adata=adata, marker_genes=marker_genes, groupby=\"paul15_clusters\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example workflow 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dotmap plot with dendrogram" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "adata2 = sc.datasets.pbmc68k_reduced()\n", "sel_marker_genes = {\n", " \"CD14+ Mono\": [\"FCN1\"],\n", " \"CD16+ Mono\": [\"FCGR3A\"],\n", " \"ID2-hi myeloid prog\": [\"ID2\", \"S100A9\"],\n", " \"cDC2\": [\"CST3\", \"LYZ\", \"CLEC10A\", \"FCER1A\"],\n", " \"Lymph prog\": [\"CD79B\", \"IGLL1\"],\n", " \"B1 B\": [\"MS4A1\", \"BLK\"],\n", " \"Plasma cells\": [\"MZB1\"],\n", " \"CD4+ T activated\": [\"CD4\", \"IL7R\"],\n", " \"pDC\": [\"GZMB\"],\n", "}\n", "\n", "hv_anndata.Dotmap(\n", " adata=adata2,\n", " marker_genes=sel_marker_genes,\n", " groupby=\"bulk_labels\",\n", " dendrogram=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example workflow 3\n", "\n", "### Linked brushing enabled between the Manifoldmap and the Dotmap plots" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ls = hv.link_selections.instance()\n", "\n", "mm = hv_anndata.ManifoldMap(\n", " adata=adata, reduction=\"X_umap\", show_labels=True, responsive=True, ls=ls\n", ")\n", "\n", "marker_genes = {\n", " \"Erythroids\": [\"Gata1\", \"Klf1\", \"Epor\", \"Gypa\", \"Hba-a2\"],\n", " \"Neutrophils\": [\"Elane\", \"Cebpe\", \"Ctsg\", \"Mpo\", \"Gfi1\"],\n", " \"Monocytes\": [\"Irf8\", \"Csf1r\", \"Ctsg\", \"Mpo\"],\n", " \"Megakaryocytes\": [\"Itga2b\", \"Pbx1\", \"Sdpr\", \"Vwf\"],\n", " \"Basophils\": [\"Mcpt8\", \"Prss34\"],\n", " \"Mast cells\": [\"Cma1\", \"Gzmb\"],\n", "}\n", "\n", "dmop = hv_anndata.dotmap_from_manifoldmap(\n", " mm,\n", " marker_genes=marker_genes,\n", " groupby=\"paul15_clusters\",\n", " plot_opts=dict(height=500),\n", ")\n", "\n", "pn.Column(mm, dmop)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{toctree}\n", ":hidden:\n", ":maxdepth: 2\n", "\n", "api/index\n", "examples/AnnData\n", "examples/Violin\n", "examples/scanpy/index\n", "```" ] } ], "metadata": { "kernelspec": { "display_name": "hv-anndata", "language": "python", "name": "hv-anndata" }, "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.13.9" } }, "nbformat": 4, "nbformat_minor": 4 }