Skip to content

Commit b2f2c74

Browse files
author
Shaokun An
authored
Merge pull request #1 from vitessce/keller-mark/sq-updates
Updates to SpatialQuery widget pull request branch
2 parents 9c19b20 + 78b0921 commit b2f2c74

3 files changed

Lines changed: 80 additions & 23 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ For a development installation (requires NodeJS and NPM),
3131
$ uv sync --extra dev --extra docs --extra all
3232

3333

34+
Alternatively, use conda:
35+
36+
$ conda create -n vitessce-dev python=3.12
37+
$ conda activate vitessce-dev
38+
$ pip install -e ".[dev,docs,all]"
39+
40+
Troubleshooting SpatialQuery installation on macOS:
41+
42+
$ # Use the macOS clang instead of from homebrew.
43+
$ CC=/usr/bin/clang CXX=/usr/bin/clang++ pip install -e ".[dev,docs,all,sq]"
44+
45+
3446
## Linting and testing
3547

3648
```sh

docs/notebooks/widget_plugin_spatial-query.ipynb

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919
{
2020
"cell_type": "code",
2121
"execution_count": null,
22-
"metadata": {
23-
"tags": []
24-
},
25-
"outputs": [],
26-
"source": [
27-
"#!pip install \"vitessce[all]==3.3.0\" esbuild_py anndata\n",
28-
"!pip install \"mlxtend~=0.23.0\"\n",
29-
"#!pip install -i \"https://test.pypi.org/simple/\" SpatialQuery\n",
30-
"!pip install \"SpatialQuery @ git+https://github.com/ShaokunAn/Spatial-Query@main\""
31-
]
32-
},
33-
{
34-
"cell_type": "code",
35-
"execution_count": 1,
3622
"metadata": {},
3723
"outputs": [],
3824
"source": [
@@ -44,41 +30,81 @@
4430
" ViewType as vt,\n",
4531
" CoordinationType as ct,\n",
4632
" CoordinationLevel as CL,\n",
33+
" hconcat,\n",
34+
" vconcat,\n",
4735
")\n",
4836
"from vitessce.widget_plugins import SpatialQueryPlugin"
4937
]
5038
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"## Download example dataset\n",
44+
"\n",
45+
"Download the `secondary_analysis.h5ad` file for sample `HBM838.LDFP.578` from the HuBMAP Portal at https://portal.hubmapconsortium.org/browse/dataset/5bf1e7b295343c4537206beda25aa4ca"
46+
]
47+
},
5148
{
5249
"cell_type": "code",
53-
"execution_count": 2,
50+
"execution_count": null,
5451
"metadata": {},
5552
"outputs": [],
5653
"source": [
57-
"adata = read_h5ad(join(\"data\", \"HBM987_KWLK_254\", \"secondary_analysis.h5ad\"))\n",
54+
"import os\n",
55+
"from os.path import join, isfile, isdir\n",
56+
"from urllib.request import urlretrieve\n",
57+
"\n",
58+
"adata_path = join(\"data\", \"HBM987_KWLK_254\", \"secondary_analysis.h5ad\")\n",
5859
"zarr_path = join(\"data\", \"HBM987_KWLK_254\", \"secondary_analysis.h5ad.zarr\")\n",
60+
"\n",
61+
"if not isdir(join(\"data\")):\n",
62+
" os.makedirs(join(\"data\"), exist_ok=True)\n",
63+
" if not isdir(join(\"data\", \"HBM987_KWLK_254\")):\n",
64+
" os.makedirs(join(\"data\", \"HBM987_KWLK_254\"), exist_ok=True)\n",
65+
" if not isfile(adata_path):\n",
66+
" urlretrieve('https://assets.hubmapconsortium.org/0a21f3fa27109790483f2a0729be53de/secondary_analysis.h5ad', adata_path)"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"metadata": {},
73+
"outputs": [],
74+
"source": [
75+
"adata = read_h5ad(adata_path)\n",
5976
"adata.write_zarr(zarr_path)"
6077
]
6178
},
6279
{
6380
"cell_type": "code",
64-
"execution_count": 3,
81+
"execution_count": null,
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"adata"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
6591
"metadata": {},
6692
"outputs": [],
6793
"source": [
68-
"plugin = SpatialQueryPlugin(adata)"
94+
"plugin = SpatialQueryPlugin(adata, label_key=\"predicted_label\", spatial_key=\"X_spatial\", feature_name=\"hugo_symbol\")"
6995
]
7096
},
7197
{
7298
"cell_type": "code",
73-
"execution_count": 12,
99+
"execution_count": null,
74100
"metadata": {},
75101
"outputs": [],
76102
"source": [
77103
"vc = VitessceConfig(schema_version=\"1.0.16\", name=\"Spatial-Query\")\n",
78104
"dataset = vc.add_dataset(\"Query results\").add_object(AnnDataWrapper(\n",
79105
" adata_path=zarr_path,\n",
80106
" obs_feature_matrix_path=\"X\",\n",
81-
" obs_set_paths=[\"obs/predicted.ASCT.celltype\"],\n",
107+
" obs_set_paths=[\"obs/predicted_label\"],\n",
82108
" obs_set_names=[\"Cell Type\"],\n",
83109
" obs_spots_path=\"obsm/X_spatial\",\n",
84110
" feature_labels_path=\"var/hugo_symbol\",\n",
@@ -92,6 +118,8 @@
92118
"sets_view = vc.add_view(\"obsSets\", dataset=dataset)\n",
93119
"features_view = vc.add_view(\"featureList\", dataset=dataset)\n",
94120
"sq_view = vc.add_view(\"spatialQuery\", dataset=dataset)\n",
121+
"sq_heatmap = vc.add_view(\"spatialQueryHeatmap\", dataset=dataset)\n",
122+
"\n",
95123
"\n",
96124
"obs_set_selection_scope, = vc.add_coordination(\"obsSetSelection\",)\n",
97125
"obs_set_selection_scope.set_value(None)\n",
@@ -114,18 +142,25 @@
114142
" ])\n",
115143
"})\n",
116144
"\n",
117-
"vc.layout((spatial_view | (lc_view / features_view)) / (sets_view | sq_view));"
145+
"vc.layout((spatial_view | (lc_view / features_view)) / hconcat(sets_view, sq_heatmap, sq_view, split=[1, 1, 1]));"
118146
]
119147
},
120148
{
121149
"cell_type": "code",
122-
"execution_count": 13,
150+
"execution_count": null,
123151
"metadata": {},
124152
"outputs": [],
125153
"source": [
126154
"vw = vc.widget(height=900, plugins=[plugin], remount_on_uid_change=False)\n",
127155
"vw"
128156
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": null,
161+
"metadata": {},
162+
"outputs": [],
163+
"source": []
129164
}
130165
],
131166
"metadata": {
@@ -144,7 +179,7 @@
144179
"name": "python",
145180
"nbconvert_exporter": "python",
146181
"pygments_lexer": "ipython3",
147-
"version": "3.10.14"
182+
"version": "3.12.13"
148183
}
149184
},
150185
"nbformat": 4,

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ demos = [
9999
"snakemake",
100100
"pyyaml",
101101
]
102+
# SpatialQuery
103+
sq = [
104+
# When installing with `uv`, may need --no-build-isolation-package SpatialQuery
105+
"pybind11",
106+
# As of writing, `main` reflects SpatialQuery commit 9dde563 (April 4, 2026).
107+
"SpatialQuery @ git+https://github.com/ShaokunAn/Spatial-Query@main"
108+
]
102109

103110
[dependency-groups]
104111
dev = [
@@ -125,6 +132,9 @@ override-dependencies = []
125132
[tool.hatch.build]
126133
exclude = [".github", "docs", "demos", "binder"]
127134

135+
[tool.hatch.metadata]
136+
allow-direct-references = true
137+
128138
[project.urls]
129139
repository = "https://github.com/vitessce/vitessce-python"
130140

0 commit comments

Comments
 (0)