1313 "cell_type" : " markdown" ,
1414 "metadata" : {},
1515 "source" : [
16- " # Visualization of SpatialData Object "
16+ " # Visualization of a SpatialData object "
1717 ]
1818 },
1919 {
2020 "cell_type" : " markdown" ,
2121 "metadata" : {},
2222 "source" : [
23- " ## 1. Import dependencies\n " ,
24- " \n " ,
25- " We need to import the classes and functions that we will be using from the corresponding packages."
23+ " ## Import dependencies\n "
2624 ]
2725 },
2826 {
3129 "metadata" : {},
3230 "outputs" : [],
3331 "source" : [
34- " %load_ext autoreload\n " ,
35- " %autoreload 2\n " ,
36- " \n " ,
37- " from pathlib import Path\n " ,
32+ " import os\n " ,
33+ " from os.path import join, isfile, isdir\n " ,
3834 " from urllib.request import urlretrieve\n " ,
39- " import dask\n " ,
40- " \n " ,
41- " dask.config.set({'dataframe.query-planning-warning': False})\n " ,
42- " \n " ,
43- " from spatialdata import read_zarr\n " ,
44- " import scanpy as sc\n " ,
35+ " import zipfile\n " ,
4536 " \n " ,
4637 " from vitessce import (\n " ,
4738 " VitessceConfig,\n " ,
48- " Component as cm ,\n " ,
39+ " ViewType as vt ,\n " ,
4940 " CoordinationType as ct,\n " ,
5041 " CoordinationLevel as CL,\n " ,
51- " AbstractWrapper,\n " ,
5242 " SpatialDataWrapper,\n " ,
5343 " get_initial_coordination_scope_prefix\n " ,
54- " )\n " ,
55- " from vitessce.data_utils import (\n " ,
56- " optimize_adata,\n " ,
57- " VAR_CHUNK_SIZE,\n " ,
58- " )\n " ,
59- " import zipfile\n "
60- ]
61- },
62- {
63- "cell_type" : " code" ,
64- "execution_count" : null ,
65- "metadata" : {},
66- "outputs" : [],
67- "source" : [
68- " zip_filepath = Path(\" data/visium.spatialdata.zarr.zip\" )\n " ,
69- " spatialdata_filepath = zip_filepath.with_suffix('')\n " ,
70- " if not zip_filepath.exists():\n " ,
71- " spatialdata_filepath.parent.mkdir(exist_ok=True)\n " ,
72- " urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_associated_xenium_io.zip', zip_filepath)\n " ,
73- " if not spatialdata_filepath.exists():\n " ,
74- " with zipfile.ZipFile(zip_filepath,\" r\" ) as zip_ref:\n " ,
75- " zip_ref.extractall(spatialdata_filepath.parent)\n " ,
76- " (spatialdata_filepath.parent / \" data.zarr\" ).rename(spatialdata_filepath)"
77- ]
78- },
79- {
80- "cell_type" : " markdown" ,
81- "metadata" : {},
82- "source" : [
83- " ## 2. Load the data"
44+ " )"
8445 ]
8546 },
8647 {
8950 "metadata" : {},
9051 "outputs" : [],
9152 "source" : [
92- " spatialdata = read_zarr(spatialdata_filepath)"
53+ " data_dir = \" data\"\n " ,
54+ " zip_filepath = join(data_dir, \" visium.spatialdata.zarr.zip\" )\n " ,
55+ " spatialdata_filepath = join(data_dir, \" visium.spatialdata.zarr\" )"
9356 ]
9457 },
9558 {
9861 "metadata" : {},
9962 "outputs" : [],
10063 "source" : [
101- " spatialdata"
64+ " if not isdir(spatialdata_filepath):\n " ,
65+ " if not isfile(zip_filepath):\n " ,
66+ " os.makedirs(data_dir, exist_ok=True)\n " ,
67+ " urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_associated_xenium_io.zip', zip_filepath)\n " ,
68+ " with zipfile.ZipFile(zip_filepath,\" r\" ) as zip_ref:\n " ,
69+ " zip_ref.extractall(data_dir)\n " ,
70+ " os.rename(join(data_dir, \" data.zarr\" ), spatialdata_filepath)"
10271 ]
10372 },
10473 {
10574 "cell_type" : " markdown" ,
10675 "metadata" : {},
10776 "source" : [
108- " ## 3. Create the Vitessce widget configuration \n " ,
77+ " ## Configure Vitessce\n " ,
10978 " \n " ,
11079 " Vitessce needs to know which pieces of data we are interested in visualizing, the visualization types we would like to use, and how we want to coordinate (or link) the views."
11180 ]
11988 " vc = VitessceConfig(\n " ,
12089 " schema_version=\" 1.0.16\" ,\n " ,
12190 " name='Visium SpatialData Demo (visium_associated_xenium_io)',\n " ,
122- " description='From https://spatialdata.scverse.org/en/latest/tutorials/notebooks/datasets/README.html'\n " ,
12391 " )\n " ,
12492 " # Add data to the configuration:\n " ,
12593 " wrapper = SpatialDataWrapper(\n " ,
140108 " \n " ,
141109 " # Add views (visualizations) to the configuration:\n " ,
142110 " spatial = vc.add_view(\" spatialBeta\" , dataset=dataset)\n " ,
143- " feature_list = vc.add_view(cm .FEATURE_LIST, dataset=dataset)\n " ,
111+ " feature_list = vc.add_view(vt .FEATURE_LIST, dataset=dataset)\n " ,
144112 " layer_controller = vc.add_view(\" layerControllerBeta\" , dataset=dataset)\n " ,
145113 " vc.link_views_by_dict([spatial, layer_controller], {\n " ,
146114 " 'imageLayer': CL([{\n " ,
147115 " 'photometricInterpretation': 'RGB',\n " ,
148116 " }]),\n " ,
149117 " }, scope_prefix=get_initial_coordination_scope_prefix(\" A\" , \" image\" ))\n " ,
150- " obs_sets = vc.add_view(cm .OBS_SETS, dataset=dataset)\n " ,
118+ " obs_sets = vc.add_view(vt .OBS_SETS, dataset=dataset)\n " ,
151119 " vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])\n " ,
152120 " \n " ,
153121 " # Layout the views\n " ,
158126 "cell_type" : " markdown" ,
159127 "metadata" : {},
160128 "source" : [
161- " ### 4. Render the widget"
129+ " ### Render the widget"
162130 ]
163131 },
164132 {
200168 },
201169 "nbformat" : 4 ,
202170 "nbformat_minor" : 4
203- }
171+ }
0 commit comments