@vitessce/json 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.
Files changed (168) hide show
  1. package/dist/deflate-a2d6b257.js +12 -0
  2. package/dist/index-8cb529a4.js +151122 -0
  3. package/dist/index.js +19 -4
  4. package/dist/jpeg-e323e6ed.js +839 -0
  5. package/dist/lerc-0dc6a58a.js +2005 -0
  6. package/dist/lzw-e9c82d83.js +127 -0
  7. package/dist/packbits-0a0f672b.js +29 -0
  8. package/dist/pako.esm-68f84e2a.js +4022 -0
  9. package/dist/raw-3f989896.js +11 -0
  10. package/dist/webimage-f799ed95.js +31 -0
  11. package/dist-tsc/JsonSource.d.ts +11 -0
  12. package/dist-tsc/JsonSource.d.ts.map +1 -0
  13. package/dist-tsc/index.d.ts +5 -0
  14. package/dist-tsc/index.d.ts.map +1 -0
  15. package/dist-tsc/index.js +5 -0
  16. package/dist-tsc/json-loaders/JsonLoader.d.ts +8 -0
  17. package/dist-tsc/json-loaders/JsonLoader.d.ts.map +1 -0
  18. package/{dist → dist-tsc}/json-loaders/JsonLoader.js +8 -8
  19. package/dist-tsc/json-loaders/JsonLoader.test.d.ts +2 -0
  20. package/dist-tsc/json-loaders/JsonLoader.test.d.ts.map +1 -0
  21. package/{dist → dist-tsc}/json-loaders/JsonLoader.test.js +2 -2
  22. package/dist-tsc/json-loaders/ObsSegmentationsJson.d.ts +21 -0
  23. package/dist-tsc/json-loaders/ObsSegmentationsJson.d.ts.map +1 -0
  24. package/{dist → dist-tsc}/json-loaders/ObsSegmentationsJson.js +2 -6
  25. package/dist-tsc/json-loaders/ObsSetsJson.d.ts +5 -0
  26. package/dist-tsc/json-loaders/ObsSetsJson.d.ts.map +1 -0
  27. package/{dist → dist-tsc}/json-loaders/ObsSetsJson.js +4 -3
  28. package/dist-tsc/json-loaders/ObsSetsJson.test-old.d.ts +1 -0
  29. package/dist-tsc/json-loaders/ObsSetsJson.test-old.d.ts.map +1 -0
  30. package/dist-tsc/json-loaders/index.d.ts +4 -0
  31. package/dist-tsc/json-loaders/index.d.ts.map +1 -0
  32. package/dist-tsc/json-loaders/index.js +3 -0
  33. package/dist-tsc/legacy-loaders/CellsJsonAsObsEmbedding.d.ts +38 -0
  34. package/dist-tsc/legacy-loaders/CellsJsonAsObsEmbedding.d.ts.map +1 -0
  35. package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsEmbedding.js +2 -2
  36. package/dist-tsc/legacy-loaders/CellsJsonAsObsLabels.d.ts +32 -0
  37. package/dist-tsc/legacy-loaders/CellsJsonAsObsLabels.d.ts.map +1 -0
  38. package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsLabels.js +2 -2
  39. package/dist-tsc/legacy-loaders/CellsJsonAsObsLocations.d.ts +38 -0
  40. package/dist-tsc/legacy-loaders/CellsJsonAsObsLocations.d.ts.map +1 -0
  41. package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsLocations.js +2 -2
  42. package/dist-tsc/legacy-loaders/CellsJsonAsObsSegmentations.d.ts +38 -0
  43. package/dist-tsc/legacy-loaders/CellsJsonAsObsSegmentations.d.ts.map +1 -0
  44. package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsSegmentations.js +2 -2
  45. package/dist-tsc/legacy-loaders/CellsJsonLoaders.test.d.ts +2 -0
  46. package/dist-tsc/legacy-loaders/CellsJsonLoaders.test.d.ts.map +1 -0
  47. package/{dist → dist-tsc}/legacy-loaders/CellsJsonLoaders.test.js +4 -4
  48. package/dist-tsc/legacy-loaders/ClustersJsonAsObsFeatureMatrix.d.ts +32 -0
  49. package/dist-tsc/legacy-loaders/ClustersJsonAsObsFeatureMatrix.d.ts.map +1 -0
  50. package/{dist → dist-tsc}/legacy-loaders/ClustersJsonAsObsFeatureMatrix.js +3 -3
  51. package/dist-tsc/legacy-loaders/ClustersJsonLoaders.test.d.ts +2 -0
  52. package/dist-tsc/legacy-loaders/ClustersJsonLoaders.test.d.ts.map +1 -0
  53. package/{dist → dist-tsc}/legacy-loaders/ClustersJsonLoaders.test.js +2 -2
  54. package/dist-tsc/legacy-loaders/GenesJsonAsObsFeatureMatrix.d.ts +29 -0
  55. package/dist-tsc/legacy-loaders/GenesJsonAsObsFeatureMatrix.d.ts.map +1 -0
  56. package/{dist → dist-tsc}/legacy-loaders/GenesJsonAsObsFeatureMatrix.js +2 -2
  57. package/dist-tsc/legacy-loaders/GenesJsonLoaders.test.d.ts +2 -0
  58. package/dist-tsc/legacy-loaders/GenesJsonLoaders.test.d.ts.map +1 -0
  59. package/{dist → dist-tsc}/legacy-loaders/GenesJsonLoaders.test.js +2 -2
  60. package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLabels.d.ts +14 -0
  61. package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLabels.d.ts.map +1 -0
  62. package/{dist → dist-tsc}/legacy-loaders/MoleculesJsonAsObsLabels.js +3 -4
  63. package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLocations.d.ts +20 -0
  64. package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLocations.d.ts.map +1 -0
  65. package/{dist → dist-tsc}/legacy-loaders/MoleculesJsonAsObsLocations.js +3 -4
  66. package/dist-tsc/legacy-loaders/MoleculesJsonLoaders.test.d.ts +2 -0
  67. package/dist-tsc/legacy-loaders/MoleculesJsonLoaders.test.d.ts.map +1 -0
  68. package/{dist → dist-tsc}/legacy-loaders/MoleculesJsonLoaders.test.js +3 -3
  69. package/dist-tsc/legacy-loaders/index.d.ts +9 -0
  70. package/dist-tsc/legacy-loaders/index.d.ts.map +1 -0
  71. package/{dist → dist-tsc}/legacy-loaders/index.js +8 -8
  72. package/dist-tsc/legacy-loaders/schemas/cells.d.ts +21 -0
  73. package/dist-tsc/legacy-loaders/schemas/cells.d.ts.map +1 -0
  74. package/dist-tsc/legacy-loaders/schemas/cells.js +9 -0
  75. package/dist-tsc/legacy-loaders/schemas/clusters.d.ts +15 -0
  76. package/dist-tsc/legacy-loaders/schemas/clusters.d.ts.map +1 -0
  77. package/dist-tsc/legacy-loaders/schemas/clusters.js +6 -0
  78. package/dist-tsc/legacy-loaders/schemas/fixtures/cells.bad.message.json +11 -0
  79. package/dist-tsc/legacy-loaders/schemas/fixtures/clusters.bad.json +9 -0
  80. package/dist-tsc/legacy-loaders/schemas/fixtures/clusters.bad.message.json +13 -0
  81. package/dist-tsc/legacy-loaders/schemas/fixtures/genes.bad.json +6 -0
  82. package/dist-tsc/legacy-loaders/schemas/fixtures/genes.bad.message.json +13 -0
  83. package/dist-tsc/legacy-loaders/schemas/fixtures/molecules.bad.json +7 -0
  84. package/dist-tsc/legacy-loaders/schemas/fixtures/molecules.bad.message.json +11 -0
  85. package/dist-tsc/legacy-loaders/schemas/fixtures/neighborhoods.bad.json +4 -0
  86. package/dist-tsc/legacy-loaders/schemas/fixtures/neighborhoods.bad.message.json +11 -0
  87. package/dist-tsc/legacy-loaders/schemas/fixtures/neighborhoods.good.json +4 -0
  88. package/dist-tsc/legacy-loaders/schemas/genes.d.ts +12 -0
  89. package/dist-tsc/legacy-loaders/schemas/genes.d.ts.map +1 -0
  90. package/dist-tsc/legacy-loaders/schemas/genes.js +5 -0
  91. package/dist-tsc/legacy-loaders/schemas/molecules.d.ts +3 -0
  92. package/dist-tsc/legacy-loaders/schemas/molecules.d.ts.map +1 -0
  93. package/dist-tsc/legacy-loaders/schemas/molecules.js +4 -0
  94. package/dist-tsc/legacy-loaders/schemas/neighborhoods.d.ts +9 -0
  95. package/dist-tsc/legacy-loaders/schemas/neighborhoods.d.ts.map +1 -0
  96. package/dist-tsc/legacy-loaders/schemas/neighborhoods.js +6 -0
  97. package/dist-tsc/raster-json-loaders/RasterJsonAsImageLoader.d.ts +4 -0
  98. package/dist-tsc/raster-json-loaders/RasterJsonAsImageLoader.d.ts.map +1 -0
  99. package/{dist → dist-tsc}/raster-json-loaders/RasterJsonAsImageLoader.js +1 -1
  100. package/dist-tsc/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.d.ts +4 -0
  101. package/dist-tsc/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.d.ts.map +1 -0
  102. package/{dist → dist-tsc}/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.js +1 -1
  103. package/dist-tsc/raster-json-loaders/RasterJsonLoader.d.ts +6 -0
  104. package/dist-tsc/raster-json-loaders/RasterJsonLoader.d.ts.map +1 -0
  105. package/{dist → dist-tsc}/raster-json-loaders/RasterJsonLoader.js +3 -2
  106. package/dist-tsc/raster-json-loaders/index.d.ts +3 -0
  107. package/dist-tsc/raster-json-loaders/index.d.ts.map +1 -0
  108. package/{dist → dist-tsc}/raster-json-loaders/index.js +2 -2
  109. package/package.json +22 -15
  110. package/src/JsonSource.js +21 -0
  111. package/src/index.js +5 -0
  112. package/src/json-loaders/JsonLoader.js +64 -0
  113. package/src/json-loaders/JsonLoader.test.js +28 -0
  114. package/src/json-loaders/ObsSegmentationsJson.js +31 -0
  115. package/src/json-loaders/ObsSetsJson.js +54 -0
  116. package/{dist/json-loaders/ObsSetsJson.test.js → src/json-loaders/ObsSetsJson.test-old.js} +5 -2
  117. package/src/json-loaders/index.js +3 -0
  118. package/src/legacy-loaders/CellsJsonAsObsEmbedding.js +53 -0
  119. package/src/legacy-loaders/CellsJsonAsObsLabels.js +32 -0
  120. package/src/legacy-loaders/CellsJsonAsObsLocations.js +45 -0
  121. package/src/legacy-loaders/CellsJsonAsObsSegmentations.js +57 -0
  122. package/src/legacy-loaders/CellsJsonLoaders.test.js +68 -0
  123. package/src/legacy-loaders/ClustersJsonAsObsFeatureMatrix.js +55 -0
  124. package/src/legacy-loaders/ClustersJsonLoaders.test.js +33 -0
  125. package/src/legacy-loaders/GenesJsonAsObsFeatureMatrix.js +44 -0
  126. package/src/legacy-loaders/GenesJsonLoaders.test.js +33 -0
  127. package/src/legacy-loaders/MoleculesJsonAsObsLabels.js +38 -0
  128. package/src/legacy-loaders/MoleculesJsonAsObsLocations.js +49 -0
  129. package/src/legacy-loaders/MoleculesJsonLoaders.test.js +46 -0
  130. package/src/legacy-loaders/index.js +8 -0
  131. package/src/legacy-loaders/schemas/cells.js +13 -0
  132. package/src/legacy-loaders/schemas/clusters.js +7 -0
  133. package/src/legacy-loaders/schemas/fixtures/cells.bad.json +8 -0
  134. package/src/legacy-loaders/schemas/fixtures/cells.bad.message.json +11 -0
  135. package/src/legacy-loaders/schemas/fixtures/cells.good.json +29 -0
  136. package/src/legacy-loaders/schemas/fixtures/clusters.bad.json +9 -0
  137. package/src/legacy-loaders/schemas/fixtures/clusters.bad.message.json +13 -0
  138. package/src/legacy-loaders/schemas/fixtures/clusters.good.json +9 -0
  139. package/src/legacy-loaders/schemas/fixtures/genes.bad.json +6 -0
  140. package/src/legacy-loaders/schemas/fixtures/genes.bad.message.json +13 -0
  141. package/src/legacy-loaders/schemas/fixtures/genes.good.json +4 -0
  142. package/src/legacy-loaders/schemas/fixtures/molecules.bad.json +7 -0
  143. package/src/legacy-loaders/schemas/fixtures/molecules.bad.message.json +11 -0
  144. package/src/legacy-loaders/schemas/fixtures/molecules.good.json +7 -0
  145. package/src/legacy-loaders/schemas/fixtures/neighborhoods.bad.json +4 -0
  146. package/src/legacy-loaders/schemas/fixtures/neighborhoods.bad.message.json +11 -0
  147. package/src/legacy-loaders/schemas/fixtures/neighborhoods.good.json +4 -0
  148. package/src/legacy-loaders/schemas/genes.js +6 -0
  149. package/src/legacy-loaders/schemas/molecules.js +8 -0
  150. package/src/legacy-loaders/schemas/neighborhoods.js +10 -0
  151. package/src/raster-json-loaders/RasterJsonAsImageLoader.js +45 -0
  152. package/src/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.js +46 -0
  153. package/src/raster-json-loaders/RasterJsonLoader.js +128 -0
  154. package/src/raster-json-loaders/index.js +2 -0
  155. package/dist/json-loaders/index.js +0 -3
  156. package/dist/legacy-loaders/schemas/cells.schema.json +0 -52
  157. package/dist/legacy-loaders/schemas/clusters.schema.json +0 -30
  158. package/dist/legacy-loaders/schemas/genes.schema.json +0 -27
  159. package/dist/legacy-loaders/schemas/molecules.schema.json +0 -20
  160. package/dist/legacy-loaders/schemas/neighborhoods.schema.json +0 -28
  161. package/dist/legacy-loaders/schemas/schema.test.js +0 -48
  162. /package/{dist → dist-tsc}/JsonSource.js +0 -0
  163. /package/{dist → dist-tsc}/json-loaders/ObsSetsJson.test-old.js +0 -0
  164. /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/cells.bad.json +0 -0
  165. /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/cells.good.json +0 -0
  166. /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/clusters.good.json +0 -0
  167. /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/genes.good.json +0 -0
  168. /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/molecules.good.json +0 -0
@@ -0,0 +1,8 @@
1
+ {
2
+ "778": {
3
+ "tsne": [
4
+ -58.13238525390625,
5
+ "not a number"
6
+ ]
7
+ }
8
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "dataPath": "['778']",
4
+ "keyword": "additionalProperties",
5
+ "message": "should NOT have additional properties",
6
+ "params": {
7
+ "additionalProperty": "tsne"
8
+ },
9
+ "schemaPath": "#/patternProperties/./additionalProperties"
10
+ }
11
+ ]
@@ -0,0 +1,29 @@
1
+ {
2
+ "778": {
3
+ "mappings": {
4
+ "t-SNE": [
5
+ -58.13238525390625,
6
+ 5.219181060791016
7
+ ],
8
+ "PCA": [
9
+ 1, 2
10
+ ]
11
+ },
12
+ "factors": {
13
+ "cluster": "Inhibitory CP"
14
+ },
15
+ "genes": {
16
+ "Gad2": 35,
17
+ "Slc32a1": 41
18
+ },
19
+ "xy": [
20
+ 18171.230942376023,
21
+ 24590.795274569497
22
+ ],
23
+ "poly": [
24
+ [1,2],
25
+ [3,4],
26
+ [5,6]
27
+ ]
28
+ }
29
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "rows": ["Lamp5", "Sox10", "Crhbp"],
3
+ "cols": ["3572", "1904", "1670"],
4
+ "matrix": [
5
+ [123, 456, 789],
6
+ [12, 45, 78],
7
+ ["x", 4, 7]
8
+ ]
9
+ }
@@ -0,0 +1,13 @@
1
+ [
2
+ {
3
+ "dataPath": ".matrix[0][0]",
4
+ "keyword": "maximum",
5
+ "message": "should be <= 1",
6
+ "params": {
7
+ "comparison": "<=",
8
+ "exclusive": false,
9
+ "limit": 1
10
+ },
11
+ "schemaPath": "#/definitions/matrix/items/items/maximum"
12
+ }
13
+ ]
@@ -0,0 +1,9 @@
1
+ {
2
+ "rows": ["Lamp5", "Sox10", "Crhbp"],
3
+ "cols": ["3572", "1904", "1670"],
4
+ "matrix": [
5
+ [0.123, 0.456, 0.789],
6
+ [0.12, 0.45, 0.78],
7
+ [0.1, 0.4, 0.7]
8
+ ]
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "gene-id": {
3
+ "cells": {"cell-id": -999},
4
+ "max": 1
5
+ }
6
+ }
@@ -0,0 +1,13 @@
1
+ [
2
+ {
3
+ "dataPath": "['gene-id'].cells['cell-id']",
4
+ "keyword": "minimum",
5
+ "message": "should be >= 0",
6
+ "params": {
7
+ "comparison": ">=",
8
+ "exclusive": false,
9
+ "limit": 0
10
+ },
11
+ "schemaPath": "#/definitions/positiveFloatValues/patternProperties/./minimum"
12
+ }
13
+ ]
@@ -0,0 +1,4 @@
1
+ {
2
+ "Gad2": {"max": 95, "cells": {"778": 35, "1409": 16, "3642": 95}},
3
+ "Slc32a1": {"max": 49, "cells": {"778": 41, "1409": 26, "3642": 49}}
4
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "Klk6_Hybridization5":[
3
+ [27008.0, 949.0],
4
+ [8315.0, 22747.0],
5
+ [1, 2, 3, 4, 5]
6
+ ]
7
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "dataPath": "['Klk6_Hybridization5'][2]",
4
+ "keyword": "maxItems",
5
+ "message": "should NOT have more than 2 items",
6
+ "params": {
7
+ "limit": 2
8
+ },
9
+ "schemaPath": "#/definitions/coord/maxItems"
10
+ }
11
+ ]
@@ -0,0 +1,7 @@
1
+ {
2
+ "Klk6_Hybridization5":[
3
+ [27008.0, 949.0],
4
+ [8315.0, 22747.0],
5
+ [18683.0, 19476.0]
6
+ ]
7
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "4031::4028::4008": {"poly": [[-43.9, 394.39], [-45.25, 409.18]]},
3
+ "4031::4008::4014": {"poly": [[-43.9, 394.39], [-2.07, 390.45]]}
4
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "dataPath": "['4031::4028::4008'].poly",
4
+ "keyword": "minItems",
5
+ "message": "should NOT have fewer than 3 items",
6
+ "params": {
7
+ "limit": 3
8
+ },
9
+ "schemaPath": "#/patternProperties/./properties/poly/minItems"
10
+ }
11
+ ]
@@ -0,0 +1,4 @@
1
+ {
2
+ "4031::4028::4008": {"poly": [[-43.9, 394.39], [-45.25, 409.18], [-2.07, 390.45]]},
3
+ "4031::4008::4014": {"poly": [[-43.9, 394.39], [-2.07, 390.45], [-17.6, 376.96]]}
4
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+
3
+ export const genesSchema = z.record(z.object({
4
+ max: z.number(),
5
+ cells: z.record(z.number()),
6
+ }));
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+
3
+ export const moleculesSchema = z.record(
4
+ z.array(
5
+ // XY coordinate
6
+ z.array(z.number()).length(2),
7
+ ),
8
+ );
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+
3
+ export const neighborhoodsSchema = z.record(
4
+ z.object({
5
+ poly: z.array(
6
+ // Coordinate
7
+ z.array(z.number()).length(2),
8
+ ),
9
+ }).strict(),
10
+ );
@@ -0,0 +1,45 @@
1
+ import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
2
+ import RasterLoader from './RasterJsonLoader.js';
3
+
4
+ export default class RasterJsonAsImageLoader extends RasterLoader {
5
+ async load() {
6
+ const loaderResult = await super.load().catch(reason => Promise.resolve(reason));
7
+ if (loaderResult instanceof AbstractLoaderError) {
8
+ return Promise.reject(loaderResult);
9
+ }
10
+ const { data = {}, url: urls, coordinationValues } = loaderResult;
11
+ const { loaders: allLoaders = [], meta: allMeta = [] } = data;
12
+
13
+ const loaders = [];
14
+ const meta = [];
15
+
16
+ // Only include non-bitmask items.
17
+ allMeta.forEach((layer, i) => {
18
+ if (!layer?.metadata?.isBitmask) {
19
+ loaders.push(allLoaders[i]);
20
+ meta.push(allMeta[i]);
21
+ }
22
+ });
23
+
24
+ if (!coordinationValues?.spatialImageLayer) {
25
+ console.warn('Could not initialize coordinationValues.spatialImageLayer in RasterJsonAsImageLoader. This may be an indicator that the image could not be loaded.');
26
+ }
27
+
28
+ return new LoaderResult(
29
+ {
30
+ image: (loaders.length > 0 && meta.length > 0 ? { loaders, meta } : null),
31
+ },
32
+ urls,
33
+ {
34
+ // Filter coordinationValues, keeping only non-bitmask layers.
35
+ spatialImageLayer: coordinationValues?.spatialImageLayer?.filter(l => l.type !== 'bitmask')
36
+ // Re-index since we removed the bitmask layers,
37
+ // so the indices may have gaps.
38
+ .map(layer => ({
39
+ ...layer,
40
+ index: meta.findIndex(metaItem => metaItem.name === allMeta[layer.index].name),
41
+ })),
42
+ },
43
+ );
44
+ }
45
+ }
@@ -0,0 +1,46 @@
1
+ import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
2
+ import RasterLoader from './RasterJsonLoader.js';
3
+
4
+ export default class RasterJsonAsObsSegmentationsLoader extends RasterLoader {
5
+ async load() {
6
+ const loaderResult = await super.load().catch(reason => Promise.resolve(reason));
7
+ if (loaderResult instanceof AbstractLoaderError) {
8
+ return Promise.reject(loaderResult);
9
+ }
10
+ const { data = {}, url: urls, coordinationValues } = loaderResult;
11
+ const { loaders: allLoaders = [], meta: allMeta = [] } = data;
12
+
13
+ const loaders = [];
14
+ const meta = [];
15
+
16
+ // Only include bitmask items.
17
+ allMeta.forEach((layer, i) => {
18
+ if (layer?.metadata?.isBitmask) {
19
+ loaders.push(allLoaders[i]);
20
+ meta.push(allMeta[i]);
21
+ }
22
+ });
23
+
24
+ if (!coordinationValues?.spatialImageLayer) {
25
+ console.warn('Could not initialize coordinationValues.spatialImageLayer in RasterJsonAsObsSegmentationsLoader. This may be an indicator that the image could not be loaded.');
26
+ }
27
+
28
+ return new LoaderResult(
29
+ {
30
+ obsSegmentationsType: 'bitmask',
31
+ obsSegmentations: (loaders.length > 0 && meta.length > 0 ? { loaders, meta } : null),
32
+ },
33
+ urls,
34
+ {
35
+ // Filter coordinationValues, keeping only bitmask layers.
36
+ spatialSegmentationLayer: coordinationValues?.spatialImageLayer?.filter(l => l.type === 'bitmask')
37
+ // Re-index since we removed the bitmask layers,
38
+ // so the indices may have gaps.
39
+ .map(layer => ({
40
+ ...layer,
41
+ index: meta.findIndex(metaItem => metaItem.name === allMeta[layer.index].name),
42
+ })),
43
+ },
44
+ );
45
+ }
46
+ }
@@ -0,0 +1,128 @@
1
+ import { viv } from '@vitessce/gl';
2
+ import { initializeRasterLayersAndChannels } from '@vitessce/spatial-utils';
3
+ import { openArray } from 'zarr';
4
+ import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
5
+ import { rasterJsonSchema as rasterSchema } from '@vitessce/schemas';
6
+ import JsonLoader from '../json-loaders/JsonLoader.js';
7
+
8
+ async function initLoader(imageData) {
9
+ const {
10
+ type, url, metadata, requestInit,
11
+ } = imageData;
12
+ switch (type) {
13
+ case ('zarr'): {
14
+ const {
15
+ dimensions, isPyramid, transform,
16
+ } = metadata || {};
17
+ const labels = dimensions.map(d => d.field);
18
+ let source;
19
+ if (isPyramid) {
20
+ const metadataUrl = `${url}${
21
+ url.slice(-1) === '/' ? '' : '/'
22
+ }.zmetadata`;
23
+ const response = await fetch(metadataUrl);
24
+ const { metadata: zarrMetadata } = await response.json();
25
+ const paths = Object.keys(zarrMetadata)
26
+ .filter(metaKey => metaKey.includes('.zarray'))
27
+ .map(arrMetaKeys => arrMetaKeys.slice(0, -7));
28
+ const data = await Promise.all(
29
+ paths.map(path => openArray({ store: url, path })),
30
+ );
31
+ const [yChunk, xChunk] = data[0].chunks.slice(-2);
32
+ const size = Math.min(yChunk, xChunk);
33
+ // deck.gl requirement for power-of-two tile size.
34
+ const tileSize = 2 ** Math.floor(Math.log2(size));
35
+ source = data.map(d => new viv.ZarrPixelSource(d, labels, tileSize));
36
+ } else {
37
+ const data = await openArray({ store: url });
38
+ source = new viv.ZarrPixelSource(data, labels);
39
+ }
40
+ return { data: source, metadata: { dimensions, transform }, channels: (dimensions.find(d => d.field === 'channel') || dimensions[0]).values };
41
+ }
42
+ case ('ome-tiff'): {
43
+ let loader;
44
+ // Fetch offsets for ome-tiff if needed.
45
+ if (metadata && 'omeTiffOffsetsUrl' in metadata) {
46
+ const { omeTiffOffsetsUrl } = metadata;
47
+ const res = await fetch(omeTiffOffsetsUrl, (requestInit || {}));
48
+ if (res.ok) {
49
+ const offsets = await res.json();
50
+ loader = await viv.loadOmeTiff(
51
+ url,
52
+ {
53
+ offsets,
54
+ headers: requestInit?.headers,
55
+ },
56
+ );
57
+ } else {
58
+ throw new Error(`Offsets not found but provided: ${res.status} from ${res.url}`);
59
+ }
60
+ } else {
61
+ loader = await viv.loadOmeTiff(url, { headers: requestInit?.headers });
62
+ }
63
+ const { Pixels: { Channels } } = loader.metadata;
64
+ const channels = Array.isArray(Channels)
65
+ ? Channels.map((channel, i) => channel.Name || `Channel ${i}`)
66
+ : [Channels.Name || `Channel ${0}`];
67
+ return { ...loader, channels };
68
+ }
69
+ default: {
70
+ throw Error(`Image type (${type}) is not supported`);
71
+ }
72
+ }
73
+ }
74
+
75
+ export default class RasterLoader extends JsonLoader {
76
+ constructor(dataSource, params) {
77
+ const { url, options } = params;
78
+ if (!url && options) {
79
+ // eslint-disable-next-line no-param-reassign
80
+ dataSource.url = URL.createObjectURL(new Blob([JSON.stringify(options)]));
81
+ }
82
+ super(dataSource, params);
83
+ this.schema = rasterSchema;
84
+ }
85
+
86
+ async load() {
87
+ const payload = await super.load().catch(reason => Promise.resolve(reason));
88
+ if (payload instanceof AbstractLoaderError) {
89
+ return Promise.reject(payload);
90
+ }
91
+ const { data: raster } = payload;
92
+ const { images, renderLayers, usePhysicalSizeScaling = false } = raster;
93
+
94
+ // Get image name and URL tuples.
95
+ const urls = images
96
+ .filter(image => !image.url.includes('zarr'))
97
+ .map(image => ([image.url, image.name]));
98
+
99
+ // Add a loaderCreator function for each image layer.
100
+ const imagesWithLoaderCreators = images.map(image => ({
101
+ ...image,
102
+ loaderCreator: async () => initLoader(image),
103
+ }));
104
+
105
+ // TODO: use options for initial selection of channels
106
+ // which omit domain/slider ranges.
107
+ if (!this.autoImageCache) {
108
+ this.autoImageCache = initializeRasterLayersAndChannels(
109
+ imagesWithLoaderCreators,
110
+ renderLayers,
111
+ usePhysicalSizeScaling,
112
+ );
113
+ }
114
+
115
+ return this.autoImageCache.then((autoImages) => {
116
+ const [autoImageLayers, imageLayerLoaders, imageLayerMeta] = autoImages;
117
+
118
+ const coordinationValues = {
119
+ spatialImageLayer: autoImageLayers,
120
+ };
121
+ return new LoaderResult(
122
+ { loaders: imageLayerLoaders, meta: imageLayerMeta },
123
+ urls,
124
+ coordinationValues,
125
+ );
126
+ });
127
+ }
128
+ }
@@ -0,0 +1,2 @@
1
+ export { default as RasterJsonAsImageLoader } from './RasterJsonAsImageLoader.js';
2
+ export { default as RasterJsonAsObsSegmentationsLoader } from './RasterJsonAsObsSegmentationsLoader.js';
@@ -1,3 +0,0 @@
1
- export { default as JsonLoader } from './JsonLoader';
2
- export { default as ObsSegmentationsJsonLoader } from './ObsSegmentationsJson';
3
- export { default as ObsSetsJsonLoader } from './ObsSetsJson';
@@ -1,52 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://github.com/vitessce/vitessce/#cells",
4
- "title": "Vitessce cell data",
5
- "type": "object",
6
- "definitions": {
7
- "coord": {
8
- "type": "array",
9
- "minItems": 2,
10
- "maxItems": 2,
11
- "items": { "type": "number" }
12
- },
13
- "positiveFloatValues": {
14
- "type": "object",
15
- "patternProperties": {
16
- ".": {
17
- "type": "number",
18
- "minimum": 0
19
- }
20
- }
21
- },
22
- "stringValues": {
23
- "type": "object",
24
- "patternProperties": {
25
- ".": {
26
- "type": "string"
27
- }
28
- }
29
- }
30
- },
31
- "patternProperties": {
32
- ".": {
33
- "additionalProperties": false,
34
- "required": [],
35
- "properties": {
36
- "mappings": {
37
- "type": "object",
38
- "patternProperties": {
39
- ".": { "$ref": "#/definitions/coord" }
40
- }
41
- },
42
- "xy": { "$ref": "#/definitions/coord" },
43
- "genes": { "$ref": "#/definitions/positiveFloatValues" },
44
- "factors": { "$ref": "#/definitions/stringValues" },
45
- "poly": {
46
- "type": "array",
47
- "items": { "$ref": "#/definitions/coord" }
48
- }
49
- }
50
- }
51
- }
52
- }
@@ -1,30 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://github.com/vitessce/vitessce/#clusters",
4
- "title": "Vitessce cluster data",
5
- "type": "object",
6
- "definitions": {
7
- "stringArray": {
8
- "type": "array",
9
- "items": { "type": "string" }
10
- },
11
- "matrix": {
12
- "type": "array",
13
- "items": {
14
- "type": "array",
15
- "items": {
16
- "type": "number",
17
- "minimum": 0,
18
- "maximum": 1
19
- }
20
- }
21
- }
22
- },
23
- "additionalProperties": false,
24
- "required": ["rows", "cols", "matrix"],
25
- "properties": {
26
- "rows": { "$ref": "#/definitions/stringArray" },
27
- "cols": { "$ref": "#/definitions/stringArray" },
28
- "matrix": { "$ref": "#/definitions/matrix" }
29
- }
30
- }
@@ -1,27 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://github.com/vitessce/vitessce/#genes",
4
- "title": "Vitessce gene data",
5
- "type": "object",
6
- "definitions": {
7
- "positiveFloatValues": {
8
- "type": "object",
9
- "patternProperties": {
10
- ".": {
11
- "type": "number",
12
- "minimum": 0
13
- }
14
- }
15
- }
16
- },
17
- "patternProperties": {
18
- ".": {
19
- "additionalProperties": false,
20
- "required": ["max", "cells"],
21
- "properties": {
22
- "max": { "type": "number" },
23
- "cells": { "$ref": "#/definitions/positiveFloatValues" }
24
- }
25
- }
26
- }
27
- }
@@ -1,20 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://github.com/vitessce/vitessce/#molecules",
4
- "title": "Vitessce molecule data",
5
- "type": "object",
6
- "definitions": {
7
- "coord": {
8
- "type": "array",
9
- "maxItems": 2,
10
- "minItems": 2,
11
- "items": { "type": "number" }
12
- }
13
- },
14
- "patternProperties": {
15
- ".": {
16
- "type": "array",
17
- "items": { "$ref": "#/definitions/coord" }
18
- }
19
- }
20
- }
@@ -1,28 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://github.com/vitessce/vitessce/#neighborhoods",
4
- "title": "Vitessce neighborhood data",
5
- "type": "object",
6
- "definitions": {
7
- "coord": {
8
- "type": "array",
9
- "maxItems": 2,
10
- "minItems": 2,
11
- "items": { "type": "number" }
12
- }
13
- },
14
- "patternProperties": {
15
- ".": {
16
- "additionalProperties": false,
17
- "required": ["poly"],
18
- "properties": {
19
- "poly": {
20
- "type": "array",
21
- "maxItems": 3,
22
- "minItems": 3,
23
- "items": { "$ref": "#/definitions/coord" }
24
- }
25
- }
26
- }
27
- }
28
- }
@@ -1,48 +0,0 @@
1
- import Ajv from 'ajv';
2
- import { obsSetsSchema, rasterSchema } from '@vitessce/vit-s';
3
- /* eslint-disable import/no-dynamic-require */
4
- /* eslint-disable global-require */
5
- describe('schemas', () => {
6
- [
7
- 'cells',
8
- 'clusters',
9
- 'genes',
10
- 'molecules',
11
- 'neighborhoods',
12
- ].forEach((type) => {
13
- const schemaFile = `${type}.schema.json`;
14
- describe(schemaFile, () => {
15
- const schema = require(`./${schemaFile}`);
16
- let validate;
17
- if (type === 'config-1.0.1') {
18
- const obsSets = obsSetsSchema;
19
- const raster = rasterSchema;
20
- validate = new Ajv()
21
- .addSchema(obsSets)
22
- .addSchema(raster)
23
- .compile(schema);
24
- }
25
- else {
26
- validate = new Ajv().compile(schema);
27
- }
28
- const [goodFixture, badFixture, badMessage] = [
29
- 'good', 'bad', 'bad.message',
30
- ].map(stem => `${type}.${stem}.json`);
31
- it(`passes ${goodFixture}`, () => {
32
- const data = require(`./fixtures/${goodFixture}`);
33
- const valid = validate(data);
34
- if (!valid) {
35
- console.warn(validate.errors);
36
- }
37
- expect(valid).toEqual(true);
38
- });
39
- it(`fails ${badFixture}`, () => {
40
- const data = require(`./fixtures/${badFixture}`);
41
- const message = require(`./fixtures/${badMessage}`);
42
- const valid = validate(data);
43
- expect(valid).toEqual(false);
44
- expect(validate.errors).toEqual(message);
45
- });
46
- });
47
- });
48
- });
File without changes