@vitessce/config 2.0.3-beta.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,465 @@
1
+ import { generateConfigs } from './VitessceAutoConfig.js';
2
+
3
+ describe('src/VitessceAutoConfig.js', () => {
4
+ it('generates config for OME-TIFF file correctly', async () => {
5
+ const urls = ['somefile.ome.tif'];
6
+ const expectedName = urls[0].split('/').at(-1);
7
+ const expectedConfig = {
8
+ version: '1.0.15',
9
+ name: 'An automatically generated config. Adjust values and add layout components if needed.',
10
+ description: 'Populate with text relevant to this visualisation.',
11
+ datasets: [
12
+ {
13
+ uid: 'A',
14
+ name: expectedName,
15
+ files: [
16
+ {
17
+ fileType: 'raster.json',
18
+ options: {
19
+ images: [
20
+ {
21
+ metadata: {
22
+ isBitmask: false,
23
+ },
24
+ name: expectedName,
25
+ type: 'ome-tiff',
26
+ url: urls[0],
27
+ },
28
+ ],
29
+ schemaVersion: '0.0.2',
30
+ usePhysicalSizeScaling: false,
31
+ },
32
+ },
33
+ ],
34
+ },
35
+ ],
36
+ coordinationSpace: {
37
+ dataset: {
38
+ A: 'A',
39
+ },
40
+ },
41
+ layout: [
42
+ {
43
+ component: 'description',
44
+ coordinationScopes: {
45
+ dataset: 'A',
46
+ },
47
+ x: 0,
48
+ y: 0,
49
+ w: 6,
50
+ h: 6,
51
+ },
52
+ {
53
+ component: 'spatial',
54
+ coordinationScopes: {
55
+ dataset: 'A',
56
+ },
57
+ x: 6,
58
+ y: 0,
59
+ w: 6,
60
+ h: 6,
61
+ },
62
+ {
63
+ component: 'layerController',
64
+ coordinationScopes: {
65
+ dataset: 'A',
66
+ },
67
+ x: 0,
68
+ y: 6,
69
+ w: 6,
70
+ h: 6,
71
+ props: {
72
+ disable3d: [],
73
+ disableChannelsIfRgbDetected: true,
74
+ },
75
+ },
76
+ ],
77
+ initStrategy: 'auto',
78
+ };
79
+
80
+ const config = await generateConfigs(urls);
81
+ expect(config).toEqual(expectedConfig);
82
+ });
83
+
84
+ it('generates config for OME-ZARR file correctly', async () => {
85
+ const urls = ['anotherfile.ome.zarr'];
86
+ const expectedName = urls[0].split('/').at(-1);
87
+ const expectedConfig = {
88
+ version: '1.0.15',
89
+ name: 'An automatically generated config. Adjust values and add layout components if needed.',
90
+ description: 'Populate with text relevant to this visualisation.',
91
+ datasets: [
92
+ {
93
+ uid: 'A',
94
+ name: expectedName,
95
+ files: [
96
+ {
97
+ url: urls[0],
98
+ fileType: 'raster.ome-zarr',
99
+ },
100
+ ],
101
+ },
102
+ ],
103
+ coordinationSpace: {
104
+ dataset: {
105
+ A: 'A',
106
+ },
107
+ },
108
+ layout: [
109
+ {
110
+ component: 'description',
111
+ coordinationScopes: {
112
+ dataset: 'A',
113
+ },
114
+ x: 0,
115
+ y: 0,
116
+ w: 6,
117
+ h: 6,
118
+ },
119
+ {
120
+ component: 'spatial',
121
+ coordinationScopes: {
122
+ dataset: 'A',
123
+ },
124
+ x: 6,
125
+ y: 0,
126
+ w: 6,
127
+ h: 6,
128
+ },
129
+ {
130
+ component: 'layerController',
131
+ coordinationScopes: {
132
+ dataset: 'A',
133
+ },
134
+ x: 0,
135
+ y: 6,
136
+ w: 6,
137
+ h: 6,
138
+ },
139
+ {
140
+ component: 'status',
141
+ coordinationScopes: {
142
+ dataset: 'A',
143
+ },
144
+ x: 6,
145
+ y: 6,
146
+ w: 6,
147
+ h: 6,
148
+ },
149
+ ],
150
+ initStrategy: 'auto',
151
+ };
152
+
153
+ const config = await generateConfigs(urls);
154
+ expect(config).toEqual(expectedConfig);
155
+ });
156
+
157
+ it('generates config for Anndata-ZARR file correctly', async () => {
158
+ const urls = ['http://localhost:51204/@fixtures/zarr/partials/.anndata.zarr'];
159
+ const expectedName = urls[0].split('/').at(-1);
160
+ const expectedConfig = {
161
+ version: '1.0.15',
162
+ name: 'An automatically generated config. Adjust values and add layout components if needed.',
163
+ description: 'Populate with text relevant to this visualisation.',
164
+ datasets: [
165
+ {
166
+ uid: 'A',
167
+ name: expectedName,
168
+ files: [
169
+ {
170
+ url: urls[0],
171
+ fileType: 'anndata.zarr',
172
+ coordinationValues: {
173
+ obsType: 'cell',
174
+ featureType: 'gene',
175
+ featureValueType: 'expression',
176
+ },
177
+ options: {
178
+ obsEmbedding: [
179
+ {
180
+ path: 'obsm/X_umap',
181
+ embeddingType: 'UMAP',
182
+ },
183
+ ],
184
+ obsFeatureMatrix: {
185
+ path: 'X',
186
+ },
187
+ obsSets: [
188
+ {
189
+ name: 'Cell Type',
190
+ path: [
191
+ 'obs/cell_type',
192
+ 'obs/disease',
193
+ 'obs/leiden',
194
+ 'obs/organism',
195
+ 'obs/self_reported_ethnicity',
196
+ 'obs/sex',
197
+ 'obs/tissue'],
198
+ },
199
+ ],
200
+ },
201
+ },
202
+ ],
203
+ },
204
+ ],
205
+ coordinationSpace: {
206
+ dataset: {
207
+ A: 'A',
208
+ },
209
+ embeddingType: {
210
+ A: 'UMAP',
211
+ },
212
+ },
213
+ layout: [
214
+ {
215
+ component: 'obsSets',
216
+ coordinationScopes: {
217
+ dataset: 'A',
218
+ },
219
+ x: 0,
220
+ y: 0,
221
+ w: 6,
222
+ h: 6,
223
+ },
224
+ {
225
+ component: 'scatterplot',
226
+ coordinationScopes: {
227
+ dataset: 'A',
228
+ embeddingType: 'A',
229
+ },
230
+ x: 6,
231
+ y: 0,
232
+ w: 6,
233
+ h: 6,
234
+ },
235
+ {
236
+ component: 'heatmap',
237
+ coordinationScopes: {
238
+ dataset: 'A',
239
+ },
240
+ x: 0,
241
+ y: 6,
242
+ w: 6,
243
+ h: 6,
244
+ props: {
245
+ transpose: true,
246
+ },
247
+ },
248
+ {
249
+ component: 'featureList',
250
+ coordinationScopes: {
251
+ dataset: 'A',
252
+ },
253
+ x: 6,
254
+ y: 6,
255
+ w: 6,
256
+ h: 6,
257
+ },
258
+ ],
259
+ initStrategy: 'auto',
260
+ };
261
+
262
+ const config = await generateConfigs(urls);
263
+ expect(config).toEqual(expectedConfig);
264
+ });
265
+
266
+ it('generates empty config for Anndata-ZARR file with empty .zmetadata', async () => {
267
+ const urls = ['http://localhost:51204/@fixtures/zarr/partials/emptymeta.h5ad.zarr'];
268
+ const expectedName = urls[0].split('/').at(-1);
269
+ const expectedConfig = {
270
+ version: '1.0.15',
271
+ name: 'An automatically generated config. Adjust values and add layout components if needed.',
272
+ description: 'Populate with text relevant to this visualisation.',
273
+ datasets: [
274
+ {
275
+ uid: 'A',
276
+ name: expectedName,
277
+ files: [
278
+ {
279
+ url: urls[0],
280
+ fileType: 'anndata.zarr',
281
+ coordinationValues: {
282
+ obsType: 'cell',
283
+ featureType: 'gene',
284
+ featureValueType: 'expression',
285
+ },
286
+ options: {
287
+ obsEmbedding: [],
288
+ obsFeatureMatrix: {
289
+ path: 'X',
290
+ },
291
+ },
292
+ },
293
+ ],
294
+ },
295
+ ],
296
+ coordinationSpace: {
297
+ dataset: {
298
+ A: 'A',
299
+ },
300
+ },
301
+ layout: [],
302
+ initStrategy: 'auto',
303
+ };
304
+
305
+ const config = await generateConfigs(urls);
306
+ expect(config).toEqual(expectedConfig);
307
+ });
308
+
309
+ it('raises an error for Anndata-ZARR file with misconfigured .zmetadata', async () => {
310
+ const urls = ['http://localhost:51204/@fixtures/zarr/partials/invalidmeta.adata.zarr'];
311
+
312
+ await generateConfigs(urls).catch(
313
+ e => expect(e.message).toContain('Could not generate config: .zmetadata file is not valid.'),
314
+ );
315
+ });
316
+
317
+ it('generates config for multiple files correctly', async () => {
318
+ const urls = ['somefile.ome.tif', 'anoterfile.ome.zarr'];
319
+ const expectedNames = [urls[0].split('/').at(-1), urls[1].split('/').at(-1)];
320
+
321
+ const expectedConfig = {
322
+ version: '1.0.15',
323
+ name: 'An automatically generated config. Adjust values and add layout components if needed.',
324
+ description: 'Populate with text relevant to this visualisation.',
325
+ datasets: [
326
+ {
327
+ uid: 'A',
328
+ name: expectedNames[0],
329
+ files: [
330
+ {
331
+ fileType: 'raster.json',
332
+ options: {
333
+ images: [
334
+ {
335
+ metadata: {
336
+ isBitmask: false,
337
+ },
338
+ name: expectedNames[0],
339
+ type: 'ome-tiff',
340
+ url: urls[0],
341
+ },
342
+ ],
343
+ schemaVersion: '0.0.2',
344
+ usePhysicalSizeScaling: false,
345
+ },
346
+ },
347
+ ],
348
+ },
349
+ {
350
+ uid: 'B',
351
+ name: expectedNames[1],
352
+ files: [
353
+ {
354
+ url: urls[1],
355
+ fileType: 'raster.ome-zarr',
356
+ },
357
+ ],
358
+ },
359
+ ],
360
+ coordinationSpace: {
361
+ dataset: {
362
+ A: 'A',
363
+ B: 'B',
364
+ },
365
+ },
366
+ layout: [
367
+ {
368
+ component: 'description',
369
+ coordinationScopes: {
370
+ dataset: 'A',
371
+ },
372
+ x: 0,
373
+ y: 0,
374
+ w: 4,
375
+ h: 4,
376
+ },
377
+ {
378
+ component: 'spatial',
379
+ coordinationScopes: {
380
+ dataset: 'A',
381
+ },
382
+ x: 4,
383
+ y: 0,
384
+ w: 4,
385
+ h: 4,
386
+ },
387
+ {
388
+ component: 'layerController',
389
+ coordinationScopes: {
390
+ dataset: 'A',
391
+ },
392
+ x: 8,
393
+ y: 0,
394
+ w: 4,
395
+ h: 4,
396
+ props: {
397
+ disable3d: [],
398
+ disableChannelsIfRgbDetected: true,
399
+ },
400
+ },
401
+ {
402
+ component: 'description',
403
+ coordinationScopes: {
404
+ dataset: 'B',
405
+ },
406
+ x: 0,
407
+ y: 4,
408
+ w: 4,
409
+ h: 4,
410
+ },
411
+ {
412
+ component: 'spatial',
413
+ coordinationScopes: {
414
+ dataset: 'B',
415
+ },
416
+ x: 4,
417
+ y: 4,
418
+ w: 4,
419
+ h: 4,
420
+ },
421
+ {
422
+ component: 'layerController',
423
+ coordinationScopes: {
424
+ dataset: 'B',
425
+ },
426
+ x: 8,
427
+ y: 4,
428
+ w: 4,
429
+ h: 4,
430
+ },
431
+ {
432
+ component: 'status',
433
+ coordinationScopes: {
434
+ dataset: 'B',
435
+ },
436
+ x: 0,
437
+ y: 8,
438
+ w: 4,
439
+ h: 4,
440
+ },
441
+ ],
442
+ initStrategy: 'auto',
443
+ };
444
+
445
+ const config = await generateConfigs(urls);
446
+ expect(config).toEqual(expectedConfig);
447
+ });
448
+
449
+
450
+ it('raises an Error when .zmetadata file not present in folder', async () => {
451
+ const urls = ['http://localhost:51204/@fixtures/zarr/partials/invalid.adata.zarr'];
452
+
453
+ await generateConfigs(urls).catch(
454
+ e => expect(e.message).toContain('Could not generate config. File .zmetadata not found in supplied file URL'),
455
+ );
456
+ });
457
+
458
+ it('raises an error when URL with unsupported file format is passed', async () => {
459
+ const urls = ['http://localhost:51204/@fixtures/zarr/anndata-0.7/somefile.zarr'];
460
+
461
+ await generateConfigs(urls).catch(
462
+ e => expect(e.message).toContain('This file type is not supported.'),
463
+ );
464
+ });
465
+ });