@vitessce/zarr 3.1.2 → 3.2.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.
- package/dist/{deflate-c5075574.js → deflate-2b2b285b.js} +1 -1
- package/dist/{index-e14e0548.js → index-9ae02eab.js} +1194 -105
- package/dist/index.js +8 -6
- package/dist/{jpeg-917d48dd.js → jpeg-af2abb26.js} +1 -1
- package/dist/{lerc-c153da1f.js → lerc-ac5abe1c.js} +1 -1
- package/dist/{lzw-dc6a7beb.js → lzw-b264d65a.js} +1 -1
- package/dist/{packbits-d627fc76.js → packbits-58bf813f.js} +1 -1
- package/dist/{raw-10e4baac.js → raw-4015af9c.js} +1 -1
- package/dist/{webimage-6254ac4a.js → webimage-d31de7e9.js} +1 -1
- package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts +13 -0
- package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.js +33 -0
- package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts +13 -0
- package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.js +33 -0
- package/dist-tsc/anndata-loaders/index.d.ts +2 -0
- package/dist-tsc/anndata-loaders/index.js +2 -0
- package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts.map +1 -1
- package/dist-tsc/ome-loaders/OmeZarrLoader.js +60 -25
- package/package.json +8 -7
- package/src/anndata-loaders/ObsPointsAnndataLoader.js +40 -0
- package/src/anndata-loaders/ObsSpotsAnndataLoader.js +40 -0
- package/src/anndata-loaders/index.js +2 -0
- package/src/ome-loaders/OmeZarrLoader.js +75 -25
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A, F, G, a, M, b, O,
|
|
1
|
+
import { A, F, G, a, M, b, O, i, e, d, f, h, c, j, Z } from "./index-9ae02eab.js";
|
|
2
2
|
import "@vitessce/vit-s";
|
|
3
3
|
import "react";
|
|
4
4
|
export {
|
|
@@ -9,10 +9,12 @@ export {
|
|
|
9
9
|
M as MuDataSource,
|
|
10
10
|
b as ObsEmbeddingAnndataLoader,
|
|
11
11
|
O as ObsFeatureMatrixAnndataLoader,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
d as
|
|
15
|
-
|
|
16
|
-
h as
|
|
12
|
+
i as ObsLabelsAnndataLoader,
|
|
13
|
+
e as ObsLocationsAnndataLoader,
|
|
14
|
+
d as ObsPointsAnndataLoader,
|
|
15
|
+
f as ObsSegmentationsAnndataLoader,
|
|
16
|
+
h as ObsSetsAnndataLoader,
|
|
17
|
+
c as ObsSpotsAnndataLoader,
|
|
18
|
+
j as OmeZarrLoader,
|
|
17
19
|
Z as ZarrDataSource
|
|
18
20
|
};
|
|
@@ -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-9ae02eab.js";
|
|
3
3
|
import "@vitessce/vit-s";
|
|
4
4
|
import "react";
|
|
5
5
|
const LercParameters = {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for embedding arrays located in anndata.zarr stores.
|
|
3
|
+
*/
|
|
4
|
+
export default class ObsPointsAnndataLoader {
|
|
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
|
+
loadPoints(): Promise<any>;
|
|
10
|
+
locations: any;
|
|
11
|
+
load(): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ObsPointsAnndataLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObsPointsAnndataLoader.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/ObsPointsAnndataLoader.js"],"names":[],"mappings":"AAIA;;GAEG;AACH;IACE;;;OAGG;IACH,2BAWC;IALG,eAA+D;IAOnE,qBAaC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError, } from '@vitessce/vit-s';
|
|
2
|
+
/**
|
|
3
|
+
* Loader for embedding arrays located in anndata.zarr stores.
|
|
4
|
+
*/
|
|
5
|
+
export default class ObsPointsAnndataLoader extends AbstractTwoStepLoader {
|
|
6
|
+
/**
|
|
7
|
+
* Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
|
|
8
|
+
* @returns {Promise} A promise for an array of columns.
|
|
9
|
+
*/
|
|
10
|
+
loadPoints() {
|
|
11
|
+
const { path, dims = [0, 1] } = this.options;
|
|
12
|
+
if (this.locations) {
|
|
13
|
+
return this.locations;
|
|
14
|
+
}
|
|
15
|
+
if (!this.locations) {
|
|
16
|
+
this.locations = this.dataSource.loadNumericForDims(path, dims);
|
|
17
|
+
return this.locations;
|
|
18
|
+
}
|
|
19
|
+
this.locations = Promise.resolve(null);
|
|
20
|
+
return this.locations;
|
|
21
|
+
}
|
|
22
|
+
async load() {
|
|
23
|
+
const { path } = this.options;
|
|
24
|
+
const superResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
25
|
+
if (superResult instanceof AbstractLoaderError) {
|
|
26
|
+
return Promise.reject(superResult);
|
|
27
|
+
}
|
|
28
|
+
return Promise.all([
|
|
29
|
+
this.dataSource.loadObsIndex(path),
|
|
30
|
+
this.loadPoints(),
|
|
31
|
+
]).then(([obsIndex, obsPoints]) => Promise.resolve(new LoaderResult({ obsIndex, obsPoints }, null)));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for embedding arrays located in anndata.zarr stores.
|
|
3
|
+
*/
|
|
4
|
+
export default class ObsSpotsAnndataLoader {
|
|
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=ObsSpotsAnndataLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObsSpotsAnndataLoader.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/ObsSpotsAnndataLoader.js"],"names":[],"mappings":"AAIA;;GAEG;AACH;IACE;;;OAGG;IACH,0BAWC;IALG,eAA+D;IAOnE,qBAaC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError, } from '@vitessce/vit-s';
|
|
2
|
+
/**
|
|
3
|
+
* Loader for embedding arrays located in anndata.zarr stores.
|
|
4
|
+
*/
|
|
5
|
+
export default class ObsSpotsAnndataLoader extends AbstractTwoStepLoader {
|
|
6
|
+
/**
|
|
7
|
+
* Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
|
|
8
|
+
* @returns {Promise} A promise for an array of columns.
|
|
9
|
+
*/
|
|
10
|
+
loadSpots() {
|
|
11
|
+
const { path, dims = [0, 1] } = this.options;
|
|
12
|
+
if (this.locations) {
|
|
13
|
+
return this.locations;
|
|
14
|
+
}
|
|
15
|
+
if (!this.locations) {
|
|
16
|
+
this.locations = this.dataSource.loadNumericForDims(path, dims);
|
|
17
|
+
return this.locations;
|
|
18
|
+
}
|
|
19
|
+
this.locations = Promise.resolve(null);
|
|
20
|
+
return this.locations;
|
|
21
|
+
}
|
|
22
|
+
async load() {
|
|
23
|
+
const { path } = this.options;
|
|
24
|
+
const superResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
25
|
+
if (superResult instanceof AbstractLoaderError) {
|
|
26
|
+
return Promise.reject(superResult);
|
|
27
|
+
}
|
|
28
|
+
return Promise.all([
|
|
29
|
+
this.dataSource.loadObsIndex(path),
|
|
30
|
+
this.loadSpots(),
|
|
31
|
+
]).then(([obsIndex, obsSpots]) => Promise.resolve(new LoaderResult({ obsIndex, obsSpots }, null)));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as ObsFeatureMatrixAnndataLoader } from "./ObsFeatureMatrixAnndataLoader.js";
|
|
2
2
|
export { default as ObsEmbeddingAnndataLoader } from "./ObsEmbeddingAnndataLoader.js";
|
|
3
|
+
export { default as ObsSpotsAnndataLoader } from "./ObsSpotsAnndataLoader.js";
|
|
4
|
+
export { default as ObsPointsAnndataLoader } from "./ObsPointsAnndataLoader.js";
|
|
3
5
|
export { default as ObsLocationsAnndataLoader } from "./ObsLocationsAnndataLoader.js";
|
|
4
6
|
export { default as ObsSegmentationsAnndataLoader } from "./ObsSegmentationsAnndataLoader.js";
|
|
5
7
|
export { default as ObsSetsAnndataLoader } from "./ObsSetsAnndataLoader.js";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as ObsFeatureMatrixAnndataLoader } from './ObsFeatureMatrixAnndataLoader.js';
|
|
2
2
|
export { default as ObsEmbeddingAnndataLoader } from './ObsEmbeddingAnndataLoader.js';
|
|
3
|
+
export { default as ObsSpotsAnndataLoader } from './ObsSpotsAnndataLoader.js';
|
|
4
|
+
export { default as ObsPointsAnndataLoader } from './ObsPointsAnndataLoader.js';
|
|
3
5
|
export { default as ObsLocationsAnndataLoader } from './ObsLocationsAnndataLoader.js';
|
|
4
6
|
export { default as ObsSegmentationsAnndataLoader } from './ObsSegmentationsAnndataLoader.js';
|
|
5
7
|
export { default as ObsSetsAnndataLoader } from './ObsSetsAnndataLoader.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OmeZarrLoader.d.ts","sourceRoot":"","sources":["../../src/ome-loaders/OmeZarrLoader.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OmeZarrLoader.d.ts","sourceRoot":"","sources":["../../src/ome-loaders/OmeZarrLoader.js"],"names":[],"mappings":"AAkBA;IACE,qBAgJC;CACF"}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { viv } from '@vitessce/gl';
|
|
2
|
-
import { initializeRasterLayersAndChannels, coordinateTransformationsToMatrix, getNgffAxes, } from '@vitessce/spatial-utils';
|
|
2
|
+
import { initializeRasterLayersAndChannels, coordinateTransformationsToMatrix, getNgffAxes, hexToRgb, normalizeCoordinateTransformations, } from '@vitessce/spatial-utils';
|
|
3
|
+
import { ImageWrapper, } from '@vitessce/image-utils';
|
|
3
4
|
import { AbstractLoaderError, LoaderResult, AbstractTwoStepLoader, } from '@vitessce/vit-s';
|
|
4
|
-
function hexToRgb(hex) {
|
|
5
|
-
const result = /^#?([A-F\d]{2})([A-F\d]{2})([A-F\d]{2})$/i.exec(hex);
|
|
6
|
-
return [
|
|
7
|
-
parseInt(result[1].toLowerCase(), 16),
|
|
8
|
-
parseInt(result[2].toLowerCase(), 16),
|
|
9
|
-
parseInt(result[3].toLowerCase(), 16),
|
|
10
|
-
];
|
|
11
|
-
}
|
|
12
5
|
export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
13
6
|
async load() {
|
|
14
7
|
const payload = await this.dataSource.getJson('.zattrs').catch(reason => Promise.resolve(reason));
|
|
@@ -17,24 +10,28 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
17
10
|
}
|
|
18
11
|
const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
|
|
19
12
|
const loader = await viv.loadOmeZarr(this.url, { fetchOptions: this.requestInit, type: 'multiscales' });
|
|
13
|
+
const imageWrapper = new ImageWrapper(loader, this.options);
|
|
20
14
|
const { metadata, data } = loader;
|
|
21
|
-
const { omero, multiscales } = metadata;
|
|
22
|
-
if
|
|
23
|
-
|
|
15
|
+
const { omero, multiscales, channels_metadata: spatialDataChannels } = metadata;
|
|
16
|
+
// Crude way to check if this is a SpatialData OME-NGFF.
|
|
17
|
+
const isSpatialData = !!spatialDataChannels;
|
|
18
|
+
if (!isSpatialData && !omero) {
|
|
19
|
+
console.error('image.ome-zarr must have omero metadata in attributes.');
|
|
24
20
|
return Promise.reject(payload);
|
|
25
21
|
}
|
|
26
22
|
if (!Array.isArray(multiscales) || multiscales.length === 0) {
|
|
27
23
|
console.error('Multiscales array must exist and have at least one element');
|
|
28
24
|
}
|
|
29
|
-
const { coordinateTransformations } = multiscales[0];
|
|
25
|
+
const { datasets, coordinateTransformations: coordinateTransformationsFromFile, name: imageName, } = multiscales[0];
|
|
30
26
|
// Axes in v0.4 format.
|
|
31
27
|
const axes = getNgffAxes(multiscales[0].axes);
|
|
28
|
+
// SpatialData uses the new coordinateTransformations spec.
|
|
29
|
+
// Reference: https://github.com/ome/ngff/pull/138
|
|
30
|
+
// This new spec is very flexible, so here we will attepmpt to convert it back to the old spec.
|
|
31
|
+
const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(coordinateTransformationsFromFile, datasets);
|
|
32
32
|
const transformMatrixFromOptions = coordinateTransformationsToMatrix(coordinateTransformationsFromOptions, axes);
|
|
33
|
-
const transformMatrixFromFile = coordinateTransformationsToMatrix(
|
|
33
|
+
const transformMatrixFromFile = coordinateTransformationsToMatrix(normCoordinateTransformationsFromFile, axes);
|
|
34
34
|
const transformMatrix = transformMatrixFromFile.multiplyLeft(transformMatrixFromOptions);
|
|
35
|
-
const { rdefs, channels, name: omeroName } = omero;
|
|
36
|
-
const t = rdefs.defaultT ?? 0;
|
|
37
|
-
const z = rdefs.defaultZ ?? 0;
|
|
38
35
|
const filterSelection = (sel) => {
|
|
39
36
|
// Remove selection keys for which there is no dimension.
|
|
40
37
|
if (data.length > 0) {
|
|
@@ -50,14 +47,45 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
50
47
|
}
|
|
51
48
|
return sel;
|
|
52
49
|
};
|
|
50
|
+
let channelObjects;
|
|
51
|
+
let channelLabels = [];
|
|
52
|
+
let initialTargetT = 0;
|
|
53
|
+
let initialTargetZ = 0;
|
|
54
|
+
if (isSpatialData) {
|
|
55
|
+
// TODO: Consider removing support for `channels_metadata` once OME-NGFF loosens
|
|
56
|
+
// requirements for channel metadata fields such as `window` and `color`.
|
|
57
|
+
// (Unclear if we will need to keep this around for backwards compatibility with
|
|
58
|
+
// those SpatialData objects generated in the meantime though.)
|
|
59
|
+
// References:
|
|
60
|
+
// - https://github.com/ome/ngff/issues/192
|
|
61
|
+
// - https://github.com/ome/ome-zarr-py/pull/261
|
|
62
|
+
const { channels } = spatialDataChannels;
|
|
63
|
+
channelObjects = channels.map((channel, i) => ({
|
|
64
|
+
selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
|
|
65
|
+
slider: [0, 255],
|
|
66
|
+
color: [255, 255, 255],
|
|
67
|
+
}));
|
|
68
|
+
channelLabels = channels.map(c => c.label);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const { rdefs, channels } = omero;
|
|
72
|
+
if (typeof rdefs.defaultT === 'number') {
|
|
73
|
+
initialTargetT = rdefs.defaultT;
|
|
74
|
+
}
|
|
75
|
+
if (typeof rdefs.defaultZ === 'number') {
|
|
76
|
+
initialTargetZ = rdefs.defaultZ;
|
|
77
|
+
}
|
|
78
|
+
channelObjects = channels.map((channel, i) => ({
|
|
79
|
+
selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
|
|
80
|
+
slider: [channel.window.start, channel.window.end],
|
|
81
|
+
color: hexToRgb(channel.color),
|
|
82
|
+
}));
|
|
83
|
+
channelLabels = channels.map(c => c.label);
|
|
84
|
+
}
|
|
53
85
|
const imagesWithLoaderCreators = [
|
|
54
86
|
{
|
|
55
|
-
name:
|
|
56
|
-
channels:
|
|
57
|
-
selection: filterSelection({ z, t, c: i }),
|
|
58
|
-
slider: [channel.window.start, channel.window.end],
|
|
59
|
-
color: hexToRgb(channel.color),
|
|
60
|
-
})),
|
|
87
|
+
name: imageName || 'Image',
|
|
88
|
+
channels: channelObjects,
|
|
61
89
|
...(transformMatrix ? {
|
|
62
90
|
metadata: {
|
|
63
91
|
transform: {
|
|
@@ -65,7 +93,7 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
65
93
|
},
|
|
66
94
|
},
|
|
67
95
|
} : {}),
|
|
68
|
-
loaderCreator: async () => ({ ...loader, channels:
|
|
96
|
+
loaderCreator: async () => ({ ...loader, channels: channelLabels }),
|
|
69
97
|
},
|
|
70
98
|
];
|
|
71
99
|
// TODO: use options for initial selection of channels
|
|
@@ -74,6 +102,13 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
74
102
|
const coordinationValues = {
|
|
75
103
|
spatialImageLayer: autoImageLayers,
|
|
76
104
|
};
|
|
77
|
-
return Promise.resolve(new LoaderResult({
|
|
105
|
+
return Promise.resolve(new LoaderResult({
|
|
106
|
+
image: {
|
|
107
|
+
loaders: imageLayerLoaders,
|
|
108
|
+
meta: imageLayerMeta,
|
|
109
|
+
instance: imageWrapper, // TODO: make this the root value of LoaderResult.image.
|
|
110
|
+
},
|
|
111
|
+
featureIndex: imageWrapper.getChannelNames(),
|
|
112
|
+
}, [], coordinationValues));
|
|
78
113
|
}
|
|
79
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/zarr",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
"d3-array": "^2.4.0",
|
|
20
20
|
"lodash-es": "^4.17.21",
|
|
21
21
|
"zarr": "0.5.1",
|
|
22
|
-
"@vitessce/constants-internal": "3.
|
|
23
|
-
"@vitessce/gl": "3.
|
|
24
|
-
"@vitessce/sets-utils": "3.
|
|
25
|
-
"@vitessce/spatial-utils": "3.
|
|
26
|
-
"@vitessce/utils": "3.
|
|
27
|
-
"@vitessce/
|
|
22
|
+
"@vitessce/constants-internal": "3.2.0",
|
|
23
|
+
"@vitessce/gl": "3.2.0",
|
|
24
|
+
"@vitessce/sets-utils": "3.2.0",
|
|
25
|
+
"@vitessce/spatial-utils": "3.2.0",
|
|
26
|
+
"@vitessce/image-utils": "3.2.0",
|
|
27
|
+
"@vitessce/utils": "3.2.0",
|
|
28
|
+
"@vitessce/vit-s": "3.2.0"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LoaderResult, AbstractTwoStepLoader, AbstractLoaderError,
|
|
3
|
+
} from '@vitessce/vit-s';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loader for embedding arrays located in anndata.zarr stores.
|
|
7
|
+
*/
|
|
8
|
+
export default class ObsPointsAnndataLoader 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
|
+
loadPoints() {
|
|
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(path, dims);
|
|
20
|
+
return this.locations;
|
|
21
|
+
}
|
|
22
|
+
this.locations = Promise.resolve(null);
|
|
23
|
+
return this.locations;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async load() {
|
|
27
|
+
const { path } = this.options;
|
|
28
|
+
const superResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
29
|
+
if (superResult instanceof AbstractLoaderError) {
|
|
30
|
+
return Promise.reject(superResult);
|
|
31
|
+
}
|
|
32
|
+
return Promise.all([
|
|
33
|
+
this.dataSource.loadObsIndex(path),
|
|
34
|
+
this.loadPoints(),
|
|
35
|
+
]).then(([obsIndex, obsPoints]) => Promise.resolve(new LoaderResult(
|
|
36
|
+
{ obsIndex, obsPoints },
|
|
37
|
+
null,
|
|
38
|
+
)));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LoaderResult, AbstractTwoStepLoader, AbstractLoaderError,
|
|
3
|
+
} from '@vitessce/vit-s';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loader for embedding arrays located in anndata.zarr stores.
|
|
7
|
+
*/
|
|
8
|
+
export default class ObsSpotsAnndataLoader 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(path, dims);
|
|
20
|
+
return this.locations;
|
|
21
|
+
}
|
|
22
|
+
this.locations = Promise.resolve(null);
|
|
23
|
+
return this.locations;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async load() {
|
|
27
|
+
const { path } = this.options;
|
|
28
|
+
const superResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
29
|
+
if (superResult instanceof AbstractLoaderError) {
|
|
30
|
+
return Promise.reject(superResult);
|
|
31
|
+
}
|
|
32
|
+
return Promise.all([
|
|
33
|
+
this.dataSource.loadObsIndex(path),
|
|
34
|
+
this.loadSpots(),
|
|
35
|
+
]).then(([obsIndex, obsSpots]) => Promise.resolve(new LoaderResult(
|
|
36
|
+
{ obsIndex, obsSpots },
|
|
37
|
+
null,
|
|
38
|
+
)));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as ObsFeatureMatrixAnndataLoader } from './ObsFeatureMatrixAnndataLoader.js';
|
|
2
2
|
export { default as ObsEmbeddingAnndataLoader } from './ObsEmbeddingAnndataLoader.js';
|
|
3
|
+
export { default as ObsSpotsAnndataLoader } from './ObsSpotsAnndataLoader.js';
|
|
4
|
+
export { default as ObsPointsAnndataLoader } from './ObsPointsAnndataLoader.js';
|
|
3
5
|
export { default as ObsLocationsAnndataLoader } from './ObsLocationsAnndataLoader.js';
|
|
4
6
|
export { default as ObsSegmentationsAnndataLoader } from './ObsSegmentationsAnndataLoader.js';
|
|
5
7
|
export { default as ObsSetsAnndataLoader } from './ObsSetsAnndataLoader.js';
|
|
@@ -3,21 +3,18 @@ import {
|
|
|
3
3
|
initializeRasterLayersAndChannels,
|
|
4
4
|
coordinateTransformationsToMatrix,
|
|
5
5
|
getNgffAxes,
|
|
6
|
+
hexToRgb,
|
|
7
|
+
normalizeCoordinateTransformations,
|
|
6
8
|
} from '@vitessce/spatial-utils';
|
|
9
|
+
import {
|
|
10
|
+
ImageWrapper,
|
|
11
|
+
} from '@vitessce/image-utils';
|
|
7
12
|
import {
|
|
8
13
|
AbstractLoaderError,
|
|
9
14
|
LoaderResult,
|
|
10
15
|
AbstractTwoStepLoader,
|
|
11
16
|
} from '@vitessce/vit-s';
|
|
12
17
|
|
|
13
|
-
function hexToRgb(hex) {
|
|
14
|
-
const result = /^#?([A-F\d]{2})([A-F\d]{2})([A-F\d]{2})$/i.exec(hex);
|
|
15
|
-
return [
|
|
16
|
-
parseInt(result[1].toLowerCase(), 16),
|
|
17
|
-
parseInt(result[2].toLowerCase(), 16),
|
|
18
|
-
parseInt(result[3].toLowerCase(), 16),
|
|
19
|
-
];
|
|
20
|
-
}
|
|
21
18
|
|
|
22
19
|
export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
23
20
|
async load() {
|
|
@@ -29,36 +26,51 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
29
26
|
const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
|
|
30
27
|
|
|
31
28
|
const loader = await viv.loadOmeZarr(this.url, { fetchOptions: this.requestInit, type: 'multiscales' });
|
|
29
|
+
|
|
30
|
+
const imageWrapper = new ImageWrapper(loader, this.options);
|
|
31
|
+
|
|
32
32
|
const { metadata, data } = loader;
|
|
33
33
|
|
|
34
|
-
const { omero, multiscales } = metadata;
|
|
34
|
+
const { omero, multiscales, channels_metadata: spatialDataChannels } = metadata;
|
|
35
35
|
|
|
36
|
-
if
|
|
37
|
-
|
|
36
|
+
// Crude way to check if this is a SpatialData OME-NGFF.
|
|
37
|
+
const isSpatialData = !!spatialDataChannels;
|
|
38
|
+
|
|
39
|
+
if (!isSpatialData && !omero) {
|
|
40
|
+
console.error('image.ome-zarr must have omero metadata in attributes.');
|
|
38
41
|
return Promise.reject(payload);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
if (!Array.isArray(multiscales) || multiscales.length === 0) {
|
|
42
45
|
console.error('Multiscales array must exist and have at least one element');
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
datasets,
|
|
50
|
+
coordinateTransformations: coordinateTransformationsFromFile,
|
|
51
|
+
name: imageName,
|
|
52
|
+
} = multiscales[0];
|
|
45
53
|
|
|
46
54
|
// Axes in v0.4 format.
|
|
47
55
|
const axes = getNgffAxes(multiscales[0].axes);
|
|
48
56
|
|
|
57
|
+
// SpatialData uses the new coordinateTransformations spec.
|
|
58
|
+
// Reference: https://github.com/ome/ngff/pull/138
|
|
59
|
+
|
|
60
|
+
// This new spec is very flexible, so here we will attepmpt to convert it back to the old spec.
|
|
61
|
+
const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(
|
|
62
|
+
coordinateTransformationsFromFile, datasets,
|
|
63
|
+
);
|
|
64
|
+
|
|
49
65
|
const transformMatrixFromOptions = coordinateTransformationsToMatrix(
|
|
50
66
|
coordinateTransformationsFromOptions, axes,
|
|
51
67
|
);
|
|
52
68
|
const transformMatrixFromFile = coordinateTransformationsToMatrix(
|
|
53
|
-
|
|
69
|
+
normCoordinateTransformationsFromFile, axes,
|
|
54
70
|
);
|
|
55
71
|
|
|
56
72
|
const transformMatrix = transformMatrixFromFile.multiplyLeft(transformMatrixFromOptions);
|
|
57
73
|
|
|
58
|
-
const { rdefs, channels, name: omeroName } = omero;
|
|
59
|
-
|
|
60
|
-
const t = rdefs.defaultT ?? 0;
|
|
61
|
-
const z = rdefs.defaultZ ?? 0;
|
|
62
74
|
|
|
63
75
|
const filterSelection = (sel) => {
|
|
64
76
|
// Remove selection keys for which there is no dimension.
|
|
@@ -76,14 +88,45 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
76
88
|
return sel;
|
|
77
89
|
};
|
|
78
90
|
|
|
91
|
+
let channelObjects;
|
|
92
|
+
let channelLabels = [];
|
|
93
|
+
let initialTargetT = 0;
|
|
94
|
+
let initialTargetZ = 0;
|
|
95
|
+
if (isSpatialData) {
|
|
96
|
+
// TODO: Consider removing support for `channels_metadata` once OME-NGFF loosens
|
|
97
|
+
// requirements for channel metadata fields such as `window` and `color`.
|
|
98
|
+
// (Unclear if we will need to keep this around for backwards compatibility with
|
|
99
|
+
// those SpatialData objects generated in the meantime though.)
|
|
100
|
+
// References:
|
|
101
|
+
// - https://github.com/ome/ngff/issues/192
|
|
102
|
+
// - https://github.com/ome/ome-zarr-py/pull/261
|
|
103
|
+
const { channels } = spatialDataChannels;
|
|
104
|
+
channelObjects = channels.map((channel, i) => ({
|
|
105
|
+
selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
|
|
106
|
+
slider: [0, 255],
|
|
107
|
+
color: [255, 255, 255],
|
|
108
|
+
}));
|
|
109
|
+
channelLabels = channels.map(c => c.label);
|
|
110
|
+
} else {
|
|
111
|
+
const { rdefs, channels } = omero;
|
|
112
|
+
if (typeof rdefs.defaultT === 'number') {
|
|
113
|
+
initialTargetT = rdefs.defaultT;
|
|
114
|
+
}
|
|
115
|
+
if (typeof rdefs.defaultZ === 'number') {
|
|
116
|
+
initialTargetZ = rdefs.defaultZ;
|
|
117
|
+
}
|
|
118
|
+
channelObjects = channels.map((channel, i) => ({
|
|
119
|
+
selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
|
|
120
|
+
slider: [channel.window.start, channel.window.end],
|
|
121
|
+
color: hexToRgb(channel.color),
|
|
122
|
+
}));
|
|
123
|
+
channelLabels = channels.map(c => c.label);
|
|
124
|
+
}
|
|
125
|
+
|
|
79
126
|
const imagesWithLoaderCreators = [
|
|
80
127
|
{
|
|
81
|
-
name:
|
|
82
|
-
channels:
|
|
83
|
-
selection: filterSelection({ z, t, c: i }),
|
|
84
|
-
slider: [channel.window.start, channel.window.end],
|
|
85
|
-
color: hexToRgb(channel.color),
|
|
86
|
-
})),
|
|
128
|
+
name: imageName || 'Image',
|
|
129
|
+
channels: channelObjects,
|
|
87
130
|
...(transformMatrix ? {
|
|
88
131
|
metadata: {
|
|
89
132
|
transform: {
|
|
@@ -91,7 +134,7 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
91
134
|
},
|
|
92
135
|
},
|
|
93
136
|
} : {}),
|
|
94
|
-
loaderCreator: async () => ({ ...loader, channels:
|
|
137
|
+
loaderCreator: async () => ({ ...loader, channels: channelLabels }),
|
|
95
138
|
},
|
|
96
139
|
];
|
|
97
140
|
|
|
@@ -107,7 +150,14 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
|
|
|
107
150
|
spatialImageLayer: autoImageLayers,
|
|
108
151
|
};
|
|
109
152
|
return Promise.resolve(new LoaderResult(
|
|
110
|
-
{
|
|
153
|
+
{
|
|
154
|
+
image: {
|
|
155
|
+
loaders: imageLayerLoaders, // TODO: replace with imageWrapper
|
|
156
|
+
meta: imageLayerMeta, // TODO: replace with imageWrapper
|
|
157
|
+
instance: imageWrapper, // TODO: make this the root value of LoaderResult.image.
|
|
158
|
+
},
|
|
159
|
+
featureIndex: imageWrapper.getChannelNames(),
|
|
160
|
+
},
|
|
111
161
|
[],
|
|
112
162
|
coordinationValues,
|
|
113
163
|
));
|