Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move spatialdata dependency to dev #384

Merged
merged 3 commits into from
Oct 28, 2024
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
76 changes: 22 additions & 54 deletions docs/notebooks/spatial_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -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"
")"
]
},
{
Expand All @@ -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\")"
]
},
{
Expand All @@ -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."
]
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -158,7 +126,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4. Render the widget"
"### Render the widget"
]
},
{
Expand Down Expand Up @@ -200,4 +168,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
]
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion vitessce/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading