@vitessce/zarr 3.2.2 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/blosc-0acfcf7e.js +975 -0
  2. package/dist/{deflate-f2b94bed.js → deflate-cbfc7dda.js} +1 -1
  3. package/dist/gzip-dd5ab7c8.js +28 -0
  4. package/dist/{index-11e344fb.js → index-f6c69b65.js} +43900 -44563
  5. package/dist/index.js +16 -10
  6. package/dist/{jpeg-f5f84485.js → jpeg-6aa85133.js} +1 -1
  7. package/dist/{lerc-2dbc6d98.js → lerc-b3d50536.js} +1 -1
  8. package/dist/lz4-abb4416a.js +919 -0
  9. package/dist/{lzw-88a53998.js → lzw-5e6de0df.js} +1 -1
  10. package/dist/{packbits-93df2294.js → packbits-7e23e08a.js} +1 -1
  11. package/dist/pako.esm-856454b6-c5c8cd15.js +4066 -0
  12. package/dist/{raw-53282bb2.js → raw-4e6560dc.js} +1 -1
  13. package/dist/{webimage-9f58dd5d.js → webimage-6b964081.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
@@ -0,0 +1,13 @@
1
+ import { OmeZarrLoader } from '../ome-loaders/index.js';
2
+ export default class SpatialDataImageLoader extends OmeZarrLoader {
3
+ constructor(dataSource, params) {
4
+ // Re-use the OmeZarrLoader, but change the url to point
5
+ // to the specified OME-NGFF image within the SpatialData store.
6
+ const newParams = {
7
+ ...params,
8
+ url: `${params.url}/${params.options.path}`,
9
+ };
10
+ super(dataSource, newParams);
11
+ this.dataSource = dataSource;
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ export default class SpatialDataLabelsLoader extends SpatialDataImageLoader {
2
+ }
3
+ import SpatialDataImageLoader from "./SpatialDataImageLoader.js";
4
+ //# sourceMappingURL=SpatialDataLabelsLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialDataLabelsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataLabelsLoader.js"],"names":[],"mappings":"AAKA;CAaC"}
@@ -0,0 +1,15 @@
1
+ import { AbstractLoaderError, } from '@vitessce/vit-s';
2
+ import SpatialDataImageLoader from './SpatialDataImageLoader.js';
3
+ export default class SpatialDataLabelsLoader extends SpatialDataImageLoader {
4
+ async load() {
5
+ const result = await super.load();
6
+ if (result instanceof AbstractLoaderError) {
7
+ return Promise.reject(result);
8
+ }
9
+ result.data = {
10
+ obsSegmentations: result.data.image,
11
+ obsSegmentationsType: 'bitmask',
12
+ };
13
+ return Promise.resolve(result);
14
+ }
15
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Loader for embedding arrays located in anndata.zarr stores.
3
+ */
4
+ export default class SpatialDataObsSetsLoader extends ObsSetsAnndataLoader {
5
+ constructor(dataSource: any, params: any);
6
+ region: any;
7
+ options: any;
8
+ }
9
+ import ObsSetsAnndataLoader from "../anndata-loaders/ObsSetsAnndataLoader.js";
10
+ //# sourceMappingURL=SpatialDataObsSetsLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialDataObsSetsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataObsSetsLoader.js"],"names":[],"mappings":"AAEA;;KAEK;AACL;IACE,0CAIC;IAFC,YAAiC;IACjC,aAAmC;CAEtC"}
@@ -0,0 +1,11 @@
1
+ import ObsSetsAnndataLoader from '../anndata-loaders/ObsSetsAnndataLoader.js';
2
+ /**
3
+ * Loader for embedding arrays located in anndata.zarr stores.
4
+ */
5
+ export default class SpatialDataObsSetsLoader extends ObsSetsAnndataLoader {
6
+ constructor(dataSource, params) {
7
+ super(dataSource, params);
8
+ this.region = this.options.region;
9
+ this.options = this.options.obsSets;
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Loader for embedding arrays located in anndata.zarr stores.
3
+ */
4
+ export default class SpatialDataObsSpotsLoader {
5
+ /**
6
+ * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
7
+ * @returns {Promise} A promise for an array of columns.
8
+ */
9
+ loadSpots(): Promise<any>;
10
+ locations: any;
11
+ load(): Promise<any>;
12
+ }
13
+ //# sourceMappingURL=SpatialDataObsSpotsLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialDataObsSpotsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataObsSpotsLoader.js"],"names":[],"mappings":"AAQA;;KAEK;AACL;IACE;;;SAGK;IACL,0BAWC;IALG,eAA8E;IAOlF,qBAaC;CACF"}
@@ -0,0 +1,36 @@
1
+ import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError, } from '@vitessce/vit-s';
2
+ function getCoordsPath(path) {
3
+ return `${path}/coords`;
4
+ }
5
+ /**
6
+ * Loader for embedding arrays located in anndata.zarr stores.
7
+ */
8
+ export default class SpatialDataObsSpotsLoader extends AbstractTwoStepLoader {
9
+ /**
10
+ * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
11
+ * @returns {Promise} A promise for an array of columns.
12
+ */
13
+ loadSpots() {
14
+ const { path, dims = [0, 1] } = this.options;
15
+ if (this.locations) {
16
+ return this.locations;
17
+ }
18
+ if (!this.locations) {
19
+ this.locations = this.dataSource.loadNumericForDims(getCoordsPath(path), dims);
20
+ return this.locations;
21
+ }
22
+ this.locations = Promise.resolve(null);
23
+ return this.locations;
24
+ }
25
+ async load() {
26
+ const { path, tablePath } = this.options;
27
+ const superResult = await super.load().catch(reason => Promise.resolve(reason));
28
+ if (superResult instanceof AbstractLoaderError) {
29
+ return Promise.reject(superResult);
30
+ }
31
+ return Promise.all([
32
+ this.dataSource.loadObsIndex(getCoordsPath(path), tablePath),
33
+ this.loadSpots(),
34
+ ]).then(([obsIndex, obsSpots]) => Promise.resolve(new LoaderResult({ obsIndex, obsSpots }, null)));
35
+ }
36
+ }
@@ -0,0 +1,5 @@
1
+ export { default as SpatialDataImageLoader } from "./SpatialDataImageLoader.js";
2
+ export { default as SpatialDataLabelsLoader } from "./SpatialDataLabelsLoader.js";
3
+ export { default as SpatialDataObsSpotsLoader } from "./SpatialDataObsSpotsLoader.js";
4
+ export { default as SpatialDataObsSetsLoader } from "./SpatialDataObsSetsLoader.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export { default as SpatialDataImageLoader } from './SpatialDataImageLoader.js';
2
+ export { default as SpatialDataLabelsLoader } from './SpatialDataLabelsLoader.js';
3
+ export { default as SpatialDataObsSpotsLoader } from './SpatialDataObsSpotsLoader.js';
4
+ export { default as SpatialDataObsSetsLoader } from './SpatialDataObsSetsLoader.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/zarr",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -18,14 +18,15 @@
18
18
  "dependencies": {
19
19
  "d3-array": "^2.4.0",
20
20
  "lodash-es": "^4.17.21",
21
- "zarr": "0.5.1",
22
- "@vitessce/constants-internal": "3.2.2",
23
- "@vitessce/gl": "3.2.2",
24
- "@vitessce/sets-utils": "3.2.2",
25
- "@vitessce/spatial-utils": "3.2.2",
26
- "@vitessce/image-utils": "3.2.2",
27
- "@vitessce/utils": "3.2.2",
28
- "@vitessce/vit-s": "3.2.2"
21
+ "zarrita": "0.4.0-next.4",
22
+ "@vitessce/constants-internal": "3.3.0",
23
+ "@vitessce/gl": "3.3.0",
24
+ "@vitessce/sets-utils": "3.3.0",
25
+ "@vitessce/spatial-utils": "3.3.0",
26
+ "@vitessce/image-utils": "3.3.0",
27
+ "@vitessce/utils": "3.3.0",
28
+ "@vitessce/vit-s": "3.3.0",
29
+ "@vitessce/zarr-utils": "3.3.0"
29
30
  },
30
31
  "scripts": {
31
32
  "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
@@ -1,48 +1,8 @@
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
5
 
7
- const readFloat32FromUint8 = (bytes) => {
8
- if (bytes.length !== 4) {
9
- throw new Error('readFloat32 only takes in length 4 byte buffers');
10
- }
11
- return new Int32Array(bytes.buffer)[0];
12
- };
13
-
14
- const HEADER_LENGTH = 4;
15
-
16
- /**
17
- * Method for decoding text arrays from zarr.
18
- * Largerly a port of https://github.com/zarr-developers/numcodecs/blob/2c1aff98e965c3c4747d9881d8b8d4aad91adb3a/numcodecs/vlen.pyx#L135-L178
19
- * @returns {string[]} An array of strings.
20
- */
21
- function parseVlenUtf8(buffer) {
22
- const decoder = new TextDecoder();
23
- let data = 0;
24
- const dataEnd = data + buffer.length;
25
- const length = readFloat32FromUint8(buffer.slice(data, HEADER_LENGTH));
26
- if (buffer.length < HEADER_LENGTH) {
27
- throw new Error('corrupt buffer, missing or truncated header');
28
- }
29
- data += HEADER_LENGTH;
30
- const output = new Array(length);
31
- for (let i = 0; i < length; i += 1) {
32
- if (data + 4 > dataEnd) {
33
- throw new Error('corrupt buffer, data seem truncated');
34
- }
35
- const l = readFloat32FromUint8(buffer.slice(data, data + 4));
36
- data += 4;
37
- if (data + l > dataEnd) {
38
- throw new Error('corrupt buffer, data seem truncated');
39
- }
40
- output[i] = decoder.decode(buffer.slice(data, data + l));
41
- data += l;
42
- }
43
- return output;
44
- }
45
-
46
6
  /**
47
7
  * A base AnnData loader which has all shared methods for more comlpex laoders,
48
8
  * like loading cell names and ids. It inherits from AbstractLoader.
@@ -95,34 +55,34 @@ export default class AnnDataSource extends ZarrDataSource {
95
55
  }
96
56
 
97
57
  async _loadColumn(path) {
98
- const { store } = this;
58
+ const { storeRoot } = this;
99
59
  const prefix = dirname(path);
100
60
  const { categories, 'encoding-type': encodingType } = await this.getJson(`${path}/.zattrs`);
101
61
  let categoriesValues;
102
62
  let codes;
103
63
  if (categories) {
104
- const { dtype } = await this.getJson(`/${prefix}/${categories}/.zarray`);
105
- if (dtype === '|O') {
64
+ const { dtype } = await zarrOpen(storeRoot.resolve(`/${prefix}/${categories}`));
65
+ if (dtype === 'v2:object') {
106
66
  categoriesValues = await this.getFlatArrDecompressed(
107
67
  `/${prefix}/${categories}`,
108
68
  );
109
69
  }
110
70
  } else if (encodingType === 'categorical') {
111
- const { dtype } = await this.getJson(`/${path}/categories/.zarray`);
112
- if (dtype === '|O') {
71
+ const { dtype } = await zarrOpen(storeRoot.resolve(`/${path}/categories`));
72
+ if (dtype === 'v2:object') {
113
73
  categoriesValues = await this.getFlatArrDecompressed(
114
74
  `/${path}/categories`,
115
75
  );
116
76
  }
117
77
  codes = `/${path}/codes`;
118
78
  } else {
119
- const { dtype } = await this.getJson(`/${path}/.zarray`);
120
- if (dtype === '|O') {
79
+ const { dtype } = await zarrOpen(storeRoot.resolve(`/${path}`));
80
+ if (dtype === 'v2:object') {
121
81
  return this.getFlatArrDecompressed(path);
122
82
  }
123
83
  }
124
- const arr = await openArray({ store, path: codes || path, mode: 'r' });
125
- const values = await arr.get();
84
+ const arr = await zarrOpen(storeRoot.resolve(codes || path), { kind: 'array' });
85
+ const values = await zarrGet(arr, [null]);
126
86
  const { data } = values;
127
87
  const mappedValues = Array.from(data).map(
128
88
  i => (!categoriesValues ? String(i) : categoriesValues[i]),
@@ -136,12 +96,9 @@ export default class AnnDataSource extends ZarrDataSource {
136
96
  * @returns {Promise} A promise for a zarr array containing the data.
137
97
  */
138
98
  loadNumeric(path) {
139
- const { store } = this;
140
- return openArray({
141
- store,
142
- path,
143
- mode: 'r',
144
- }).then(arr => arr.get());
99
+ const { storeRoot } = this;
100
+ return zarrOpen(storeRoot.resolve(path), { kind: 'array' })
101
+ .then(arr => zarrGet(arr));
145
102
  }
146
103
 
147
104
  /**
@@ -151,15 +108,11 @@ export default class AnnDataSource extends ZarrDataSource {
151
108
  * @returns {Promise} A promise for a zarr array containing the data.
152
109
  */
153
110
  loadNumericForDims(path, dims) {
154
- const { store } = this;
155
- const arr = openArray({
156
- store,
157
- path,
158
- mode: 'r',
159
- });
111
+ const { storeRoot } = this;
112
+ const arr = zarrOpen(storeRoot.resolve(path), { kind: 'array' });
160
113
  return Promise.all(
161
114
  dims.map(dim => arr.then(
162
- loadedArr => loadedArr.get([null, dim]),
115
+ loadedArr => zarrGet(loadedArr, [null, dim]),
163
116
  )),
164
117
  ).then(cols => ({
165
118
  data: cols.map(col => col.data),
@@ -173,59 +126,15 @@ export default class AnnDataSource extends ZarrDataSource {
173
126
  * @param {string} path A path to a flat array location, like obs/_index
174
127
  * @returns {Array} The data from the zarr array.
175
128
  */
176
- getFlatArrDecompressed(path) {
177
- const { store } = this;
178
- return openArray({
179
- store,
180
- path,
181
- mode: 'r',
182
- }).then(async (z) => {
183
- let data;
184
- const parseAndMergeTextBytes = (dbytes) => {
185
- const text = parseVlenUtf8(dbytes);
186
- if (!data) {
187
- data = text;
188
- } else {
189
- data = data.concat(text);
190
- }
191
- };
192
- const mergeBytes = (dbytes) => {
193
- if (!data) {
194
- data = dbytes;
195
- } else {
196
- const tmp = new Uint8Array(
197
- dbytes.buffer.byteLength + data.buffer.byteLength,
198
- );
199
- tmp.set(new Uint8Array(data.buffer), 0);
200
- tmp.set(dbytes, data.buffer.byteLength);
201
- data = tmp;
202
- }
203
- };
204
- const numRequests = Math.ceil(z.meta.shape[0] / z.meta.chunks[0]);
205
- const requests = range(numRequests).map(async item => store
206
- .getItem(`${z.keyPrefix}${String(item)}`)
207
- .then(buf => z.compressor.then(compressor => compressor.decode(buf))));
208
- const dbytesArr = await Promise.all(requests);
209
- dbytesArr.forEach((dbytes) => {
210
- // Use vlenutf-8 decoding if necessary and merge `data` as a normal array.
211
- if (
212
- Array.isArray(z.meta.filters)
213
- && z.meta.filters[0].id === 'vlen-utf8'
214
- ) {
215
- parseAndMergeTextBytes(dbytes);
216
- // Otherwise just merge the bytes as a typed array.
217
- } else {
218
- mergeBytes(dbytes);
219
- }
220
- });
221
- const {
222
- meta: {
223
- shape: [length],
224
- },
225
- } = z;
226
- // truncate the filled in values
227
- return data.slice(0, length);
228
- });
129
+ async getFlatArrDecompressed(path) {
130
+ const { storeRoot } = this;
131
+ const arr = await zarrOpen(storeRoot.resolve(path), { kind: 'array' });
132
+ // Zarrita supports decoding vlen-utf8-encoded string arrays.
133
+ const data = await zarrGet(arr);
134
+ if (data.data?.[Symbol.iterator]) {
135
+ return Array.from(data.data);
136
+ }
137
+ return data.data;
229
138
  }
230
139
 
231
140
  /**
@@ -267,4 +176,56 @@ export default class AnnDataSource extends ZarrDataSource {
267
176
  );
268
177
  return this.varAlias;
269
178
  }
179
+
180
+ async _loadAttrs(path) {
181
+ return this.getJson(`${path}/.zattrs`);
182
+ }
183
+
184
+ async _loadString(path) {
185
+ const { storeRoot } = this;
186
+ const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
187
+
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);
193
+ }
194
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadString`);
195
+ }
196
+
197
+ async _loadStringArray(path) {
198
+ const { 'encoding-type': encodingType, 'encoding-version': encodingVersion } = await this._loadAttrs(path);
199
+
200
+ if (encodingType === 'string-array' && encodingVersion === '0.2.0') {
201
+ return this.getFlatArrDecompressed(path);
202
+ }
203
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadStringArray`);
204
+ }
205
+
206
+
207
+ 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);
213
+ }
214
+ // TODO: support more elements
215
+ return null;
216
+ }
217
+
218
+ 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;
228
+ }
229
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadDict`);
230
+ }
270
231
  }
@@ -1,19 +1,31 @@
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';
7
+
3
8
 
4
9
  describe('sources/AnnDataSource', () => {
5
10
  describe('AnnData v0.7', () => {
6
11
  it('getJson returns json', async () => {
7
12
  const dataSource = new AnnDataSource({
8
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
13
+ url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
14
+ store: createStoreFromMapContents(anndata_0_7_DenseFixture),
9
15
  });
10
- const zGroup = await dataSource.getJson('.zgroup');
11
- expect(zGroup.zarr_format).toEqual(2);
16
+ const zAttrs = await dataSource.getJson('obs/.zattrs');
17
+ expect(Object.keys(zAttrs)).toEqual([
18
+ '_index',
19
+ 'column-order',
20
+ 'encoding-type',
21
+ 'encoding-version',
22
+ ]);
12
23
  });
13
24
 
14
25
  it('loadObsColumns returns ids for location in store', async () => {
15
26
  const dataSource = new AnnDataSource({
16
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
27
+ url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
28
+ store: createStoreFromMapContents(anndata_0_7_DenseFixture),
17
29
  });
18
30
  const ids = await dataSource.loadObsColumns(['obs/leiden']);
19
31
  expect(ids).toEqual([['1', '1', '2']]);
@@ -21,7 +33,8 @@ describe('sources/AnnDataSource', () => {
21
33
 
22
34
  it('loadObsIndex returns names', async () => {
23
35
  const dataSource = new AnnDataSource({
24
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
36
+ url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
37
+ store: createStoreFromMapContents(anndata_0_7_DenseFixture),
25
38
  });
26
39
  const names = await dataSource.loadObsIndex();
27
40
  expect(names).toEqual(['CTG', 'GCA', 'CTG']);
@@ -31,15 +44,22 @@ describe('sources/AnnDataSource', () => {
31
44
  describe('AnnData v0.8', () => {
32
45
  it('getJson returns json', async () => {
33
46
  const dataSource = new AnnDataSource({
34
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
47
+ url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
48
+ store: createStoreFromMapContents(anndata_0_8_DenseFixture),
35
49
  });
36
- const zGroup = await dataSource.getJson('.zgroup');
37
- expect(zGroup.zarr_format).toEqual(2);
50
+ const zAttrs = await dataSource.getJson('obs/.zattrs');
51
+ expect(Object.keys(zAttrs)).toEqual([
52
+ '_index',
53
+ 'column-order',
54
+ 'encoding-type',
55
+ 'encoding-version',
56
+ ]);
38
57
  });
39
58
 
40
59
  it('loadObsColumns returns ids for location in store', async () => {
41
60
  const dataSource = new AnnDataSource({
42
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
61
+ url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
62
+ store: createStoreFromMapContents(anndata_0_8_DenseFixture),
43
63
  });
44
64
  const ids = await dataSource.loadObsColumns(['obs/leiden']);
45
65
  expect(ids).toEqual([['1', '1', '2']]);
@@ -47,7 +67,8 @@ describe('sources/AnnDataSource', () => {
47
67
 
48
68
  it('loadObsIndex returns names', async () => {
49
69
  const dataSource = new AnnDataSource({
50
- url: 'http://localhost:4204/@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
70
+ url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
71
+ store: createStoreFromMapContents(anndata_0_8_DenseFixture),
51
72
  });
52
73
  const names = await dataSource.loadObsIndex();
53
74
  expect(names).toEqual(['CTG', 'GCA', 'CTG']);
@@ -1,11 +1,16 @@
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';
7
+
4
8
 
5
9
  describe('sources/MuDataSource', () => {
6
10
  it('loadObsColumns returns ids for location in store, with joint-modality path', async () => {
7
11
  const dataSource = new MuDataSource({
8
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
12
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
13
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
9
14
  });
10
15
  const ids = await dataSource.loadObsColumns(['obs/leiden']);
11
16
  expect(ids).toEqual([['3', '2', '3', '1', '1']]);
@@ -13,7 +18,8 @@ describe('sources/MuDataSource', () => {
13
18
 
14
19
  it('loadObsColumns returns ids for location in store, with modality-specific path', async () => {
15
20
  const dataSource = new MuDataSource({
16
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
21
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
22
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
17
23
  });
18
24
  const ids = await dataSource.loadObsColumns(['mod/rna/obs/leiden']);
19
25
  expect(ids).toEqual([['1', '1', '2', '2']]);
@@ -21,7 +27,8 @@ describe('sources/MuDataSource', () => {
21
27
 
22
28
  it('loadVarIndex supports modality-specific paths', async () => {
23
29
  const dataSource = new MuDataSource({
24
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
30
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
31
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
25
32
  });
26
33
  const names = await dataSource.loadVarIndex('mod/atac/X');
27
34
  expect(names).toEqual(range(15).map(i => `peak_${i}`));
@@ -29,7 +36,8 @@ describe('sources/MuDataSource', () => {
29
36
 
30
37
  it('loadObsIndex returns names', async () => {
31
38
  const dataSource = new MuDataSource({
32
- url: 'http://localhost:4204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
39
+ url: '@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
40
+ store: createStoreFromMapContents(mudata_0_2_DenseFixture),
33
41
  });
34
42
  const names = await dataSource.loadObsIndex('mod/atac/X');
35
43
  expect(names).toEqual(['CTG', 'GCA', 'CTT', 'GGG']);
@@ -0,0 +1,103 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import AnnDataSource from './AnnDataSource.js';
3
+
4
+ // If the array path starts with table/something/rest
5
+ // capture table/something.
6
+ const regex = /^shapes\/([^/]*)\/(.*)$/;
7
+
8
+ function getShapesPrefix(arrPath) {
9
+ if (arrPath) {
10
+ const matches = arrPath.match(regex);
11
+ if (matches && matches.length === 3) {
12
+ return `shapes/${matches[1]}/`;
13
+ }
14
+ }
15
+ return '';
16
+ }
17
+ export function getIndexPath(arrPath) {
18
+ return `${getShapesPrefix(arrPath)}Index`;
19
+ }
20
+
21
+ export function getVarPath(arrPath) {
22
+ return `${getShapesPrefix(arrPath)}var`;
23
+ }
24
+
25
+
26
+ export default class SpatialDataShapesSource extends AnnDataSource {
27
+ async loadSpatialDataAttrs(tablePath) {
28
+ return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
29
+ }
30
+
31
+ /**
32
+ * Class method for loading the obs index.
33
+ * @returns {Promise} An promise for a zarr array containing the indices.
34
+ */
35
+ async loadObsIndex(path = null, tablePath = null) {
36
+ if (!this.obsIndex) {
37
+ this.obsIndex = {};
38
+ }
39
+
40
+ let indexPath = getIndexPath(path);
41
+ if (tablePath) {
42
+ // TODO: given a path to the shapes,
43
+ // is there a better way to know which table annotates it
44
+ // (without the manually-specified table path)?
45
+ // Reference: https://github.com/scverse/spatialdata/issues/298#issuecomment-1718161329
46
+ const obsPath = `${tablePath}/obs`;
47
+ const { _index } = await this.getJson(`${obsPath}/.zattrs`);
48
+ indexPath = `${obsPath}/${_index}`;
49
+
50
+ const {
51
+ instance_key: instanceKey,
52
+ // TODO: filter table index by region and element type.
53
+ // region_key: regionKey,
54
+ // region,
55
+ } = await this.loadSpatialDataAttrs(tablePath);
56
+
57
+
58
+ indexPath = `${obsPath}/${instanceKey}`;
59
+ }
60
+ if (this.obsIndex[indexPath]) {
61
+ return this.obsIndex[indexPath];
62
+ }
63
+ this.obsIndex[indexPath] = this._loadColumn(indexPath);
64
+ return this.obsIndex[indexPath];
65
+ }
66
+
67
+ /**
68
+ * Class method for loading the var index.
69
+ * @returns {Promise} An promise for a zarr array containing the indices.
70
+ */
71
+ loadVarIndex(path = null) {
72
+ if (!this.varIndex) {
73
+ this.varIndex = {};
74
+ }
75
+ const varPath = getVarPath(path);
76
+ if (this.varIndex[varPath]) {
77
+ return this.varIndex[varPath];
78
+ }
79
+ this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`)
80
+ .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
81
+ return this.varIndex[varPath];
82
+ }
83
+
84
+ /**
85
+ * Class method for loading the var alias.
86
+ * @returns {Promise} An promise for a zarr array containing the aliased names.
87
+ */
88
+ async loadVarAlias(varPath, matrixPath) {
89
+ if (!this.varAlias) {
90
+ this.varAlias = {};
91
+ }
92
+ if (this.varAlias[varPath]) {
93
+ return this.varAlias[varPath];
94
+ }
95
+ const [varAliasData] = await this.loadVarColumns([varPath]);
96
+ this.varAlias[varPath] = varAliasData;
97
+ const index = await this.loadVarIndex(matrixPath);
98
+ this.varAlias[varPath] = this.varAlias[varPath].map(
99
+ (val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]),
100
+ );
101
+ return this.varAlias[varPath];
102
+ }
103
+ }