@vitessce/zarr 3.2.2 → 3.3.1

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 (98) hide show
  1. package/dist/blosc-0acfcf7e.js +975 -0
  2. package/dist/{deflate-f2b94bed.js → deflate-9cfe31b4.js} +1 -1
  3. package/dist/gzip-dd5ab7c8.js +28 -0
  4. package/dist/{index-11e344fb.js → index-2d09430a.js} +44013 -44627
  5. package/dist/index.js +16 -10
  6. package/dist/{jpeg-f5f84485.js → jpeg-e623e3f3.js} +1 -1
  7. package/dist/{lerc-2dbc6d98.js → lerc-3b89a300.js} +1 -1
  8. package/dist/lz4-abb4416a.js +919 -0
  9. package/dist/{lzw-88a53998.js → lzw-834edf30.js} +1 -1
  10. package/dist/{packbits-93df2294.js → packbits-37beb194.js} +1 -1
  11. package/dist/pako.esm-856454b6-c5c8cd15.js +4066 -0
  12. package/dist/{raw-53282bb2.js → raw-f349901d.js} +1 -1
  13. package/dist/{webimage-9f58dd5d.js → webimage-89dafa8c.js} +1 -1
  14. package/dist/zlib-cd823c38.js +28 -0
  15. package/dist/zstd-4072ca78.js +919 -0
  16. package/dist-tsc/AnnDataSource.d.ts +5 -0
  17. package/dist-tsc/AnnDataSource.d.ts.map +1 -1
  18. package/dist-tsc/AnnDataSource.js +69 -108
  19. package/dist-tsc/AnnDataSource.test.js +30 -10
  20. package/dist-tsc/MuDataSource.test.js +11 -4
  21. package/dist-tsc/SpatialDataShapesSource.d.ts +22 -0
  22. package/dist-tsc/SpatialDataShapesSource.d.ts.map +1 -0
  23. package/dist-tsc/SpatialDataShapesSource.js +88 -0
  24. package/dist-tsc/SpatialDataTableSource.d.ts +22 -0
  25. package/dist-tsc/SpatialDataTableSource.d.ts.map +1 -0
  26. package/dist-tsc/SpatialDataTableSource.js +83 -0
  27. package/dist-tsc/ZarrDataSource.d.ts +3 -3
  28. package/dist-tsc/ZarrDataSource.d.ts.map +1 -1
  29. package/dist-tsc/ZarrDataSource.js +16 -18
  30. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.test.js +14 -8
  31. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts +3 -5
  32. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts.map +1 -1
  33. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.js +22 -18
  34. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.test.js +39 -27
  35. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts.map +1 -1
  36. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.js +20 -5
  37. package/dist-tsc/index.d.ts +4 -1
  38. package/dist-tsc/index.js +4 -1
  39. package/dist-tsc/json-fixtures/anndata-0.7/anndata-csc.json +110 -0
  40. package/dist-tsc/json-fixtures/anndata-0.7/anndata-csr.json +110 -0
  41. package/dist-tsc/json-fixtures/anndata-0.7/anndata-dense.json +86 -0
  42. package/dist-tsc/json-fixtures/anndata-0.8/anndata-csc.json +174 -0
  43. package/dist-tsc/json-fixtures/anndata-0.8/anndata-csr.adata.json +174 -0
  44. package/dist-tsc/json-fixtures/anndata-0.8/anndata-dense.json +154 -0
  45. package/dist-tsc/json-fixtures/mudata-0.2/mudata-csc.json +554 -0
  46. package/dist-tsc/json-fixtures/mudata-0.2/mudata-csr.json +554 -0
  47. package/dist-tsc/json-fixtures/mudata-0.2/mudata-dense-updated.json +534 -0
  48. package/dist-tsc/json-fixtures/mudata-0.2/mudata-dense.json +534 -0
  49. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts +1 -1
  50. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts.map +1 -1
  51. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.js +6 -7
  52. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts.map +1 -1
  53. package/dist-tsc/ome-loaders/OmeZarrLoader.js +22 -12
  54. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts +6 -0
  55. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts.map +1 -0
  56. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.js +13 -0
  57. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts +4 -0
  58. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts.map +1 -0
  59. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.js +15 -0
  60. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts +10 -0
  61. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts.map +1 -0
  62. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.js +11 -0
  63. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts +13 -0
  64. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts.map +1 -0
  65. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.js +36 -0
  66. package/dist-tsc/spatialdata-loaders/index.d.ts +5 -0
  67. package/dist-tsc/spatialdata-loaders/index.d.ts.map +1 -0
  68. package/dist-tsc/spatialdata-loaders/index.js +4 -0
  69. package/package.json +10 -9
  70. package/src/AnnDataSource.js +77 -116
  71. package/src/AnnDataSource.test.js +31 -10
  72. package/src/MuDataSource.test.js +12 -4
  73. package/src/SpatialDataShapesSource.js +103 -0
  74. package/src/SpatialDataTableSource.js +96 -0
  75. package/src/ZarrDataSource.js +16 -17
  76. package/src/anndata-loaders/ObsEmbeddingAnndataLoader.test.js +17 -8
  77. package/src/anndata-loaders/ObsFeatureMatrixAnndataLoader.js +22 -18
  78. package/src/anndata-loaders/ObsFeatureMatrixAnndataLoader.test.js +102 -27
  79. package/src/anndata-loaders/ObsSegmentationsAnndataLoader.js +20 -5
  80. package/src/index.js +4 -1
  81. package/src/json-fixtures/README.md +18 -0
  82. package/src/json-fixtures/anndata-0.7/anndata-csc.json +110 -0
  83. package/src/json-fixtures/anndata-0.7/anndata-csr.json +110 -0
  84. package/src/json-fixtures/anndata-0.7/anndata-dense.json +86 -0
  85. package/src/json-fixtures/anndata-0.8/anndata-csc.json +174 -0
  86. package/src/json-fixtures/anndata-0.8/anndata-csr.adata.json +174 -0
  87. package/src/json-fixtures/anndata-0.8/anndata-dense.json +154 -0
  88. package/src/json-fixtures/mudata-0.2/mudata-csc.json +554 -0
  89. package/src/json-fixtures/mudata-0.2/mudata-csr.json +554 -0
  90. package/src/json-fixtures/mudata-0.2/mudata-dense-updated.json +534 -0
  91. package/src/json-fixtures/mudata-0.2/mudata-dense.json +534 -0
  92. package/src/matrix-loaders/MatrixZarrAsObsFeatureMatrix.js +6 -7
  93. package/src/ome-loaders/OmeZarrLoader.js +22 -13
  94. package/src/spatialdata-loaders/SpatialDataImageLoader.js +14 -0
  95. package/src/spatialdata-loaders/SpatialDataLabelsLoader.js +19 -0
  96. package/src/spatialdata-loaders/SpatialDataObsSetsLoader.js +12 -0
  97. package/src/spatialdata-loaders/SpatialDataObsSpotsLoader.js +44 -0
  98. package/src/spatialdata-loaders/index.js +4 -0
@@ -55,6 +55,11 @@ export default class AnnDataSource extends ZarrDataSource {
55
55
  */
56
56
  loadVarAlias(varPath: any): Promise<any>;
57
57
  varAlias: any;
58
+ _loadAttrs(path: any): Promise<any>;
59
+ _loadString(path: any): Promise<any>;
60
+ _loadStringArray(path: any): Promise<any[]>;
61
+ _loadElement(path: any): Promise<any>;
62
+ _loadDict(path: any, keys: any): Promise<{}>;
58
63
  }
59
64
  import ZarrDataSource from "./ZarrDataSource.js";
60
65
  //# sourceMappingURL=AnnDataSource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AnnDataSource.d.ts","sourceRoot":"","sources":["../src/AnnDataSource.js"],"names":[],"mappings":"AA6CA;;;GAGG;AACH;IACE,4BAIC;IAFC,4CAA4C;IAC5C,UADW,IAAI,MAAM,EAAE,QAAQ,MAAM,EAAE,CAAC,CAAA,CACf;IAG3B,yCAEC;IAED,yCAEC;IAED;;;;;;OAMG;IACH,oBAHW,MAAM,EAAE,gBA0BlB;IAED,uCAkCC;IAED;;;;OAIG;IACH,kBAHW,MAAM,gBAUhB;IAED;;;;;OAKG;IACH,yBAJW,MAAM,QACN,MAAM,EAAE,gBAkBlB;IAED;;;;;OAKG;IACH,6BAHW,MAAM,SAwDhB;IAED;;;OAGG;IACH,6BAMC;IAFC,qCAA+G;IAIjH;;;OAGG;IACH,6BAMC;IAFC,qCAA+G;IAIjH;;;OAGG;IACH,yCAUC;IAJC,cAEC;CAGJ"}
1
+ {"version":3,"file":"AnnDataSource.d.ts","sourceRoot":"","sources":["../src/AnnDataSource.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH;IACE,4BAIC;IAFC,4CAA4C;IAC5C,UADW,IAAI,MAAM,EAAE,QAAQ,MAAM,EAAE,CAAC,CAAA,CACf;IAG3B,yCAEC;IAED,yCAEC;IAED;;;;;;OAMG;IACH,oBAHW,MAAM,EAAE,gBA0BlB;IAED,uCAkCC;IAED;;;;OAIG;IACH,kBAHW,MAAM,gBAOhB;IAED;;;;;OAKG;IACH,yBAJW,MAAM,QACN,MAAM,EAAE,gBAclB;IAED;;;;;OAKG;IACH,6BAHW,MAAM,SAYhB;IAED;;;OAGG;IACH,6BAMC;IAFC,qCAA+G;IAIjH;;;OAGG;IACH,6BAMC;IAFC,qCAA+G;IAIjH;;;OAGG;IACH,yCAUC;IAJC,cAEC;IAIH,oCAEC;IAED,qCAWC;IAED,4CAOC;IAGD,sCASC;IAED,6CAYC;CACF"}
@@ -1,44 +1,7 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- import { openArray } from 'zarr';
3
- import { range } from 'lodash-es';
2
+ import { open as zarrOpen, get as zarrGet } from 'zarrita';
4
3
  import { dirname } from './utils.js';
5
4
  import ZarrDataSource from './ZarrDataSource.js';
6
- const readFloat32FromUint8 = (bytes) => {
7
- if (bytes.length !== 4) {
8
- throw new Error('readFloat32 only takes in length 4 byte buffers');
9
- }
10
- return new Int32Array(bytes.buffer)[0];
11
- };
12
- const HEADER_LENGTH = 4;
13
- /**
14
- * Method for decoding text arrays from zarr.
15
- * Largerly a port of https://github.com/zarr-developers/numcodecs/blob/2c1aff98e965c3c4747d9881d8b8d4aad91adb3a/numcodecs/vlen.pyx#L135-L178
16
- * @returns {string[]} An array of strings.
17
- */
18
- function parseVlenUtf8(buffer) {
19
- const decoder = new TextDecoder();
20
- let data = 0;
21
- const dataEnd = data + buffer.length;
22
- const length = readFloat32FromUint8(buffer.slice(data, HEADER_LENGTH));
23
- if (buffer.length < HEADER_LENGTH) {
24
- throw new Error('corrupt buffer, missing or truncated header');
25
- }
26
- data += HEADER_LENGTH;
27
- const output = new Array(length);
28
- for (let i = 0; i < length; i += 1) {
29
- if (data + 4 > dataEnd) {
30
- throw new Error('corrupt buffer, data seem truncated');
31
- }
32
- const l = readFloat32FromUint8(buffer.slice(data, data + 4));
33
- data += 4;
34
- if (data + l > dataEnd) {
35
- throw new Error('corrupt buffer, data seem truncated');
36
- }
37
- output[i] = decoder.decode(buffer.slice(data, data + l));
38
- data += l;
39
- }
40
- return output;
41
- }
42
5
  /**
43
6
  * A base AnnData loader which has all shared methods for more comlpex laoders,
44
7
  * like loading cell names and ids. It inherits from AbstractLoader.
@@ -87,32 +50,32 @@ export default class AnnDataSource extends ZarrDataSource {
87
50
  return Promise.all(promises);
88
51
  }
89
52
  async _loadColumn(path) {
90
- const { store } = this;
53
+ const { storeRoot } = this;
91
54
  const prefix = dirname(path);
92
55
  const { categories, 'encoding-type': encodingType } = await this.getJson(`${path}/.zattrs`);
93
56
  let categoriesValues;
94
57
  let codes;
95
58
  if (categories) {
96
- const { dtype } = await this.getJson(`/${prefix}/${categories}/.zarray`);
97
- if (dtype === '|O') {
59
+ const { dtype } = await zarrOpen(storeRoot.resolve(`/${prefix}/${categories}`));
60
+ if (dtype === 'v2:object') {
98
61
  categoriesValues = await this.getFlatArrDecompressed(`/${prefix}/${categories}`);
99
62
  }
100
63
  }
101
64
  else if (encodingType === 'categorical') {
102
- const { dtype } = await this.getJson(`/${path}/categories/.zarray`);
103
- if (dtype === '|O') {
65
+ const { dtype } = await zarrOpen(storeRoot.resolve(`/${path}/categories`));
66
+ if (dtype === 'v2:object') {
104
67
  categoriesValues = await this.getFlatArrDecompressed(`/${path}/categories`);
105
68
  }
106
69
  codes = `/${path}/codes`;
107
70
  }
108
71
  else {
109
- const { dtype } = await this.getJson(`/${path}/.zarray`);
110
- if (dtype === '|O') {
72
+ const { dtype } = await zarrOpen(storeRoot.resolve(`/${path}`));
73
+ if (dtype === 'v2:object') {
111
74
  return this.getFlatArrDecompressed(path);
112
75
  }
113
76
  }
114
- const arr = await openArray({ store, path: codes || path, mode: 'r' });
115
- const values = await arr.get();
77
+ const arr = await zarrOpen(storeRoot.resolve(codes || path), { kind: 'array' });
78
+ const values = await zarrGet(arr, [null]);
116
79
  const { data } = values;
117
80
  const mappedValues = Array.from(data).map(i => (!categoriesValues ? String(i) : categoriesValues[i]));
118
81
  return mappedValues;
@@ -123,12 +86,9 @@ export default class AnnDataSource extends ZarrDataSource {
123
86
  * @returns {Promise} A promise for a zarr array containing the data.
124
87
  */
125
88
  loadNumeric(path) {
126
- const { store } = this;
127
- return openArray({
128
- store,
129
- path,
130
- mode: 'r',
131
- }).then(arr => arr.get());
89
+ const { storeRoot } = this;
90
+ return zarrOpen(storeRoot.resolve(path), { kind: 'array' })
91
+ .then(arr => zarrGet(arr));
132
92
  }
133
93
  /**
134
94
  * Class method for loading specific columns of numeric arrays.
@@ -137,13 +97,9 @@ export default class AnnDataSource extends ZarrDataSource {
137
97
  * @returns {Promise} A promise for a zarr array containing the data.
138
98
  */
139
99
  loadNumericForDims(path, dims) {
140
- const { store } = this;
141
- const arr = openArray({
142
- store,
143
- path,
144
- mode: 'r',
145
- });
146
- return Promise.all(dims.map(dim => arr.then(loadedArr => loadedArr.get([null, dim])))).then(cols => ({
100
+ const { storeRoot } = this;
101
+ const arr = zarrOpen(storeRoot.resolve(path), { kind: 'array' });
102
+ return Promise.all(dims.map(dim => arr.then(loadedArr => zarrGet(loadedArr, [null, dim])))).then(cols => ({
147
103
  data: cols.map(col => col.data),
148
104
  shape: [dims.length, cols[0].shape[0]],
149
105
  }));
@@ -154,54 +110,15 @@ export default class AnnDataSource extends ZarrDataSource {
154
110
  * @param {string} path A path to a flat array location, like obs/_index
155
111
  * @returns {Array} The data from the zarr array.
156
112
  */
157
- getFlatArrDecompressed(path) {
158
- const { store } = this;
159
- return openArray({
160
- store,
161
- path,
162
- mode: 'r',
163
- }).then(async (z) => {
164
- let data;
165
- const parseAndMergeTextBytes = (dbytes) => {
166
- const text = parseVlenUtf8(dbytes);
167
- if (!data) {
168
- data = text;
169
- }
170
- else {
171
- data = data.concat(text);
172
- }
173
- };
174
- const mergeBytes = (dbytes) => {
175
- if (!data) {
176
- data = dbytes;
177
- }
178
- else {
179
- const tmp = new Uint8Array(dbytes.buffer.byteLength + data.buffer.byteLength);
180
- tmp.set(new Uint8Array(data.buffer), 0);
181
- tmp.set(dbytes, data.buffer.byteLength);
182
- data = tmp;
183
- }
184
- };
185
- const numRequests = Math.ceil(z.meta.shape[0] / z.meta.chunks[0]);
186
- const requests = range(numRequests).map(async (item) => store
187
- .getItem(`${z.keyPrefix}${String(item)}`)
188
- .then(buf => z.compressor.then(compressor => compressor.decode(buf))));
189
- const dbytesArr = await Promise.all(requests);
190
- dbytesArr.forEach((dbytes) => {
191
- // Use vlenutf-8 decoding if necessary and merge `data` as a normal array.
192
- if (Array.isArray(z.meta.filters)
193
- && z.meta.filters[0].id === 'vlen-utf8') {
194
- parseAndMergeTextBytes(dbytes);
195
- // Otherwise just merge the bytes as a typed array.
196
- }
197
- else {
198
- mergeBytes(dbytes);
199
- }
200
- });
201
- const { meta: { shape: [length], }, } = z;
202
- // truncate the filled in values
203
- return data.slice(0, length);
204
- });
113
+ async getFlatArrDecompressed(path) {
114
+ const { storeRoot } = this;
115
+ const arr = await zarrOpen(storeRoot.resolve(path), { kind: 'array' });
116
+ // Zarrita supports decoding vlen-utf8-encoded string arrays.
117
+ const data = await zarrGet(arr);
118
+ if (data.data?.[Symbol.iterator]) {
119
+ return Array.from(data.data);
120
+ }
121
+ return data.data;
205
122
  }
206
123
  /**
207
124
  * Class method for loading the obs index.
@@ -238,4 +155,48 @@ export default class AnnDataSource extends ZarrDataSource {
238
155
  this.varAlias = this.varAlias.map((val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]));
239
156
  return this.varAlias;
240
157
  }
158
+ async _loadAttrs(path) {
159
+ return this.getJson(`${path}/.zattrs`);
160
+ }
161
+ async _loadString(path) {
162
+ const { storeRoot } = this;
163
+ const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
164
+ if (encodingType === 'string' && encodingVersion === '0.2.0') {
165
+ const arr = await zarrOpen(storeRoot.resolve(path), { kind: 'array' });
166
+ // TODO: Use zarrGet once it supports zero-dimensional array access.
167
+ const { data } = await arr.getChunk([]);
168
+ return data.get(0);
169
+ }
170
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadString`);
171
+ }
172
+ async _loadStringArray(path) {
173
+ const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
174
+ if (encodingType === 'string-array' && encodingVersion === '0.2.0') {
175
+ return this.getFlatArrDecompressed(path);
176
+ }
177
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadStringArray`);
178
+ }
179
+ async _loadElement(path) {
180
+ const { 'encoding-type': encodingType } = await this._loadAttrs(path);
181
+ if (encodingType === 'string') {
182
+ return this._loadString(path);
183
+ }
184
+ if (encodingType === 'string-array') {
185
+ return this._loadStringArray(path);
186
+ }
187
+ // TODO: support more elements
188
+ return null;
189
+ }
190
+ async _loadDict(path, keys) {
191
+ const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
192
+ if (encodingType === 'dict' && encodingVersion === '0.1.0') {
193
+ const result = {};
194
+ await Promise.all(keys.map(async (key) => {
195
+ const val = await this._loadElement(`${path}/${key}`);
196
+ result[key] = val;
197
+ }));
198
+ return result;
199
+ }
200
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadDict`);
201
+ }
241
202
  }
@@ -1,24 +1,36 @@
1
+ /* eslint-disable camelcase */
1
2
  import { describe, it, expect } from 'vitest';
3
+ import { createStoreFromMapContents } from '@vitessce/zarr-utils';
2
4
  import AnnDataSource from './AnnDataSource.js';
5
+ import anndata_0_7_DenseFixture from './json-fixtures/anndata-0.7/anndata-dense.json';
6
+ import anndata_0_8_DenseFixture from './json-fixtures/anndata-0.8/anndata-dense.json';
3
7
  describe('sources/AnnDataSource', () => {
4
8
  describe('AnnData v0.7', () => {
5
9
  it('getJson returns json', async () => {
6
10
  const dataSource = new AnnDataSource({
7
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
11
+ url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
12
+ store: createStoreFromMapContents(anndata_0_7_DenseFixture),
8
13
  });
9
- const zGroup = await dataSource.getJson('.zgroup');
10
- expect(zGroup.zarr_format).toEqual(2);
14
+ const zAttrs = await dataSource.getJson('obs/.zattrs');
15
+ expect(Object.keys(zAttrs)).toEqual([
16
+ '_index',
17
+ 'column-order',
18
+ 'encoding-type',
19
+ 'encoding-version',
20
+ ]);
11
21
  });
12
22
  it('loadObsColumns returns ids for location in store', async () => {
13
23
  const dataSource = new AnnDataSource({
14
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
24
+ url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
25
+ store: createStoreFromMapContents(anndata_0_7_DenseFixture),
15
26
  });
16
27
  const ids = await dataSource.loadObsColumns(['obs/leiden']);
17
28
  expect(ids).toEqual([['1', '1', '2']]);
18
29
  });
19
30
  it('loadObsIndex returns names', async () => {
20
31
  const dataSource = new AnnDataSource({
21
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
32
+ url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
33
+ store: createStoreFromMapContents(anndata_0_7_DenseFixture),
22
34
  });
23
35
  const names = await dataSource.loadObsIndex();
24
36
  expect(names).toEqual(['CTG', 'GCA', 'CTG']);
@@ -27,21 +39,29 @@ describe('sources/AnnDataSource', () => {
27
39
  describe('AnnData v0.8', () => {
28
40
  it('getJson returns json', async () => {
29
41
  const dataSource = new AnnDataSource({
30
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
42
+ url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
43
+ store: createStoreFromMapContents(anndata_0_8_DenseFixture),
31
44
  });
32
- const zGroup = await dataSource.getJson('.zgroup');
33
- expect(zGroup.zarr_format).toEqual(2);
45
+ const zAttrs = await dataSource.getJson('obs/.zattrs');
46
+ expect(Object.keys(zAttrs)).toEqual([
47
+ '_index',
48
+ 'column-order',
49
+ 'encoding-type',
50
+ 'encoding-version',
51
+ ]);
34
52
  });
35
53
  it('loadObsColumns returns ids for location in store', async () => {
36
54
  const dataSource = new AnnDataSource({
37
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
55
+ url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
56
+ store: createStoreFromMapContents(anndata_0_8_DenseFixture),
38
57
  });
39
58
  const ids = await dataSource.loadObsColumns(['obs/leiden']);
40
59
  expect(ids).toEqual([['1', '1', '2']]);
41
60
  });
42
61
  it('loadObsIndex returns names', async () => {
43
62
  const dataSource = new AnnDataSource({
44
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
63
+ url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
64
+ store: createStoreFromMapContents(anndata_0_8_DenseFixture),
45
65
  });
46
66
  const names = await dataSource.loadObsIndex();
47
67
  expect(names).toEqual(['CTG', 'GCA', 'CTG']);
@@ -1,31 +1,38 @@
1
+ /* eslint-disable camelcase */
1
2
  import { describe, it, expect } from 'vitest';
2
3
  import { range } from 'lodash-es';
4
+ import { createStoreFromMapContents } from '@vitessce/zarr-utils';
3
5
  import MuDataSource, { getObsPath, getVarPath } from './MuDataSource.js';
6
+ import mudata_0_2_DenseFixture from './json-fixtures/mudata-0.2/mudata-dense.json';
4
7
  describe('sources/MuDataSource', () => {
5
8
  it('loadObsColumns returns ids for location in store, with joint-modality path', async () => {
6
9
  const dataSource = new MuDataSource({
7
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
10
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
11
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
8
12
  });
9
13
  const ids = await dataSource.loadObsColumns(['obs/leiden']);
10
14
  expect(ids).toEqual([['3', '2', '3', '1', '1']]);
11
15
  });
12
16
  it('loadObsColumns returns ids for location in store, with modality-specific path', async () => {
13
17
  const dataSource = new MuDataSource({
14
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
18
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
19
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
15
20
  });
16
21
  const ids = await dataSource.loadObsColumns(['mod/rna/obs/leiden']);
17
22
  expect(ids).toEqual([['1', '1', '2', '2']]);
18
23
  });
19
24
  it('loadVarIndex supports modality-specific paths', async () => {
20
25
  const dataSource = new MuDataSource({
21
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
26
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
27
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
22
28
  });
23
29
  const names = await dataSource.loadVarIndex('mod/atac/X');
24
30
  expect(names).toEqual(range(15).map(i => `peak_${i}`));
25
31
  });
26
32
  it('loadObsIndex returns names', async () => {
27
33
  const dataSource = new MuDataSource({
28
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
34
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
35
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
29
36
  });
30
37
  const names = await dataSource.loadObsIndex('mod/atac/X');
31
38
  expect(names).toEqual(['CTG', 'GCA', 'CTT', 'GGG']);
@@ -0,0 +1,22 @@
1
+ export function getIndexPath(arrPath: any): string;
2
+ export function getVarPath(arrPath: any): string;
3
+ export default class SpatialDataShapesSource extends AnnDataSource {
4
+ loadSpatialDataAttrs(tablePath: any): Promise<{}>;
5
+ /**
6
+ * Class method for loading the obs index.
7
+ * @returns {Promise} An promise for a zarr array containing the indices.
8
+ */
9
+ loadObsIndex(path?: null, tablePath?: null): Promise<any>;
10
+ /**
11
+ * Class method for loading the var index.
12
+ * @returns {Promise} An promise for a zarr array containing the indices.
13
+ */
14
+ loadVarIndex(path?: null): Promise<any>;
15
+ /**
16
+ * Class method for loading the var alias.
17
+ * @returns {Promise} An promise for a zarr array containing the aliased names.
18
+ */
19
+ loadVarAlias(varPath: any, matrixPath: any): Promise<any>;
20
+ }
21
+ import AnnDataSource from "./AnnDataSource.js";
22
+ //# sourceMappingURL=SpatialDataShapesSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialDataShapesSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataShapesSource.js"],"names":[],"mappings":"AAgBA,mDAEC;AAED,iDAEC;AAGD;IACE,kDAEC;IAED;;;OAGG;IACH,0DA8BC;IAED;;;OAGG;IACH,wCAWC;IAED;;;OAGG;IACH,0DAcC;CACF"}
@@ -0,0 +1,88 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import AnnDataSource from './AnnDataSource.js';
3
+ // If the array path starts with table/something/rest
4
+ // capture table/something.
5
+ const regex = /^shapes\/([^/]*)\/(.*)$/;
6
+ function getShapesPrefix(arrPath) {
7
+ if (arrPath) {
8
+ const matches = arrPath.match(regex);
9
+ if (matches && matches.length === 3) {
10
+ return `shapes/${matches[1]}/`;
11
+ }
12
+ }
13
+ return '';
14
+ }
15
+ export function getIndexPath(arrPath) {
16
+ return `${getShapesPrefix(arrPath)}Index`;
17
+ }
18
+ export function getVarPath(arrPath) {
19
+ return `${getShapesPrefix(arrPath)}var`;
20
+ }
21
+ export default class SpatialDataShapesSource extends AnnDataSource {
22
+ async loadSpatialDataAttrs(tablePath) {
23
+ return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
24
+ }
25
+ /**
26
+ * Class method for loading the obs index.
27
+ * @returns {Promise} An promise for a zarr array containing the indices.
28
+ */
29
+ async loadObsIndex(path = null, tablePath = null) {
30
+ if (!this.obsIndex) {
31
+ this.obsIndex = {};
32
+ }
33
+ let indexPath = getIndexPath(path);
34
+ if (tablePath) {
35
+ // TODO: given a path to the shapes,
36
+ // is there a better way to know which table annotates it
37
+ // (without the manually-specified table path)?
38
+ // Reference: https://github.com/scverse/spatialdata/issues/298#issuecomment-1718161329
39
+ const obsPath = `${tablePath}/obs`;
40
+ const { _index } = await this.getJson(`${obsPath}/.zattrs`);
41
+ indexPath = `${obsPath}/${_index}`;
42
+ const { instance_key: instanceKey,
43
+ // TODO: filter table index by region and element type.
44
+ // region_key: regionKey,
45
+ // region,
46
+ } = await this.loadSpatialDataAttrs(tablePath);
47
+ indexPath = `${obsPath}/${instanceKey}`;
48
+ }
49
+ if (this.obsIndex[indexPath]) {
50
+ return this.obsIndex[indexPath];
51
+ }
52
+ this.obsIndex[indexPath] = this._loadColumn(indexPath);
53
+ return this.obsIndex[indexPath];
54
+ }
55
+ /**
56
+ * Class method for loading the var index.
57
+ * @returns {Promise} An promise for a zarr array containing the indices.
58
+ */
59
+ loadVarIndex(path = null) {
60
+ if (!this.varIndex) {
61
+ this.varIndex = {};
62
+ }
63
+ const varPath = getVarPath(path);
64
+ if (this.varIndex[varPath]) {
65
+ return this.varIndex[varPath];
66
+ }
67
+ this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`)
68
+ .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
69
+ return this.varIndex[varPath];
70
+ }
71
+ /**
72
+ * Class method for loading the var alias.
73
+ * @returns {Promise} An promise for a zarr array containing the aliased names.
74
+ */
75
+ async loadVarAlias(varPath, matrixPath) {
76
+ if (!this.varAlias) {
77
+ this.varAlias = {};
78
+ }
79
+ if (this.varAlias[varPath]) {
80
+ return this.varAlias[varPath];
81
+ }
82
+ const [varAliasData] = await this.loadVarColumns([varPath]);
83
+ this.varAlias[varPath] = varAliasData;
84
+ const index = await this.loadVarIndex(matrixPath);
85
+ this.varAlias[varPath] = this.varAlias[varPath].map((val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]));
86
+ return this.varAlias[varPath];
87
+ }
88
+ }
@@ -0,0 +1,22 @@
1
+ export function getObsPath(arrPath: any): string;
2
+ export function getVarPath(arrPath: any): string;
3
+ export default class SpatialDataTableSource extends AnnDataSource {
4
+ loadSpatialDataAttrs(tablePath: any): Promise<{}>;
5
+ /**
6
+ * Class method for loading the obs index.
7
+ * @returns {Promise} An promise for a zarr array containing the indices.
8
+ */
9
+ loadObsIndex(path?: null): Promise<any>;
10
+ /**
11
+ * Class method for loading the var index.
12
+ * @returns {Promise} An promise for a zarr array containing the indices.
13
+ */
14
+ loadVarIndex(path?: null): Promise<any>;
15
+ /**
16
+ * Class method for loading the var alias.
17
+ * @returns {Promise} An promise for a zarr array containing the aliased names.
18
+ */
19
+ loadVarAlias(varPath: any, matrixPath: any): Promise<any>;
20
+ }
21
+ import AnnDataSource from "./AnnDataSource.js";
22
+ //# sourceMappingURL=SpatialDataTableSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialDataTableSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataTableSource.js"],"names":[],"mappings":"AAkBA,iDAEC;AAED,iDAEC;AAED;IACE,kDAEC;IAED;;;OAGG;IACH,wCAsBC;IAED;;;OAGG;IACH,wCAWC;IAED;;;OAGG;IACH,0DAcC;CACF"}
@@ -0,0 +1,83 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import AnnDataSource from './AnnDataSource.js';
3
+ // If the array path starts with table/something/rest
4
+ // capture table/something.
5
+ const regex = /^table\/([^/]*)\/(.*)$/;
6
+ function getTablePrefix(arrPath) {
7
+ if (arrPath) {
8
+ const matches = arrPath.match(regex);
9
+ if (matches && matches.length === 3) {
10
+ return `table/${matches[1]}/`;
11
+ }
12
+ }
13
+ // TODO: what to do here when there are multiple tables?
14
+ // ObsSetsAnndataLoader will need to pass a path to loadObsIndex().
15
+ return 'table/table/';
16
+ }
17
+ export function getObsPath(arrPath) {
18
+ return `${getTablePrefix(arrPath)}obs`;
19
+ }
20
+ export function getVarPath(arrPath) {
21
+ return `${getTablePrefix(arrPath)}var`;
22
+ }
23
+ export default class SpatialDataTableSource extends AnnDataSource {
24
+ async loadSpatialDataAttrs(tablePath) {
25
+ return this._loadDict(`${tablePath}uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
26
+ }
27
+ /**
28
+ * Class method for loading the obs index.
29
+ * @returns {Promise} An promise for a zarr array containing the indices.
30
+ */
31
+ async loadObsIndex(path = null) {
32
+ if (!this.obsIndex) {
33
+ this.obsIndex = {};
34
+ }
35
+ const obsPath = getObsPath(path);
36
+ const { _index } = await this.getJson(`${obsPath}/.zattrs`);
37
+ let indexPath = `${obsPath}/${_index}`;
38
+ const { instance_key: instanceKey,
39
+ // TODO: filter table index by region and element type.
40
+ // region_key: regionKey,
41
+ // region,
42
+ } = await this.loadSpatialDataAttrs(getTablePrefix(path));
43
+ indexPath = `${obsPath}/${instanceKey}`;
44
+ if (this.obsIndex[indexPath]) {
45
+ return this.obsIndex[indexPath];
46
+ }
47
+ this.obsIndex[indexPath] = this._loadColumn(indexPath);
48
+ return this.obsIndex[indexPath];
49
+ }
50
+ /**
51
+ * Class method for loading the var index.
52
+ * @returns {Promise} An promise for a zarr array containing the indices.
53
+ */
54
+ loadVarIndex(path = null) {
55
+ if (!this.varIndex) {
56
+ this.varIndex = {};
57
+ }
58
+ const varPath = getVarPath(path);
59
+ if (this.varIndex[varPath]) {
60
+ return this.varIndex[varPath];
61
+ }
62
+ this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`)
63
+ .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
64
+ return this.varIndex[varPath];
65
+ }
66
+ /**
67
+ * Class method for loading the var alias.
68
+ * @returns {Promise} An promise for a zarr array containing the aliased names.
69
+ */
70
+ async loadVarAlias(varPath, matrixPath) {
71
+ if (!this.varAlias) {
72
+ this.varAlias = {};
73
+ }
74
+ if (this.varAlias[varPath]) {
75
+ return this.varAlias[varPath];
76
+ }
77
+ const [varAliasData] = await this.loadVarColumns([varPath]);
78
+ this.varAlias[varPath] = varAliasData;
79
+ const index = await this.loadVarIndex(matrixPath);
80
+ this.varAlias[varPath] = this.varAlias[varPath].map((val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]));
81
+ return this.varAlias[varPath];
82
+ }
83
+ }
@@ -3,11 +3,12 @@
3
3
  * and a stub for the required load() method.
4
4
  */
5
5
  export default class ZarrDataSource {
6
- constructor({ url, requestInit }: {
6
+ constructor({ url, requestInit, store }: {
7
7
  url: any;
8
8
  requestInit: any;
9
+ store: any;
9
10
  });
10
- store: HTTPStore;
11
+ storeRoot: any;
11
12
  /**
12
13
  * Class method for decoding json from the store.
13
14
  * @param {string} key A path to the item.
@@ -17,5 +18,4 @@ export default class ZarrDataSource {
17
18
  */
18
19
  getJson(key: string): Promise<any>;
19
20
  }
20
- import { HTTPStore } from "zarr/types/storage/httpStore";
21
21
  //# sourceMappingURL=ZarrDataSource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ZarrDataSource.d.ts","sourceRoot":"","sources":["../src/ZarrDataSource.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IACE;;;OAOC;IAHC,iBAEE;IAGJ;;;;;;OAMG;IACH,aALW,MAAM,gBAgBhB;CACF"}
1
+ {"version":3,"file":"ZarrDataSource.d.ts","sourceRoot":"","sources":["../src/ZarrDataSource.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH;IACE;;;;OAOC;IAJG,eAAgC;IAMpC;;;;;;OAMG;IACH,aALW,MAAM,gBAchB;CACF"}