Skip to content

Commit ba20ced

Browse files
committed
WIP: 03
1 parent f1fe3db commit ba20ced

1 file changed

Lines changed: 251 additions & 21 deletions

File tree

notebooks/03-Available-View-Types.ipynb

Lines changed: 251 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
"Vitessce ships with a large number of interactive visualization and control views. In this notebook, we look at some types of views that you may not be familiar with.\n",
1212
"\n",
1313
"\n",
14-
"The views available in Vitessce can generally be categorized into:\n",
14+
"The views available in Vitessce can be categorized into:\n",
1515
"- Spatial view (covered in notebook 01)\n",
1616
"- Scatterplot view for dimensionality reductions / embeddings\n",
1717
"- Heatmap for expression data\n",
18-
"- Genomic profiles for quantitative features aggregated by cell type\n",
1918
"- Control views\n",
2019
" - Cell set manager\n",
2120
" - Feature list\n",
@@ -37,7 +36,7 @@
3736
"3. **Spatial views** — tissue image, layer controller\n",
3837
"4. **Control views** — cell-set tree, gene list, status bar\n",
3938
"\n",
40-
"We use the EasyVitessce Scanpy API for most examples because it is the most concise, then show how to access additional view types through the lower-level `VitessceConfig` API."
39+
"We use the EasyVitessce Scanpy API for most examples because it is the most concise, then show how to access additional view types through the lower-level `VitessceConfig` API. The list of view types available via EasyVitessce can be found at the [documentation](https://vitessce.github.io/easy_vitessce/easy_vitessce.html)."
4140
]
4241
},
4342
{
@@ -59,21 +58,262 @@
5958
},
6059
"outputs": [],
6160
"source": [
62-
"import easy_vitessce as ev\n",
6361
"import scanpy as sc\n",
62+
"import os\n",
63+
"from os.path import join, isdir\n",
6464
"\n",
65-
"# Load the reduced PBMC dataset (ships with Scanpy, no download required)\n",
65+
"from vitessce import (\n",
66+
" VitessceConfig,\n",
67+
" ViewType as vt,\n",
68+
" AnnDataWrapper,\n",
69+
" SpatialDataWrapper,\n",
70+
" vconcat, hconcat,\n",
71+
")\n",
72+
"from vitessce.data_utils import VAR_CHUNK_SIZE"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"## Load the data"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
6688
"adata = sc.datasets.pbmc68k_reduced()\n",
89+
"\n",
90+
"# Run t-SNE to be able to demonstrate sc.pl.tsne.\n",
91+
"sc.tl.tsne(adata)\n",
92+
"\n",
93+
"zarr_path = join(\"data\", \"pbmc68k.zarr\")\n",
94+
"if not isdir(zarr_path):\n",
95+
" os.makedirs(\"data\", exist_ok=True)\n",
96+
" adata.write_zarr(zarr_path, chunks=[adata.shape[0], VAR_CHUNK_SIZE])\n",
97+
"\n",
6798
"adata"
6899
]
69100
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"## Scatterplot"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"metadata": {},
112+
"outputs": [],
113+
"source": [
114+
"vc_scatterplot = VitessceConfig(schema_version=\"1.0.18\", name=\"PBMC 68k dataset with Multiple Views\")\n",
115+
"\n",
116+
"dataset = vc_scatterplot.add_dataset(name=\"PBMC 68k\").add_object(\n",
117+
" AnnDataWrapper(\n",
118+
" adata_store=zarr_path,\n",
119+
" obs_set_paths=[\"obs/bulk_labels\", \"obs/louvain\"],\n",
120+
" obs_set_names=[\"Cell Type\", \"Leiden Cluster\"],\n",
121+
" obs_embedding_paths=[\"obsm/X_umap\", \"obsm/X_pca\"],\n",
122+
" obs_embedding_names=[\"UMAP\", \"PCA\"],\n",
123+
" obs_feature_matrix_path=\"X\",\n",
124+
" )\n",
125+
")\n",
126+
"\n",
127+
"# --- Define views ---\n",
128+
"umap = vc_scatterplot.add_view(vt.SCATTERPLOT, dataset=dataset)\n",
129+
"obs_sets = vc_scatterplot.add_view(vt.OBS_SETS, dataset=dataset)\n",
130+
"genes = vc_scatterplot.add_view(vt.FEATURE_LIST, dataset=dataset)\n",
131+
"\n",
132+
"vc_scatterplot.link_views_by_dict([umap], {\n",
133+
" \"embeddingType\": \"UMAP\",\n",
134+
" \"embeddingObsSetLabelsVisible\": False,\n",
135+
"})\n",
136+
"\n",
137+
"# --- Define the layout ---\n",
138+
"vc_scatterplot.layout(umap | (obs_sets / genes))\n",
139+
"vc_scatterplot.widget()"
140+
]
141+
},
142+
{
143+
"cell_type": "markdown",
144+
"metadata": {},
145+
"source": [
146+
"## Heatmap"
147+
]
148+
},
149+
{
150+
"cell_type": "code",
151+
"execution_count": null,
152+
"metadata": {},
153+
"outputs": [],
154+
"source": [
155+
"vc_heatmap = VitessceConfig(schema_version=\"1.0.18\", name=\"PBMC 68k dataset with Multiple Views\")\n",
156+
"\n",
157+
"dataset = vc_heatmap.add_dataset(name=\"PBMC 68k\").add_object(\n",
158+
" AnnDataWrapper(\n",
159+
" adata_store=zarr_path,\n",
160+
" obs_set_paths=[\"obs/bulk_labels\", \"obs/louvain\"],\n",
161+
" obs_set_names=[\"Cell Type\", \"Leiden Cluster\"],\n",
162+
" obs_feature_matrix_path=\"X\",\n",
163+
" )\n",
164+
")\n",
165+
"\n",
166+
"# --- Define views ---\n",
167+
"heatmap = vc_heatmap.add_view(vt.HEATMAP, dataset=dataset).set_props(transpose=True)\n",
168+
"obs_sets = vc_heatmap.add_view(vt.OBS_SETS, dataset=dataset)\n",
169+
"\n",
170+
"vc_heatmap.link_views_by_dict([heatmap], { \"featureValueColormapRange\": [0.0, 0.25] })\n",
171+
"\n",
172+
"\n",
173+
"# --- Define the layout ---\n",
174+
"vc_heatmap.layout(heatmap | obs_sets)\n",
175+
"vc_heatmap.widget()"
176+
]
177+
},
178+
{
179+
"cell_type": "markdown",
180+
"metadata": {},
181+
"source": [
182+
"## Cell set sizes bar plot"
183+
]
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": null,
188+
"metadata": {},
189+
"outputs": [],
190+
"source": [
191+
"vc_barplot = VitessceConfig(schema_version=\"1.0.18\", name=\"PBMC 68k dataset with Multiple Views\")\n",
192+
"\n",
193+
"dataset = vc_barplot.add_dataset(name=\"PBMC 68k\").add_object(\n",
194+
" AnnDataWrapper(\n",
195+
" adata_store=zarr_path,\n",
196+
" obs_set_paths=[\"obs/bulk_labels\", \"obs/louvain\"],\n",
197+
" obs_set_names=[\"Cell Type\", \"Leiden Cluster\"],\n",
198+
" )\n",
199+
")\n",
200+
"\n",
201+
"# --- Define views ---\n",
202+
"obs_set_sizes = vc_barplot.add_view(vt.OBS_SET_SIZES, dataset=dataset)\n",
203+
"obs_sets = vc_barplot.add_view(vt.OBS_SETS, dataset=dataset)\n",
204+
"\n",
205+
"# --- Define the layout ---\n",
206+
"vc_barplot.layout(obs_set_sizes | obs_sets)\n",
207+
"vc_barplot.widget()"
208+
]
209+
},
210+
{
211+
"cell_type": "markdown",
212+
"metadata": {},
213+
"source": [
214+
"## Histogram"
215+
]
216+
},
217+
{
218+
"cell_type": "code",
219+
"execution_count": null,
220+
"metadata": {},
221+
"outputs": [],
222+
"source": [
223+
"vc_histogram = VitessceConfig(schema_version=\"1.0.18\", name=\"PBMC 68k dataset with Multiple Views\")\n",
224+
"\n",
225+
"dataset = vc_histogram.add_dataset(name=\"PBMC 68k\").add_object(\n",
226+
" AnnDataWrapper(\n",
227+
" adata_store=zarr_path,\n",
228+
" obs_feature_matrix_path=\"X\",\n",
229+
" )\n",
230+
")\n",
231+
"\n",
232+
"# --- Define views ---\n",
233+
"obs_set_sizes = vc_histogram.add_view(vt.FEATURE_VALUE_HISTOGRAM, dataset=dataset)\n",
234+
"genes = vc_histogram.add_view(vt.FEATURE_LIST, dataset=dataset)\n",
235+
"\n",
236+
"# --- Define the layout ---\n",
237+
"vc_histogram.layout(obs_set_sizes | genes)\n",
238+
"vc_histogram.widget()"
239+
]
240+
},
241+
{
242+
"cell_type": "markdown",
243+
"metadata": {},
244+
"source": [
245+
"## Violin plots"
246+
]
247+
},
248+
{
249+
"cell_type": "code",
250+
"execution_count": null,
251+
"metadata": {},
252+
"outputs": [],
253+
"source": [
254+
"vc_violin = VitessceConfig(schema_version=\"1.0.18\", name=\"PBMC 68k dataset with Multiple Views\")\n",
255+
"\n",
256+
"dataset = vc_violin.add_dataset(name=\"PBMC 68k\").add_object(\n",
257+
" AnnDataWrapper(\n",
258+
" adata_store=zarr_path,\n",
259+
" obs_set_paths=[\"obs/bulk_labels\", \"obs/louvain\"],\n",
260+
" obs_set_names=[\"Cell Type\", \"Leiden Cluster\"],\n",
261+
" obs_feature_matrix_path=\"X\",\n",
262+
" )\n",
263+
")\n",
264+
"\n",
265+
"# --- Define views ---\n",
266+
"obs_set_sizes = vc_violin.add_view(vt.OBS_SET_FEATURE_VALUE_DISTRIBUTION, dataset=dataset)\n",
267+
"obs_sets = vc_violin.add_view(vt.OBS_SETS, dataset=dataset)\n",
268+
"genes = vc_violin.add_view(vt.FEATURE_LIST, dataset=dataset)\n",
269+
"\n",
270+
"# --- Define the layout ---\n",
271+
"vc_violin.layout(obs_set_sizes | (obs_sets/genes))\n",
272+
"vc_violin.widget()"
273+
]
274+
},
275+
{
276+
"cell_type": "markdown",
277+
"metadata": {},
278+
"source": [
279+
"# The EasyVitessce approach"
280+
]
281+
},
282+
{
283+
"cell_type": "code",
284+
"execution_count": null,
285+
"metadata": {},
286+
"outputs": [],
287+
"source": [
288+
"import easy_vitessce as ev"
289+
]
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": null,
294+
"metadata": {},
295+
"outputs": [],
296+
"source": [
297+
"# Begin Colab-specific lines. Not required when running locally.\n",
298+
"# Reference: https://vitessce.github.io/easy_vitessce/customization.html\n",
299+
"ev.register_data_path(adata, zarr_path)\n",
300+
"ev.config.set({ 'data.wrapper_param_suffix': '_store' })\n",
301+
"# End Colab-specific lines."
302+
]
303+
},
304+
{
305+
"cell_type": "markdown",
306+
"metadata": {},
307+
"source": [
308+
"## Dot plot"
309+
]
310+
},
70311
{
71312
"cell_type": "code",
72313
"execution_count": null,
73314
"metadata": {},
74315
"outputs": [],
75316
"source": [
76-
"# Exercise 2 — interactive dot plot\n",
77317
"sc.pl.dotplot(\n",
78318
" adata,\n",
79319
" var_names=[\"C1QA\", \"PSAP\", \"CD79A\", \"CD79B\", \"CST3\", \"LYZ\", \"ANXA1\", \"S100A4\"],\n",
@@ -331,7 +571,11 @@
331571
},
332572
{
333573
"cell_type": "markdown",
334-
"metadata": {},
574+
"metadata": {
575+
"jupyter": {
576+
"source_hidden": true
577+
}
578+
},
335579
"source": [
336580
"## 2. Expression views\n",
337581
"\n",
@@ -364,20 +608,6 @@
364608
"# UMAP colored by cell type label\n",
365609
"sc.pl.embedding(adata, basis=\"umap\", color=\"bulk_labels\")"
366610
]
367-
},
368-
{
369-
"cell_type": "markdown",
370-
"metadata": {},
371-
"source": [
372-
"## 1. Embedding views (`scatterplot`)\n",
373-
"\n",
374-
"A **scatterplot** view renders a 2D dimensionality reduction such as UMAP or PCA. Each point is one cell. Points can be colored by:\n",
375-
"\n",
376-
"- **Cell type / cluster label** — categorical coloring\n",
377-
"- **Gene expression** — continuous colormap from low (gray) to high (color)\n",
378-
"\n",
379-
"EasyVitessce hooks into `sc.pl.embedding()`. Pass `basis=` to choose the embedding and `color=` to choose what to encode with color."
380-
]
381611
}
382612
],
383613
"metadata": {

0 commit comments

Comments
 (0)