Skip to content

Commit 7828f80

Browse files
committed
Update vis nb
1 parent 11c6c60 commit 7828f80

File tree

1 file changed

+48
-163
lines changed

1 file changed

+48
-163
lines changed

docs/notebooks/spatial_data_kpmp_vis.ipynb

Lines changed: 48 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -16,137 +16,13 @@
1616
"## Import dependencies\n"
1717
]
1818
},
19-
{
20-
"cell_type": "markdown",
21-
"metadata": {},
22-
"source": [
23-
"https://github.com/vitessce/vitessce/blob/main/examples/configs/src/view-configs/spatial-beta/kpmp.js"
24-
]
25-
},
26-
{
27-
"cell_type": "code",
28-
"execution_count": null,
29-
"metadata": {},
30-
"outputs": [],
31-
"source": [
32-
"from os.path import join"
33-
]
34-
},
35-
{
36-
"cell_type": "code",
37-
"execution_count": null,
38-
"metadata": {},
39-
"outputs": [],
40-
"source": [
41-
"base_dir = join(\"..\", \"..\", \"..\", \"kpmp-f2f-march-2023\", \"S-1905-017737\")"
42-
]
43-
},
44-
{
45-
"cell_type": "code",
46-
"execution_count": null,
47-
"metadata": {},
48-
"outputs": [],
49-
"source": [
50-
"sdata_path = join(base_dir, \"sdata.zarr\")"
51-
]
52-
},
53-
{
54-
"cell_type": "code",
55-
"execution_count": null,
56-
"metadata": {},
57-
"outputs": [],
58-
"source": [
59-
"from spatialdata import read_zarr, to_polygons"
60-
]
61-
},
62-
{
63-
"cell_type": "code",
64-
"execution_count": null,
65-
"metadata": {},
66-
"outputs": [],
67-
"source": [
68-
"sdata = read_zarr(sdata_path)"
69-
]
70-
},
71-
{
72-
"cell_type": "code",
73-
"execution_count": null,
74-
"metadata": {},
75-
"outputs": [],
76-
"source": [
77-
"sdata"
78-
]
79-
},
80-
{
81-
"cell_type": "code",
82-
"execution_count": null,
83-
"metadata": {},
84-
"outputs": [],
85-
"source": [
86-
"sdata.tables[\"table_tubules\"].var"
87-
]
88-
},
89-
{
90-
"cell_type": "code",
91-
"execution_count": null,
92-
"metadata": {},
93-
"outputs": [],
94-
"source": [
95-
"sdata.tables[\"table_tubules\"].obs"
96-
]
97-
},
98-
{
99-
"cell_type": "code",
100-
"execution_count": null,
101-
"metadata": {},
102-
"outputs": [],
103-
"source": [
104-
"sdata.tables[\"table_peritubular_capillaries\"].obs"
105-
]
106-
},
107-
{
108-
"cell_type": "code",
109-
"execution_count": null,
110-
"metadata": {},
111-
"outputs": [],
112-
"source": [
113-
"sdata.tables[\"table_globally_sclerotic_glomeruli\"].obs"
114-
]
115-
},
116-
{
117-
"cell_type": "code",
118-
"execution_count": null,
119-
"metadata": {},
120-
"outputs": [],
121-
"source": [
122-
"!ls {sdata_path}/images"
123-
]
124-
},
125-
{
126-
"cell_type": "code",
127-
"execution_count": null,
128-
"metadata": {},
129-
"outputs": [],
130-
"source": [
131-
"!ls {sdata_path}/labels"
132-
]
133-
},
134-
{
135-
"cell_type": "code",
136-
"execution_count": null,
137-
"metadata": {},
138-
"outputs": [],
139-
"source": [
140-
"!ls {sdata_path}/tables"
141-
]
142-
},
14319
{
14420
"cell_type": "code",
14521
"execution_count": null,
14622
"metadata": {},
14723
"outputs": [],
14824
"source": [
149-
"!ls {sdata_path}/tables/table_cortical_interstitia/obs"
25+
"# Reference: https://github.com/vitessce/vitessce/blob/main/examples/configs/src/view-configs/spatial-beta/kpmp.js"
15026
]
15127
},
15228
{
@@ -168,7 +44,24 @@
16844
" get_initial_coordination_scope_prefix,\n",
16945
" hconcat,\n",
17046
" vconcat,\n",
171-
")"
47+
")\n",
48+
"from os.path import join"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"metadata": {},
54+
"source": [
55+
"## Configure Vitessce"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"sdata_url = \"https://storage.googleapis.com/vitessce-demo-data/kpmp-f2f-march-2023/S-1905-017737/sdata.zarr\""
17265
]
17366
},
17467
{
@@ -180,17 +73,25 @@
18073
"# Create a VitessceConfig instance.\n",
18174
"vc = VitessceConfig(schema_version=\"1.0.17\", name=\"SpatialData\")\n",
18275
"\n",
76+
"t_obstype = \"Tubule\"\n",
77+
"a_obstype = \"Artery\"\n",
78+
"ci_obstype = \"Cortical Interstitium\"\n",
79+
"gsg_obstype = \"G. S. Glomerulus\"\n",
80+
"ngsg_obstype = \"Non-G. S. Glomerulus\"\n",
81+
"ifta_obstype = \"Interstitial Fibrosis and Tubular Atrophy\"\n",
82+
"ptc_obstype = \"Peritubular Capillaries\"\n",
83+
"\n",
18384
"# Add a new dataset to the Vitessce configuration,\n",
18485
"# then add the wrapper class instance to this dataset.\n",
18586
"dataset = vc.add_dataset(name='KPMP').add_object(\n",
18687
" SpatialDataWrapper(\n",
187-
" sdata_path=sdata_path,\n",
88+
" sdata_url=sdata_url,\n",
18889
" image_path=\"images/image\",\n",
18990
" coordinate_system=\"global\",\n",
19091
" )\n",
19192
").add_object(\n",
19293
" SpatialDataWrapper(\n",
193-
" sdata_path=sdata_path,\n",
94+
" sdata_url=sdata_url,\n",
19495
" table_path=\"tables/table_tubules\",\n",
19596
" labels_path=\"labels/labels_tubules\",\n",
19697
" obs_feature_matrix_path=\"tables/table_tubules/X\",\n",
@@ -201,14 +102,14 @@
201102
" coordinate_system=\"global\",\n",
202103
" coordination_values={\n",
203104
" \"fileUid\": \"labels_tubules\",\n",
204-
" \"obsType\": \"Tubule\",\n",
105+
" \"obsType\": t_obstype,\n",
205106
" \"featureType\": 'feature',\n",
206107
" \"featureValueType\": 'value',\n",
207108
" }\n",
208109
" )\n",
209110
").add_object(\n",
210111
" SpatialDataWrapper(\n",
211-
" sdata_path=sdata_path,\n",
112+
" sdata_url=sdata_url,\n",
212113
" labels_path=\"labels/labels_arteries_arterioles\",\n",
213114
" #obs_feature_matrix_path=\"tables/table/X\",\n",
214115
" #obs_set_paths=[\"tables/table/obs/annotation\"],\n",
@@ -217,14 +118,14 @@
217118
" coordinate_system=\"global\",\n",
218119
" coordination_values={\n",
219120
" \"fileUid\": \"labels_arteries_arterioles\",\n",
220-
" \"obsType\": \"Artery\",\n",
121+
" \"obsType\": a_obstype,\n",
221122
" \"featureType\": 'feature',\n",
222123
" \"featureValueType\": 'value',\n",
223124
" }\n",
224125
" )\n",
225126
").add_object(\n",
226127
" SpatialDataWrapper(\n",
227-
" sdata_path=sdata_path,\n",
128+
" sdata_url=sdata_url,\n",
228129
" table_path=\"tables/table_cortical_interstitia\",\n",
229130
" labels_path=\"labels/labels_cortical_interstitia\",\n",
230131
" obs_feature_matrix_path=\"tables/table_cortical_interstitia/X\",\n",
@@ -236,14 +137,14 @@
236137
" coordinate_system=\"global\",\n",
237138
" coordination_values={\n",
238139
" \"fileUid\": \"labels_cortical_interstitia\",\n",
239-
" \"obsType\": \"Cortical Interstitium\",\n",
140+
" \"obsType\": ci_obstype,\n",
240141
" \"featureType\": 'feature',\n",
241142
" \"featureValueType\": 'value',\n",
242143
" }\n",
243144
" )\n",
244145
").add_object(\n",
245146
" SpatialDataWrapper(\n",
246-
" sdata_path=sdata_path,\n",
147+
" sdata_url=sdata_url,\n",
247148
" table_path=\"tables/table_globally_sclerotic_glomeruli\",\n",
248149
" labels_path=\"labels/labels_globally_sclerotic_glomeruli\",\n",
249150
" obs_feature_matrix_path=\"tables/table_globally_sclerotic_glomeruli/X\",\n",
@@ -254,14 +155,14 @@
254155
" coordinate_system=\"global\",\n",
255156
" coordination_values={\n",
256157
" \"fileUid\": \"labels_globally_sclerotic_glomeruli\",\n",
257-
" \"obsType\": \"Globally Sclerotic Glomerulus\",\n",
158+
" \"obsType\": gsg_obstype,\n",
258159
" \"featureType\": 'feature',\n",
259160
" \"featureValueType\": 'value',\n",
260161
" }\n",
261162
" )\n",
262163
").add_object(\n",
263164
" SpatialDataWrapper(\n",
264-
" sdata_path=sdata_path,\n",
165+
" sdata_url=sdata_url,\n",
265166
" table_path=\"tables/table_non_globally_sclerotic_glomeruli\",\n",
266167
" labels_path=\"labels/labels_non_globally_sclerotic_glomeruli\",\n",
267168
" obs_feature_matrix_path=\"tables/table_non_globally_sclerotic_glomeruli/X\",\n",
@@ -272,14 +173,14 @@
272173
" coordinate_system=\"global\",\n",
273174
" coordination_values={\n",
274175
" \"fileUid\": \"labels_non_globally_sclerotic_glomeruli\",\n",
275-
" \"obsType\": \"Non-Globally Sclerotic Glomerulus\",\n",
176+
" \"obsType\": ngsg_obstype,\n",
276177
" \"featureType\": 'feature',\n",
277178
" \"featureValueType\": 'value',\n",
278179
" }\n",
279180
" )\n",
280181
").add_object(\n",
281182
" SpatialDataWrapper(\n",
282-
" sdata_path=sdata_path,\n",
183+
" sdata_url=sdata_url,\n",
283184
" table_path=\"tables/table_interstitialfibrosis_and_tubular_atrophy\",\n",
284185
" labels_path=\"labels/labels_interstitialfibrosis_and_tubular_atrophy\",\n",
285186
" #obs_feature_matrix_path=\"tables/table/X\",\n",
@@ -289,14 +190,14 @@
289190
" coordinate_system=\"global\",\n",
290191
" coordination_values={\n",
291192
" \"fileUid\": \"labels_interstitialfibrosis_and_tubular_atrophy\",\n",
292-
" \"obsType\": \"Interstitial Fibrosis and Tubular Atrophy\",\n",
193+
" \"obsType\": ifta_obstype,\n",
293194
" \"featureType\": 'feature',\n",
294195
" \"featureValueType\": 'value',\n",
295196
" }\n",
296197
" )\n",
297198
").add_object(\n",
298199
" SpatialDataWrapper(\n",
299-
" sdata_path=sdata_path,\n",
200+
" sdata_url=sdata_url,\n",
300201
" table_path=\"tables/table_peritubular_capillaries\",\n",
301202
" labels_path=\"labels/labels_peritubular_capillaries\",\n",
302203
" obs_feature_matrix_path=\"tables/table_peritubular_capillaries/X\",\n",
@@ -307,7 +208,7 @@
307208
" coordinate_system=\"global\",\n",
308209
" coordination_values={\n",
309210
" \"fileUid\": \"labels_peritubular_capillaries\",\n",
310-
" \"obsType\": \"Peritubular Capillaries\",\n",
211+
" \"obsType\": ptc_obstype,\n",
311212
" \"featureType\": 'feature',\n",
312213
" \"featureValueType\": 'value',\n",
313214
" }\n",
@@ -326,39 +227,34 @@
326227
"# GSG\n",
327228
"gsg_feature_list = vc.add_view(\"featureList\", dataset=dataset).set_props(title=\"Globally Sclerotic Glomeruli\")\n",
328229
"gsg_histogram = vc.add_view(\"featureValueHistogram\", dataset=dataset)\n",
329-
"\n",
330230
"# NGSG\n",
331231
"ngsg_feature_list = vc.add_view(\"featureList\", dataset=dataset).set_props(title=\"Non-Globally Sclerotic Glomeruli\")\n",
332232
"ngsg_histogram = vc.add_view(\"featureValueHistogram\", dataset=dataset)\n",
333233
"\n",
334-
"\n",
335-
"#obs_sets = vc.add_view(\"obsSets\", dataset=dataset)\n",
336-
"#heatmap = vc.add_view(\"heatmap\", dataset=dataset)\n",
337-
"\n",
234+
"# Coordination of views.\n",
338235
"[ft_scope, fvt_scope] = vc.add_coordination(\"featureType\", \"featureValueType\")\n",
339236
"ft_scope.set_value(\"feature\")\n",
340237
"fvt_scope.set_value(\"value\")\n",
341238
"\n",
342239
"[t_ot_scope, t_fs_scope, t_oce_scope] = vc.add_coordination(\"obsType\", \"featureSelection\", \"obsColorEncoding\")\n",
343-
"t_ot_scope.set_value(\"Tubule\")\n",
240+
"t_ot_scope.set_value(t_obstype)\n",
344241
"t_oce_scope.set_value(\"spatialChannelColor\")\n",
345242
"\n",
346243
"[pt_ot_scope, pt_fs_scope, pt_oce_scope] = vc.add_coordination(\"obsType\", \"featureSelection\", \"obsColorEncoding\")\n",
347-
"pt_ot_scope.set_value(\"Peritubular Capillaries\")\n",
244+
"pt_ot_scope.set_value(ptc_obstype)\n",
348245
"pt_oce_scope.set_value(\"spatialChannelColor\")\n",
349246
"\n",
350247
"\n",
351248
"[gsg_ot_scope, gsg_fs_scope, gsg_oce_scope, gsg_fvcr_scope] = vc.add_coordination(\"obsType\", \"featureSelection\", \"obsColorEncoding\", \"featureValueColormapRange\")\n",
352-
"gsg_ot_scope.set_value(\"Globally Sclerotic Glomerulus\")\n",
249+
"gsg_ot_scope.set_value(gsg_obstype)\n",
353250
"gsg_oce_scope.set_value(\"spatialChannelColor\")\n",
354251
"gsg_fvcr_scope.set_value([(3077 - 2333) / (29911 - 2333), 1.0])\n",
355252
"\n",
356253
"[ngsg_ot_scope, ngsg_fs_scope, ngsg_oce_scope, ngsg_fvcr_scope] = vc.add_coordination(\"obsType\", \"featureSelection\", \"obsColorEncoding\", \"featureValueColormapRange\")\n",
357-
"ngsg_ot_scope.set_value(\"Non-Globally Sclerotic Glomerulus\")\n",
254+
"ngsg_ot_scope.set_value(ngsg_obstype)\n",
358255
"ngsg_oce_scope.set_value(\"spatialChannelColor\")\n",
359256
"ngsg_fvcr_scope.set_value([0.0, 1 - (59451 - 29911) / (59451 - 3077)])\n",
360257
"\n",
361-
"\n",
362258
"vc.link_views_by_dict([spatial, layer_controller], {\n",
363259
" \"imageLayer\": CL([{\n",
364260
" \"photometricInterpretation\": \"RGB\",\n",
@@ -486,7 +382,6 @@
486382
" ]),\n",
487383
"}, meta=True, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n",
488384
"\n",
489-
"#vc.link_views([spatial, layer_controller, feature_list, obs_sets, heatmap], [], [])\n",
490385
"tubules_feature_list.use_coordination(t_ot_scope, ft_scope, fvt_scope, t_fs_scope, t_oce_scope)\n",
491386
"tubules_histogram.use_coordination(t_ot_scope, ft_scope, fvt_scope, t_fs_scope, t_oce_scope)\n",
492387
"\n",
@@ -509,16 +404,6 @@
509404
")));"
510405
]
511406
},
512-
{
513-
"cell_type": "code",
514-
"execution_count": null,
515-
"metadata": {},
516-
"outputs": [],
517-
"source": [
518-
"#import json\n",
519-
"#print(json.dumps(vc.to_dict(base_url=\"http://localhost:8003\")))"
520-
]
521-
},
522407
{
523408
"cell_type": "code",
524409
"execution_count": null,
@@ -527,7 +412,7 @@
527412
},
528413
"outputs": [],
529414
"source": [
530-
"vw = vc.widget(js_package_version=\"3.6.3\")\n",
415+
"vw = vc.widget(height=1000)\n",
531416
"vw"
532417
]
533418
},

0 commit comments

Comments
 (0)