diff --git a/docs/notebooks/spatial_data.ipynb b/docs/notebooks/spatial_data.ipynb index 6e14a24..ff0725e 100644 --- a/docs/notebooks/spatial_data.ipynb +++ b/docs/notebooks/spatial_data.ipynb @@ -80,9 +80,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 3. Load the data\n", - "\n", - "Note: this function may print a `FutureWarning`" + "## 2. Load the data" ] }, { @@ -107,69 +105,40 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 4. Create the Vitessce widget configuration\n", + "## 3. Create the Vitessce widget configuration\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": "markdown", - "metadata": {}, - "source": [ - "### 4.1. Instantiate a `VitessceConfig` object\n", - "\n", - "Use the `VitessceConfig` constructor to create an instance." - ] - }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "vc = VitessceConfig(schema_version=\"1.0.16\", name='Visium SpatialData Demo (visium_associated_xenium_io)', description='From https://spatialdata.scverse.org/en/latest/tutorials/notebooks/datasets/README.html')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 4.2. Add a dataset to the `VitessceConfig` instance\n", - "\n", - "In Vitessce, a dataset is a container for one file per data type. The `.add_dataset(name)` method on the `vc` instance sets up and returns a new dataset instance.\n", - "\n", - "Then, we can call the dataset's `.add_object(wrapper_object)` method to attach a \"data wrapper\" instance to our new dataset. For example, the `AnnDataWrapper` helps to configure AnnData Zarr stores for use in the Vitessce configuration.\n", + "vc = VitessceConfig(\n", + " schema_version=\"1.0.16\",\n", + " name='Visium SpatialData Demo (visium_associated_xenium_io)',\n", + " description='From https://spatialdata.scverse.org/en/latest/tutorials/notebooks/datasets/README.html'\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/CytAssist_FFPE_Human_Breast_Cancer_full_image\",\n", + " table_path=\"table/table\",\n", + " obs_feature_matrix_path=\"table/table/X\",\n", + " obs_spots_path=\"shapes/CytAssist_FFPE_Human_Breast_Cancer\",\n", + " region=\"CytAssist_FFPE_Human_Breast_Cancer\",\n", + " coordinate_system=\"global\",\n", + " coordination_values={\n", + " # The following tells Vitessce to consider each observation as a \"spot\"\n", + " \"obsType\": \"spot\",\n", + " }\n", + ")\n", + "dataset = vc.add_dataset(name='Breast Cancer Visium').add_object(wrapper)\n", "\n", - "Dataset wrapper classes may require additional parameters to resolve ambiguities. For instance, `AnnData` objects may store multiple clusterings or cell type annotation columns in the `adata.obs` dataframe. We can use the parameter `obs_set_paths` to tell Vitessce that certain columns of the `obs` dataframe correspond to cell type annotations or cell clusterings." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "[wrapper] = SpatialDataWrapper.from_object(\n", - " spatialdata,\n", - " table_keys_to_image_elems={\"table\": \"images/CytAssist_FFPE_Human_Breast_Cancer_full_image\"},\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dataset = vc.add_dataset(name='Breast Cancer Visium').add_object(wrapper)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "# Add views (visualizations) to the configuration:\n", "spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n", "feature_list = vc.add_view(cm.FEATURE_LIST, dataset=dataset)\n", "layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n", @@ -178,22 +147,18 @@ " 'photometricInterpretation': 'RGB',\n", " }]),\n", "}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n", - "vc.link_views_by_dict([spatial, layer_controller], {\n", - " 'spotLayer': CL([{\n", - " 'obsType': 'spot',\n", - " }]),\n", - "}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSpots\"))\n", "obs_sets = vc.add_view(cm.OBS_SETS, dataset=dataset)\n", - "vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])" + "vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])\n", + "\n", + "# Layout the views\n", + "vc.layout(spatial | (feature_list / layer_controller / obs_sets));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### 4.4. Define the visualization layout\n", - "\n", - "The `vc.layout(view_concat)` method allows us to specify how our views will be arranged in the layout grid in the widget. The `|` and `/` characters are magic syntax for `hconcat(v1, v2)` and `vconcat(v1, v2)`, respectively." + "### 4. Render the widget" ] }, { @@ -201,40 +166,11 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "vc.layout(spatial | (feature_list / layer_controller / obs_sets));" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "vw = vc.widget()\n", "vw" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vw.close()\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vc.to_dict(\"\")" - ] - }, { "cell_type": "code", "execution_count": null,