@vitessce/zarr 3.3.9 → 3.3.10

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 (75) hide show
  1. package/dist/{deflate-2f7f502f.js → deflate-b162c7aa.js} +1 -1
  2. package/dist/{index-200d5108.js → index-184aee21.js} +290 -124
  3. package/dist/index.js +1 -1
  4. package/dist/{jpeg-3ff942a5.js → jpeg-dbb0f9d9.js} +1 -1
  5. package/dist/{lerc-762cc666.js → lerc-e45d57dc.js} +1 -1
  6. package/dist/{lzw-97464fce.js → lzw-05e88e18.js} +1 -1
  7. package/dist/{packbits-daaf8f04.js → packbits-922f4592.js} +1 -1
  8. package/dist/{raw-8fdba750.js → raw-a8de9c08.js} +1 -1
  9. package/dist/{webimage-e98ea52f.js → webimage-27013e2d.js} +1 -1
  10. package/dist-tsc/AnnDataSource.d.ts +96 -30
  11. package/dist-tsc/AnnDataSource.d.ts.map +1 -1
  12. package/dist-tsc/AnnDataSource.js +147 -53
  13. package/dist-tsc/MuDataSource.d.ts +1 -1
  14. package/dist-tsc/MuDataSource.d.ts.map +1 -1
  15. package/dist-tsc/SpatialDataShapesSource.d.ts +40 -12
  16. package/dist-tsc/SpatialDataShapesSource.d.ts.map +1 -1
  17. package/dist-tsc/SpatialDataShapesSource.js +58 -27
  18. package/dist-tsc/SpatialDataTableSource.d.ts +35 -14
  19. package/dist-tsc/SpatialDataTableSource.d.ts.map +1 -1
  20. package/dist-tsc/SpatialDataTableSource.js +57 -27
  21. package/dist-tsc/ZarrDataSource.d.ts +22 -11
  22. package/dist-tsc/ZarrDataSource.d.ts.map +1 -1
  23. package/dist-tsc/ZarrDataSource.js +20 -3
  24. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.d.ts +18 -5
  25. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.d.ts.map +1 -1
  26. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.js +12 -4
  27. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.d.ts +22 -5
  28. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.d.ts.map +1 -1
  29. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.js +13 -5
  30. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.d.ts +9 -2
  31. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.d.ts.map +1 -1
  32. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts +9 -2
  33. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts.map +1 -1
  34. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.d.ts +8 -2
  35. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.d.ts.map +1 -1
  36. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.d.ts +8 -2
  37. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.d.ts.map +1 -1
  38. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts +8 -2
  39. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts.map +1 -1
  40. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts +9 -2
  41. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts.map +1 -1
  42. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.d.ts +10 -3
  43. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.d.ts.map +1 -1
  44. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts +8 -2
  45. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts.map +1 -1
  46. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.d.ts +8 -2
  47. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.d.ts.map +1 -1
  48. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts +3 -1
  49. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts.map +1 -1
  50. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts +9 -2
  51. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts.map +1 -1
  52. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.d.ts +10 -1
  53. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.d.ts.map +1 -1
  54. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts +12 -2
  55. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts.map +1 -1
  56. package/dist-tsc/ome-loaders/OmeZarrLoader.js +2 -2
  57. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts +1 -1
  58. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts.map +1 -1
  59. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts +1 -1
  60. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts.map +1 -1
  61. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts +1 -2
  62. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts.map +1 -1
  63. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts +8 -2
  64. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts.map +1 -1
  65. package/dist-tsc/utils.d.ts +14 -2
  66. package/dist-tsc/utils.d.ts.map +1 -1
  67. package/dist-tsc/utils.js +19 -1
  68. package/package.json +16 -10
  69. package/src/AnnDataSource.js +170 -53
  70. package/src/SpatialDataShapesSource.js +61 -28
  71. package/src/SpatialDataTableSource.js +60 -27
  72. package/src/ZarrDataSource.js +20 -3
  73. package/src/anndata-loaders/FeatureLabelsAnndataLoader.js +13 -4
  74. package/src/anndata-loaders/ObsEmbeddingAnndataLoader.js +14 -5
  75. package/src/utils.js +20 -1
@@ -1,23 +1,48 @@
1
+ // @ts-check
1
2
  /* eslint-disable no-underscore-dangle */
2
3
  import { open as zarrOpen, get as zarrGet } from 'zarrita';
3
4
  import { dirname } from './utils.js';
4
5
  import ZarrDataSource from './ZarrDataSource.js';
5
6
 
7
+ /** @import { DataSourceParams } from '@vitessce/types' */
8
+ /** @import { ByteStringArray } from '@zarrita/typedarray' */
9
+ /** @import { TypedArray as ZarrTypedArray, Chunk } from '@zarrita/core' */
10
+
6
11
  /**
7
12
  * A base AnnData loader which has all shared methods for more comlpex laoders,
8
13
  * like loading cell names and ids. It inherits from AbstractLoader.
9
14
  */
10
15
  export default class AnnDataSource extends ZarrDataSource {
11
- constructor(...args) {
12
- super(...args);
13
- /** @type {Map<string, Promise<string[]>} */
16
+ /**
17
+ *
18
+ * @param {DataSourceParams} params
19
+ */
20
+ constructor(params) {
21
+ super(params);
22
+ /** @type {Map<string, Promise<(undefined | string[] | string[][])>>} */
14
23
  this.promises = new Map();
15
24
  }
16
25
 
26
+ /**
27
+ *
28
+ * @param {string[]} paths Paths to multiple string-valued columns
29
+ * within the obs dataframe.
30
+ * @returns {Promise<(undefined | string[] | string[][])[]>} Returns
31
+ * each column as an array of strings,
32
+ * ordered the same as the paths.
33
+ */
17
34
  loadObsColumns(paths) {
18
35
  return this._loadColumns(paths);
19
36
  }
20
37
 
38
+ /**
39
+ *
40
+ * @param {string[]} paths Paths to multiple string-valued columns
41
+ * within the var dataframe.
42
+ * @returns {Promise<(undefined | string[] | string[][])[]>} Returns
43
+ * each column as an array of strings,
44
+ * ordered the same as the paths.
45
+ */
21
46
  loadVarColumns(paths) {
22
47
  return this._loadColumns(paths);
23
48
  }
@@ -26,11 +51,14 @@ export default class AnnDataSource extends ZarrDataSource {
26
51
  * Class method for loading obs variables.
27
52
  * Takes the location as an argument because this is shared across objects,
28
53
  * which have different ways of specifying location.
29
- * @param {string[]} paths An array of strings like "obs/leiden" or "obs/bulk_labels."
30
- * @returns {Promise} A promise for an array of ids with one per cell.
54
+ * @param {string[] | string[][]} paths An array of strings like
55
+ * "obs/leiden" or "obs/bulk_labels."
56
+ * @returns {Promise<(undefined | string[] | string[][])[]>} A promise
57
+ * for an array of ids with one per cell.
31
58
  */
32
59
  _loadColumns(paths) {
33
60
  const promises = paths.map((path) => {
61
+ /** @type {(a: string) => Promise<string[]>} */
34
62
  const getCol = (col) => {
35
63
  if (!this.promises.has(col)) {
36
64
  const obsPromise = this._loadColumn(col).catch((err) => {
@@ -41,7 +69,7 @@ export default class AnnDataSource extends ZarrDataSource {
41
69
  });
42
70
  this.promises.set(col, obsPromise);
43
71
  }
44
- return this.promises.get(col);
72
+ return /** @type {Promise<string[]>} */ (this.promises.get(col));
45
73
  };
46
74
  if (!path) {
47
75
  return Promise.resolve(undefined);
@@ -54,34 +82,53 @@ export default class AnnDataSource extends ZarrDataSource {
54
82
  return Promise.all(promises);
55
83
  }
56
84
 
85
+ /**
86
+ *
87
+ * @param {string} path
88
+ * @returns
89
+ */
57
90
  async _loadColumn(path) {
58
91
  const { storeRoot } = this;
59
92
  const prefix = dirname(path);
60
93
  const { categories, 'encoding-type': encodingType } = await this.getJson(`${path}/.zattrs`);
94
+ /** @type {string[]} */
61
95
  let categoriesValues;
62
- let codes;
96
+ /** @type {undefined | string} */
97
+ let codesPath;
63
98
  if (categories) {
64
- const { dtype } = await zarrOpen(storeRoot.resolve(`/${prefix}/${categories}`));
99
+ const { dtype } = await zarrOpen(
100
+ storeRoot.resolve(`/${prefix}/${categories}`),
101
+ { kind: 'array' },
102
+ );
65
103
  if (dtype === 'v2:object') {
66
104
  categoriesValues = await this.getFlatArrDecompressed(
67
105
  `/${prefix}/${categories}`,
68
106
  );
69
107
  }
70
108
  } else if (encodingType === 'categorical') {
71
- const { dtype } = await zarrOpen(storeRoot.resolve(`/${path}/categories`));
109
+ const { dtype } = await zarrOpen(
110
+ storeRoot.resolve(`/${path}/categories`),
111
+ { kind: 'array' },
112
+ );
72
113
  if (dtype === 'v2:object') {
73
114
  categoriesValues = await this.getFlatArrDecompressed(
74
115
  `/${path}/categories`,
75
116
  );
76
117
  }
77
- codes = `/${path}/codes`;
118
+ codesPath = `/${path}/codes`;
78
119
  } else {
79
- const { dtype } = await zarrOpen(storeRoot.resolve(`/${path}`));
120
+ const { dtype } = await zarrOpen(
121
+ storeRoot.resolve(`/${path}`),
122
+ { kind: 'array' },
123
+ );
80
124
  if (dtype === 'v2:object') {
81
125
  return this.getFlatArrDecompressed(path);
82
126
  }
83
127
  }
84
- const arr = await zarrOpen(storeRoot.resolve(codes || path), { kind: 'array' });
128
+ const arr = await zarrOpen(
129
+ storeRoot.resolve(codesPath || path),
130
+ { kind: 'array' },
131
+ );
85
132
  const values = await zarrGet(arr, [null]);
86
133
  const { data } = values;
87
134
  const mappedValues = Array.from(data).map(
@@ -93,7 +140,7 @@ export default class AnnDataSource extends ZarrDataSource {
93
140
  /**
94
141
  * Class method for loading general numeric arrays.
95
142
  * @param {string} path A string like obsm.X_pca.
96
- * @returns {Promise} A promise for a zarr array containing the data.
143
+ * @returns {Promise<Chunk<any>>} A promise for a zarr array containing the data.
97
144
  */
98
145
  loadNumeric(path) {
99
146
  const { storeRoot } = this;
@@ -104,8 +151,11 @@ export default class AnnDataSource extends ZarrDataSource {
104
151
  /**
105
152
  * Class method for loading specific columns of numeric arrays.
106
153
  * @param {string} path A string like obsm.X_pca.
107
- * @param {number[]} dims The column indices to load.
108
- * @returns {Promise} A promise for a zarr array containing the data.
154
+ * @param {[number, number]} dims The column indices to load.
155
+ * @returns {Promise<{
156
+ * data: [ZarrTypedArray<any>, ZarrTypedArray<any>],
157
+ * shape: [number, number],
158
+ * }>} A promise for a zarr array containing the data.
109
159
  */
110
160
  loadNumericForDims(path, dims) {
111
161
  const { storeRoot } = this;
@@ -115,7 +165,9 @@ export default class AnnDataSource extends ZarrDataSource {
115
165
  loadedArr => zarrGet(loadedArr, [null, dim]),
116
166
  )),
117
167
  ).then(cols => ({
118
- data: cols.map(col => col.data),
168
+ data: /** @type {[ZarrTypedArray<any>, ZarrTypedArray<any>]} */ (
169
+ cols.map(col => col.data)
170
+ ),
119
171
  shape: [dims.length, cols[0].shape[0]],
120
172
  }));
121
173
  }
@@ -124,7 +176,7 @@ export default class AnnDataSource extends ZarrDataSource {
124
176
  * A common method for loading flattened data
125
177
  * i.e that which has shape [n] where n is a natural number.
126
178
  * @param {string} path A path to a flat array location, like obs/_index
127
- * @returns {Array} The data from the zarr array.
179
+ * @returns {Promise<string[]>} The data from the zarr array.
128
180
  */
129
181
  async getFlatArrDecompressed(path) {
130
182
  const { storeRoot } = this;
@@ -134,98 +186,163 @@ export default class AnnDataSource extends ZarrDataSource {
134
186
  if (data.data?.[Symbol.iterator]) {
135
187
  return Array.from(data.data);
136
188
  }
137
- return data.data;
189
+ return /** @type {string[]} */ (data.data);
138
190
  }
139
191
 
140
192
  /**
141
193
  * Class method for loading the obs index.
142
- * @returns {Promise} An promise for a zarr array containing the indices.
194
+ * @param {string|undefined} path Used by subclasses.
195
+ * @returns {Promise<string[]>} An promise for a zarr array
196
+ * containing the indices.
143
197
  */
144
- loadObsIndex() {
198
+ loadObsIndex(
199
+ // eslint-disable-next-line no-unused-vars
200
+ path = undefined,
201
+ ) {
145
202
  if (this.obsIndex) {
146
203
  return this.obsIndex;
147
204
  }
148
- this.obsIndex = this.getJson('obs/.zattrs').then(({ _index }) => this.getFlatArrDecompressed(`/obs/${_index}`));
205
+ this.obsIndex = this.getJson('obs/.zattrs')
206
+ .then(({ _index }) => this.getFlatArrDecompressed(`/obs/${_index}`));
149
207
  return this.obsIndex;
150
208
  }
151
209
 
152
210
  /**
153
211
  * Class method for loading the var index.
154
- * @returns {Promise} An promise for a zarr array containing the indices.
212
+ * @param {string|undefined} path Used by subclasses.
213
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
155
214
  */
156
- loadVarIndex() {
215
+ loadVarIndex(
216
+ // eslint-disable-next-line no-unused-vars
217
+ path = undefined,
218
+ ) {
157
219
  if (this.varIndex) {
158
220
  return this.varIndex;
159
221
  }
160
- this.varIndex = this.getJson('var/.zattrs').then(({ _index }) => this.getFlatArrDecompressed(`/var/${_index}`));
222
+ this.varIndex = this.getJson('var/.zattrs')
223
+ .then(({ _index }) => this.getFlatArrDecompressed(`/var/${_index}`));
161
224
  return this.varIndex;
162
225
  }
163
226
 
164
227
  /**
165
228
  * Class method for loading the var alias.
166
- * @returns {Promise} An promise for a zarr array containing the aliased names.
229
+ * @param {string} varPath
230
+ * @param {string|undefined} matrixPath
231
+ * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
167
232
  */
168
- async loadVarAlias(varPath) {
233
+ async loadVarAlias(
234
+ varPath,
235
+ // eslint-disable-next-line no-unused-vars
236
+ matrixPath = undefined,
237
+ ) {
169
238
  if (this.varAlias) {
170
239
  return this.varAlias;
171
240
  }
172
241
  [this.varAlias] = await this.loadVarColumns([varPath]);
173
242
  const index = await this.loadVarIndex();
174
243
  this.varAlias = this.varAlias.map(
244
+ /** @type {(val: string, ind: number) => string} */
175
245
  (val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]),
176
246
  );
177
247
  return this.varAlias;
178
248
  }
179
249
 
250
+ /**
251
+ *
252
+ * @param {string} path
253
+ * @returns {Promise<object>}
254
+ */
180
255
  async _loadAttrs(path) {
181
256
  return this.getJson(`${path}/.zattrs`);
182
257
  }
183
258
 
259
+ /**
260
+ *
261
+ * @param {string} path
262
+ * @returns {Promise<string>}
263
+ */
184
264
  async _loadString(path) {
185
265
  const { storeRoot } = this;
186
- const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
266
+ const zattrs = await this._loadAttrs(path);
267
+ if ('encoding-type' in zattrs && 'encoding-version' in zattrs) {
268
+ const {
269
+ 'encoding-type': encodingType,
270
+ 'encoding-version': encodingVersion,
271
+ } = zattrs;
187
272
 
188
- if (encodingType === 'string' && encodingVersion === '0.2.0') {
189
- const arr = await zarrOpen(storeRoot.resolve(path), { kind: 'array' });
190
- // TODO: Use zarrGet once it supports zero-dimensional array access.
191
- const { data } = await arr.getChunk([]);
192
- return data.get(0);
273
+ if (encodingType === 'string' && encodingVersion === '0.2.0') {
274
+ const arr = await zarrOpen(storeRoot.resolve(path), { kind: 'array' });
275
+ // TODO: Use zarrGet once it supports zero-dimensional array access.
276
+ const { data } = /** @type {{ data: ByteStringArray }} */ (await arr.getChunk([]));
277
+ return data.get(0);
278
+ }
279
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadString`);
193
280
  }
194
- throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadString`);
281
+ throw new Error('Keys for encoding-type or encoding-version not found in AnnDataSource._loadString');
195
282
  }
196
283
 
284
+ /**
285
+ *
286
+ * @param {string} path
287
+ * @returns {Promise<string[]>}
288
+ */
197
289
  async _loadStringArray(path) {
198
- const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
290
+ const zattrs = await this._loadAttrs(path);
291
+ if ('encoding-type' in zattrs && 'encoding-version' in zattrs) {
292
+ const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = zattrs;
199
293
 
200
- if (encodingType === 'string-array' && encodingVersion === '0.2.0') {
201
- return this.getFlatArrDecompressed(path);
294
+ if (encodingType === 'string-array' && encodingVersion === '0.2.0') {
295
+ return this.getFlatArrDecompressed(path);
296
+ }
297
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadStringArray`);
202
298
  }
203
- throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadStringArray`);
299
+ throw new Error('Keys for encoding-type or encoding-version not found in AnnDataSource._loadString');
204
300
  }
205
301
 
206
-
302
+ /**
303
+ *
304
+ * @param {string} path
305
+ * @returns
306
+ */
207
307
  async _loadElement(path) {
208
- const { 'encoding-type': encodingType } = await this._loadAttrs(path);
209
- if (encodingType === 'string') {
210
- return this._loadString(path);
211
- } if (encodingType === 'string-array') {
212
- return this._loadStringArray(path);
308
+ const zattrs = await this._loadAttrs(path);
309
+ if ('encoding-type' in zattrs) {
310
+ const { 'encoding-type': encodingType } = zattrs;
311
+ if (encodingType === 'string') {
312
+ return this._loadString(path);
313
+ } if (encodingType === 'string-array') {
314
+ return this._loadStringArray(path);
315
+ }
213
316
  }
214
317
  // TODO: support more elements
215
318
  return null;
216
319
  }
217
320
 
321
+ /**
322
+ *
323
+ * @param {string} path
324
+ * @param {string[]} keys
325
+ * @returns
326
+ */
218
327
  async _loadDict(path, keys) {
219
- const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
220
-
221
- if (encodingType === 'dict' && encodingVersion === '0.1.0') {
222
- const result = {};
223
- await Promise.all(keys.map(async (key) => {
224
- const val = await this._loadElement(`${path}/${key}`);
225
- result[key] = val;
226
- }));
227
- return result;
328
+ const zattrs = await this._loadAttrs(path);
329
+ if ('encoding-type' in zattrs && 'encoding-version' in zattrs) {
330
+ const {
331
+ 'encoding-type': encodingType,
332
+ 'encoding-version': encodingVersion,
333
+ } = zattrs;
334
+
335
+ if (encodingType === 'dict' && encodingVersion === '0.1.0') {
336
+ /** @type {{ [k: string]: string|string[]|null }} */
337
+ const result = {};
338
+ await Promise.all(keys.map(async (key) => {
339
+ const val = await this._loadElement(`${path}/${key}`);
340
+ result[key] = val;
341
+ }));
342
+ return result;
343
+ }
344
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadDict`);
228
345
  }
229
- throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadDict`);
346
+ throw new Error('Keys for encoding-type or encoding-version not found in AnnDataSource._loadString');
230
347
  }
231
348
  }
@@ -1,10 +1,18 @@
1
+ // @ts-check
1
2
  /* eslint-disable no-underscore-dangle */
2
3
  import AnnDataSource from './AnnDataSource.js';
3
4
 
5
+ /** @import { DataSourceParams } from '@vitessce/types' */
6
+
4
7
  // If the array path starts with table/something/rest
5
8
  // capture table/something.
6
9
  const regex = /^shapes\/([^/]*)\/(.*)$/;
7
10
 
11
+ /**
12
+ *
13
+ * @param {string|undefined} arrPath
14
+ * @returns
15
+ */
8
16
  function getShapesPrefix(arrPath) {
9
17
  if (arrPath) {
10
18
  const matches = arrPath.match(regex);
@@ -14,29 +22,57 @@ function getShapesPrefix(arrPath) {
14
22
  }
15
23
  return '';
16
24
  }
25
+
26
+ /**
27
+ *
28
+ * @param {string|undefined} arrPath
29
+ * @returns
30
+ */
17
31
  export function getIndexPath(arrPath) {
18
32
  return `${getShapesPrefix(arrPath)}Index`;
19
33
  }
20
34
 
35
+ /**
36
+ *
37
+ * @param {string|undefined} arrPath
38
+ * @returns
39
+ */
21
40
  export function getVarPath(arrPath) {
22
41
  return `${getShapesPrefix(arrPath)}var`;
23
42
  }
24
43
 
25
44
 
26
45
  export default class SpatialDataShapesSource extends AnnDataSource {
46
+ /**
47
+ *
48
+ * @param {DataSourceParams} params
49
+ */
50
+ constructor(params) {
51
+ super(params);
52
+ /** @type {{ [k: string]: Promise<string[]> }} */
53
+ this.obsIndices = {};
54
+ /** @type {{ [k: string]: Promise<string[]> }} */
55
+ this.varIndices = {};
56
+ /** @type {{ [k: string]: string[] }} */
57
+ this.varAliases = {};
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @param {string} tablePath
63
+ * @returns
64
+ */
27
65
  async loadSpatialDataAttrs(tablePath) {
28
66
  return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
29
67
  }
30
68
 
31
69
  /**
32
70
  * Class method for loading the obs index.
33
- * @returns {Promise} An promise for a zarr array containing the indices.
71
+ * @param {string|undefined} path
72
+ * @param {string|undefined} tablePath
73
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
34
74
  */
35
- async loadObsIndex(path = null, tablePath = null) {
36
- if (!this.obsIndex) {
37
- this.obsIndex = {};
38
- }
39
-
75
+ async loadObsIndex(path = undefined, tablePath = undefined) {
40
76
  let indexPath = getIndexPath(path);
41
77
  if (tablePath) {
42
78
  // TODO: given a path to the shapes,
@@ -57,47 +93,44 @@ export default class SpatialDataShapesSource extends AnnDataSource {
57
93
 
58
94
  indexPath = `${obsPath}/${instanceKey}`;
59
95
  }
60
- if (this.obsIndex[indexPath]) {
61
- return this.obsIndex[indexPath];
96
+ if (indexPath in this.obsIndices) {
97
+ return this.obsIndices[indexPath];
62
98
  }
63
- this.obsIndex[indexPath] = this._loadColumn(indexPath);
64
- return this.obsIndex[indexPath];
99
+ this.obsIndices[indexPath] = this._loadColumn(indexPath);
100
+ return this.obsIndices[indexPath];
65
101
  }
66
102
 
67
103
  /**
68
104
  * Class method for loading the var index.
69
- * @returns {Promise} An promise for a zarr array containing the indices.
105
+ * @param {string|undefined} path
106
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
70
107
  */
71
- loadVarIndex(path = null) {
72
- if (!this.varIndex) {
73
- this.varIndex = {};
74
- }
108
+ loadVarIndex(path = undefined) {
75
109
  const varPath = getVarPath(path);
76
- if (this.varIndex[varPath]) {
77
- return this.varIndex[varPath];
110
+ if (varPath in this.varIndices) {
111
+ return this.varIndices[varPath];
78
112
  }
79
- this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`)
113
+ this.varIndices[varPath] = this.getJson(`${varPath}/.zattrs`)
80
114
  .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
81
- return this.varIndex[varPath];
115
+ return this.varIndices[varPath];
82
116
  }
83
117
 
84
118
  /**
85
119
  * Class method for loading the var alias.
86
- * @returns {Promise} An promise for a zarr array containing the aliased names.
120
+ * @param {string} varPath
121
+ * @param {string} matrixPath
122
+ * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
87
123
  */
88
124
  async loadVarAlias(varPath, matrixPath) {
89
- if (!this.varAlias) {
90
- this.varAlias = {};
91
- }
92
- if (this.varAlias[varPath]) {
93
- return this.varAlias[varPath];
125
+ if (varPath in this.varAliases) {
126
+ return this.varAliases[varPath];
94
127
  }
95
128
  const [varAliasData] = await this.loadVarColumns([varPath]);
96
- this.varAlias[varPath] = varAliasData;
129
+ this.varAliases[varPath] = /** @type {string[]} */ (varAliasData);
97
130
  const index = await this.loadVarIndex(matrixPath);
98
- this.varAlias[varPath] = this.varAlias[varPath].map(
131
+ this.varAliases[varPath] = this.varAliases[varPath].map(
99
132
  (val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]),
100
133
  );
101
- return this.varAlias[varPath];
134
+ return this.varAliases[varPath];
102
135
  }
103
136
  }
@@ -1,10 +1,18 @@
1
+ // @ts-check
1
2
  /* eslint-disable no-underscore-dangle */
2
3
  import AnnDataSource from './AnnDataSource.js';
3
4
 
5
+ /** @import { DataSourceParams } from '@vitessce/types' */
6
+
4
7
  // If the array path starts with table/something/rest
5
8
  // capture table/something.
6
9
  const regex = /^table\/([^/]*)\/(.*)$/;
7
10
 
11
+ /**
12
+ *
13
+ * @param {string|undefined} arrPath
14
+ * @returns
15
+ */
8
16
  function getTablePrefix(arrPath) {
9
17
  if (arrPath) {
10
18
  const matches = arrPath.match(regex);
@@ -16,27 +24,55 @@ function getTablePrefix(arrPath) {
16
24
  // ObsSetsAnndataLoader will need to pass a path to loadObsIndex().
17
25
  return 'table/table/';
18
26
  }
27
+
28
+ /**
29
+ *
30
+ * @param {string|undefined} arrPath
31
+ * @returns
32
+ */
19
33
  export function getObsPath(arrPath) {
20
34
  return `${getTablePrefix(arrPath)}obs`;
21
35
  }
22
36
 
37
+ /**
38
+ *
39
+ * @param {string|undefined} arrPath
40
+ * @returns
41
+ */
23
42
  export function getVarPath(arrPath) {
24
43
  return `${getTablePrefix(arrPath)}var`;
25
44
  }
26
45
 
27
46
  export default class SpatialDataTableSource extends AnnDataSource {
47
+ /**
48
+ *
49
+ * @param {DataSourceParams} params
50
+ */
51
+ constructor(params) {
52
+ super(params);
53
+ /** @type {{ [k: string]: Promise<string[]> }} */
54
+ this.obsIndices = {};
55
+ /** @type {{ [k: string]: Promise<string[]> }} */
56
+ this.varIndices = {};
57
+ /** @type {{ [k: string]: string[] }} */
58
+ this.varAliases = {};
59
+ }
60
+
61
+ /**
62
+ *
63
+ * @param {string} tablePath
64
+ * @returns
65
+ */
28
66
  async loadSpatialDataAttrs(tablePath) {
29
67
  return this._loadDict(`${tablePath}uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
30
68
  }
31
69
 
32
70
  /**
33
71
  * Class method for loading the obs index.
34
- * @returns {Promise} An promise for a zarr array containing the indices.
72
+ * @param {string|undefined} path
73
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
35
74
  */
36
- async loadObsIndex(path = null) {
37
- if (!this.obsIndex) {
38
- this.obsIndex = {};
39
- }
75
+ async loadObsIndex(path = undefined) {
40
76
  const obsPath = getObsPath(path);
41
77
  const { _index } = await this.getJson(`${obsPath}/.zattrs`);
42
78
  let indexPath = `${obsPath}/${_index}`;
@@ -50,47 +86,44 @@ export default class SpatialDataTableSource extends AnnDataSource {
50
86
 
51
87
  indexPath = `${obsPath}/${instanceKey}`;
52
88
 
53
- if (this.obsIndex[indexPath]) {
54
- return this.obsIndex[indexPath];
89
+ if (indexPath in this.obsIndices) {
90
+ return this.obsIndices[indexPath];
55
91
  }
56
- this.obsIndex[indexPath] = this._loadColumn(indexPath);
57
- return this.obsIndex[indexPath];
92
+ this.obsIndices[indexPath] = this._loadColumn(indexPath);
93
+ return this.obsIndices[indexPath];
58
94
  }
59
95
 
60
96
  /**
61
97
  * Class method for loading the var index.
62
- * @returns {Promise} An promise for a zarr array containing the indices.
98
+ * @param {string|undefined} path
99
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
63
100
  */
64
- loadVarIndex(path = null) {
65
- if (!this.varIndex) {
66
- this.varIndex = {};
67
- }
101
+ loadVarIndex(path = undefined) {
68
102
  const varPath = getVarPath(path);
69
- if (this.varIndex[varPath]) {
70
- return this.varIndex[varPath];
103
+ if (varPath in this.varIndices) {
104
+ return this.varIndices[varPath];
71
105
  }
72
- this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`)
106
+ this.varIndices[varPath] = this.getJson(`${varPath}/.zattrs`)
73
107
  .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
74
- return this.varIndex[varPath];
108
+ return this.varIndices[varPath];
75
109
  }
76
110
 
77
111
  /**
78
112
  * Class method for loading the var alias.
79
- * @returns {Promise} An promise for a zarr array containing the aliased names.
113
+ * @param {string} varPath
114
+ * @param {string} matrixPath
115
+ * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
80
116
  */
81
117
  async loadVarAlias(varPath, matrixPath) {
82
- if (!this.varAlias) {
83
- this.varAlias = {};
84
- }
85
- if (this.varAlias[varPath]) {
86
- return this.varAlias[varPath];
118
+ if (varPath in this.varAliases) {
119
+ return this.varAliases[varPath];
87
120
  }
88
121
  const [varAliasData] = await this.loadVarColumns([varPath]);
89
- this.varAlias[varPath] = varAliasData;
122
+ this.varAliases[varPath] = /** @type {string[]} */ (varAliasData);
90
123
  const index = await this.loadVarIndex(matrixPath);
91
- this.varAlias[varPath] = this.varAlias[varPath].map(
124
+ this.varAliases[varPath] = this.varAliases[varPath].map(
92
125
  (val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]),
93
126
  );
94
- return this.varAlias[varPath];
127
+ return this.varAliases[varPath];
95
128
  }
96
129
  }