Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions docs/api_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ vitessce.config
:exclude-members: VitessceConfig, VitessceChainableConfig
:member-order: bysource

vitessce.widget
***************

.. autoclass:: vitessce.widget.VitessceWidget()
:members:
:private-members:
:exclude-members: close

.. autoclass:: vitessce.widget.VitesscePlugin
:members:

vitessce.constants
******************

Expand Down
4 changes: 2 additions & 2 deletions docs/api_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ vitessce.wrappers
:members:

vitessce.export
*****************
***************

.. automodule:: vitessce.export
:members:

vitessce.data_utils
*****************
*******************

.. automodule:: vitessce.data_utils.ome
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/marimo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def _(mo):

@app.cell
def _(vw):
vw.config
vw._config
return


@app.cell
def _(vw):
vw.config["coordinationSpace"]["embeddingZoom"]
vw._config["coordinationSpace"]["embeddingZoom"]
return


Expand Down
247 changes: 247 additions & 0 deletions docs/notebooks/spatial_data_visium_hd.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbsphinx": "hidden"
},
"source": [
"# Vitessce Widget Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualization of a SpatialData object"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import dependencies\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from os.path import join, isfile, isdir\n",
"from urllib.request import urlretrieve\n",
"import zipfile\n",
"\n",
"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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_dir = \"data\"\n",
"zip_filepath = join(data_dir, \"visium_hd_3.0.0_io.zip\")\n",
"spatialdata_filepath = join(data_dir, \"visium_hd_3.0.0.spatialdata.zarr\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not isdir(spatialdata_filepath):\n",
" if not isfile(zip_filepath):\n",
" os.makedirs(data_dir, exist_ok=True)\n",
" urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_hd_3.0.0_io.zip', zip_filepath)\n",
" with zipfile.ZipFile(zip_filepath,\"r\") as zip_ref:\n",
" zip_ref.extractall(data_dir)\n",
" os.rename(join(data_dir, \"data.zarr\"), spatialdata_filepath)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rasterize bins\n",
"Reference: https://spatialdata.scverse.org/en/stable/tutorials/notebooks/notebooks/examples/technology_visium_hd.html#performant-on-the-fly-data-rasterization"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from spatialdata import (\n",
" read_zarr,\n",
" rasterize_bins,\n",
" rasterize_bins_link_table_to_labels\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sdata = read_zarr(spatialdata_filepath)\n",
"sdata"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for bin_size in [\"016\", \"008\", \"002\"]:\n",
" # rasterize_bins() requires a compresed sparse column (csc) matrix\n",
" sdata.tables[f\"square_{bin_size}um\"].X = sdata.tables[f\"square_{bin_size}um\"].X.tocsc()\n",
" rasterized = rasterize_bins(\n",
" sdata,\n",
" f\"Visium_HD_Mouse_Small_Intestine_square_{bin_size}um\",\n",
" f\"square_{bin_size}um\",\n",
" \"array_col\",\n",
" \"array_row\",\n",
" # We want to rasterize to a Labels element, rather than an Image element.\n",
" return_region_as_labels=True\n",
" )\n",
" sdata[f\"rasterized_{bin_size}um\"] = rasterized\n",
" rasterize_bins_link_table_to_labels(\n",
" sdata,\n",
" table_name=f\"square_{bin_size}um\",\n",
" rasterized_labels_name=f\"rasterized_{bin_size}um\",\n",
" )\n",
" sdata.write_element(f\"rasterized_{bin_size}um\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sdata"
]
},
{
"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.18\",\n",
" name='Visium HD SpatialData Demo',\n",
")\n",
"# Add data to the configuration:\n",
"wrapper = SpatialDataWrapper(\n",
" sdata_path=spatialdata_filepath,\n",
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
" image_path=\"images/Visium_HD_Mouse_Small_Intestine_full_image\",\n",
" table_path=\"tables/square_016um\",\n",
" obs_feature_matrix_path=\"tables/square_016um/X\",\n",
" obs_segmentations_path=\"labels/rasterized_016um\",\n",
" #region=\"CytAssist_FFPE_Human_Breast_Cancer\",\n",
" coordinate_system=\"Visium_HD_Mouse_Small_Intestine\",\n",
" coordination_values={\n",
" # The following tells Vitessce to consider each observation as a \"bin\"\n",
" \"obsType\": \"bin\",\n",
" }\n",
")\n",
"dataset = vc.add_dataset(name='Visium HD').add_object(wrapper)\n",
"\n",
"# Add views (visualizations) to the configuration:\n",
"spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n",
"feature_list = vc.add_view(\"featureList\", dataset=dataset)\n",
"layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" 'imageLayer': CL([{\n",
" 'photometricInterpretation': 'RGB',\n",
" }]),\n",
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" 'segmentationLayer': CL([{\n",
" 'segmentationChannel': CL([{\n",
" 'spatialChannelOpacity': 0.5,\n",
" 'obsColorEncoding': 'geneSelection',\n",
" 'featureValueColormapRange': [0, 0.5],\n",
" }])\n",
" }]),\n",
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n",
"obs_sets = vc.add_view(vt.OBS_SETS, dataset=dataset)\n",
"vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType', 'featureSelection'], [wrapper.obs_type_label, ['AA986860']])\n",
"\n",
"# Layout the views\n",
"vc.layout(spatial | (feature_list / layer_controller / obs_sets));"
]
},
{
"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": []
}
],
"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
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "vitessce"
version = "3.6.9"
version = "3.7.0"
authors = [
{ name="Mark Keller", email="[email protected]" },
]
Expand Down
24 changes: 24 additions & 0 deletions src/vitessce/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,19 @@ def stop_server(self, port):
del self.background_servers[port]

def stop_all_servers(self):
"""
Stop all background servers associated with this config instance.

.. code-block:: python
:emphasize-lines: 5

from vitessce import VitessceConfig

vc = VitessceConfig(schema_version="1.0.18", name='My Config')
vw = vc.widget()
# ... do something with the widget ...
vc.stop_all_servers()
"""
for server in self.background_servers.values():
server.stop()
self.background_servers = {}
Expand Down Expand Up @@ -1791,6 +1804,17 @@ def widget(self, **kwargs):
:param int height: The height of the widget, in pixels. By default, 600.
:param int port: The port to use when serving data objects on localhost. By default, 8000.
:param bool proxy: Is this widget being served through a proxy, for example with a cloud notebook (e.g. Binder)?
:param str js_package_version: The version of the NPM package ('vitessce' if not js_dev_mode else '@vitessce/dev').
:param bool js_dev_mode: Should @vitessce/dev be used (typically for debugging purposes)? By default, False.
:param str custom_js_url: A URL to a JavaScript file to use (instead of 'vitessce' or '@vitessce/dev' NPM package).
:param list[VitesscePlugin] plugins: A list of subclasses of VitesscePlugin. Optional.
:param bool remount_on_uid_change: Passed to the remountOnUidChange prop of the <Vitessce/> React component. By default, True.
:param bool prefer_local: Should local data be preferred (only applies to `*_artifact` data objects)? By default, True.
:param int invoke_timeout: The timeout in milliseconds for invoking Python functions from JavaScript. By default, 300000.
:param bool invoke_batched: Should invocations (Zarr gets) be submitted in batch, or individually? By default, True.
:param bool page_mode: Whether to render the <Vitessce/> component in grid-mode or page-mode. By default, False.
:param str page_esm: The ES module string for the page component creation function. Optional.
:param bool prevent_scroll: Should mouseover in the Vitessce widget prevent disable the scrolling of the notebook? By default, True.

:returns: The Jupyter widget.
:rtype: VitessceWidget
Expand Down
Loading