@vitessce/zarr 3.4.11 → 3.4.14
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.
- package/dist/{deflate-f092f055.js → deflate-b2db2606.js} +1 -1
- package/dist/{index-010ccee4.js → index-40df751d.js} +16456 -880
- package/dist/index.js +1 -1
- package/dist/{jpeg-96acb184.js → jpeg-4eb208e2.js} +1 -1
- package/dist/{lerc-41914740.js → lerc-488045ad.js} +1 -1
- package/dist/{lzw-ed481c3b.js → lzw-7dbd05ec.js} +1 -1
- package/dist/{packbits-14e4265c.js → packbits-86870a09.js} +1 -1
- package/dist/{raw-1e87ff8b.js → raw-997b5663.js} +1 -1
- package/dist/{webimage-df74a5df.js → webimage-fc1b5b38.js} +1 -1
- package/dist-tsc/SpatialDataShapesSource.d.ts +25 -0
- package/dist-tsc/SpatialDataShapesSource.d.ts.map +1 -1
- package/dist-tsc/SpatialDataShapesSource.js +153 -0
- package/dist-tsc/ome-loaders/OmeZarrLoader.js +3 -3
- package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts.map +1 -1
- package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.js +0 -1
- package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts +3 -0
- package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts.map +1 -1
- package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.js +114 -2
- package/package.json +15 -11
- package/src/SpatialDataShapesSource.js +164 -2
- package/src/missing-types.d.ts +1 -0
- package/src/ome-loaders/OmeZarrLoader.js +3 -3
- package/src/spatialdata-loaders/SpatialDataObsSetsLoader.js +0 -1
- 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-
|
|
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-40df751d.js";
|
|
2
2
|
import "@vitessce/vit-s";
|
|
3
3
|
import "react";
|
|
4
4
|
export {
|
|
@@ -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-
|
|
2
|
+
import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-40df751d.js";
|
|
3
3
|
import "@vitessce/vit-s";
|
|
4
4
|
import "react";
|
|
5
5
|
const LercParameters = {
|
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"SpatialDataShapesSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataShapesSource.js"],"names":[],"mappings":"AA+DA;;;;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;0BAlSyB,oBAAoB"}
|
|
@@ -1,7 +1,43 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
/* eslint-disable no-underscore-dangle */
|
|
3
|
+
/* eslint-disable import/no-unresolved */
|
|
4
|
+
/* eslint-disable no-undef */
|
|
5
|
+
import dynamicImportPolyfill from 'dynamic-import-polyfill';
|
|
6
|
+
import { tableFromIPC } from 'apache-arrow';
|
|
7
|
+
import WKB from 'ol/format/WKB.js';
|
|
3
8
|
import AnnDataSource from './AnnDataSource.js';
|
|
9
|
+
import { basename } from './utils.js';
|
|
4
10
|
/** @import { DataSourceParams } from '@vitessce/types' */
|
|
11
|
+
/** @import { TypedArray as ZarrTypedArray, Chunk } from '@zarrita/core' */
|
|
12
|
+
// Initialize the dynamic __import__() function.
|
|
13
|
+
if (dynamicImportPolyfill) {
|
|
14
|
+
dynamicImportPolyfill.initialize();
|
|
15
|
+
}
|
|
16
|
+
async function getReadParquet() {
|
|
17
|
+
// Reference: https://observablehq.com/@kylebarron/geoparquet-on-the-web
|
|
18
|
+
// TODO: host somewhere we control, like cdn.vitessce.io?
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const module = await __import__('https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm.js');
|
|
21
|
+
await module.default();
|
|
22
|
+
// We cannot use regulary dynamic import here because it breaks NextJS builds
|
|
23
|
+
// due to pointing to a remote URL.
|
|
24
|
+
// I could not figure out a NextJS webpack configuration to resolve it.
|
|
25
|
+
// The following becomes inlined by Vite in library mode
|
|
26
|
+
// eliminating the benefit of dynamic import.
|
|
27
|
+
// Reference: https://github.com/vitejs/vite/issues/4454
|
|
28
|
+
// const responsePromise = await fetch(
|
|
29
|
+
// new URL('parquet-wasm/esm/parquet_wasm_bg.wasm', import.meta.url).href
|
|
30
|
+
// );
|
|
31
|
+
// const responsePromise = await fetch('https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm_bg.wasm');
|
|
32
|
+
// const wasmBuffer = await responsePromise.arrayBuffer();
|
|
33
|
+
// module.initSync(wasmBuffer);
|
|
34
|
+
// Another issue is that when we import parquet-wasm JS from node_modules,
|
|
35
|
+
// running module.default there is a MIME type issue because the Vite dev
|
|
36
|
+
// server does not serve the .wasm with a MIME type of application/wasm.
|
|
37
|
+
// I can't seem to get a custom Vite plugin that sets the MIME type in
|
|
38
|
+
// request headers to work.
|
|
39
|
+
return module.readParquet;
|
|
40
|
+
}
|
|
5
41
|
// If the array path starts with table/something/rest
|
|
6
42
|
// capture table/something.
|
|
7
43
|
const regex = /^shapes\/([^/]*)\/(.*)$/;
|
|
@@ -35,6 +71,22 @@ export function getIndexPath(arrPath) {
|
|
|
35
71
|
export function getVarPath(arrPath) {
|
|
36
72
|
return `${getShapesPrefix(arrPath)}var`;
|
|
37
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param {string|undefined} arrPath
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
export function getParquetPath(arrPath) {
|
|
80
|
+
return `${getShapesPrefix(arrPath)}shapes.parquet`;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param {string|undefined} arrPath
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
export function getAttrsPath(arrPath) {
|
|
88
|
+
return `${getShapesPrefix(arrPath)}.zattrs`;
|
|
89
|
+
}
|
|
38
90
|
export default class SpatialDataShapesSource extends AnnDataSource {
|
|
39
91
|
/**
|
|
40
92
|
*
|
|
@@ -57,6 +109,41 @@ export default class SpatialDataShapesSource extends AnnDataSource {
|
|
|
57
109
|
async loadSpatialDataAttrs(tablePath) {
|
|
58
110
|
return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ['instance_key', 'region', 'region_key']);
|
|
59
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @param {string} path A path to within shapes.
|
|
115
|
+
* @returns {Promise<"0.1"|"0.2">} The format version.
|
|
116
|
+
*/
|
|
117
|
+
async getFormatVersion(path) {
|
|
118
|
+
const zattrs = await this.getJson(getAttrsPath(path));
|
|
119
|
+
const formatVersion = zattrs.spatialdata_attrs.version;
|
|
120
|
+
if (!(formatVersion === '0.1' || formatVersion === '0.2')) {
|
|
121
|
+
throw new Error(`Unexpected version for shapes spatialdata_attrs: ${formatVersion}`);
|
|
122
|
+
}
|
|
123
|
+
return formatVersion;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param {string} path A path to an array within shapes.
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
async loadParquetTable(path) {
|
|
131
|
+
if (this.parquetTable) {
|
|
132
|
+
// Return cached table if present.
|
|
133
|
+
return this.parquetTable;
|
|
134
|
+
}
|
|
135
|
+
const readParquet = await getReadParquet();
|
|
136
|
+
const parquetPath = getParquetPath(path);
|
|
137
|
+
const parquetBytes = await this.storeRoot.store.get(`/${parquetPath}`);
|
|
138
|
+
if (!parquetBytes) {
|
|
139
|
+
throw new Error('Failed to load parquet data from store.');
|
|
140
|
+
}
|
|
141
|
+
const wasmTable = readParquet(parquetBytes);
|
|
142
|
+
// TODO: use streaming?
|
|
143
|
+
const arrowTable = tableFromIPC(wasmTable.intoIPCStream());
|
|
144
|
+
this.parquetTable = arrowTable;
|
|
145
|
+
return this.parquetTable;
|
|
146
|
+
}
|
|
60
147
|
/**
|
|
61
148
|
* Class method for loading the obs index.
|
|
62
149
|
* @param {string|undefined} path
|
|
@@ -83,9 +170,75 @@ export default class SpatialDataShapesSource extends AnnDataSource {
|
|
|
83
170
|
if (indexPath in this.obsIndices) {
|
|
84
171
|
return this.obsIndices[indexPath];
|
|
85
172
|
}
|
|
173
|
+
// TODO: support loading from parquet if no tablePath was provided.
|
|
86
174
|
this.obsIndices[indexPath] = this._loadColumn(indexPath);
|
|
87
175
|
return this.obsIndices[indexPath];
|
|
88
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Class method for loading general numeric arrays.
|
|
179
|
+
* @param {string} path A string like obsm.X_pca.
|
|
180
|
+
* @returns {Promise<Chunk<any>>} A promise for a zarr array containing the data.
|
|
181
|
+
*/
|
|
182
|
+
async loadNumeric(path) {
|
|
183
|
+
const formatVersion = await this.getFormatVersion(path);
|
|
184
|
+
if (formatVersion === '0.1') {
|
|
185
|
+
return super.loadNumeric(path);
|
|
186
|
+
}
|
|
187
|
+
const arrowTable = await this.loadParquetTable(path);
|
|
188
|
+
const columnArr = arrowTable.getChild(basename(path))?.toArray();
|
|
189
|
+
return {
|
|
190
|
+
shape: [columnArr.length],
|
|
191
|
+
// TODO: support other kinds of TypedArrays via @vitessce/arrow-utils.
|
|
192
|
+
data: new Float32Array(columnArr),
|
|
193
|
+
stride: [1],
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Class method for loading specific columns of numeric arrays.
|
|
198
|
+
* @param {string} path A string like obsm.X_pca.
|
|
199
|
+
* @param {[number, number]} dims The column indices to load.
|
|
200
|
+
* @returns {Promise<{
|
|
201
|
+
* data: [ZarrTypedArray<any>, ZarrTypedArray<any>],
|
|
202
|
+
* shape: [number, number],
|
|
203
|
+
* }>} A promise for a zarr array containing the data.
|
|
204
|
+
*/
|
|
205
|
+
async loadNumericForDims(path, dims) {
|
|
206
|
+
const formatVersion = await this.getFormatVersion(path);
|
|
207
|
+
if (formatVersion === '0.1') {
|
|
208
|
+
return super.loadNumericForDims(path, dims);
|
|
209
|
+
}
|
|
210
|
+
let columnName = basename(path);
|
|
211
|
+
if (columnName === 'coords') {
|
|
212
|
+
// The "geometry" column was previously called "coords" in version 0.1.
|
|
213
|
+
columnName = 'geometry';
|
|
214
|
+
}
|
|
215
|
+
const arrowTable = await this.loadParquetTable(path);
|
|
216
|
+
if (columnName === 'geometry' && dims[0] === 0 && dims[1] === 1) {
|
|
217
|
+
const geometryColumn = arrowTable.getChild(columnName);
|
|
218
|
+
if (!geometryColumn) {
|
|
219
|
+
throw new Error(`Column ${columnName} not found in parquet table`);
|
|
220
|
+
}
|
|
221
|
+
if (geometryColumn.type.toString() !== 'Binary') {
|
|
222
|
+
throw new Error(`Expected geometry column to have Binary type (WKB) but got ${geometryColumn.type.toString()}`);
|
|
223
|
+
}
|
|
224
|
+
// From GeoPandas.to_parquet docs:
|
|
225
|
+
// "By default, all geometry columns present are serialized to WKB format in the file"
|
|
226
|
+
// Reference: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_parquet.html
|
|
227
|
+
// TODO: support geoarrow serialization schemes in addition to WKB.
|
|
228
|
+
const wkb = new WKB();
|
|
229
|
+
const points = geometryColumn.toArray()
|
|
230
|
+
// @ts-ignore
|
|
231
|
+
.map((/** @type {Uint8Array} */ geom) => wkb.readGeometry(geom).getFlatCoordinates());
|
|
232
|
+
return {
|
|
233
|
+
shape: [2, points.length],
|
|
234
|
+
data: [
|
|
235
|
+
new Float32Array(points.map((/** @type {[number, number]} */ p) => p[0])),
|
|
236
|
+
new Float32Array(points.map((/** @type {[number, number]} */ p) => p[1])),
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
throw new Error('Unexpected column name for loading 2D array from parquet, currently only geometry is supported');
|
|
241
|
+
}
|
|
89
242
|
/**
|
|
90
243
|
* Class method for loading the var index.
|
|
91
244
|
* @param {string|undefined} path
|
|
@@ -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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpatialDataObsSetsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataObsSetsLoader.js"],"names":[],"mappings":"AAEA;;KAEK;AACL;IACE,
|
|
1
|
+
{"version":3,"file":"SpatialDataObsSetsLoader.d.ts","sourceRoot":"","sources":["../../src/spatialdata-loaders/SpatialDataObsSetsLoader.js"],"names":[],"mappings":"AAEA;;KAEK;AACL;IACE,0CAGC;IADC,YAAiC;CAEpC;iCAVgC,4CAA4C"}
|
|
@@ -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":"
|
|
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
|
|
105
|
+
const { path } = this.options;
|
|
19
106
|
if (this.locations) {
|
|
20
107
|
return this.locations;
|
|
21
108
|
}
|
|
22
109
|
if (!this.locations) {
|
|
23
|
-
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/zarr",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.14",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -19,21 +19,25 @@
|
|
|
19
19
|
"d3-array": "^2.4.0",
|
|
20
20
|
"lodash-es": "^4.17.21",
|
|
21
21
|
"zarrita": "0.4.0-next.16",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"@vitessce/
|
|
27
|
-
"@vitessce/
|
|
28
|
-
"@vitessce/
|
|
29
|
-
"@vitessce/
|
|
30
|
-
"@vitessce/
|
|
22
|
+
"apache-arrow": "^17.0.0",
|
|
23
|
+
"parquet-wasm": "^0.6.1",
|
|
24
|
+
"ol": "^10.2.1",
|
|
25
|
+
"dynamic-import-polyfill": "^0.1.1",
|
|
26
|
+
"@vitessce/constants-internal": "3.4.14",
|
|
27
|
+
"@vitessce/gl": "3.4.14",
|
|
28
|
+
"@vitessce/sets-utils": "3.4.14",
|
|
29
|
+
"@vitessce/spatial-utils": "3.4.14",
|
|
30
|
+
"@vitessce/image-utils": "3.4.14",
|
|
31
|
+
"@vitessce/utils": "3.4.14",
|
|
32
|
+
"@vitessce/vit-s": "3.4.14",
|
|
33
|
+
"@vitessce/zarr-utils": "3.4.14",
|
|
34
|
+
"@vitessce/config": "3.4.14"
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
33
37
|
"@zarrita/core": "0.1.0-next.14",
|
|
34
38
|
"@zarrita/storage": "0.1.0-next.6",
|
|
35
39
|
"@zarrita/typedarray": "0.1.0-next.3",
|
|
36
|
-
"@vitessce/types": "3.4.
|
|
40
|
+
"@vitessce/types": "3.4.14"
|
|
37
41
|
},
|
|
38
42
|
"scripts": {
|
|
39
43
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|