Skip to content

Commit 6d229e3

Browse files
committed
Updates
1 parent 7828f80 commit 6d229e3

File tree

2 files changed

+11
-87
lines changed

2 files changed

+11
-87
lines changed
Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,15 @@
1-
#!/usr/bin/env python
2-
# coding: utf-8
3-
4-
# # Vitessce Widget Tutorial
5-
6-
# ## Import dependencies
7-
#
8-
9-
# https://github.com/vitessce/vitessce/blob/main/examples/configs/src/view-configs/spatial-beta/kpmp.js
10-
11-
# In[2]:
12-
13-
141
from os.path import join
15-
16-
17-
# In[1]:
18-
19-
20-
import spatialdata
212
from spatialdata import SpatialData, to_polygons
223
from spatialdata.models import Image2DModel, Labels2DModel, TableModel
234
from spatialdata.transformations import (
24-
Affine,
25-
MapAxis,
265
Scale,
27-
Sequence,
28-
Translation,
29-
get_transformation,
306
set_transformation,
317
)
32-
from anndata import read_zarr, AnnData
33-
import tifffile
34-
from tifffile import imread, TiffFile
35-
import xml.etree.ElementTree
36-
import io
8+
from anndata import read_zarr
9+
from tifffile import imread
3710
import zarr
3811

39-
40-
41-
# In[2]:
42-
43-
44-
45-
46-
# In[3]:
47-
48-
49-
base_dir = join("..", "..", "..", "kpmp-f2f-march-2023", "S-1905-017737")
50-
51-
52-
# In[ ]:
53-
12+
base_dir = join("S-1905-017737")
5413

5514
img_path = join(base_dir, "S-1905-017737_PAS_2of2_bf.ome.tif")
5615
seg_path = join(base_dir, "S-1905-017737_PAS_2of2.ome.tif")
@@ -65,29 +24,11 @@
6524
"peritubular_capillaries": join(base_dir, "Peritubular Capillaries renamed.adata.zarr"),
6625
}
6726

68-
69-
# In[ ]:
70-
71-
7227
# The shape of the data should be c(z)yx for 2D (3D) images
73-
74-
75-
# In[ ]:
76-
77-
7828
img_arr = imread(img_path)
79-
80-
81-
# In[ ]:
82-
83-
8429
seg_store = imread(seg_path, aszarr=True)
8530
seg_z = zarr.open(seg_store)
8631

87-
88-
# In[ ]:
89-
90-
9132
def clean_adata(adata):
9233
colnames = adata.obs.columns.tolist()
9334
adata.obs = adata.obs.rename(columns=dict([ (c, c.replace(" ", "_")) for c in colnames ]))
@@ -97,10 +38,6 @@ def clean_adata(adata):
9738
adata.obs.index = range(1, adata.obs.shape[0]+1)
9839
return adata
9940

100-
101-
# In[ ]:
102-
103-
10441
sdata = SpatialData(
10542
images={
10643
"image": Image2DModel.parse(img_arr, scale_factors=[2, 2, 2, 2, 2]),
@@ -118,26 +55,10 @@ def clean_adata(adata):
11855
scale = Scale([2.0, 2.0], axes=("y","x"))
11956
set_transformation(sdata[f"labels_{obs_type}"], scale, to_coordinate_system="global")
12057

121-
122-
# In[ ]:
123-
12458
for labels_key in sdata.labels.keys():
12559
shapes_key = "shapes" + labels_key[labels_key.index("_"):]
12660
sdata.shapes[shapes_key] = to_polygons(sdata.labels[labels_key])
12761

128-
12962
sdata.write(join(base_dir, "sdata.zarr"), overwrite=True)
130-
print(join(base_dir, "sdata.zarr"))
63+
print(join(base_dir, "S-1905-017737.sdata.zarr"))
13164
print("Done")
132-
133-
# In[ ]:
134-
135-
136-
137-
138-
139-
# In[ ]:
140-
141-
142-
143-

src/vitessce/widget.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def get_uid_str(uid):
232232
const storeUrls = view.model.get('store_urls');
233233
const invokeTimeout = view.model.get('invoke_timeout');
234234
const invokeBatched = view.model.get('invoke_batched');
235+
const preventScroll = view.model.get('prevent_scroll');
235236
236237
const pageMode = view.model.get('page_mode');
237238
const pageEsm = view.model.get('page_esm');
@@ -424,7 +425,7 @@ def get_uid_str(uid):
424425
const divRef = React.useRef();
425426
426427
React.useEffect(() => {
427-
if(!divRef.current || pageMode) {
428+
if(!divRef.current || !preventScroll) {
428429
return () => {};
429430
}
430431
@@ -450,7 +451,7 @@ def get_uid_str(uid):
450451
divRef.current.removeEventListener("mouseleave", handleMouseLeave);
451452
}
452453
};
453-
}, [divRef, pageMode]);
454+
}, [divRef, preventScroll]);
454455
455456
// Config changed on JS side (from within <Vitessce/>),
456457
// send updated config to Python side.
@@ -609,10 +610,11 @@ class VitessceWidget(anywidget.AnyWidget):
609610
page_esm = Unicode('').tag(sync=True)
610611
invoke_timeout = Int(300000).tag(sync=True)
611612
invoke_batched = Bool(True).tag(sync=True)
613+
prevent_scroll = Bool(True).tag(sync=True)
612614

613615
store_urls = List(trait=Unicode(''), default_value=[]).tag(sync=True)
614616

615-
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.6.3', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, prefer_local=True, invoke_timeout=300000, invoke_batched=True, page_mode=False, page_esm=None):
617+
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.6.3', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, prefer_local=True, invoke_timeout=300000, invoke_batched=True, page_mode=False, page_esm=None, prevent_scroll=True):
616618
"""
617619
Construct a new Vitessce widget.
618620
@@ -632,6 +634,7 @@ def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=
632634
:param bool invoke_batched: Should invocations (Zarr gets) be submitted in batch, or individually? By default, True.
633635
:param bool page_mode: Whether to render the <Vitessce/> component in grid-mode or page-mode. By default, False.
634636
:param str page_esm: The ES module string for the page component creation function. Optional.
637+
:param bool prevent_scroll: Should mouseover in the Vitessce widget prevent disable the scrolling of the notebook? By default, True.
635638
636639
.. code-block:: python
637640
:emphasize-lines: 4
@@ -665,7 +668,7 @@ def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=
665668
js_package_version=js_package_version, js_dev_mode=js_dev_mode, custom_js_url=custom_js_url,
666669
plugin_esm=plugin_esm, remount_on_uid_change=remount_on_uid_change,
667670
page_mode=page_mode, page_esm=('' if page_esm is None else page_esm),
668-
invoke_timeout=invoke_timeout, invoke_batched=invoke_batched,
671+
invoke_timeout=invoke_timeout, invoke_batched=invoke_batched, prevent_scroll=prevent_scroll,
669672
uid=uid_str, store_urls=list(self._stores.keys())
670673
)
671674

0 commit comments

Comments
 (0)