hv-anndataΒΆ

import holoviews as hv
import panel as pn
import scanpy as sc

import hv_anndata
from hv_anndata.interface import ACCESSOR as A
hv_anndata.register()
hv.extension("bokeh")
β“˜

Example workflow 1ΒΆ

adata = sc.datasets.paul15()
sc.pp.pca(adata)
sc.pp.neighbors(adata)
sc.tl.umap(adata)
adata
AnnData object with n_obs Γ— n_vars = 2730 Γ— 3451
    obs: 'paul15_clusters'
    uns: 'iroot', 'pca', 'neighbors', 'umap'
    obsm: 'X_pca', 'X_umap'
    varm: 'PCs'
    obsp: 'distances', 'connectivities'

Simple HoloViews/Bokeh scatter of UMAP resultsΒΆ

(
    hv.Scatter(
        adata, A.obsm["X_umap"][0], [A.obsm["X_umap"][1], A.obs["paul15_clusters"]]
    )
    .opts(
        color=A.obs["paul15_clusters"],
        cmap="Category20",
        legend_position="left",
        frame_width=500,
        height=500,
        alpha=0.5,
        tools=["hover"],
    )
    .hist()
)

ManifoldMap App to explore all dimensionality reduction resultsΒΆ

hv_anndata.ManifoldMap(
    adata=adata, datashade=False, reduction="X_umap", show_labels=True
)

Holoviews/Bokeh Dotmap plotΒΆ

ManifoldMap App to explore all dimensionality reduction resultsΒΆ

hv_anndata.ManifoldMap(
    adata=adata, datashade=False, reduction="X_umap", show_labels=True
)

Holoviews/Bokeh Dotmap plotΒΆ

marker_genes = {
    "Erythroids": ["Gata1", "Klf1", "Epor", "Gypa", "Hba-a2"],
    # "Neutrophils": ["Elane", "Cebpe", "Ctsg", "Mpo", "Gfi1"],
    # "Neutrophils": ["Elane", "Cebpe", "Ctsg", "Mpo", "Gfi1"],
    "Monocytes": ["Irf8", "Csf1r", "Ctsg", "Mpo"],
    "Megakaryocytes": ["Itga2b", "Pbx1", "Sdpr", "Vwf"],
    "Basophils": ["Mcpt8", "Prss34"],
    "Mast cells": ["Cma1", "Gzmb"],
}
hv_anndata.Dotmap(
    adata=adata, marker_genes=marker_genes, groupby="paul15_clusters"
).opts(width=1000, height=500)
WARNING:param.PointPlot00765: responsive mode could not be enabled because fixed width and height were specified.

Example workflow 2ΒΆ

Dotmap plot with dendrogramΒΆ

adata2 = sc.datasets.pbmc68k_reduced()
sel_marker_genes = {
    "CD14+ Mono": ["FCN1"],
    "CD16+ Mono": ["FCGR3A"],
    "ID2-hi myeloid prog": ["ID2", "S100A9"],
    "cDC2": ["CST3", "LYZ", "CLEC10A", "FCER1A"],
    "Lymph prog": ["CD79B", "IGLL1"],
    "B1 B": ["MS4A1", "BLK"],
    "Plasma cells": ["MZB1"],
    "CD4+ T activated": ["CD4", "IL7R"],
    "pDC": ["GZMB"],
}
dm2 = hv_anndata.Dotmap(
    adata=adata2, marker_genes=sel_marker_genes, groupby="bulk_labels"
).opts(height=500, width=1200)
hv.operation.dendrogram(
    dm2, adjoint_dims=["cluster"], main_dim="mean_expression", invert=True
)
WARNING:param.PointPlot01018: responsive mode could not be enabled because fixed width and height were specified.

Example workflow 3ΒΆ

Dotmap plot configurable with the AutoCompleteMultiChoice widgetΒΆ

# Required for the AutoCompleteMultiChoice to render properly
pn.extension("jsoneditor")
marker_genes = {
    "Erythroids": ["Gata1", "Klf1", "Epor", "Gypa", "Hba-a2"],
    "Neutrophils": ["Elane", "Cebpe", "Ctsg", "Mpo", "Gfi1"],
    "Monocytes": ["Irf8", "Csf1r", "Ctsg", "Mpo"],
    "Megakaryocytes": ["Itga2b", "Pbx1", "Sdpr", "Vwf"],
    "Basophils": ["Mcpt8", "Prss34"],
    "Mast cells": ["Cma1", "Gzmb"],
}
options = sorted(gene for genes in marker_genes.values() for gene in genes)
w_autocompletemc = hv_anndata.AutoCompleteMultiChoice(options=options)
def dotmap_plot(adata, marker_genes, groupby):
    return hv_anndata.Dotmap(
        adata=adata, marker_genes=marker_genes, groupby=groupby
    ).opts(height=500)
pn.Row(
    w_autocompletemc,
    pn.bind(dotmap_plot, adata, w_autocompletemc.param.value, "paul15_clusters"),
)