From 7288bebb5a4b5380a1b7b435b49b41cbcf851169 Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:18:45 -0400 Subject: [PATCH 1/3] Move spatialdata dependency to optional --- pyproject.toml | 2 +- vitessce/wrappers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f5b5f17..4f9a679 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,6 @@ dependencies = [ 'black>=21.11b1', 'numpy>=1.21.2,<2.0', 'anndata>=0.7.8,<0.11', - 'spatialdata>=0.2.2', 'scanpy>=1.9.3', 'ome-zarr>=0.8.3', 'tifffile>=2020.10.1', @@ -48,6 +47,7 @@ dev = [ 'loompy>=3.0.6', 'coverage>=6.3.2', 'flake8==3.8.4', + 'spatialdata>=0.2.2', ] docs = [ 'sphinx==4.2.0', diff --git a/vitessce/wrappers.py b/vitessce/wrappers.py index fda7345..d142f5c 100644 --- a/vitessce/wrappers.py +++ b/vitessce/wrappers.py @@ -13,10 +13,10 @@ import zarr import numpy as np -from spatialdata import SpatialData if TYPE_CHECKING: import lamindb as ln + from spatialdata import SpatialData from vitessce.file_def_utils import ( gen_obs_locations_schema, From 07098770be5beeb395788968359c1f598d6bfb0f Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:37:25 -0400 Subject: [PATCH 2/3] Update spatialdata notebook --- docs/notebooks/spatial_data.ipynb | 76 +++++++++---------------------- 1 file changed, 22 insertions(+), 54 deletions(-) diff --git a/docs/notebooks/spatial_data.ipynb b/docs/notebooks/spatial_data.ipynb index 062f565..60550f2 100644 --- a/docs/notebooks/spatial_data.ipynb +++ b/docs/notebooks/spatial_data.ipynb @@ -13,16 +13,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Visualization of SpatialData Object" + "# Visualization of a SpatialData object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## 1. Import dependencies\n", - "\n", - "We need to import the classes and functions that we will be using from the corresponding packages." + "## Import dependencies\n" ] }, { @@ -31,56 +29,19 @@ "metadata": {}, "outputs": [], "source": [ - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from pathlib import Path\n", + "import os\n", + "from os.path import join, isfile, isdir\n", "from urllib.request import urlretrieve\n", - "import dask\n", - "\n", - "dask.config.set({'dataframe.query-planning-warning': False})\n", - "\n", - "from spatialdata import read_zarr\n", - "import scanpy as sc\n", + "import zipfile\n", "\n", "from vitessce import (\n", " VitessceConfig,\n", - " Component as cm,\n", + " ViewType as vt,\n", " CoordinationType as ct,\n", " CoordinationLevel as CL,\n", - " AbstractWrapper,\n", " SpatialDataWrapper,\n", " get_initial_coordination_scope_prefix\n", - ")\n", - "from vitessce.data_utils import (\n", - " optimize_adata,\n", - " VAR_CHUNK_SIZE,\n", - ")\n", - "import zipfile\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "zip_filepath = Path(\"data/visium.spatialdata.zarr.zip\")\n", - "spatialdata_filepath = zip_filepath.with_suffix('')\n", - "if not zip_filepath.exists():\n", - " spatialdata_filepath.parent.mkdir(exist_ok=True)\n", - " urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_associated_xenium_io.zip', zip_filepath)\n", - "if not spatialdata_filepath.exists():\n", - " with zipfile.ZipFile(zip_filepath,\"r\") as zip_ref:\n", - " zip_ref.extractall(spatialdata_filepath.parent)\n", - " (spatialdata_filepath.parent / \"data.zarr\").rename(spatialdata_filepath)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 2. Load the data" + ")" ] }, { @@ -89,7 +50,9 @@ "metadata": {}, "outputs": [], "source": [ - "spatialdata = read_zarr(spatialdata_filepath)" + "data_dir = \"data\"\n", + "zip_filepath = join(data_dir, \"visium.spatialdata.zarr.zip\")\n", + "spatialdata_filepath = join(data_dir, \"visium.spatialdata.zarr\")" ] }, { @@ -98,14 +61,20 @@ "metadata": {}, "outputs": [], "source": [ - "spatialdata" + "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_associated_xenium_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": [ - "## 3. Create the Vitessce widget configuration\n", + "## 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." ] @@ -119,7 +88,6 @@ "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", @@ -140,14 +108,14 @@ "\n", "# 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", + "feature_list = vc.add_view(vt.FEATURE_LIST, 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", - "obs_sets = vc.add_view(cm.OBS_SETS, dataset=dataset)\n", + "obs_sets = vc.add_view(vt.OBS_SETS, dataset=dataset)\n", "vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])\n", "\n", "# Layout the views\n", @@ -158,7 +126,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 4. Render the widget" + "### Render the widget" ] }, { @@ -200,4 +168,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} From 1f56f426278d7b314b87a51c1c995c38948ee2a9 Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:45:27 -0400 Subject: [PATCH 3/3] Version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4f9a679..7483aab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "vitessce" -version = "3.4.1" +version = "3.4.2" authors = [ { name="Mark Keller", email="mark_keller@hms.harvard.edu" }, ]