@vitessce/json 2.0.0-beta.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/LICENSE +21 -0
- package/dist/JsonSource.js +20 -0
- package/dist/index.js +4 -0
- package/dist/json-loaders/JsonLoader.js +51 -0
- package/dist/json-loaders/JsonLoader.test.js +25 -0
- package/dist/json-loaders/ObsSegmentationsJson.js +30 -0
- package/dist/json-loaders/ObsSetsJson.js +43 -0
- package/dist/json-loaders/ObsSetsJson.test-old.js +32 -0
- package/dist/json-loaders/ObsSetsJson.test.js +28 -0
- package/dist/json-loaders/index.js +3 -0
- package/dist/legacy-loaders/CellsJsonAsObsEmbedding.js +41 -0
- package/dist/legacy-loaders/CellsJsonAsObsLabels.js +28 -0
- package/dist/legacy-loaders/CellsJsonAsObsLocations.js +39 -0
- package/dist/legacy-loaders/CellsJsonAsObsSegmentations.js +55 -0
- package/dist/legacy-loaders/CellsJsonLoaders.test.js +66 -0
- package/dist/legacy-loaders/ClustersJsonAsObsFeatureMatrix.js +48 -0
- package/dist/legacy-loaders/ClustersJsonLoaders.test.js +31 -0
- package/dist/legacy-loaders/GenesJsonAsObsFeatureMatrix.js +34 -0
- package/dist/legacy-loaders/GenesJsonLoaders.test.js +31 -0
- package/dist/legacy-loaders/MoleculesJsonAsObsLabels.js +35 -0
- package/dist/legacy-loaders/MoleculesJsonAsObsLocations.js +46 -0
- package/dist/legacy-loaders/MoleculesJsonLoaders.test.js +44 -0
- package/dist/legacy-loaders/index.js +8 -0
- package/dist/legacy-loaders/schemas/cells.schema.json +52 -0
- package/dist/legacy-loaders/schemas/clusters.schema.json +30 -0
- package/dist/legacy-loaders/schemas/fixtures/cells.bad.json +8 -0
- package/dist/legacy-loaders/schemas/fixtures/cells.good.json +29 -0
- package/dist/legacy-loaders/schemas/fixtures/clusters.good.json +9 -0
- package/dist/legacy-loaders/schemas/fixtures/genes.good.json +4 -0
- package/dist/legacy-loaders/schemas/fixtures/molecules.good.json +7 -0
- package/dist/legacy-loaders/schemas/genes.schema.json +27 -0
- package/dist/legacy-loaders/schemas/molecules.schema.json +20 -0
- package/dist/legacy-loaders/schemas/neighborhoods.schema.json +28 -0
- package/dist/legacy-loaders/schemas/schema.test.js +48 -0
- package/dist/raster-json-loaders/RasterJsonAsImageLoader.js +36 -0
- package/dist/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.js +37 -0
- package/dist/raster-json-loaders/RasterJsonLoader.js +102 -0
- package/dist/raster-json-loaders/index.js +2 -0
- package/package.json +34 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import range from 'lodash/range';
|
|
2
|
+
import sum from 'lodash/sum';
|
|
3
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
4
|
+
import moleculesSchema from './schemas/molecules.schema.json';
|
|
5
|
+
import JsonLoader from '../json-loaders/JsonLoader';
|
|
6
|
+
export default class MoleculesJsonAsObsLabelsLoader extends JsonLoader {
|
|
7
|
+
constructor(dataSource, params) {
|
|
8
|
+
super(dataSource, params);
|
|
9
|
+
this.schema = moleculesSchema;
|
|
10
|
+
}
|
|
11
|
+
loadFromCache(data) {
|
|
12
|
+
if (this.cachedResult) {
|
|
13
|
+
return this.cachedResult;
|
|
14
|
+
}
|
|
15
|
+
const obsIndex = range(sum(Object.values(data).map(v => v.length))).map(i => String(i));
|
|
16
|
+
let obsLabels = [];
|
|
17
|
+
Object.entries(data).forEach(([gene, locations]) => {
|
|
18
|
+
obsLabels = [
|
|
19
|
+
...obsLabels,
|
|
20
|
+
...range(locations.length).map(() => gene),
|
|
21
|
+
];
|
|
22
|
+
});
|
|
23
|
+
this.cachedResult = { obsIndex, obsLabels };
|
|
24
|
+
return this.cachedResult;
|
|
25
|
+
}
|
|
26
|
+
async load() {
|
|
27
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
28
|
+
if (payload instanceof AbstractLoaderError) {
|
|
29
|
+
return Promise.reject(payload);
|
|
30
|
+
}
|
|
31
|
+
const { data, url } = payload;
|
|
32
|
+
const result = this.loadFromCache(data);
|
|
33
|
+
return Promise.resolve(new LoaderResult(result, url));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import range from 'lodash/range';
|
|
2
|
+
import sum from 'lodash/sum';
|
|
3
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
4
|
+
import { DEFAULT_MOLECULES_LAYER } from '@vitessce/gl';
|
|
5
|
+
import moleculesSchema from './schemas/molecules.schema.json';
|
|
6
|
+
import JsonLoader from '../json-loaders/JsonLoader';
|
|
7
|
+
export default class MoleculesJsonAsObsLocationsLoader extends JsonLoader {
|
|
8
|
+
constructor(dataSource, params) {
|
|
9
|
+
super(dataSource, params);
|
|
10
|
+
this.schema = moleculesSchema;
|
|
11
|
+
}
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const moleculesValues = Object.values(data);
|
|
17
|
+
const obsIndex = range(sum(moleculesValues.map(v => v.length))).map(i => String(i));
|
|
18
|
+
const obsLocationsX = new Float32Array(obsIndex.length);
|
|
19
|
+
const obsLocationsY = new Float32Array(obsIndex.length);
|
|
20
|
+
let startAt = 0;
|
|
21
|
+
moleculesValues.forEach((locations) => {
|
|
22
|
+
obsLocationsX.set(locations.map(l => l[0]), startAt);
|
|
23
|
+
obsLocationsY.set(locations.map(l => l[1]), startAt);
|
|
24
|
+
startAt += locations.length;
|
|
25
|
+
});
|
|
26
|
+
const obsLocations = {
|
|
27
|
+
data: [obsLocationsX, obsLocationsY],
|
|
28
|
+
shape: [2, obsLocationsX.length],
|
|
29
|
+
};
|
|
30
|
+
this.cachedResult = { obsIndex, obsLocations };
|
|
31
|
+
return this.cachedResult;
|
|
32
|
+
}
|
|
33
|
+
async load() {
|
|
34
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
35
|
+
if (payload instanceof AbstractLoaderError) {
|
|
36
|
+
return Promise.reject(payload);
|
|
37
|
+
}
|
|
38
|
+
const { data, url } = payload;
|
|
39
|
+
const result = this.loadFromCache(data);
|
|
40
|
+
const coordinationValues = {
|
|
41
|
+
// TODO: do this for anndata segmentation loader
|
|
42
|
+
spatialPointLayer: DEFAULT_MOLECULES_LAYER,
|
|
43
|
+
};
|
|
44
|
+
return Promise.resolve(new LoaderResult(result, url, coordinationValues));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import MoleculesJsonAsObsLocationsLoader from './MoleculesJsonAsObsLocations';
|
|
3
|
+
import MoleculesJsonAsObsLabelsLoader from './MoleculesJsonAsObsLabels';
|
|
4
|
+
import JsonSource from '../JsonSource';
|
|
5
|
+
const createLoader = (ClassDef, config, url) => {
|
|
6
|
+
const configWithUrl = {
|
|
7
|
+
...config,
|
|
8
|
+
url,
|
|
9
|
+
};
|
|
10
|
+
const source = new JsonSource(configWithUrl);
|
|
11
|
+
return new ClassDef(source, configWithUrl);
|
|
12
|
+
};
|
|
13
|
+
describe('loaders/molecules-json-loaders', () => {
|
|
14
|
+
describe('MoleculesJsonAsObsLocationsLoader', () => {
|
|
15
|
+
it('can load obsLocations', async () => {
|
|
16
|
+
const loader = createLoader(MoleculesJsonAsObsLocationsLoader, {
|
|
17
|
+
fileType: 'obsLocations.molecules.json',
|
|
18
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/molecules.good.json');
|
|
19
|
+
const result = await loader.load();
|
|
20
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
21
|
+
const payload = result.data;
|
|
22
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsLocations']);
|
|
23
|
+
expect(payload.obsIndex).toEqual(['0', '1', '2']);
|
|
24
|
+
expect(Array.from(payload.obsLocations.data[0])).toEqual([27008.0, 8315.0, 18683.0]);
|
|
25
|
+
expect(Array.from(payload.obsLocations.data[1])).toEqual([949.0, 22747.0, 19476.0]);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe('MoleculesJsonAsObsLabelsLoader', () => {
|
|
29
|
+
it('can load obsLabels', async () => {
|
|
30
|
+
const loader = createLoader(MoleculesJsonAsObsLabelsLoader, {
|
|
31
|
+
fileType: 'obsLabels.molecules.json',
|
|
32
|
+
coordinationValues: {
|
|
33
|
+
obsLabelsType: 'gene',
|
|
34
|
+
},
|
|
35
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/molecules.good.json');
|
|
36
|
+
const result = await loader.load();
|
|
37
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
38
|
+
const payload = result.data;
|
|
39
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsLabels']);
|
|
40
|
+
expect(payload.obsIndex).toEqual(['0', '1', '2']);
|
|
41
|
+
expect(payload.obsLabels).toEqual(['Klk6_Hybridization5', 'Klk6_Hybridization5', 'Klk6_Hybridization5']);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as CellsJsonAsObsEmbeddingLoader } from './CellsJsonAsObsEmbedding';
|
|
2
|
+
export { default as CellsJsonAsObsLabelsLoader } from './CellsJsonAsObsLabels';
|
|
3
|
+
export { default as CellsJsonAsObsLocationsLoader } from './CellsJsonAsObsLocations';
|
|
4
|
+
export { default as CellsJsonAsObsSegmentationsLoader } from './CellsJsonAsObsSegmentations';
|
|
5
|
+
export { default as ClustersJsonAsObsFeatureMatrixLoader } from './ClustersJsonAsObsFeatureMatrix';
|
|
6
|
+
export { default as GenesJsonAsObsFeatureMatrixLoader } from './GenesJsonAsObsFeatureMatrix';
|
|
7
|
+
export { default as MoleculesJsonAsObsLabelsLoader } from './MoleculesJsonAsObsLabels';
|
|
8
|
+
export { default as MoleculesJsonAsObsLocationsLoader } from './MoleculesJsonAsObsLocations';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://github.com/vitessce/vitessce/#cells",
|
|
4
|
+
"title": "Vitessce cell data",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {
|
|
7
|
+
"coord": {
|
|
8
|
+
"type": "array",
|
|
9
|
+
"minItems": 2,
|
|
10
|
+
"maxItems": 2,
|
|
11
|
+
"items": { "type": "number" }
|
|
12
|
+
},
|
|
13
|
+
"positiveFloatValues": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"patternProperties": {
|
|
16
|
+
".": {
|
|
17
|
+
"type": "number",
|
|
18
|
+
"minimum": 0
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"stringValues": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"patternProperties": {
|
|
25
|
+
".": {
|
|
26
|
+
"type": "string"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"patternProperties": {
|
|
32
|
+
".": {
|
|
33
|
+
"additionalProperties": false,
|
|
34
|
+
"required": [],
|
|
35
|
+
"properties": {
|
|
36
|
+
"mappings": {
|
|
37
|
+
"type": "object",
|
|
38
|
+
"patternProperties": {
|
|
39
|
+
".": { "$ref": "#/definitions/coord" }
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"xy": { "$ref": "#/definitions/coord" },
|
|
43
|
+
"genes": { "$ref": "#/definitions/positiveFloatValues" },
|
|
44
|
+
"factors": { "$ref": "#/definitions/stringValues" },
|
|
45
|
+
"poly": {
|
|
46
|
+
"type": "array",
|
|
47
|
+
"items": { "$ref": "#/definitions/coord" }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://github.com/vitessce/vitessce/#clusters",
|
|
4
|
+
"title": "Vitessce cluster data",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {
|
|
7
|
+
"stringArray": {
|
|
8
|
+
"type": "array",
|
|
9
|
+
"items": { "type": "string" }
|
|
10
|
+
},
|
|
11
|
+
"matrix": {
|
|
12
|
+
"type": "array",
|
|
13
|
+
"items": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"items": {
|
|
16
|
+
"type": "number",
|
|
17
|
+
"minimum": 0,
|
|
18
|
+
"maximum": 1
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"additionalProperties": false,
|
|
24
|
+
"required": ["rows", "cols", "matrix"],
|
|
25
|
+
"properties": {
|
|
26
|
+
"rows": { "$ref": "#/definitions/stringArray" },
|
|
27
|
+
"cols": { "$ref": "#/definitions/stringArray" },
|
|
28
|
+
"matrix": { "$ref": "#/definitions/matrix" }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"778": {
|
|
3
|
+
"mappings": {
|
|
4
|
+
"t-SNE": [
|
|
5
|
+
-58.13238525390625,
|
|
6
|
+
5.219181060791016
|
|
7
|
+
],
|
|
8
|
+
"PCA": [
|
|
9
|
+
1, 2
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"factors": {
|
|
13
|
+
"cluster": "Inhibitory CP"
|
|
14
|
+
},
|
|
15
|
+
"genes": {
|
|
16
|
+
"Gad2": 35,
|
|
17
|
+
"Slc32a1": 41
|
|
18
|
+
},
|
|
19
|
+
"xy": [
|
|
20
|
+
18171.230942376023,
|
|
21
|
+
24590.795274569497
|
|
22
|
+
],
|
|
23
|
+
"poly": [
|
|
24
|
+
[1, 2],
|
|
25
|
+
[3, 4],
|
|
26
|
+
[5, 6]
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://github.com/vitessce/vitessce/#genes",
|
|
4
|
+
"title": "Vitessce gene data",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {
|
|
7
|
+
"positiveFloatValues": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"patternProperties": {
|
|
10
|
+
".": {
|
|
11
|
+
"type": "number",
|
|
12
|
+
"minimum": 0
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"patternProperties": {
|
|
18
|
+
".": {
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"required": ["max", "cells"],
|
|
21
|
+
"properties": {
|
|
22
|
+
"max": { "type": "number" },
|
|
23
|
+
"cells": { "$ref": "#/definitions/positiveFloatValues" }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://github.com/vitessce/vitessce/#molecules",
|
|
4
|
+
"title": "Vitessce molecule data",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {
|
|
7
|
+
"coord": {
|
|
8
|
+
"type": "array",
|
|
9
|
+
"maxItems": 2,
|
|
10
|
+
"minItems": 2,
|
|
11
|
+
"items": { "type": "number" }
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"patternProperties": {
|
|
15
|
+
".": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": { "$ref": "#/definitions/coord" }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://github.com/vitessce/vitessce/#neighborhoods",
|
|
4
|
+
"title": "Vitessce neighborhood data",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {
|
|
7
|
+
"coord": {
|
|
8
|
+
"type": "array",
|
|
9
|
+
"maxItems": 2,
|
|
10
|
+
"minItems": 2,
|
|
11
|
+
"items": { "type": "number" }
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"patternProperties": {
|
|
15
|
+
".": {
|
|
16
|
+
"additionalProperties": false,
|
|
17
|
+
"required": ["poly"],
|
|
18
|
+
"properties": {
|
|
19
|
+
"poly": {
|
|
20
|
+
"type": "array",
|
|
21
|
+
"maxItems": 3,
|
|
22
|
+
"minItems": 3,
|
|
23
|
+
"items": { "$ref": "#/definitions/coord" }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { obsSetsSchema, rasterSchema } from '@vitessce/vit-s';
|
|
3
|
+
/* eslint-disable import/no-dynamic-require */
|
|
4
|
+
/* eslint-disable global-require */
|
|
5
|
+
describe('schemas', () => {
|
|
6
|
+
[
|
|
7
|
+
'cells',
|
|
8
|
+
'clusters',
|
|
9
|
+
'genes',
|
|
10
|
+
'molecules',
|
|
11
|
+
'neighborhoods',
|
|
12
|
+
].forEach((type) => {
|
|
13
|
+
const schemaFile = `${type}.schema.json`;
|
|
14
|
+
describe(schemaFile, () => {
|
|
15
|
+
const schema = require(`./${schemaFile}`);
|
|
16
|
+
let validate;
|
|
17
|
+
if (type === 'config-1.0.1') {
|
|
18
|
+
const obsSets = obsSetsSchema;
|
|
19
|
+
const raster = rasterSchema;
|
|
20
|
+
validate = new Ajv()
|
|
21
|
+
.addSchema(obsSets)
|
|
22
|
+
.addSchema(raster)
|
|
23
|
+
.compile(schema);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
validate = new Ajv().compile(schema);
|
|
27
|
+
}
|
|
28
|
+
const [goodFixture, badFixture, badMessage] = [
|
|
29
|
+
'good', 'bad', 'bad.message',
|
|
30
|
+
].map(stem => `${type}.${stem}.json`);
|
|
31
|
+
it(`passes ${goodFixture}`, () => {
|
|
32
|
+
const data = require(`./fixtures/${goodFixture}`);
|
|
33
|
+
const valid = validate(data);
|
|
34
|
+
if (!valid) {
|
|
35
|
+
console.warn(validate.errors);
|
|
36
|
+
}
|
|
37
|
+
expect(valid).toEqual(true);
|
|
38
|
+
});
|
|
39
|
+
it(`fails ${badFixture}`, () => {
|
|
40
|
+
const data = require(`./fixtures/${badFixture}`);
|
|
41
|
+
const message = require(`./fixtures/${badMessage}`);
|
|
42
|
+
const valid = validate(data);
|
|
43
|
+
expect(valid).toEqual(false);
|
|
44
|
+
expect(validate.errors).toEqual(message);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import RasterLoader from './RasterJsonLoader';
|
|
3
|
+
export default class RasterJsonAsImageLoader extends RasterLoader {
|
|
4
|
+
async load() {
|
|
5
|
+
const loaderResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
6
|
+
if (loaderResult instanceof AbstractLoaderError) {
|
|
7
|
+
return Promise.reject(loaderResult);
|
|
8
|
+
}
|
|
9
|
+
const { data = {}, url: urls, coordinationValues } = loaderResult;
|
|
10
|
+
const { loaders: allLoaders = [], meta: allMeta = [] } = data;
|
|
11
|
+
const loaders = [];
|
|
12
|
+
const meta = [];
|
|
13
|
+
// Only include non-bitmask items.
|
|
14
|
+
allMeta.forEach((layer, i) => {
|
|
15
|
+
if (!layer?.metadata?.isBitmask) {
|
|
16
|
+
loaders.push(allLoaders[i]);
|
|
17
|
+
meta.push(allMeta[i]);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (!coordinationValues?.spatialImageLayer) {
|
|
21
|
+
console.warn('Could not initialize coordinationValues.spatialImageLayer in RasterJsonAsImageLoader. This may be an indicator that the image could not be loaded.');
|
|
22
|
+
}
|
|
23
|
+
return new LoaderResult({
|
|
24
|
+
image: (loaders.length > 0 && meta.length > 0 ? { loaders, meta } : null),
|
|
25
|
+
}, urls, {
|
|
26
|
+
// Filter coordinationValues, keeping only non-bitmask layers.
|
|
27
|
+
spatialImageLayer: coordinationValues?.spatialImageLayer?.filter(l => l.type !== 'bitmask')
|
|
28
|
+
// Re-index since we removed the bitmask layers,
|
|
29
|
+
// so the indices may have gaps.
|
|
30
|
+
.map(layer => ({
|
|
31
|
+
...layer,
|
|
32
|
+
index: meta.findIndex(metaItem => metaItem.name === allMeta[layer.index].name),
|
|
33
|
+
})),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import RasterLoader from './RasterJsonLoader';
|
|
3
|
+
export default class RasterJsonAsObsSegmentationsLoader extends RasterLoader {
|
|
4
|
+
async load() {
|
|
5
|
+
const loaderResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
6
|
+
if (loaderResult instanceof AbstractLoaderError) {
|
|
7
|
+
return Promise.reject(loaderResult);
|
|
8
|
+
}
|
|
9
|
+
const { data = {}, url: urls, coordinationValues } = loaderResult;
|
|
10
|
+
const { loaders: allLoaders = [], meta: allMeta = [] } = data;
|
|
11
|
+
const loaders = [];
|
|
12
|
+
const meta = [];
|
|
13
|
+
// Only include bitmask items.
|
|
14
|
+
allMeta.forEach((layer, i) => {
|
|
15
|
+
if (layer?.metadata?.isBitmask) {
|
|
16
|
+
loaders.push(allLoaders[i]);
|
|
17
|
+
meta.push(allMeta[i]);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (!coordinationValues?.spatialImageLayer) {
|
|
21
|
+
console.warn('Could not initialize coordinationValues.spatialImageLayer in RasterJsonAsObsSegmentationsLoader. This may be an indicator that the image could not be loaded.');
|
|
22
|
+
}
|
|
23
|
+
return new LoaderResult({
|
|
24
|
+
obsSegmentationsType: 'bitmask',
|
|
25
|
+
obsSegmentations: (loaders.length > 0 && meta.length > 0 ? { loaders, meta } : null),
|
|
26
|
+
}, urls, {
|
|
27
|
+
// Filter coordinationValues, keeping only bitmask layers.
|
|
28
|
+
spatialSegmentationLayer: coordinationValues?.spatialImageLayer?.filter(l => l.type === 'bitmask')
|
|
29
|
+
// Re-index since we removed the bitmask layers,
|
|
30
|
+
// so the indices may have gaps.
|
|
31
|
+
.map(layer => ({
|
|
32
|
+
...layer,
|
|
33
|
+
index: meta.findIndex(metaItem => metaItem.name === allMeta[layer.index].name),
|
|
34
|
+
})),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { viv, initializeRasterLayersAndChannels } from '@vitessce/gl';
|
|
2
|
+
import { openArray } from 'zarr';
|
|
3
|
+
import { rasterSchema, AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
4
|
+
import JsonLoader from '../json-loaders/JsonLoader';
|
|
5
|
+
async function initLoader(imageData) {
|
|
6
|
+
const { type, url, metadata, requestInit, } = imageData;
|
|
7
|
+
switch (type) {
|
|
8
|
+
case ('zarr'): {
|
|
9
|
+
const { dimensions, isPyramid, transform, } = metadata || {};
|
|
10
|
+
const labels = dimensions.map(d => d.field);
|
|
11
|
+
let source;
|
|
12
|
+
if (isPyramid) {
|
|
13
|
+
const metadataUrl = `${url}${url.slice(-1) === '/' ? '' : '/'}.zmetadata`;
|
|
14
|
+
const response = await fetch(metadataUrl);
|
|
15
|
+
const { metadata: zarrMetadata } = await response.json();
|
|
16
|
+
const paths = Object.keys(zarrMetadata)
|
|
17
|
+
.filter(metaKey => metaKey.includes('.zarray'))
|
|
18
|
+
.map(arrMetaKeys => arrMetaKeys.slice(0, -7));
|
|
19
|
+
const data = await Promise.all(paths.map(path => openArray({ store: url, path })));
|
|
20
|
+
const [yChunk, xChunk] = data[0].chunks.slice(-2);
|
|
21
|
+
const size = Math.min(yChunk, xChunk);
|
|
22
|
+
// deck.gl requirement for power-of-two tile size.
|
|
23
|
+
const tileSize = 2 ** Math.floor(Math.log2(size));
|
|
24
|
+
source = data.map(d => new viv.ZarrPixelSource(d, labels, tileSize));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const data = await openArray({ store: url });
|
|
28
|
+
source = new viv.ZarrPixelSource(data, labels);
|
|
29
|
+
}
|
|
30
|
+
return { data: source, metadata: { dimensions, transform }, channels: (dimensions.find(d => d.field === 'channel') || dimensions[0]).values };
|
|
31
|
+
}
|
|
32
|
+
case ('ome-tiff'): {
|
|
33
|
+
let loader;
|
|
34
|
+
// Fetch offsets for ome-tiff if needed.
|
|
35
|
+
if (metadata && 'omeTiffOffsetsUrl' in metadata) {
|
|
36
|
+
const { omeTiffOffsetsUrl } = metadata;
|
|
37
|
+
const res = await fetch(omeTiffOffsetsUrl, (requestInit || {}));
|
|
38
|
+
if (res.ok) {
|
|
39
|
+
const offsets = await res.json();
|
|
40
|
+
loader = await viv.loadOmeTiff(url, {
|
|
41
|
+
offsets,
|
|
42
|
+
headers: requestInit?.headers,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error(`Offsets not found but provided: ${res.status} from ${res.url}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
loader = await viv.loadOmeTiff(url, { headers: requestInit?.headers });
|
|
51
|
+
}
|
|
52
|
+
const { Pixels: { Channels } } = loader.metadata;
|
|
53
|
+
const channels = Array.isArray(Channels)
|
|
54
|
+
? Channels.map((channel, i) => channel.Name || `Channel ${i}`)
|
|
55
|
+
: [Channels.Name || `Channel ${0}`];
|
|
56
|
+
return { ...loader, channels };
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
throw Error(`Image type (${type}) is not supported`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export default class RasterLoader extends JsonLoader {
|
|
64
|
+
constructor(dataSource, params) {
|
|
65
|
+
const { url, options } = params;
|
|
66
|
+
if (!url && options) {
|
|
67
|
+
// eslint-disable-next-line no-param-reassign
|
|
68
|
+
dataSource.url = URL.createObjectURL(new Blob([JSON.stringify(options)]));
|
|
69
|
+
}
|
|
70
|
+
super(dataSource, params);
|
|
71
|
+
this.schema = rasterSchema;
|
|
72
|
+
}
|
|
73
|
+
async load() {
|
|
74
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
75
|
+
if (payload instanceof AbstractLoaderError) {
|
|
76
|
+
return Promise.reject(payload);
|
|
77
|
+
}
|
|
78
|
+
const { data: raster } = payload;
|
|
79
|
+
const { images, renderLayers, usePhysicalSizeScaling = false } = raster;
|
|
80
|
+
// Get image name and URL tuples.
|
|
81
|
+
const urls = images
|
|
82
|
+
.filter(image => !image.url.includes('zarr'))
|
|
83
|
+
.map(image => ([image.url, image.name]));
|
|
84
|
+
// Add a loaderCreator function for each image layer.
|
|
85
|
+
const imagesWithLoaderCreators = images.map(image => ({
|
|
86
|
+
...image,
|
|
87
|
+
loaderCreator: async () => initLoader(image),
|
|
88
|
+
}));
|
|
89
|
+
// TODO: use options for initial selection of channels
|
|
90
|
+
// which omit domain/slider ranges.
|
|
91
|
+
if (!this.autoImageCache) {
|
|
92
|
+
this.autoImageCache = initializeRasterLayersAndChannels(imagesWithLoaderCreators, renderLayers, usePhysicalSizeScaling);
|
|
93
|
+
}
|
|
94
|
+
return this.autoImageCache.then((autoImages) => {
|
|
95
|
+
const [autoImageLayers, imageLayerLoaders, imageLayerMeta] = autoImages;
|
|
96
|
+
const coordinationValues = {
|
|
97
|
+
spatialImageLayer: autoImageLayers,
|
|
98
|
+
};
|
|
99
|
+
return new LoaderResult({ loaders: imageLayerLoaders, meta: imageLayerMeta }, urls, coordinationValues);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitessce/json",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"author": "Gehlenborg Lab",
|
|
5
|
+
"homepage": "http://vitessce.io",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@vitessce/constants-internal": "2.0.0-beta.0",
|
|
17
|
+
"@vitessce/gl": "2.0.0-beta.0",
|
|
18
|
+
"@vitessce/sets": "2.0.0-beta.0",
|
|
19
|
+
"@vitessce/utils": "2.0.0-beta.0",
|
|
20
|
+
"@vitessce/vit-s": "2.0.0-beta.0",
|
|
21
|
+
"ajv": "^6.10.0",
|
|
22
|
+
"d3-array": "^2.4.0",
|
|
23
|
+
"lodash": "^4.17.21",
|
|
24
|
+
"zarr": "0.5.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"ajv": "^6.10.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"start": "tsc --watch",
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"test": "pnpm exec vitest --run -r ../../../ --dir ."
|
|
33
|
+
}
|
|
34
|
+
}
|