@vitessce/zarr 3.4.12 → 3.5.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 (49) hide show
  1. package/dist/{deflate-0a2495db.js → deflate-e0025ccc.js} +1 -1
  2. package/dist/{index-b9ca46db.js → index-a1019708.js} +16311 -758
  3. package/dist/index.js +1 -1
  4. package/dist/{jpeg-7300e0c0.js → jpeg-54659e84.js} +1 -1
  5. package/dist/{lerc-98ac4137.js → lerc-4e84f820.js} +1 -1
  6. package/dist/{lzw-7e525855.js → lzw-40048bd4.js} +1 -1
  7. package/dist/{packbits-7dbd57b5.js → packbits-bf37d3f7.js} +1 -1
  8. package/dist/{raw-269a3143.js → raw-f9274a13.js} +1 -1
  9. package/dist/{webimage-8f0f4c44.js → webimage-88b1773f.js} +1 -1
  10. package/dist-tsc/AnnDataSource.test.js +1 -1
  11. package/dist-tsc/SpatialDataShapesSource.d.ts +25 -0
  12. package/dist-tsc/SpatialDataShapesSource.d.ts.map +1 -1
  13. package/dist-tsc/SpatialDataShapesSource.js +148 -0
  14. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.test.js +1 -1
  15. package/dist-tsc/json-fixtures/anndata-0.10/anndata-csc.json +1 -1
  16. package/dist-tsc/json-fixtures/anndata-0.10/anndata-csr.adata.json +1 -1
  17. package/dist-tsc/json-fixtures/anndata-0.10/anndata-dense.json +1 -1
  18. package/dist-tsc/json-fixtures/anndata-0.7/anndata-csc.json +1 -1
  19. package/dist-tsc/json-fixtures/anndata-0.7/anndata-csr.json +1 -1
  20. package/dist-tsc/json-fixtures/anndata-0.7/anndata-dense.json +1 -1
  21. package/dist-tsc/json-fixtures/anndata-0.8/anndata-csc.json +1 -1
  22. package/dist-tsc/json-fixtures/anndata-0.8/anndata-csr.adata.json +1 -1
  23. package/dist-tsc/json-fixtures/anndata-0.8/anndata-dense.json +1 -1
  24. package/dist-tsc/json-fixtures/anndata-0.9/anndata-csc.json +1 -1
  25. package/dist-tsc/json-fixtures/anndata-0.9/anndata-csr.adata.json +1 -1
  26. package/dist-tsc/json-fixtures/anndata-0.9/anndata-dense.json +1 -1
  27. package/dist-tsc/ome-loaders/OmeZarrLoader.js +3 -3
  28. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts +3 -0
  29. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts.map +1 -1
  30. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.js +114 -2
  31. package/package.json +15 -12
  32. package/src/AnnDataSource.test.js +1 -1
  33. package/src/SpatialDataShapesSource.js +158 -2
  34. package/src/anndata-loaders/ObsEmbeddingAnndataLoader.test.js +1 -1
  35. package/src/json-fixtures/anndata-0.10/anndata-csc.json +1 -1
  36. package/src/json-fixtures/anndata-0.10/anndata-csr.adata.json +1 -1
  37. package/src/json-fixtures/anndata-0.10/anndata-dense.json +1 -1
  38. package/src/json-fixtures/anndata-0.7/anndata-csc.json +1 -1
  39. package/src/json-fixtures/anndata-0.7/anndata-csr.json +1 -1
  40. package/src/json-fixtures/anndata-0.7/anndata-dense.json +1 -1
  41. package/src/json-fixtures/anndata-0.8/anndata-csc.json +1 -1
  42. package/src/json-fixtures/anndata-0.8/anndata-csr.adata.json +1 -1
  43. package/src/json-fixtures/anndata-0.8/anndata-dense.json +1 -1
  44. package/src/json-fixtures/anndata-0.9/anndata-csc.json +1 -1
  45. package/src/json-fixtures/anndata-0.9/anndata-csr.adata.json +1 -1
  46. package/src/json-fixtures/anndata-0.9/anndata-dense.json +1 -1
  47. package/src/missing-types.d.ts +1 -0
  48. package/src/ome-loaders/OmeZarrLoader.js +3 -3
  49. package/src/spatialdata-loaders/SpatialDataObsSpotsLoader.js +143 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A, F, G, b, M, c, k, O, j, f, e, h, i, d, n, m, l, o, p, r, q, a, S, Z } from "./index-b9ca46db.js";
1
+ import { A, F, G, b, M, c, k, O, j, f, e, h, i, d, n, m, l, o, p, r, q, a, S, Z } from "./index-a1019708.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  export {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-b9ca46db.js";
1
+ import { B as BaseDecoder } from "./index-a1019708.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  const dctZigZag = new Int32Array([
@@ -1,5 +1,5 @@
1
1
  import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
2
- import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-b9ca46db.js";
2
+ import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-a1019708.js";
3
3
  import "@vitessce/vit-s";
4
4
  import "react";
5
5
  const LercParameters = {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-b9ca46db.js";
1
+ import { B as BaseDecoder } from "./index-a1019708.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  const MIN_BITS = 9;
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-b9ca46db.js";
1
+ import { B as BaseDecoder } from "./index-a1019708.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  class PackbitsDecoder extends BaseDecoder {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-b9ca46db.js";
1
+ import { B as BaseDecoder } from "./index-a1019708.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  class RawDecoder extends BaseDecoder {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-b9ca46db.js";
1
+ import { B as BaseDecoder } from "./index-a1019708.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  class WebImageDecoder extends BaseDecoder {
@@ -36,7 +36,7 @@ describe('sources/AnnDataSource', () => {
36
36
  store: createStoreFromMapContents(fixture),
37
37
  });
38
38
  const names = await dataSource.loadObsIndex();
39
- expect(names).toEqual(['CTG', 'GCA', 'CTG']);
39
+ expect(names).toEqual(['CTG', 'GCA', 'ACG']);
40
40
  });
41
41
  });
42
42
  });
@@ -10,6 +10,18 @@ export function getIndexPath(arrPath: string | undefined): string;
10
10
  * @returns
11
11
  */
12
12
  export function getVarPath(arrPath: string | undefined): string;
13
+ /**
14
+ *
15
+ * @param {string|undefined} arrPath
16
+ * @returns
17
+ */
18
+ export function getParquetPath(arrPath: string | undefined): string;
19
+ /**
20
+ *
21
+ * @param {string|undefined} arrPath
22
+ * @returns
23
+ */
24
+ export function getAttrsPath(arrPath: string | undefined): string;
13
25
  export default class SpatialDataShapesSource extends AnnDataSource {
14
26
  /** @type {{ [k: string]: Promise<string[]> }} */
15
27
  obsIndices: {
@@ -31,6 +43,19 @@ export default class SpatialDataShapesSource extends AnnDataSource {
31
43
  loadSpatialDataAttrs(tablePath: string): Promise<{
32
44
  [k: string]: string | string[] | null;
33
45
  }>;
46
+ /**
47
+ *
48
+ * @param {string} path A path to within shapes.
49
+ * @returns {Promise<"0.1"|"0.2">} The format version.
50
+ */
51
+ getFormatVersion(path: string): Promise<"0.1" | "0.2">;
52
+ /**
53
+ *
54
+ * @param {string} path A path to an array within shapes.
55
+ * @returns
56
+ */
57
+ loadParquetTable(path: string): Promise<import("apache-arrow").Table<any>>;
58
+ parquetTable: import("apache-arrow").Table<any> | undefined;
34
59
  /**
35
60
  * Class method for loading the obs index.
36
61
  * @param {string|undefined} path
@@ -1 +1 @@
1
- {"version":3,"file":"SpatialDataShapesSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataShapesSource.js"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,sCAHW,MAAM,GAAC,SAAS,UAK1B;AAED;;;;GAIG;AACH,oCAHW,MAAM,GAAC,SAAS,UAK1B;AAGD;IAOI,iDAAiD;IACjD,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CACzB;IACpB,iDAAiD;IACjD,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CACzB;IACpB,wCAAwC;IACxC,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAChB;IAGtB;;;;OAIG;IACH,gCAHW,MAAM;;OAKhB;IAED;;;;;OAKG;IACH,oBAJW,MAAM,GAAC,SAAS,cAChB,MAAM,GAAC,SAAS,GACd,OAAO,CAAC,MAAM,EAAE,CAAC,CA4B7B;IAiBD;;;;;OAKG;IACH,sBAJW,MAAM,cACN,MAAM,GACJ,OAAO,CAAC,MAAM,EAAE,CAAC,CAa7B;CACF;0BArIyB,oBAAoB"}
1
+ {"version":3,"file":"SpatialDataShapesSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataShapesSource.js"],"names":[],"mappings":"AAyDA;;;;GAIG;AACH,sCAHW,MAAM,GAAC,SAAS,UAK1B;AAED;;;;GAIG;AACH,oCAHW,MAAM,GAAC,SAAS,UAK1B;AAED;;;;GAIG;AACH,wCAHW,MAAM,GAAC,SAAS,UAK1B;AAED;;;;GAIG;AACH,sCAHW,MAAM,GAAC,SAAS,UAK1B;AAGD;IAOI,iDAAiD;IACjD,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CACzB;IACpB,iDAAiD;IACjD,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CACzB;IACpB,wCAAwC;IACxC,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAChB;IAGtB;;;;OAIG;IACH,gCAHW,MAAM;;OAKhB;IAED;;;;OAIG;IACH,uBAHW,MAAM,GACJ,OAAO,CAAC,KAAK,GAAC,KAAK,CAAC,CAWhC;IAED;;;;OAIG;IACH,uBAHW,MAAM,8CAmBhB;IAFC,4DAA8B;IAIhC;;;;;OAKG;IACH,oBAJW,MAAM,GAAC,SAAS,cAChB,MAAM,GAAC,SAAS,GACd,OAAO,CAAC,MAAM,EAAE,CAAC,CA2B7B;IAqFD;;;;;OAKG;IACH,sBAJW,MAAM,cACN,MAAM,GACJ,OAAO,CAAC,MAAM,EAAE,CAAC,CAa7B;CACF;0BA7RyB,oBAAoB"}
@@ -1,7 +1,38 @@
1
1
  // @ts-check
2
2
  /* eslint-disable no-underscore-dangle */
3
+ /* eslint-disable import/no-unresolved */
4
+ /* eslint-disable no-undef */
5
+ import { tableFromIPC } from 'apache-arrow';
6
+ import WKB from 'ol/format/WKB.js';
3
7
  import AnnDataSource from './AnnDataSource.js';
8
+ import { basename } from './utils.js';
4
9
  /** @import { DataSourceParams } from '@vitessce/types' */
10
+ /** @import { TypedArray as ZarrTypedArray, Chunk } from '@zarrita/core' */
11
+ async function getReadParquet() {
12
+ // Reference: https://observablehq.com/@kylebarron/geoparquet-on-the-web
13
+ // TODO: host somewhere we control, like cdn.vitessce.io?
14
+ // @ts-ignore
15
+ const module = await import(/* webpackIgnore: true */ 'https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm.js');
16
+ await module.default();
17
+ // We cannot use regulary dynamic import here because it breaks NextJS builds
18
+ // due to pointing to a remote URL.
19
+ // I could not figure out a NextJS webpack configuration to resolve it.
20
+ // The following becomes inlined by Vite in library mode
21
+ // eliminating the benefit of dynamic import.
22
+ // Reference: https://github.com/vitejs/vite/issues/4454
23
+ // const responsePromise = await fetch(
24
+ // new URL('parquet-wasm/esm/parquet_wasm_bg.wasm', import.meta.url).href
25
+ // );
26
+ // const responsePromise = await fetch('https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm_bg.wasm');
27
+ // const wasmBuffer = await responsePromise.arrayBuffer();
28
+ // module.initSync(wasmBuffer);
29
+ // Another issue is that when we import parquet-wasm JS from node_modules,
30
+ // running module.default there is a MIME type issue because the Vite dev
31
+ // server does not serve the .wasm with a MIME type of application/wasm.
32
+ // I can't seem to get a custom Vite plugin that sets the MIME type in
33
+ // request headers to work.
34
+ return module.readParquet;
35
+ }
5
36
  // If the array path starts with table/something/rest
6
37
  // capture table/something.
7
38
  const regex = /^shapes\/([^/]*)\/(.*)$/;
@@ -35,6 +66,22 @@ export function getIndexPath(arrPath) {
35
66
  export function getVarPath(arrPath) {
36
67
  return `${getShapesPrefix(arrPath)}var`;
37
68
  }
69
+ /**
70
+ *
71
+ * @param {string|undefined} arrPath
72
+ * @returns
73
+ */
74
+ export function getParquetPath(arrPath) {
75
+ return `${getShapesPrefix(arrPath)}shapes.parquet`;
76
+ }
77
+ /**
78
+ *
79
+ * @param {string|undefined} arrPath
80
+ * @returns
81
+ */
82
+ export function getAttrsPath(arrPath) {
83
+ return `${getShapesPrefix(arrPath)}.zattrs`;
84
+ }
38
85
  export default class SpatialDataShapesSource extends AnnDataSource {
39
86
  /**
40
87
  *
@@ -57,6 +104,41 @@ export default class SpatialDataShapesSource extends AnnDataSource {
57
104
  async loadSpatialDataAttrs(tablePath) {
58
105
  return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
59
106
  }
107
+ /**
108
+ *
109
+ * @param {string} path A path to within shapes.
110
+ * @returns {Promise<"0.1"|"0.2">} The format version.
111
+ */
112
+ async getFormatVersion(path) {
113
+ const zattrs = await this.getJson(getAttrsPath(path));
114
+ const formatVersion = zattrs.spatialdata_attrs.version;
115
+ if (!(formatVersion === '0.1' || formatVersion === '0.2')) {
116
+ throw new Error(`Unexpected version for shapes spatialdata_attrs: ${formatVersion}`);
117
+ }
118
+ return formatVersion;
119
+ }
120
+ /**
121
+ *
122
+ * @param {string} path A path to an array within shapes.
123
+ * @returns
124
+ */
125
+ async loadParquetTable(path) {
126
+ if (this.parquetTable) {
127
+ // Return cached table if present.
128
+ return this.parquetTable;
129
+ }
130
+ const readParquet = await getReadParquet();
131
+ const parquetPath = getParquetPath(path);
132
+ const parquetBytes = await this.storeRoot.store.get(`/${parquetPath}`);
133
+ if (!parquetBytes) {
134
+ throw new Error('Failed to load parquet data from store.');
135
+ }
136
+ const wasmTable = readParquet(parquetBytes);
137
+ // TODO: use streaming?
138
+ const arrowTable = tableFromIPC(wasmTable.intoIPCStream());
139
+ this.parquetTable = arrowTable;
140
+ return this.parquetTable;
141
+ }
60
142
  /**
61
143
  * Class method for loading the obs index.
62
144
  * @param {string|undefined} path
@@ -83,9 +165,75 @@ export default class SpatialDataShapesSource extends AnnDataSource {
83
165
  if (indexPath in this.obsIndices) {
84
166
  return this.obsIndices[indexPath];
85
167
  }
168
+ // TODO: support loading from parquet if no tablePath was provided.
86
169
  this.obsIndices[indexPath] = this._loadColumn(indexPath);
87
170
  return this.obsIndices[indexPath];
88
171
  }
172
+ /**
173
+ * Class method for loading general numeric arrays.
174
+ * @param {string} path A string like obsm.X_pca.
175
+ * @returns {Promise<Chunk<any>>} A promise for a zarr array containing the data.
176
+ */
177
+ async loadNumeric(path) {
178
+ const formatVersion = await this.getFormatVersion(path);
179
+ if (formatVersion === '0.1') {
180
+ return super.loadNumeric(path);
181
+ }
182
+ const arrowTable = await this.loadParquetTable(path);
183
+ const columnArr = arrowTable.getChild(basename(path))?.toArray();
184
+ return {
185
+ shape: [columnArr.length],
186
+ // TODO: support other kinds of TypedArrays via @vitessce/arrow-utils.
187
+ data: new Float32Array(columnArr),
188
+ stride: [1],
189
+ };
190
+ }
191
+ /**
192
+ * Class method for loading specific columns of numeric arrays.
193
+ * @param {string} path A string like obsm.X_pca.
194
+ * @param {[number, number]} dims The column indices to load.
195
+ * @returns {Promise<{
196
+ * data: [ZarrTypedArray<any>, ZarrTypedArray<any>],
197
+ * shape: [number, number],
198
+ * }>} A promise for a zarr array containing the data.
199
+ */
200
+ async loadNumericForDims(path, dims) {
201
+ const formatVersion = await this.getFormatVersion(path);
202
+ if (formatVersion === '0.1') {
203
+ return super.loadNumericForDims(path, dims);
204
+ }
205
+ let columnName = basename(path);
206
+ if (columnName === 'coords') {
207
+ // The "geometry" column was previously called "coords" in version 0.1.
208
+ columnName = 'geometry';
209
+ }
210
+ const arrowTable = await this.loadParquetTable(path);
211
+ if (columnName === 'geometry' && dims[0] === 0 && dims[1] === 1) {
212
+ const geometryColumn = arrowTable.getChild(columnName);
213
+ if (!geometryColumn) {
214
+ throw new Error(`Column ${columnName} not found in parquet table`);
215
+ }
216
+ if (geometryColumn.type.toString() !== 'Binary') {
217
+ throw new Error(`Expected geometry column to have Binary type (WKB) but got ${geometryColumn.type.toString()}`);
218
+ }
219
+ // From GeoPandas.to_parquet docs:
220
+ // "By default, all geometry columns present are serialized to WKB format in the file"
221
+ // Reference: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_parquet.html
222
+ // TODO: support geoarrow serialization schemes in addition to WKB.
223
+ const wkb = new WKB();
224
+ const points = geometryColumn.toArray()
225
+ // @ts-ignore
226
+ .map((/** @type {Uint8Array} */ geom) => wkb.readGeometry(geom).getFlatCoordinates());
227
+ return {
228
+ shape: [2, points.length],
229
+ data: [
230
+ new Float32Array(points.map((/** @type {[number, number]} */ p) => p[0])),
231
+ new Float32Array(points.map((/** @type {[number, number]} */ p) => p[1])),
232
+ ],
233
+ };
234
+ }
235
+ throw new Error('Unexpected column name for loading 2D array from parquet, currently only geometry is supported');
236
+ }
89
237
  /**
90
238
  * Class method for loading the var index.
91
239
  * @param {string|undefined} path
@@ -45,7 +45,7 @@ describe('loaders/ObsEmbeddingAnndataLoader for AnnData', () => {
45
45
  expect(result).toBeInstanceOf(LoaderResult);
46
46
  const payload = result.data;
47
47
  expect(Object.keys(payload)).toEqual(['obsIndex', 'obsEmbedding']);
48
- expect(payload.obsIndex).toEqual(['CTG', 'GCA', 'CTG']);
48
+ expect(payload.obsIndex).toEqual(['CTG', 'GCA', 'ACG']);
49
49
  expect(payload.obsEmbedding.shape).toEqual([2, 3]);
50
50
  expect(Array.from(payload.obsEmbedding.data[0])).toEqual([-1, 0, 1]);
51
51
  expect(Array.from(payload.obsEmbedding.data[1])).toEqual([-1, 0, 1]);
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  [
103
103
  "/obs/_index/0",
104
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
104
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
105
105
  ],
106
106
  [
107
107
  "/obs/leiden/.zattrs",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  [
103
103
  "/obs/_index/0",
104
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
104
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
105
105
  ],
106
106
  [
107
107
  "/obs/leiden/.zattrs",
@@ -81,7 +81,7 @@
81
81
  ],
82
82
  [
83
83
  "/obs/_index/0",
84
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
84
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
85
85
  ],
86
86
  [
87
87
  "/obs/leiden/.zattrs",
@@ -93,7 +93,7 @@
93
93
  ],
94
94
  [
95
95
  "/obs/_index/0",
96
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
96
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
97
97
  ],
98
98
  [
99
99
  "/obs/leiden/.zarray",
@@ -93,7 +93,7 @@
93
93
  ],
94
94
  [
95
95
  "/obs/_index/0",
96
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
96
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
97
97
  ],
98
98
  [
99
99
  "/obs/leiden/.zarray",
@@ -69,7 +69,7 @@
69
69
  ],
70
70
  [
71
71
  "/obs/_index/0",
72
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
72
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
73
73
  ],
74
74
  [
75
75
  "/obs/leiden/.zarray",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  [
103
103
  "/obs/_index/0",
104
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
104
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
105
105
  ],
106
106
  [
107
107
  "/obs/leiden/.zattrs",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  [
103
103
  "/obs/_index/0",
104
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
104
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
105
105
  ],
106
106
  [
107
107
  "/obs/leiden/.zattrs",
@@ -81,7 +81,7 @@
81
81
  ],
82
82
  [
83
83
  "/obs/_index/0",
84
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
84
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
85
85
  ],
86
86
  [
87
87
  "/obs/leiden/.zattrs",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  [
103
103
  "/obs/_index/0",
104
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
104
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
105
105
  ],
106
106
  [
107
107
  "/obs/leiden/.zattrs",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  [
103
103
  "/obs/_index/0",
104
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
104
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
105
105
  ],
106
106
  [
107
107
  "/obs/leiden/.zattrs",
@@ -81,7 +81,7 @@
81
81
  ],
82
82
  [
83
83
  "/obs/_index/0",
84
- "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABDVEc="
84
+ "AgEzARkAAAAZAAAAKQAAAAMAAAADAAAAQ1RHAwAAAEdDQQMAAABBQ0c="
85
85
  ],
86
86
  [
87
87
  "/obs/leiden/.zattrs",
@@ -86,7 +86,7 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
86
86
  }
87
87
  }
88
88
  else {
89
- const { rdefs, channels } = omero;
89
+ const { rdefs = {}, channels } = omero;
90
90
  if (typeof rdefs.defaultT === 'number') {
91
91
  initialTargetT = rdefs.defaultT;
92
92
  }
@@ -95,8 +95,8 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
95
95
  }
96
96
  channelObjects = channels.map((channel, i) => ({
97
97
  selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
98
- slider: [channel.window.start, channel.window.end],
99
- color: hexToRgb(channel.color),
98
+ slider: channel.window ? ([channel.window.start, channel.window.end]) : [0, 255],
99
+ color: channel.color ? hexToRgb(channel.color) : [255, 255, 255],
100
100
  }));
101
101
  channelLabels = channels.map(c => c.label);
102
102
  }
@@ -3,6 +3,8 @@
3
3
  */
4
4
  export default class SpatialDataObsSpotsLoader extends AbstractTwoStepLoader<any> {
5
5
  constructor(dataSource: any, params: import("@vitessce/types").LoaderParams);
6
+ loadModelMatrix(): Promise<math.Matrix4>;
7
+ modelMatrix: math.Matrix4 | undefined;
6
8
  /**
7
9
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
8
10
  * @returns {Promise} A promise for an array of columns.
@@ -17,5 +19,6 @@ export default class SpatialDataObsSpotsLoader extends AbstractTwoStepLoader<any
17
19
  }>>;
18
20
  }
19
21
  import { AbstractTwoStepLoader } from '@vitessce/vit-s';
22
+ import { math } from '@vitessce/gl';
20
23
  import { LoaderResult } from '@vitessce/vit-s';
21
24
  //# sourceMappingURL=SpatialDataObsSpotsLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpatialDataObsSpotsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataObsSpotsLoader.js"],"names":[],"mappings":"AAaA;;KAEK;AACL;;IACE;;;SAGK;IACL,0BAWC;IALG,eAAoF;IAOxF,2BAWC;IALG,YAAoE;IAOxE;;;QAsCC;CACF;sCApFM,iBAAiB;6BAAjB,iBAAiB"}
1
+ {"version":3,"file":"SpatialDataObsSpotsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataObsSpotsLoader.js"],"names":[],"mappings":"AAuEA;;KAEK;AACL;;IACE,yCAsDC;IAFC,sCAA0C;IAI5C;;;SAGK;IACL,0BA2BC;IAnBG,eAAsF;IAqB1F,2BAsBC;IAfG,YAAoE;IAiBxE;;;QAsCC;CACF;sCAjOM,iBAAiB;qBAMH,cAAc;6BAN5B,iBAAiB"}
@@ -1,26 +1,127 @@
1
1
  import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError, } from '@vitessce/vit-s';
2
2
  import { CoordinationLevel as CL } from '@vitessce/config';
3
+ import { normalizeCoordinateTransformations, coordinateTransformationsToMatrix, } from '@vitessce/spatial-utils';
4
+ import { math } from '@vitessce/gl';
3
5
  function getCoordsPath(path) {
4
6
  return `${path}/coords`;
5
7
  }
6
8
  function getRadiusPath(path) {
7
9
  return `${path}/radius`;
8
10
  }
11
+ function getAttrsPath(path) {
12
+ return `${path}/.zattrs`;
13
+ }
14
+ const DEFAULT_AXES = [
15
+ {
16
+ name: 'x',
17
+ type: 'space',
18
+ unit: 'unit',
19
+ },
20
+ {
21
+ name: 'y',
22
+ type: 'space',
23
+ unit: 'unit',
24
+ },
25
+ ];
26
+ const DEFAULT_COORDINATE_TRANSFORMATIONS = [
27
+ {
28
+ input: {
29
+ axes: [
30
+ {
31
+ name: 'x',
32
+ type: 'space',
33
+ unit: 'unit',
34
+ },
35
+ {
36
+ name: 'y',
37
+ type: 'space',
38
+ unit: 'unit',
39
+ },
40
+ ],
41
+ name: 'xy',
42
+ },
43
+ output: {
44
+ axes: [
45
+ {
46
+ name: 'x',
47
+ type: 'space',
48
+ unit: 'unit',
49
+ },
50
+ {
51
+ name: 'y',
52
+ type: 'space',
53
+ unit: 'unit',
54
+ },
55
+ ],
56
+ name: 'global',
57
+ },
58
+ type: 'identity',
59
+ },
60
+ ];
9
61
  /**
10
62
  * Loader for embedding arrays located in anndata.zarr stores.
11
63
  */
12
64
  export default class SpatialDataObsSpotsLoader extends AbstractTwoStepLoader {
65
+ async loadModelMatrix() {
66
+ const { path, coordinateSystem = 'global' } = this.options;
67
+ if (this.modelMatrix) {
68
+ return this.modelMatrix;
69
+ }
70
+ // Load the transformations from the .zattrs for the shapes
71
+ const zattrs = await this.dataSource.getJson(getAttrsPath(path));
72
+ const { 'encoding-type': encodingType, spatialdata_attrs: { geos = {}, version: attrsVersion, }, } = zattrs;
73
+ const hasExpectedAttrs = (encodingType === 'ngff:shapes'
74
+ && ((geos?.name === 'POINT'
75
+ && geos?.type === 0
76
+ && attrsVersion === '0.1') || attrsVersion === '0.2'));
77
+ if (!hasExpectedAttrs) {
78
+ throw new AbstractLoaderError('Unexpected values for encoding-type or spatialdata_attrs for SpatialData shapes');
79
+ }
80
+ // Convert the coordinate transformations to a modelMatrix.
81
+ // For attrsVersion === "0.1", we can assume that there is always a
82
+ // coordinate system which maps from the input "xy" to the specified
83
+ // output coordinate system.
84
+ // TODO: In a future version of the shapes transformation on-disk format,
85
+ // the SpatialData team plans to relax this so that it will
86
+ // become necessary to create a full tree
87
+ // of coordinate transformations, and traverse the tree from
88
+ // the node corresponding to the output coordinate system of interest
89
+ // back to the root node, applying each transformation along the way.
90
+ const coordinateTransformationsFromFile = (zattrs?.coordinateTransformations || DEFAULT_COORDINATE_TRANSFORMATIONS).filter(({ input: { name: inputName }, output: { name: outputName } }) => (inputName === 'xy' && outputName === coordinateSystem));
91
+ const axes = zattrs?.axes || DEFAULT_AXES;
92
+ // This new spec is very flexible,
93
+ // so here we will attempt to convert it back to the old spec.
94
+ // TODO: do the reverse, convert old spec to new spec
95
+ const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(coordinateTransformationsFromFile, null);
96
+ const transformMatrixFromFile = coordinateTransformationsToMatrix(normCoordinateTransformationsFromFile, axes);
97
+ this.modelMatrix = transformMatrixFromFile;
98
+ return this.modelMatrix;
99
+ }
13
100
  /**
14
101
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
15
102
  * @returns {Promise} A promise for an array of columns.
16
103
  */
17
104
  async loadSpots() {
18
- const { path, dims = [0, 1] } = this.options;
105
+ const { path } = this.options;
19
106
  if (this.locations) {
20
107
  return this.locations;
21
108
  }
22
109
  if (!this.locations) {
23
- this.locations = await this.dataSource.loadNumericForDims(getCoordsPath(path), dims);
110
+ const modelMatrix = await this.loadModelMatrix();
111
+ this.locations = await this.dataSource.loadNumericForDims(getCoordsPath(path), [0, 1]);
112
+ // Apply transformation matrix to the coordinates
113
+ // TODO: instead of applying here, pass matrix all the way down to WebGL shader
114
+ // (or DeckGL layer)
115
+ for (let i = 0; i < this.locations.shape[1]; i++) {
116
+ const xCoord = this.locations.data[0][i];
117
+ const yCoord = this.locations.data[1][i];
118
+ const transformed = new math.Vector2(xCoord, yCoord)
119
+ .transformAsPoint(modelMatrix);
120
+ // eslint-disable-next-line prefer-destructuring
121
+ this.locations.data[0][i] = transformed[0];
122
+ // eslint-disable-next-line prefer-destructuring
123
+ this.locations.data[1][i] = transformed[1];
124
+ }
24
125
  return this.locations;
25
126
  }
26
127
  this.locations = Promise.resolve(null);
@@ -32,7 +133,18 @@ export default class SpatialDataObsSpotsLoader extends AbstractTwoStepLoader {
32
133
  return this.radius;
33
134
  }
34
135
  if (!this.radius) {
136
+ const modelMatrix = await this.loadModelMatrix();
35
137
  this.radius = await this.dataSource.loadNumeric(getRadiusPath(path));
138
+ const scaleFactors = modelMatrix.getScale();
139
+ const xScaleFactor = scaleFactors[0];
140
+ const yScaleFactor = scaleFactors[1];
141
+ if (xScaleFactor !== yScaleFactor) {
142
+ console.warn('Using x-axis scale factor for transformation of obsSpots, but x and y scale factors are not equal');
143
+ }
144
+ // Apply the scale factor to the radius column
145
+ for (let i = 0; i < this.radius.shape[0]; i++) {
146
+ this.radius.data[i] *= xScaleFactor;
147
+ }
36
148
  return this.radius;
37
149
  }
38
150
  this.radius = Promise.resolve(null);