|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "nbsphinx": "hidden" |
| 7 | + }, |
| 8 | + "source": [ |
| 9 | + "# Vitessce Widget Tutorial" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "# Visualization of a SpatialData object, blobs example" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "markdown", |
| 21 | + "metadata": {}, |
| 22 | + "source": [ |
| 23 | + "## Import dependencies\n" |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "code", |
| 28 | + "execution_count": null, |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "sdata_url = \"https://data-2.vitessce.io/data/moffitt/merfish_mouse_ileum.sdata.zarr\"" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "from vitessce import (\n", |
| 42 | + " VitessceConfig,\n", |
| 43 | + " ViewType as vt,\n", |
| 44 | + " CoordinationType as ct,\n", |
| 45 | + " CoordinationLevel as CL,\n", |
| 46 | + " SpatialDataWrapper,\n", |
| 47 | + " get_initial_coordination_scope_prefix\n", |
| 48 | + ")" |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "markdown", |
| 53 | + "metadata": {}, |
| 54 | + "source": [ |
| 55 | + "## Configure Vitessce\n", |
| 56 | + "\n", |
| 57 | + "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." |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": null, |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [], |
| 65 | + "source": [ |
| 66 | + "vc = VitessceConfig(\n", |
| 67 | + " schema_version=\"1.0.17\",\n", |
| 68 | + " name='SpatialData with MERFISH data',\n", |
| 69 | + ")\n", |
| 70 | + "# Add data to the configuration:\n", |
| 71 | + "\n", |
| 72 | + "dataset = vc.add_dataset(name='MERFISH').add_object(SpatialDataWrapper(\n", |
| 73 | + " sdata_url=sdata_url,\n", |
| 74 | + " # The following paths are relative to the root of the SpatialData zarr store on-disk.\n", |
| 75 | + " image_path=\"images/stains\",\n", |
| 76 | + " coordinate_system=\"global\",\n", |
| 77 | + " coordination_values={\n", |
| 78 | + " \"fileUid\": \"stains\"\n", |
| 79 | + " }\n", |
| 80 | + ")).add_object(SpatialDataWrapper(\n", |
| 81 | + " sdata_url=sdata_url,\n", |
| 82 | + " # The following paths are relative to the root of the SpatialData zarr store on-disk.\n", |
| 83 | + " labels_path=\"labels/dapi_labels\",\n", |
| 84 | + " coordinate_system=\"global\",\n", |
| 85 | + " coordination_values={\n", |
| 86 | + " \"obsType\": \"nucleus\",\n", |
| 87 | + " \"fileUid\": \"dapi\"\n", |
| 88 | + " }\n", |
| 89 | + ")).add_object(SpatialDataWrapper(\n", |
| 90 | + " sdata_url=sdata_url,\n", |
| 91 | + " # The following paths are relative to the root of the SpatialData zarr store on-disk.\n", |
| 92 | + " labels_path=\"labels/membrane_labels\",\n", |
| 93 | + " coordinate_system=\"global\",\n", |
| 94 | + " coordination_values={\n", |
| 95 | + " \"obsType\": \"cell\",\n", |
| 96 | + " \"fileUid\": \"membrane\"\n", |
| 97 | + " }\n", |
| 98 | + "))\n", |
| 99 | + "\n", |
| 100 | + "# Add views (visualizations) to the configuration:\n", |
| 101 | + "spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n", |
| 102 | + "layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n", |
| 103 | + "\n", |
| 104 | + "vc.link_views_by_dict([spatial, layer_controller], {\n", |
| 105 | + " 'imageLayer': CL([{\n", |
| 106 | + " \"fileUid\": \"stains\",\n", |
| 107 | + " 'photometricInterpretation': 'BlackIsZero',\n", |
| 108 | + " 'spatialLayerOpacity': 1.0,\n", |
| 109 | + " 'spatialLayerVisible': True,\n", |
| 110 | + " 'imageChannel': CL([\n", |
| 111 | + " {\n", |
| 112 | + " 'spatialChannelVisible': True,\n", |
| 113 | + " \"spatialTargetC\": 0, # DAPI, Nucleus\n", |
| 114 | + " \"spatialChannelColor\": [0, 0, 255],\n", |
| 115 | + " \"spatialChannelOpacity\": 1.0\n", |
| 116 | + " },\n", |
| 117 | + " {\n", |
| 118 | + " 'spatialChannelVisible': True,\n", |
| 119 | + " \"spatialTargetC\": 1, # Membrane, Cell\n", |
| 120 | + " \"spatialChannelColor\": [255, 255, 255],\n", |
| 121 | + " \"spatialChannelOpacity\": 1.0\n", |
| 122 | + " }\n", |
| 123 | + " ])\n", |
| 124 | + " }]),\n", |
| 125 | + "}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n", |
| 126 | + "\n", |
| 127 | + "vc.link_views_by_dict([spatial, layer_controller], {\n", |
| 128 | + " 'segmentationLayer': CL([{\n", |
| 129 | + " \"fileUid\": \"membrane\",\n", |
| 130 | + " 'spatialLayerOpacity': 1.0,\n", |
| 131 | + " 'spatialLayerVisible': True,\n", |
| 132 | + " 'segmentationChannel': CL([{\n", |
| 133 | + " 'spatialChannelVisible': True,\n", |
| 134 | + " 'obsType': 'cell',\n", |
| 135 | + " \"spatialChannelColor\": [200, 200, 200],\n", |
| 136 | + " \"obsColorEncoding\": \"spatialChannelColor\",\n", |
| 137 | + " }]),\n", |
| 138 | + " }, {\n", |
| 139 | + " \"fileUid\": \"dapi\",\n", |
| 140 | + " 'spatialLayerOpacity': 1.0,\n", |
| 141 | + " 'spatialLayerVisible': True,\n", |
| 142 | + " 'segmentationChannel': CL([{\n", |
| 143 | + " 'spatialChannelVisible': True,\n", |
| 144 | + " 'obsType': 'nucleus',\n", |
| 145 | + " \"spatialChannelColor\": [255, 255, 255],\n", |
| 146 | + " \"obsColorEncoding\": \"spatialChannelColor\",\n", |
| 147 | + " }]),\n", |
| 148 | + " }]),\n", |
| 149 | + "}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n", |
| 150 | + "\n", |
| 151 | + "# Layout the views\n", |
| 152 | + "vc.layout(spatial | layer_controller);" |
| 153 | + ] |
| 154 | + }, |
| 155 | + { |
| 156 | + "cell_type": "markdown", |
| 157 | + "metadata": {}, |
| 158 | + "source": [ |
| 159 | + "### Render the widget" |
| 160 | + ] |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "code", |
| 164 | + "execution_count": null, |
| 165 | + "metadata": {}, |
| 166 | + "outputs": [], |
| 167 | + "source": [ |
| 168 | + "vw = vc.widget()\n", |
| 169 | + "vw" |
| 170 | + ] |
| 171 | + }, |
| 172 | + { |
| 173 | + "cell_type": "code", |
| 174 | + "execution_count": null, |
| 175 | + "metadata": {}, |
| 176 | + "outputs": [], |
| 177 | + "source": [] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "code", |
| 181 | + "execution_count": null, |
| 182 | + "metadata": {}, |
| 183 | + "outputs": [], |
| 184 | + "source": [] |
| 185 | + } |
| 186 | + ], |
| 187 | + "metadata": { |
| 188 | + "kernelspec": { |
| 189 | + "display_name": "Python 3 (ipykernel)", |
| 190 | + "language": "python", |
| 191 | + "name": "python3" |
| 192 | + }, |
| 193 | + "language_info": { |
| 194 | + "codemirror_mode": { |
| 195 | + "name": "ipython", |
| 196 | + "version": 3 |
| 197 | + }, |
| 198 | + "file_extension": ".py", |
| 199 | + "mimetype": "text/x-python", |
| 200 | + "name": "python", |
| 201 | + "nbconvert_exporter": "python", |
| 202 | + "pygments_lexer": "ipython3", |
| 203 | + "version": "3.10.14" |
| 204 | + } |
| 205 | + }, |
| 206 | + "nbformat": 4, |
| 207 | + "nbformat_minor": 4 |
| 208 | +} |
0 commit comments