Visualization of 3k PBMC reference

1. Import dependencies

We need to import the classes and functions that we will be using from the corresponding packages.

[ ]:
import os
from os.path import join
from urllib.request import urlretrieve
from anndata import read_h5ad
import scanpy as sc

from vitessce import (
    Component as cm,
    CoordinationType as ct,

2. Download the dataset

Download pbmc3k_final.h5ad from

[ ]:
os.makedirs("data", exist_ok=True)
adata_filepath = join("data", "pbmc3k_final.h5ad")
urlretrieve('', adata_filepath)

3. Load the dataset

Load the dataset using AnnData’s read_h5ad function.

[ ]:
adata = read_h5ad(adata_filepath)

4. Create a Vitessce view config

Define the data and views you would like to include in the widget.

[ ]:
vc = VitessceConfig(name='PBMC Reference')
dataset = vc.add_dataset(name='PBMC 3k').add_object(AnnDataWrapper(adata, cell_set_obs=["leiden"], cell_set_obs_names=["Leiden"], mappings_obsm=["X_umap", "X_pca"], mappings_obsm_names=["UMAP", "PCA"], expression_matrix="X"))

umap = vc.add_view(cm.SCATTERPLOT, dataset=dataset, mapping="UMAP")
pca = vc.add_view(cm.SCATTERPLOT, dataset=dataset, mapping="PCA")
cell_sets = vc.add_view(cm.CELL_SETS, dataset=dataset)
genes = vc.add_view(cm.GENES, dataset=dataset)
heatmap = vc.add_view(cm.HEATMAP, dataset=dataset)

vc.layout((umap / pca) | ((cell_sets | genes) / heatmap));

5. Create the Vitessce widget

A widget can be created with the .widget() method on the config instance. Here, the proxy=True parameter allows this widget to be used in a cloud notebook environment, such as Binder.

[ ]:
vw = vc.widget()