Skip to content

Commit 843a638

Browse files
authored
Move spatialdata dependency to dev (#384)
* Move spatialdata dependency to optional * Update spatialdata notebook * Version
1 parent 390ddbb commit 843a638

File tree

3 files changed

+25
-57
lines changed

3 files changed

+25
-57
lines changed

docs/notebooks/spatial_data.ipynb

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
"cell_type": "markdown",
1414
"metadata": {},
1515
"source": [
16-
"# Visualization of SpatialData Object"
16+
"# Visualization of a SpatialData object"
1717
]
1818
},
1919
{
2020
"cell_type": "markdown",
2121
"metadata": {},
2222
"source": [
23-
"## 1. Import dependencies\n",
24-
"\n",
25-
"We need to import the classes and functions that we will be using from the corresponding packages."
23+
"## Import dependencies\n"
2624
]
2725
},
2826
{
@@ -31,56 +29,19 @@
3129
"metadata": {},
3230
"outputs": [],
3331
"source": [
34-
"%load_ext autoreload\n",
35-
"%autoreload 2\n",
36-
"\n",
37-
"from pathlib import Path\n",
32+
"import os\n",
33+
"from os.path import join, isfile, isdir\n",
3834
"from urllib.request import urlretrieve\n",
39-
"import dask\n",
40-
"\n",
41-
"dask.config.set({'dataframe.query-planning-warning': False})\n",
42-
"\n",
43-
"from spatialdata import read_zarr\n",
44-
"import scanpy as sc\n",
35+
"import zipfile\n",
4536
"\n",
4637
"from vitessce import (\n",
4738
" VitessceConfig,\n",
48-
" Component as cm,\n",
39+
" ViewType as vt,\n",
4940
" CoordinationType as ct,\n",
5041
" CoordinationLevel as CL,\n",
51-
" AbstractWrapper,\n",
5242
" SpatialDataWrapper,\n",
5343
" get_initial_coordination_scope_prefix\n",
54-
")\n",
55-
"from vitessce.data_utils import (\n",
56-
" optimize_adata,\n",
57-
" VAR_CHUNK_SIZE,\n",
58-
")\n",
59-
"import zipfile\n"
60-
]
61-
},
62-
{
63-
"cell_type": "code",
64-
"execution_count": null,
65-
"metadata": {},
66-
"outputs": [],
67-
"source": [
68-
"zip_filepath = Path(\"data/visium.spatialdata.zarr.zip\")\n",
69-
"spatialdata_filepath = zip_filepath.with_suffix('')\n",
70-
"if not zip_filepath.exists():\n",
71-
" spatialdata_filepath.parent.mkdir(exist_ok=True)\n",
72-
" urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_associated_xenium_io.zip', zip_filepath)\n",
73-
"if not spatialdata_filepath.exists():\n",
74-
" with zipfile.ZipFile(zip_filepath,\"r\") as zip_ref:\n",
75-
" zip_ref.extractall(spatialdata_filepath.parent)\n",
76-
" (spatialdata_filepath.parent / \"data.zarr\").rename(spatialdata_filepath)"
77-
]
78-
},
79-
{
80-
"cell_type": "markdown",
81-
"metadata": {},
82-
"source": [
83-
"## 2. Load the data"
44+
")"
8445
]
8546
},
8647
{
@@ -89,7 +50,9 @@
8950
"metadata": {},
9051
"outputs": [],
9152
"source": [
92-
"spatialdata = read_zarr(spatialdata_filepath)"
53+
"data_dir = \"data\"\n",
54+
"zip_filepath = join(data_dir, \"visium.spatialdata.zarr.zip\")\n",
55+
"spatialdata_filepath = join(data_dir, \"visium.spatialdata.zarr\")"
9356
]
9457
},
9558
{
@@ -98,14 +61,20 @@
9861
"metadata": {},
9962
"outputs": [],
10063
"source": [
101-
"spatialdata"
64+
"if not isdir(spatialdata_filepath):\n",
65+
" if not isfile(zip_filepath):\n",
66+
" os.makedirs(data_dir, exist_ok=True)\n",
67+
" urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_associated_xenium_io.zip', zip_filepath)\n",
68+
" with zipfile.ZipFile(zip_filepath,\"r\") as zip_ref:\n",
69+
" zip_ref.extractall(data_dir)\n",
70+
" os.rename(join(data_dir, \"data.zarr\"), spatialdata_filepath)"
10271
]
10372
},
10473
{
10574
"cell_type": "markdown",
10675
"metadata": {},
10776
"source": [
108-
"## 3. Create the Vitessce widget configuration\n",
77+
"## Configure Vitessce\n",
10978
"\n",
11079
"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."
11180
]
@@ -119,7 +88,6 @@
11988
"vc = VitessceConfig(\n",
12089
" schema_version=\"1.0.16\",\n",
12190
" name='Visium SpatialData Demo (visium_associated_xenium_io)',\n",
122-
" description='From https://spatialdata.scverse.org/en/latest/tutorials/notebooks/datasets/README.html'\n",
12391
")\n",
12492
"# Add data to the configuration:\n",
12593
"wrapper = SpatialDataWrapper(\n",
@@ -140,14 +108,14 @@
140108
"\n",
141109
"# Add views (visualizations) to the configuration:\n",
142110
"spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n",
143-
"feature_list = vc.add_view(cm.FEATURE_LIST, dataset=dataset)\n",
111+
"feature_list = vc.add_view(vt.FEATURE_LIST, dataset=dataset)\n",
144112
"layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n",
145113
"vc.link_views_by_dict([spatial, layer_controller], {\n",
146114
" 'imageLayer': CL([{\n",
147115
" 'photometricInterpretation': 'RGB',\n",
148116
" }]),\n",
149117
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
150-
"obs_sets = vc.add_view(cm.OBS_SETS, dataset=dataset)\n",
118+
"obs_sets = vc.add_view(vt.OBS_SETS, dataset=dataset)\n",
151119
"vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])\n",
152120
"\n",
153121
"# Layout the views\n",
@@ -158,7 +126,7 @@
158126
"cell_type": "markdown",
159127
"metadata": {},
160128
"source": [
161-
"### 4. Render the widget"
129+
"### Render the widget"
162130
]
163131
},
164132
{
@@ -200,4 +168,4 @@
200168
},
201169
"nbformat": 4,
202170
"nbformat_minor": 4
203-
}
171+
}

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "vitessce"
7-
version = "3.4.1"
7+
version = "3.4.2"
88
authors = [
99
{ name="Mark Keller", email="[email protected]" },
1010
]
@@ -33,7 +33,6 @@ dependencies = [
3333
'black>=21.11b1',
3434
'numpy>=1.21.2,<2.0',
3535
'anndata>=0.7.8,<0.11',
36-
'spatialdata>=0.2.2',
3736
'scanpy>=1.9.3',
3837
'ome-zarr>=0.8.3',
3938
'tifffile>=2020.10.1',
@@ -48,6 +47,7 @@ dev = [
4847
'loompy>=3.0.6',
4948
'coverage>=6.3.2',
5049
'flake8==3.8.4',
50+
'spatialdata>=0.2.2',
5151
]
5252
docs = [
5353
'sphinx==4.2.0',

vitessce/wrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import zarr
1414

1515
import numpy as np
16-
from spatialdata import SpatialData
1716

1817
if TYPE_CHECKING:
1918
import lamindb as ln
19+
from spatialdata import SpatialData
2020

2121
from vitessce.file_def_utils import (
2222
gen_obs_locations_schema,

0 commit comments

Comments
 (0)