@vitessce/zarr 3.5.2 → 3.5.4

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 (112) hide show
  1. package/dist/index.js +20564 -27
  2. package/dist-tsc/AnnDataSource.d.ts +1 -1
  3. package/dist-tsc/AnnDataSource.d.ts.map +1 -1
  4. package/dist-tsc/AnnDataSource.js +8 -2
  5. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.d.ts +2 -2
  6. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.d.ts.map +1 -1
  7. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.js +1 -1
  8. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.d.ts +2 -2
  9. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.d.ts.map +1 -1
  10. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.js +1 -1
  11. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.test.js +1 -1
  12. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.d.ts +2 -2
  13. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.d.ts.map +1 -1
  14. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.js +1 -1
  15. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts +2 -2
  16. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts.map +1 -1
  17. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.js +1 -1
  18. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.d.ts +2 -2
  19. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.d.ts.map +1 -1
  20. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.js +1 -1
  21. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.d.ts +2 -2
  22. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.d.ts.map +1 -1
  23. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.js +1 -1
  24. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts +2 -2
  25. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts.map +1 -1
  26. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.js +1 -1
  27. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts +2 -2
  28. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts.map +1 -1
  29. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.js +2 -2
  30. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.d.ts +2 -2
  31. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.d.ts.map +1 -1
  32. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.js +1 -1
  33. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts +2 -2
  34. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts.map +1 -1
  35. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.js +1 -1
  36. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.d.ts +2 -2
  37. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.d.ts.map +1 -1
  38. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.js +1 -1
  39. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts +1 -1
  40. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts.map +1 -1
  41. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.js +1 -1
  42. package/dist-tsc/index.d.ts +1 -4
  43. package/dist-tsc/index.js +1 -4
  44. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts +2 -2
  45. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts.map +1 -1
  46. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.js +1 -1
  47. package/package.json +9 -11
  48. package/src/AnnDataSource.js +7 -2
  49. package/src/anndata-loaders/FeatureLabelsAnndataLoader.js +1 -1
  50. package/src/anndata-loaders/ObsEmbeddingAnndataLoader.js +1 -1
  51. package/src/anndata-loaders/ObsEmbeddingAnndataLoader.test.js +1 -1
  52. package/src/anndata-loaders/ObsFeatureColumnsAnndataLoader.js +1 -1
  53. package/src/anndata-loaders/ObsFeatureMatrixAnndataLoader.js +1 -1
  54. package/src/anndata-loaders/ObsLabelsAnndataLoader.js +1 -1
  55. package/src/anndata-loaders/ObsLocationsAnndataLoader.js +1 -1
  56. package/src/anndata-loaders/ObsPointsAnndataLoader.js +1 -1
  57. package/src/anndata-loaders/ObsSegmentationsAnndataLoader.js +2 -2
  58. package/src/anndata-loaders/ObsSetsAnndataLoader.js +1 -1
  59. package/src/anndata-loaders/ObsSpotsAnndataLoader.js +1 -1
  60. package/src/anndata-loaders/SampleEdgesAnndataLoader.js +1 -1
  61. package/src/genomic-loaders/GenomicProfilesZarrLoader.js +1 -1
  62. package/src/index.js +2 -4
  63. package/src/matrix-loaders/MatrixZarrAsObsFeatureMatrix.js +1 -1
  64. package/dist/deflate-d6c44024.js +0 -12
  65. package/dist/index-315714b8.js +0 -165788
  66. package/dist/jpeg-2118e67e.js +0 -839
  67. package/dist/lerc-48cfdf2b.js +0 -2013
  68. package/dist/lzw-10e7c9ff.js +0 -127
  69. package/dist/packbits-166dac1c.js +0 -29
  70. package/dist/pako.esm-68f84e2a.js +0 -4022
  71. package/dist/raw-155ab7ca.js +0 -11
  72. package/dist/webimage-f1ecb720.js +0 -31
  73. package/dist-tsc/SpatialDataShapesSource.d.ts +0 -75
  74. package/dist-tsc/SpatialDataShapesSource.d.ts.map +0 -1
  75. package/dist-tsc/SpatialDataShapesSource.js +0 -267
  76. package/dist-tsc/SpatialDataTableSource.d.ts +0 -43
  77. package/dist-tsc/SpatialDataTableSource.d.ts.map +0 -1
  78. package/dist-tsc/SpatialDataTableSource.js +0 -119
  79. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.d.ts +0 -13
  80. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.d.ts.map +0 -1
  81. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.js +0 -41
  82. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts +0 -16
  83. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts.map +0 -1
  84. package/dist-tsc/ome-loaders/OmeZarrLoader.js +0 -155
  85. package/dist-tsc/ome-loaders/index.d.ts +0 -3
  86. package/dist-tsc/ome-loaders/index.d.ts.map +0 -1
  87. package/dist-tsc/ome-loaders/index.js +0 -2
  88. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts +0 -4
  89. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts.map +0 -1
  90. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.js +0 -9
  91. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts +0 -4
  92. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts.map +0 -1
  93. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.js +0 -45
  94. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts +0 -9
  95. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts.map +0 -1
  96. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.js +0 -10
  97. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts +0 -24
  98. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts.map +0 -1
  99. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.js +0 -185
  100. package/dist-tsc/spatialdata-loaders/index.d.ts +0 -5
  101. package/dist-tsc/spatialdata-loaders/index.d.ts.map +0 -1
  102. package/dist-tsc/spatialdata-loaders/index.js +0 -4
  103. package/src/SpatialDataShapesSource.js +0 -292
  104. package/src/SpatialDataTableSource.js +0 -135
  105. package/src/ome-loaders/OmeZarrAsObsSegmentationsLoader.js +0 -49
  106. package/src/ome-loaders/OmeZarrLoader.js +0 -208
  107. package/src/ome-loaders/index.js +0 -2
  108. package/src/spatialdata-loaders/SpatialDataImageLoader.js +0 -11
  109. package/src/spatialdata-loaders/SpatialDataLabelsLoader.js +0 -53
  110. package/src/spatialdata-loaders/SpatialDataObsSetsLoader.js +0 -11
  111. package/src/spatialdata-loaders/SpatialDataObsSpotsLoader.js +0 -228
  112. package/src/spatialdata-loaders/index.js +0 -4
@@ -1,292 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable no-underscore-dangle */
3
- /* eslint-disable import/no-unresolved */
4
- /* eslint-disable no-undef */
5
- import { tableFromIPC } from 'apache-arrow';
6
- import WKB from 'ol/format/WKB.js';
7
- import AnnDataSource from './AnnDataSource.js';
8
- import { basename } from './utils.js';
9
-
10
- /** @import { DataSourceParams } from '@vitessce/types' */
11
- /** @import { TypedArray as ZarrTypedArray, Chunk } from '@zarrita/core' */
12
-
13
- async function getReadParquet() {
14
- // Reference: https://observablehq.com/@kylebarron/geoparquet-on-the-web
15
- // TODO: host somewhere we control, like cdn.vitessce.io?
16
- // @ts-ignore
17
- const module = await import(/* webpackIgnore: true */ 'https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm.js');
18
- await module.default();
19
- // We cannot use regulary dynamic import here because it breaks NextJS builds
20
- // due to pointing to a remote URL.
21
- // I could not figure out a NextJS webpack configuration to resolve it.
22
- // The following becomes inlined by Vite in library mode
23
- // eliminating the benefit of dynamic import.
24
- // Reference: https://github.com/vitejs/vite/issues/4454
25
- // const responsePromise = await fetch(
26
- // new URL('parquet-wasm/esm/parquet_wasm_bg.wasm', import.meta.url).href
27
- // );
28
- // const responsePromise = await fetch('https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm_bg.wasm');
29
- // const wasmBuffer = await responsePromise.arrayBuffer();
30
- // module.initSync(wasmBuffer);
31
- // Another issue is that when we import parquet-wasm JS from node_modules,
32
- // running module.default there is a MIME type issue because the Vite dev
33
- // server does not serve the .wasm with a MIME type of application/wasm.
34
- // I can't seem to get a custom Vite plugin that sets the MIME type in
35
- // request headers to work.
36
- return module.readParquet;
37
- }
38
-
39
- // If the array path starts with table/something/rest
40
- // capture table/something.
41
- const regex = /^shapes\/([^/]*)\/(.*)$/;
42
-
43
- /**
44
- *
45
- * @param {string|undefined} arrPath
46
- * @returns
47
- */
48
- function getShapesPrefix(arrPath) {
49
- if (arrPath) {
50
- const matches = arrPath.match(regex);
51
- if (matches && matches.length === 3) {
52
- return `shapes/${matches[1]}/`;
53
- }
54
- }
55
- return '';
56
- }
57
-
58
- /**
59
- *
60
- * @param {string|undefined} arrPath
61
- * @returns
62
- */
63
- export function getIndexPath(arrPath) {
64
- return `${getShapesPrefix(arrPath)}Index`;
65
- }
66
-
67
- /**
68
- *
69
- * @param {string|undefined} arrPath
70
- * @returns
71
- */
72
- export function getVarPath(arrPath) {
73
- return `${getShapesPrefix(arrPath)}var`;
74
- }
75
-
76
- /**
77
- *
78
- * @param {string|undefined} arrPath
79
- * @returns
80
- */
81
- export function getParquetPath(arrPath) {
82
- return `${getShapesPrefix(arrPath)}shapes.parquet`;
83
- }
84
-
85
- /**
86
- *
87
- * @param {string|undefined} arrPath
88
- * @returns
89
- */
90
- export function getAttrsPath(arrPath) {
91
- return `${getShapesPrefix(arrPath)}.zattrs`;
92
- }
93
-
94
-
95
- export default class SpatialDataShapesSource extends AnnDataSource {
96
- /**
97
- *
98
- * @param {DataSourceParams} params
99
- */
100
- constructor(params) {
101
- super(params);
102
- /** @type {{ [k: string]: Promise<string[]> }} */
103
- this.obsIndices = {};
104
- /** @type {{ [k: string]: Promise<string[]> }} */
105
- this.varIndices = {};
106
- /** @type {{ [k: string]: string[] }} */
107
- this.varAliases = {};
108
- }
109
-
110
- /**
111
- *
112
- * @param {string} tablePath
113
- * @returns
114
- */
115
- async loadSpatialDataAttrs(tablePath) {
116
- return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
117
- }
118
-
119
- /**
120
- *
121
- * @param {string} path A path to within shapes.
122
- * @returns {Promise<"0.1"|"0.2">} The format version.
123
- */
124
- async getFormatVersion(path) {
125
- const zattrs = await this.getJson(getAttrsPath(path));
126
- const formatVersion = zattrs.spatialdata_attrs.version;
127
- if (!(formatVersion === '0.1' || formatVersion === '0.2')) {
128
- throw new Error(
129
- `Unexpected version for shapes spatialdata_attrs: ${formatVersion}`,
130
- );
131
- }
132
- return formatVersion;
133
- }
134
-
135
- /**
136
- *
137
- * @param {string} path A path to an array within shapes.
138
- * @returns
139
- */
140
- async loadParquetTable(path) {
141
- if (this.parquetTable) {
142
- // Return cached table if present.
143
- return this.parquetTable;
144
- }
145
- const readParquet = await getReadParquet();
146
- const parquetPath = getParquetPath(path);
147
- const parquetBytes = await this.storeRoot.store.get(`/${parquetPath}`);
148
- if (!parquetBytes) {
149
- throw new Error('Failed to load parquet data from store.');
150
- }
151
- const wasmTable = readParquet(parquetBytes);
152
- // TODO: use streaming?
153
- const arrowTable = tableFromIPC(wasmTable.intoIPCStream());
154
- this.parquetTable = arrowTable;
155
- return this.parquetTable;
156
- }
157
-
158
- /**
159
- * Class method for loading the obs index.
160
- * @param {string|undefined} path
161
- * @param {string|undefined} tablePath
162
- * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
163
- */
164
- async loadObsIndex(path = undefined, tablePath = undefined) {
165
- let indexPath = getIndexPath(path);
166
- if (tablePath) {
167
- // TODO: given a path to the shapes,
168
- // is there a better way to know which table annotates it
169
- // (without the manually-specified table path)?
170
- // Reference: https://github.com/scverse/spatialdata/issues/298#issuecomment-1718161329
171
- const obsPath = `${tablePath}/obs`;
172
- const { _index } = await this.getJson(`${obsPath}/.zattrs`);
173
- indexPath = `${obsPath}/${_index}`;
174
- const {
175
- instance_key: instanceKey,
176
- // TODO: filter table index by region and element type.
177
- // region_key: regionKey,
178
- // region,
179
- } = await this.loadSpatialDataAttrs(tablePath);
180
-
181
- indexPath = `${obsPath}/${instanceKey}`;
182
- }
183
- if (indexPath in this.obsIndices) {
184
- return this.obsIndices[indexPath];
185
- }
186
- // TODO: support loading from parquet if no tablePath was provided.
187
- this.obsIndices[indexPath] = this._loadColumn(indexPath);
188
- return this.obsIndices[indexPath];
189
- }
190
-
191
- /**
192
- * Class method for loading general numeric arrays.
193
- * @param {string} path A string like obsm.X_pca.
194
- * @returns {Promise<Chunk<any>>} A promise for a zarr array containing the data.
195
- */
196
- async loadNumeric(path) {
197
- const formatVersion = await this.getFormatVersion(path);
198
- if (formatVersion === '0.1') {
199
- return super.loadNumeric(path);
200
- }
201
- const arrowTable = await this.loadParquetTable(path);
202
- const columnArr = arrowTable.getChild(basename(path))?.toArray();
203
- return {
204
- shape: [columnArr.length],
205
- // TODO: support other kinds of TypedArrays via @vitessce/arrow-utils.
206
- data: new Float32Array(columnArr),
207
- stride: [1],
208
- };
209
- }
210
-
211
- /**
212
- * Class method for loading specific columns of numeric arrays.
213
- * @param {string} path A string like obsm.X_pca.
214
- * @param {[number, number]} dims The column indices to load.
215
- * @returns {Promise<{
216
- * data: [ZarrTypedArray<any>, ZarrTypedArray<any>],
217
- * shape: [number, number],
218
- * }>} A promise for a zarr array containing the data.
219
- */
220
- async loadNumericForDims(path, dims) {
221
- const formatVersion = await this.getFormatVersion(path);
222
- if (formatVersion === '0.1') {
223
- return super.loadNumericForDims(path, dims);
224
- }
225
- let columnName = basename(path);
226
- if (columnName === 'coords') {
227
- // The "geometry" column was previously called "coords" in version 0.1.
228
- columnName = 'geometry';
229
- }
230
- const arrowTable = await this.loadParquetTable(path);
231
- if (columnName === 'geometry' && dims[0] === 0 && dims[1] === 1) {
232
- const geometryColumn = arrowTable.getChild(columnName);
233
- if (!geometryColumn) {
234
- throw new Error(`Column ${columnName} not found in parquet table`);
235
- }
236
- if (geometryColumn.type.toString() !== 'Binary') {
237
- throw new Error(`Expected geometry column to have Binary type (WKB) but got ${geometryColumn.type.toString()}`);
238
- }
239
- // From GeoPandas.to_parquet docs:
240
- // "By default, all geometry columns present are serialized to WKB format in the file"
241
- // Reference: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_parquet.html
242
- // TODO: support geoarrow serialization schemes in addition to WKB.
243
- const wkb = new WKB();
244
- const points = geometryColumn.toArray()
245
- // @ts-ignore
246
- .map((/** @type {Uint8Array} */ geom) => wkb.readGeometry(geom).getFlatCoordinates());
247
- return {
248
- shape: [2, points.length],
249
- data: [
250
- new Float32Array(points.map((/** @type {[number, number]} */ p) => p[0])),
251
- new Float32Array(points.map((/** @type {[number, number]} */ p) => p[1])),
252
- ],
253
- };
254
- }
255
- throw new Error('Unexpected column name for loading 2D array from parquet, currently only geometry is supported');
256
- }
257
-
258
-
259
- /**
260
- * Class method for loading the var index.
261
- * @param {string|undefined} path
262
- * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
263
- */
264
- loadVarIndex(path = undefined) {
265
- const varPath = getVarPath(path);
266
- if (varPath in this.varIndices) {
267
- return this.varIndices[varPath];
268
- }
269
- this.varIndices[varPath] = this.getJson(`${varPath}/.zattrs`)
270
- .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
271
- return this.varIndices[varPath];
272
- }
273
-
274
- /**
275
- * Class method for loading the var alias.
276
- * @param {string} varPath
277
- * @param {string} matrixPath
278
- * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
279
- */
280
- async loadVarAlias(varPath, matrixPath) {
281
- if (varPath in this.varAliases) {
282
- return this.varAliases[varPath];
283
- }
284
- const [varAliasData] = await this.loadVarColumns([varPath]);
285
- this.varAliases[varPath] = /** @type {string[]} */ (varAliasData);
286
- const index = await this.loadVarIndex(matrixPath);
287
- this.varAliases[varPath] = this.varAliases[varPath].map(
288
- (val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]),
289
- );
290
- return this.varAliases[varPath];
291
- }
292
- }
@@ -1,135 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable no-underscore-dangle */
3
- import AnnDataSource from './AnnDataSource.js';
4
-
5
- /** @import { DataSourceParams } from '@vitessce/types' */
6
-
7
- // If the array path starts with table/something/rest
8
- // capture table/something.
9
- const pluralRegex = /^tables\/([^/]*)\/(.*)$/;
10
- const singularRegex = /^table\/([^/]*)\/(.*)$/;
11
-
12
- /**
13
- *
14
- * @param {string|undefined} arrPath
15
- * @returns
16
- */
17
- function getTablePrefix(arrPath) {
18
- if (arrPath) {
19
- // First try the plural "tables/{something}"
20
- const pluralMatches = arrPath.match(pluralRegex);
21
- if (pluralMatches && pluralMatches.length === 3) {
22
- return `tables/${pluralMatches[1]}/`;
23
- }
24
- const singularMatches = arrPath.match(singularRegex);
25
- if (singularMatches && singularMatches.length === 3) {
26
- return `table/${singularMatches[1]}/`;
27
- }
28
- }
29
- // TODO: what to do here when there are multiple tables?
30
- // ObsSetsAnndataLoader will need to pass a path to loadObsIndex().
31
- return 'table/table/';
32
- }
33
-
34
- /**
35
- *
36
- * @param {string|undefined} arrPath
37
- * @returns
38
- */
39
- export function getObsPath(arrPath) {
40
- return `${getTablePrefix(arrPath)}obs`;
41
- }
42
-
43
- /**
44
- *
45
- * @param {string|undefined} arrPath
46
- * @returns
47
- */
48
- export function getVarPath(arrPath) {
49
- return `${getTablePrefix(arrPath)}var`;
50
- }
51
-
52
- export default class SpatialDataTableSource extends AnnDataSource {
53
- /**
54
- *
55
- * @param {DataSourceParams} params
56
- */
57
- constructor(params) {
58
- super(params);
59
- /** @type {{ [k: string]: Promise<string[]> }} */
60
- this.obsIndices = {};
61
- /** @type {{ [k: string]: Promise<string[]> }} */
62
- this.varIndices = {};
63
- /** @type {{ [k: string]: string[] }} */
64
- this.varAliases = {};
65
- }
66
-
67
- /**
68
- *
69
- * @param {string} tablePath
70
- * @returns
71
- */
72
- async loadSpatialDataAttrs(tablePath) {
73
- return this._loadDict(`${tablePath}uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
74
- }
75
-
76
- /**
77
- * Class method for loading the obs index.
78
- * @param {string|undefined} path
79
- * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
80
- */
81
- async loadObsIndex(path = undefined) {
82
- const obsPath = getObsPath(path);
83
- const { _index } = await this.getJson(`${obsPath}/.zattrs`);
84
- let indexPath = `${obsPath}/${_index}`;
85
-
86
- const {
87
- instance_key: instanceKey,
88
- // TODO: filter table index by region and element type.
89
- // region_key: regionKey,
90
- // region,
91
- } = await this.loadSpatialDataAttrs(getTablePrefix(path));
92
-
93
- indexPath = `${obsPath}/${instanceKey}`;
94
-
95
- if (indexPath in this.obsIndices) {
96
- return this.obsIndices[indexPath];
97
- }
98
- this.obsIndices[indexPath] = this._loadColumn(indexPath);
99
- return this.obsIndices[indexPath];
100
- }
101
-
102
- /**
103
- * Class method for loading the var index.
104
- * @param {string|undefined} path
105
- * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
106
- */
107
- loadVarIndex(path = undefined) {
108
- const varPath = getVarPath(path);
109
- if (varPath in this.varIndices) {
110
- return this.varIndices[varPath];
111
- }
112
- this.varIndices[varPath] = this.getJson(`${varPath}/.zattrs`)
113
- .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
114
- return this.varIndices[varPath];
115
- }
116
-
117
- /**
118
- * Class method for loading the var alias.
119
- * @param {string} varPath
120
- * @param {string} matrixPath
121
- * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
122
- */
123
- async loadVarAlias(varPath, matrixPath) {
124
- if (varPath in this.varAliases) {
125
- return this.varAliases[varPath];
126
- }
127
- const [varAliasData] = await this.loadVarColumns([varPath]);
128
- this.varAliases[varPath] = /** @type {string[]} */ (varAliasData);
129
- const index = await this.loadVarIndex(matrixPath);
130
- this.varAliases[varPath] = this.varAliases[varPath].map(
131
- (val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]),
132
- );
133
- return this.varAliases[varPath];
134
- }
135
- }
@@ -1,49 +0,0 @@
1
- import { CoordinationLevel as CL } from '@vitessce/config';
2
- import { LoaderResult } from '@vitessce/vit-s';
3
- import OmeZarrLoader from './OmeZarrLoader.js';
4
-
5
- export default class OmeZarrAsObsSegmentationsLoader extends OmeZarrLoader {
6
- async load() {
7
- const { obsTypesFromChannelNames } = this.options || {};
8
- const result = await super.load();
9
-
10
- const imageWrapper = result.data.image.instance;
11
- const channelObjects = imageWrapper.getChannelObjects();
12
- const channelCoordination = channelObjects.slice(0, 5).map((channelObj, i) => ({
13
- spatialTargetC: i,
14
- spatialChannelColor: (channelObj.defaultColor || channelObj.autoDefaultColor).slice(0, 3),
15
- spatialChannelVisible: true,
16
- spatialChannelOpacity: 1.0,
17
- spatialChannelWindow: channelObj.defaultWindow || null,
18
- // featureType: 'feature',
19
- // featureValueType: 'value',
20
- obsColorEncoding: 'spatialChannelColor',
21
- spatialSegmentationFilled: true,
22
- spatialSegmentationStrokeWidth: 1.0,
23
- obsHighlight: null,
24
- ...(obsTypesFromChannelNames ? { obsType: channelObj.name } : {}),
25
- }));
26
-
27
- const coordinationValues = {
28
- spatialTargetZ: imageWrapper.getDefaultTargetZ(),
29
- spatialTargetT: imageWrapper.getDefaultTargetT(),
30
- segmentationLayer: CL([
31
- {
32
- fileUid: this.coordinationValues?.fileUid || null,
33
- spatialLayerOpacity: 1.0,
34
- spatialLayerVisible: true,
35
- segmentationChannel: CL(channelCoordination),
36
- },
37
- ]),
38
- };
39
-
40
- return Promise.resolve(new LoaderResult(
41
- {
42
- obsSegmentationsType: 'bitmask',
43
- obsSegmentations: result.data.image,
44
- },
45
- result.url,
46
- coordinationValues,
47
- ));
48
- }
49
- }
@@ -1,208 +0,0 @@
1
- import {
2
- initializeRasterLayersAndChannels,
3
- coordinateTransformationsToMatrix,
4
- getNgffAxes,
5
- hexToRgb,
6
- normalizeCoordinateTransformations,
7
- loadOmeZarr,
8
- } from '@vitessce/spatial-utils';
9
- import {
10
- ImageWrapper,
11
- } from '@vitessce/image-utils';
12
- import {
13
- AbstractLoaderError,
14
- LoaderResult,
15
- AbstractTwoStepLoader,
16
- } from '@vitessce/vit-s';
17
- import { CoordinationLevel as CL } from '@vitessce/config';
18
-
19
-
20
- export default class OmeZarrLoader extends AbstractTwoStepLoader {
21
- constructor(dataSource, params) {
22
- super(dataSource, params);
23
- this.storeRoot = this.dataSource.storeRoot;
24
- }
25
-
26
- async load() {
27
- const payload = await this.dataSource.getJson('.zattrs', this.storeRoot).catch(reason => Promise.resolve(reason));
28
- if (payload instanceof AbstractLoaderError) {
29
- return Promise.reject(payload);
30
- }
31
-
32
- const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
33
-
34
- // Here, we use this.storeRoot as opposed to this.dataSource.storeRoot.
35
- // Loader sub-classes may override this.storeRoot in their constructor
36
- // if their OME-Zarr image is not at the root of the store.
37
- const loader = await loadOmeZarr(this.storeRoot);
38
- const imageWrapper = new ImageWrapper(loader, this.options);
39
-
40
- const { metadata, data } = loader;
41
- const { omero, multiscales, channels_metadata: spatialDataChannels, 'image-label': imageLabel } = metadata;
42
-
43
- // Crude way to check if this is a SpatialData OME-NGFF.
44
- const isSpatialData = !!spatialDataChannels || !!imageLabel;
45
- const isLabels = !!imageLabel;
46
-
47
- if (!isSpatialData && !omero) {
48
- console.error('image.ome-zarr must have omero metadata in attributes.');
49
- return Promise.reject(payload);
50
- }
51
-
52
- if (!Array.isArray(multiscales) || multiscales.length === 0) {
53
- console.error('Multiscales array must exist and have at least one element');
54
- }
55
-
56
- const {
57
- datasets,
58
- coordinateTransformations: coordinateTransformationsFromFile,
59
- name: imageName,
60
- } = multiscales[0];
61
-
62
- // Axes in v0.4 format.
63
- const axes = getNgffAxes(multiscales[0].axes);
64
-
65
- // SpatialData uses the new coordinateTransformations spec.
66
- // Reference: https://github.com/ome/ngff/pull/138
67
-
68
- // This new spec is very flexible, so here we will attepmpt to convert it back to the old spec.
69
- const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(
70
- coordinateTransformationsFromFile, datasets,
71
- );
72
-
73
- const transformMatrixFromOptions = coordinateTransformationsToMatrix(
74
- coordinateTransformationsFromOptions, axes,
75
- );
76
- const transformMatrixFromFile = coordinateTransformationsToMatrix(
77
- normCoordinateTransformationsFromFile, axes,
78
- );
79
-
80
- const transformMatrix = transformMatrixFromFile.multiplyLeft(transformMatrixFromOptions);
81
-
82
-
83
- const filterSelection = (sel) => {
84
- // Remove selection keys for which there is no dimension.
85
- if (data.length > 0) {
86
- const nextSel = {};
87
- // eslint-disable-next-line prefer-destructuring
88
- const labels = data[0].labels;
89
- Object.keys(sel).forEach((key) => {
90
- if (labels.includes(key)) {
91
- nextSel[key] = sel[key];
92
- }
93
- });
94
- return nextSel;
95
- }
96
- return sel;
97
- };
98
-
99
- let channelObjects;
100
- let channelLabels = [];
101
- let initialTargetT = 0;
102
- let initialTargetZ = 0;
103
- if (isSpatialData) {
104
- // TODO: Consider removing support for `channels_metadata` once OME-NGFF loosens
105
- // requirements for channel metadata fields such as `window` and `color`.
106
- // (Unclear if we will need to keep this around for backwards compatibility with
107
- // those SpatialData objects generated in the meantime though.)
108
- // References:
109
- // - https://github.com/ome/ngff/issues/192
110
- // - https://github.com/ome/ome-zarr-py/pull/261
111
- if (isLabels) {
112
- channelObjects = [{
113
- selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: 0 }),
114
- slider: [0, 255],
115
- color: [255, 255, 255],
116
- }];
117
- channelLabels = ['labels'];
118
- } else {
119
- const { channels } = spatialDataChannels;
120
- channelObjects = channels.map((channel, i) => ({
121
- selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
122
- slider: [0, 255],
123
- color: [255, 255, 255],
124
- }));
125
- channelLabels = channels.map(c => c.label);
126
- }
127
- } else {
128
- const { rdefs = {}, channels } = omero;
129
- if (typeof rdefs.defaultT === 'number') {
130
- initialTargetT = rdefs.defaultT;
131
- }
132
- if (typeof rdefs.defaultZ === 'number') {
133
- initialTargetZ = rdefs.defaultZ;
134
- }
135
- channelObjects = channels.map((channel, i) => ({
136
- selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
137
- slider: channel.window ? ([channel.window.start, channel.window.end]) : [0, 255],
138
- color: channel.color ? hexToRgb(channel.color) : [255, 255, 255],
139
- }));
140
- channelLabels = channels.map(c => c.label);
141
- }
142
-
143
- const imagesWithLoaderCreators = [
144
- {
145
- name: imageName || 'Image',
146
- channels: channelObjects,
147
- ...(transformMatrix ? {
148
- metadata: {
149
- transform: {
150
- matrix: transformMatrix,
151
- },
152
- },
153
- } : {}),
154
- loaderCreator: async () => ({ ...loader, channels: channelLabels }),
155
- },
156
- ];
157
-
158
- // TODO: use options for initial selection of channels
159
- // which omit domain/slider ranges.
160
- const [
161
- autoImageLayers, imageLayerLoaders, imageLayerMeta,
162
- ] = await initializeRasterLayersAndChannels(
163
- imagesWithLoaderCreators, undefined,
164
- );
165
-
166
- const channelObjects2 = imageWrapper.getChannelObjects();
167
- const channelCoordination = channelObjects2.slice(0, 5).map((channelObj, i) => ({
168
- spatialTargetC: i,
169
- spatialChannelColor: (channelObj.defaultColor || channelObj.autoDefaultColor).slice(0, 3),
170
- spatialChannelVisible: true,
171
- spatialChannelOpacity: 1.0,
172
- spatialChannelWindow: channelObj.defaultWindow || null,
173
- }));
174
-
175
-
176
- const coordinationValues = {
177
- // Old
178
- spatialImageLayer: autoImageLayers,
179
- // New
180
- spatialTargetZ: imageWrapper.getDefaultTargetZ(),
181
- spatialTargetT: imageWrapper.getDefaultTargetT(),
182
- imageLayer: CL([
183
- {
184
- fileUid: this.coordinationValues?.fileUid || null,
185
- spatialLayerOpacity: 1.0,
186
- spatialLayerVisible: true,
187
- photometricInterpretation: imageWrapper.getPhotometricInterpretation(),
188
- volumetricRenderingAlgorithm: 'maximumIntensityProjection',
189
- spatialTargetResolution: null,
190
- imageChannel: CL(channelCoordination),
191
- },
192
- ]),
193
- };
194
-
195
- return Promise.resolve(new LoaderResult(
196
- {
197
- image: {
198
- loaders: imageLayerLoaders, // TODO: replace with imageWrapper
199
- meta: imageLayerMeta, // TODO: replace with imageWrapper
200
- instance: imageWrapper, // TODO: make this the root value of LoaderResult.image.
201
- },
202
- featureIndex: imageWrapper.getChannelNames(),
203
- },
204
- null,
205
- coordinationValues,
206
- ));
207
- }
208
- }
@@ -1,2 +0,0 @@
1
- export { default as OmeZarrLoader } from './OmeZarrLoader.js';
2
- export { default as OmeZarrAsObsSegmentationsLoader } from './OmeZarrAsObsSegmentationsLoader.js';
@@ -1,11 +0,0 @@
1
- import { OmeZarrLoader } from '../ome-loaders/index.js';
2
-
3
- export default class SpatialDataImageLoader extends OmeZarrLoader {
4
- constructor(dataSource, params) {
5
- super(dataSource, params);
6
-
7
- // Re-use the OmeZarrLoader, but change the store root to point
8
- // to the specified OME-NGFF image within the SpatialData store.
9
- this.storeRoot = this.dataSource.getStoreRoot(params.options.path);
10
- }
11
- }