|
16 | 16 | "## Import dependencies\n" |
17 | 17 | ] |
18 | 18 | }, |
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 | | - }, |
143 | 19 | { |
144 | 20 | "cell_type": "code", |
145 | 21 | "execution_count": null, |
146 | 22 | "metadata": {}, |
147 | 23 | "outputs": [], |
148 | 24 | "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" |
150 | 26 | ] |
151 | 27 | }, |
152 | 28 | { |
|
168 | 44 | " get_initial_coordination_scope_prefix,\n", |
169 | 45 | " hconcat,\n", |
170 | 46 | " 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\"" |
172 | 65 | ] |
173 | 66 | }, |
174 | 67 | { |
|
180 | 73 | "# Create a VitessceConfig instance.\n", |
181 | 74 | "vc = VitessceConfig(schema_version=\"1.0.17\", name=\"SpatialData\")\n", |
182 | 75 | "\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", |
183 | 84 | "# Add a new dataset to the Vitessce configuration,\n", |
184 | 85 | "# then add the wrapper class instance to this dataset.\n", |
185 | 86 | "dataset = vc.add_dataset(name='KPMP').add_object(\n", |
186 | 87 | " SpatialDataWrapper(\n", |
187 | | - " sdata_path=sdata_path,\n", |
| 88 | + " sdata_url=sdata_url,\n", |
188 | 89 | " image_path=\"images/image\",\n", |
189 | 90 | " coordinate_system=\"global\",\n", |
190 | 91 | " )\n", |
191 | 92 | ").add_object(\n", |
192 | 93 | " SpatialDataWrapper(\n", |
193 | | - " sdata_path=sdata_path,\n", |
| 94 | + " sdata_url=sdata_url,\n", |
194 | 95 | " table_path=\"tables/table_tubules\",\n", |
195 | 96 | " labels_path=\"labels/labels_tubules\",\n", |
196 | 97 | " obs_feature_matrix_path=\"tables/table_tubules/X\",\n", |
|
201 | 102 | " coordinate_system=\"global\",\n", |
202 | 103 | " coordination_values={\n", |
203 | 104 | " \"fileUid\": \"labels_tubules\",\n", |
204 | | - " \"obsType\": \"Tubule\",\n", |
| 105 | + " \"obsType\": t_obstype,\n", |
205 | 106 | " \"featureType\": 'feature',\n", |
206 | 107 | " \"featureValueType\": 'value',\n", |
207 | 108 | " }\n", |
208 | 109 | " )\n", |
209 | 110 | ").add_object(\n", |
210 | 111 | " SpatialDataWrapper(\n", |
211 | | - " sdata_path=sdata_path,\n", |
| 112 | + " sdata_url=sdata_url,\n", |
212 | 113 | " labels_path=\"labels/labels_arteries_arterioles\",\n", |
213 | 114 | " #obs_feature_matrix_path=\"tables/table/X\",\n", |
214 | 115 | " #obs_set_paths=[\"tables/table/obs/annotation\"],\n", |
|
217 | 118 | " coordinate_system=\"global\",\n", |
218 | 119 | " coordination_values={\n", |
219 | 120 | " \"fileUid\": \"labels_arteries_arterioles\",\n", |
220 | | - " \"obsType\": \"Artery\",\n", |
| 121 | + " \"obsType\": a_obstype,\n", |
221 | 122 | " \"featureType\": 'feature',\n", |
222 | 123 | " \"featureValueType\": 'value',\n", |
223 | 124 | " }\n", |
224 | 125 | " )\n", |
225 | 126 | ").add_object(\n", |
226 | 127 | " SpatialDataWrapper(\n", |
227 | | - " sdata_path=sdata_path,\n", |
| 128 | + " sdata_url=sdata_url,\n", |
228 | 129 | " table_path=\"tables/table_cortical_interstitia\",\n", |
229 | 130 | " labels_path=\"labels/labels_cortical_interstitia\",\n", |
230 | 131 | " obs_feature_matrix_path=\"tables/table_cortical_interstitia/X\",\n", |
|
236 | 137 | " coordinate_system=\"global\",\n", |
237 | 138 | " coordination_values={\n", |
238 | 139 | " \"fileUid\": \"labels_cortical_interstitia\",\n", |
239 | | - " \"obsType\": \"Cortical Interstitium\",\n", |
| 140 | + " \"obsType\": ci_obstype,\n", |
240 | 141 | " \"featureType\": 'feature',\n", |
241 | 142 | " \"featureValueType\": 'value',\n", |
242 | 143 | " }\n", |
243 | 144 | " )\n", |
244 | 145 | ").add_object(\n", |
245 | 146 | " SpatialDataWrapper(\n", |
246 | | - " sdata_path=sdata_path,\n", |
| 147 | + " sdata_url=sdata_url,\n", |
247 | 148 | " table_path=\"tables/table_globally_sclerotic_glomeruli\",\n", |
248 | 149 | " labels_path=\"labels/labels_globally_sclerotic_glomeruli\",\n", |
249 | 150 | " obs_feature_matrix_path=\"tables/table_globally_sclerotic_glomeruli/X\",\n", |
|
254 | 155 | " coordinate_system=\"global\",\n", |
255 | 156 | " coordination_values={\n", |
256 | 157 | " \"fileUid\": \"labels_globally_sclerotic_glomeruli\",\n", |
257 | | - " \"obsType\": \"Globally Sclerotic Glomerulus\",\n", |
| 158 | + " \"obsType\": gsg_obstype,\n", |
258 | 159 | " \"featureType\": 'feature',\n", |
259 | 160 | " \"featureValueType\": 'value',\n", |
260 | 161 | " }\n", |
261 | 162 | " )\n", |
262 | 163 | ").add_object(\n", |
263 | 164 | " SpatialDataWrapper(\n", |
264 | | - " sdata_path=sdata_path,\n", |
| 165 | + " sdata_url=sdata_url,\n", |
265 | 166 | " table_path=\"tables/table_non_globally_sclerotic_glomeruli\",\n", |
266 | 167 | " labels_path=\"labels/labels_non_globally_sclerotic_glomeruli\",\n", |
267 | 168 | " obs_feature_matrix_path=\"tables/table_non_globally_sclerotic_glomeruli/X\",\n", |
|
272 | 173 | " coordinate_system=\"global\",\n", |
273 | 174 | " coordination_values={\n", |
274 | 175 | " \"fileUid\": \"labels_non_globally_sclerotic_glomeruli\",\n", |
275 | | - " \"obsType\": \"Non-Globally Sclerotic Glomerulus\",\n", |
| 176 | + " \"obsType\": ngsg_obstype,\n", |
276 | 177 | " \"featureType\": 'feature',\n", |
277 | 178 | " \"featureValueType\": 'value',\n", |
278 | 179 | " }\n", |
279 | 180 | " )\n", |
280 | 181 | ").add_object(\n", |
281 | 182 | " SpatialDataWrapper(\n", |
282 | | - " sdata_path=sdata_path,\n", |
| 183 | + " sdata_url=sdata_url,\n", |
283 | 184 | " table_path=\"tables/table_interstitialfibrosis_and_tubular_atrophy\",\n", |
284 | 185 | " labels_path=\"labels/labels_interstitialfibrosis_and_tubular_atrophy\",\n", |
285 | 186 | " #obs_feature_matrix_path=\"tables/table/X\",\n", |
|
289 | 190 | " coordinate_system=\"global\",\n", |
290 | 191 | " coordination_values={\n", |
291 | 192 | " \"fileUid\": \"labels_interstitialfibrosis_and_tubular_atrophy\",\n", |
292 | | - " \"obsType\": \"Interstitial Fibrosis and Tubular Atrophy\",\n", |
| 193 | + " \"obsType\": ifta_obstype,\n", |
293 | 194 | " \"featureType\": 'feature',\n", |
294 | 195 | " \"featureValueType\": 'value',\n", |
295 | 196 | " }\n", |
296 | 197 | " )\n", |
297 | 198 | ").add_object(\n", |
298 | 199 | " SpatialDataWrapper(\n", |
299 | | - " sdata_path=sdata_path,\n", |
| 200 | + " sdata_url=sdata_url,\n", |
300 | 201 | " table_path=\"tables/table_peritubular_capillaries\",\n", |
301 | 202 | " labels_path=\"labels/labels_peritubular_capillaries\",\n", |
302 | 203 | " obs_feature_matrix_path=\"tables/table_peritubular_capillaries/X\",\n", |
|
307 | 208 | " coordinate_system=\"global\",\n", |
308 | 209 | " coordination_values={\n", |
309 | 210 | " \"fileUid\": \"labels_peritubular_capillaries\",\n", |
310 | | - " \"obsType\": \"Peritubular Capillaries\",\n", |
| 211 | + " \"obsType\": ptc_obstype,\n", |
311 | 212 | " \"featureType\": 'feature',\n", |
312 | 213 | " \"featureValueType\": 'value',\n", |
313 | 214 | " }\n", |
|
326 | 227 | "# GSG\n", |
327 | 228 | "gsg_feature_list = vc.add_view(\"featureList\", dataset=dataset).set_props(title=\"Globally Sclerotic Glomeruli\")\n", |
328 | 229 | "gsg_histogram = vc.add_view(\"featureValueHistogram\", dataset=dataset)\n", |
329 | | - "\n", |
330 | 230 | "# NGSG\n", |
331 | 231 | "ngsg_feature_list = vc.add_view(\"featureList\", dataset=dataset).set_props(title=\"Non-Globally Sclerotic Glomeruli\")\n", |
332 | 232 | "ngsg_histogram = vc.add_view(\"featureValueHistogram\", dataset=dataset)\n", |
333 | 233 | "\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", |
338 | 235 | "[ft_scope, fvt_scope] = vc.add_coordination(\"featureType\", \"featureValueType\")\n", |
339 | 236 | "ft_scope.set_value(\"feature\")\n", |
340 | 237 | "fvt_scope.set_value(\"value\")\n", |
341 | 238 | "\n", |
342 | 239 | "[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", |
344 | 241 | "t_oce_scope.set_value(\"spatialChannelColor\")\n", |
345 | 242 | "\n", |
346 | 243 | "[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", |
348 | 245 | "pt_oce_scope.set_value(\"spatialChannelColor\")\n", |
349 | 246 | "\n", |
350 | 247 | "\n", |
351 | 248 | "[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", |
353 | 250 | "gsg_oce_scope.set_value(\"spatialChannelColor\")\n", |
354 | 251 | "gsg_fvcr_scope.set_value([(3077 - 2333) / (29911 - 2333), 1.0])\n", |
355 | 252 | "\n", |
356 | 253 | "[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", |
358 | 255 | "ngsg_oce_scope.set_value(\"spatialChannelColor\")\n", |
359 | 256 | "ngsg_fvcr_scope.set_value([0.0, 1 - (59451 - 29911) / (59451 - 3077)])\n", |
360 | 257 | "\n", |
361 | | - "\n", |
362 | 258 | "vc.link_views_by_dict([spatial, layer_controller], {\n", |
363 | 259 | " \"imageLayer\": CL([{\n", |
364 | 260 | " \"photometricInterpretation\": \"RGB\",\n", |
|
486 | 382 | " ]),\n", |
487 | 383 | "}, meta=True, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n", |
488 | 384 | "\n", |
489 | | - "#vc.link_views([spatial, layer_controller, feature_list, obs_sets, heatmap], [], [])\n", |
490 | 385 | "tubules_feature_list.use_coordination(t_ot_scope, ft_scope, fvt_scope, t_fs_scope, t_oce_scope)\n", |
491 | 386 | "tubules_histogram.use_coordination(t_ot_scope, ft_scope, fvt_scope, t_fs_scope, t_oce_scope)\n", |
492 | 387 | "\n", |
|
509 | 404 | ")));" |
510 | 405 | ] |
511 | 406 | }, |
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 | | - }, |
522 | 407 | { |
523 | 408 | "cell_type": "code", |
524 | 409 | "execution_count": null, |
|
527 | 412 | }, |
528 | 413 | "outputs": [], |
529 | 414 | "source": [ |
530 | | - "vw = vc.widget(js_package_version=\"3.6.3\")\n", |
| 415 | + "vw = vc.widget(height=1000)\n", |
531 | 416 | "vw" |
532 | 417 | ] |
533 | 418 | }, |
|
0 commit comments