Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions docs/notebooks/spatial_data_merfish.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbsphinx": "hidden"
},
"source": [
"# Vitessce Widget Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualization of a SpatialData object, blobs example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import dependencies\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sdata_url = \"https://data-2.vitessce.io/data/moffitt/merfish_mouse_ileum.sdata.zarr\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from vitessce import (\n",
" VitessceConfig,\n",
" ViewType as vt,\n",
" CoordinationType as ct,\n",
" CoordinationLevel as CL,\n",
" SpatialDataWrapper,\n",
" get_initial_coordination_scope_prefix\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure Vitessce\n",
"\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vc = VitessceConfig(\n",
" schema_version=\"1.0.17\",\n",
" name='SpatialData with MERFISH data',\n",
")\n",
"# Add data to the configuration:\n",
"\n",
"dataset = vc.add_dataset(name='MERFISH').add_object(SpatialDataWrapper(\n",
" sdata_url=sdata_url,\n",
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
" image_path=\"images/stains\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"fileUid\": \"stains\"\n",
" }\n",
")).add_object(SpatialDataWrapper(\n",
" sdata_url=sdata_url,\n",
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
" labels_path=\"labels/dapi_labels\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"obsType\": \"nucleus\",\n",
" \"fileUid\": \"dapi\"\n",
" }\n",
")).add_object(SpatialDataWrapper(\n",
" sdata_url=sdata_url,\n",
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
" labels_path=\"labels/membrane_labels\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"obsType\": \"cell\",\n",
" \"fileUid\": \"membrane\"\n",
" }\n",
"))\n",
"\n",
"# Add views (visualizations) to the configuration:\n",
"spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n",
"layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n",
"\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" 'imageLayer': CL([{\n",
" \"fileUid\": \"stains\",\n",
" 'photometricInterpretation': 'BlackIsZero',\n",
" 'spatialLayerOpacity': 1.0,\n",
" 'spatialLayerVisible': True,\n",
" 'imageChannel': CL([\n",
" {\n",
" 'spatialChannelVisible': True,\n",
" \"spatialTargetC\": 0, # DAPI, Nucleus\n",
" \"spatialChannelColor\": [0, 0, 255],\n",
" \"spatialChannelOpacity\": 1.0\n",
" },\n",
" {\n",
" 'spatialChannelVisible': True,\n",
" \"spatialTargetC\": 1, # Membrane, Cell\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"spatialChannelOpacity\": 1.0\n",
" }\n",
" ])\n",
" }]),\n",
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
"\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" 'segmentationLayer': CL([{\n",
" \"fileUid\": \"membrane\",\n",
" 'spatialLayerOpacity': 1.0,\n",
" 'spatialLayerVisible': True,\n",
" 'segmentationChannel': CL([{\n",
" 'spatialChannelVisible': True,\n",
" 'obsType': 'cell',\n",
" \"spatialChannelColor\": [200, 200, 200],\n",
" \"obsColorEncoding\": \"spatialChannelColor\",\n",
" }]),\n",
" }, {\n",
" \"fileUid\": \"dapi\",\n",
" 'spatialLayerOpacity': 1.0,\n",
" 'spatialLayerVisible': True,\n",
" 'segmentationChannel': CL([{\n",
" 'spatialChannelVisible': True,\n",
" 'obsType': 'nucleus',\n",
" \"spatialChannelColor\": [255, 255, 255],\n",
" \"obsColorEncoding\": \"spatialChannelColor\",\n",
" }]),\n",
" }]),\n",
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n",
"\n",
"# Layout the views\n",
"vc.layout(spatial | layer_controller);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Render the widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vw = vc.widget()\n",
"vw"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 4
}