Easy Vitessce Documentation#

Easy Vitessce is a Python package for turning Scanpy and SpatialData plots into interactive Vitessce visualizations with minimal code changes.

Installation#

Requires Python 3.9 or greater.

pip install 'easy_vitessce @ git+https://github.com/vitessce/easy_vitessce@main'

How to Use and Examples#

The package can be imported with

from easy_vitessce.VitessceSpatialData import VitessceSpatialData
from easy_vitessce import configure_plots

Scanpy is also required for this package.

import scanpy as sc

Note: All example datasets are from Scanpy unless otherwise noted.

Deactivating/Reactivating Interactive Plots#

Passing disable_plots into configure_plots will deactivate Vitessce plots.

Passing enable_plots into configure_plots will reactivate Vitessce plots.

Note: While diable_plots and enable_plots can be passed in at the same time, listing the same plot in both will result in an error.

configure_plots(disable_plots = ["spatial", "violin"])

configure_plots(enable_plots = ["spatial", "violin"])

Spatial Plot (SpatialData version)#

Note: This example uses SpatialData’s mouse brain MERFISH dataset.

sdata = sd.read_zarr(spatialdata_filepath)
sdata.pl.render_images(element="rasterized").pl.render_shapes(element="cells", color="Acta2").pl.show()

spatialdata_filepath should lead to a .zarr file containing spatial data with an Images folder. The file structure of the example above is as follows. Since it does not have a Labels folder, calling pl.render_labels() will not display any data.

   SpatialData object, with associated Zarr store:
├── Images
│     └── 'rasterized': DataArray[cyx] (1, 522, 575)
├── Points
│     └── 'single_molecule': DataFrame with shape: (<Delayed>, 3) (2D points)
├── Shapes
│     ├── 'anatomical': GeoDataFrame shape: (6, 1) (2D shapes)
│     └── 'cells': GeoDataFrame shape: (2389, 2) (2D shapes)
└── Tables
      └── 'table': AnnData (2389, 268)

easy_vitessce_example

Spatial Plot (Scanpy version)#

Easy Vitessce’s spatial function also displays a spatial plot, but with Scanpy’s syntax. This example uses Scanpy’s Visium dataset.

adata = sc.datasets.visium_sge(sample_id="Targeted_Visium_Human_Glioblastoma_Pan_Cancer", include_hires_tiff=True)

sc.pl.spatial(adata, color = "log1p_n_genes_by_counts")
_images/sc_spatial_documentation.gif

Scatterplots#

Easy Vitessce’s embedding function displays UMAP, PCA, and t-SNE scatterplots.

adata = sc.datasets.pbmc68k_reduced()

sc.pl.embedding(adata, basis="umap", color="CD79A")
sc.pl.embedding(adata, basis="pca", color=["CD79A", "CD53"])
sc.pl.embedding(adata, basis="tsne", color=["bulk_labels", "louvain", "phase"])
_images/updated_umap.gif

Example of UMAP using Easy Vitessce

Dotplot#

Note: To select/deselect multiple genes, hold SHIFT while clicking on genes in the Gene List.

adata = sc.datasets.pbmc68k_reduced()

sc.pl.dotplot(adata, markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"], groupby="bulk_labels")
_images/dotplot_example.gif

Violin Plot#

adata = sc.datasets.pbmc68k_reduced()

sc.pl.violin(adata, markers = "AP2S1", groupby = "bulk_labels")
_images/updated_violin.gif

Heatmap#

adata = sc.datasets.pbmc68k_reduced()

sc.pl.heatmap(adata, groupby = "bulk_labels", markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ'])
_images/heatmap.gif