{ "cells": [ { "cell_type": "markdown", "metadata": { "nbsphinx": "hidden" }, "source": [ "# Vitessce Widget Tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualization of 3k PBMC reference from Remote Zarr Store" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Import dependencies\n", "\n", "We need to import the classes and functions that we will be using from the corresponding packages." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "from os.path import join\n", "from urllib.request import urlretrieve\n", "from anndata import read_h5ad\n", "import scanpy as sc\n", "\n", "from vitessce import (\n", " VitessceConfig,\n", " Component as cm,\n", " CoordinationType as ct,\n", " AnnDataWrapper,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Set the URL for the Remote Dataset\n", "\n", "For this example, we already have uploaded the `pbmc3k` dataset as a zarr store from the [scanpy docs](https://scanpy.readthedocs.io/en/stable/api/scanpy.datasets.pbmc3k.html) to the cloud." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://storage.googleapis.com/vitessce-demo-data/anndata-test/pbmc3k_processed.zarr/'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Create a Vitessce view config\n", "\n", "Define the data and views you would like to include in the widget." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vc = VitessceConfig(schema_version=\"1.0.15\", name='PBMC Reference')\n", "dataset = vc.add_dataset(name='PBMC 3k').add_object(AnnDataWrapper(adata_url=url, obs_set_paths=[\"obs/louvain\"], obs_set_names=[\"Louvain\"], obs_embedding_paths=[\"obsm/X_umap\", \"obsm/X_pca\"], obs_embedding_names=[\"UMAP\", \"PCA\"], obs_feature_matrix_path=\"X\"))\n", "\n", "umap = vc.add_view(cm.SCATTERPLOT, dataset=dataset, mapping=\"UMAP\")\n", "pca = vc.add_view(cm.SCATTERPLOT, dataset=dataset, mapping=\"PCA\")\n", "cell_sets = vc.add_view(cm.OBS_SETS, dataset=dataset)\n", "genes = vc.add_view(cm.FEATURE_LIST, dataset=dataset)\n", "heatmap = vc.add_view(cm.HEATMAP, dataset=dataset)\n", "\n", "vc.layout((umap / pca) | ((cell_sets | genes) / heatmap));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Create the Vitessce widget" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vw = vc.widget()\n", "vw" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "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.0" } }, "nbformat": 4, "nbformat_minor": 4 }