@vitessce/json 2.0.3-beta.0 → 3.0.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-a2d6b257.js +12 -0
- package/dist/index-8cb529a4.js +151122 -0
- package/dist/index.js +19 -4
- package/dist/jpeg-e323e6ed.js +839 -0
- package/dist/lerc-0dc6a58a.js +2005 -0
- package/dist/lzw-e9c82d83.js +127 -0
- package/dist/packbits-0a0f672b.js +29 -0
- package/dist/pako.esm-68f84e2a.js +4022 -0
- package/dist/raw-3f989896.js +11 -0
- package/dist/webimage-f799ed95.js +31 -0
- package/dist-tsc/JsonSource.d.ts +11 -0
- package/dist-tsc/JsonSource.d.ts.map +1 -0
- package/dist-tsc/index.d.ts +5 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +5 -0
- package/dist-tsc/json-loaders/JsonLoader.d.ts +8 -0
- package/dist-tsc/json-loaders/JsonLoader.d.ts.map +1 -0
- package/{dist → dist-tsc}/json-loaders/JsonLoader.js +8 -8
- package/dist-tsc/json-loaders/JsonLoader.test.d.ts +2 -0
- package/dist-tsc/json-loaders/JsonLoader.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/json-loaders/JsonLoader.test.js +2 -2
- package/dist-tsc/json-loaders/ObsSegmentationsJson.d.ts +21 -0
- package/dist-tsc/json-loaders/ObsSegmentationsJson.d.ts.map +1 -0
- package/{dist → dist-tsc}/json-loaders/ObsSegmentationsJson.js +2 -6
- package/dist-tsc/json-loaders/ObsSetsJson.d.ts +5 -0
- package/dist-tsc/json-loaders/ObsSetsJson.d.ts.map +1 -0
- package/{dist → dist-tsc}/json-loaders/ObsSetsJson.js +4 -3
- package/dist-tsc/json-loaders/ObsSetsJson.test-old.d.ts +1 -0
- package/dist-tsc/json-loaders/ObsSetsJson.test-old.d.ts.map +1 -0
- package/dist-tsc/json-loaders/index.d.ts +4 -0
- package/dist-tsc/json-loaders/index.d.ts.map +1 -0
- package/dist-tsc/json-loaders/index.js +3 -0
- package/dist-tsc/legacy-loaders/CellsJsonAsObsEmbedding.d.ts +38 -0
- package/dist-tsc/legacy-loaders/CellsJsonAsObsEmbedding.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsEmbedding.js +2 -2
- package/dist-tsc/legacy-loaders/CellsJsonAsObsLabels.d.ts +32 -0
- package/dist-tsc/legacy-loaders/CellsJsonAsObsLabels.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsLabels.js +2 -2
- package/dist-tsc/legacy-loaders/CellsJsonAsObsLocations.d.ts +38 -0
- package/dist-tsc/legacy-loaders/CellsJsonAsObsLocations.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsLocations.js +2 -2
- package/dist-tsc/legacy-loaders/CellsJsonAsObsSegmentations.d.ts +38 -0
- package/dist-tsc/legacy-loaders/CellsJsonAsObsSegmentations.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/CellsJsonAsObsSegmentations.js +2 -2
- package/dist-tsc/legacy-loaders/CellsJsonLoaders.test.d.ts +2 -0
- package/dist-tsc/legacy-loaders/CellsJsonLoaders.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/CellsJsonLoaders.test.js +4 -4
- package/dist-tsc/legacy-loaders/ClustersJsonAsObsFeatureMatrix.d.ts +32 -0
- package/dist-tsc/legacy-loaders/ClustersJsonAsObsFeatureMatrix.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/ClustersJsonAsObsFeatureMatrix.js +3 -3
- package/dist-tsc/legacy-loaders/ClustersJsonLoaders.test.d.ts +2 -0
- package/dist-tsc/legacy-loaders/ClustersJsonLoaders.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/ClustersJsonLoaders.test.js +2 -2
- package/dist-tsc/legacy-loaders/GenesJsonAsObsFeatureMatrix.d.ts +29 -0
- package/dist-tsc/legacy-loaders/GenesJsonAsObsFeatureMatrix.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/GenesJsonAsObsFeatureMatrix.js +2 -2
- package/dist-tsc/legacy-loaders/GenesJsonLoaders.test.d.ts +2 -0
- package/dist-tsc/legacy-loaders/GenesJsonLoaders.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/GenesJsonLoaders.test.js +2 -2
- package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLabels.d.ts +14 -0
- package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLabels.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/MoleculesJsonAsObsLabels.js +3 -4
- package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLocations.d.ts +20 -0
- package/dist-tsc/legacy-loaders/MoleculesJsonAsObsLocations.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/MoleculesJsonAsObsLocations.js +3 -4
- package/dist-tsc/legacy-loaders/MoleculesJsonLoaders.test.d.ts +2 -0
- package/dist-tsc/legacy-loaders/MoleculesJsonLoaders.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/MoleculesJsonLoaders.test.js +3 -3
- package/dist-tsc/legacy-loaders/index.d.ts +9 -0
- package/dist-tsc/legacy-loaders/index.d.ts.map +1 -0
- package/{dist → dist-tsc}/legacy-loaders/index.js +8 -8
- package/dist-tsc/legacy-loaders/schemas/cells.d.ts +21 -0
- package/dist-tsc/legacy-loaders/schemas/cells.d.ts.map +1 -0
- package/dist-tsc/legacy-loaders/schemas/cells.js +9 -0
- package/dist-tsc/legacy-loaders/schemas/clusters.d.ts +15 -0
- package/dist-tsc/legacy-loaders/schemas/clusters.d.ts.map +1 -0
- package/dist-tsc/legacy-loaders/schemas/clusters.js +6 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/cells.bad.message.json +11 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/clusters.bad.json +9 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/clusters.bad.message.json +13 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/genes.bad.json +6 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/genes.bad.message.json +13 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/molecules.bad.json +7 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/molecules.bad.message.json +11 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/neighborhoods.bad.json +4 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/neighborhoods.bad.message.json +11 -0
- package/dist-tsc/legacy-loaders/schemas/fixtures/neighborhoods.good.json +4 -0
- package/dist-tsc/legacy-loaders/schemas/genes.d.ts +12 -0
- package/dist-tsc/legacy-loaders/schemas/genes.d.ts.map +1 -0
- package/dist-tsc/legacy-loaders/schemas/genes.js +5 -0
- package/dist-tsc/legacy-loaders/schemas/molecules.d.ts +3 -0
- package/dist-tsc/legacy-loaders/schemas/molecules.d.ts.map +1 -0
- package/dist-tsc/legacy-loaders/schemas/molecules.js +4 -0
- package/dist-tsc/legacy-loaders/schemas/neighborhoods.d.ts +9 -0
- package/dist-tsc/legacy-loaders/schemas/neighborhoods.d.ts.map +1 -0
- package/dist-tsc/legacy-loaders/schemas/neighborhoods.js +6 -0
- package/dist-tsc/raster-json-loaders/RasterJsonAsImageLoader.d.ts +4 -0
- package/dist-tsc/raster-json-loaders/RasterJsonAsImageLoader.d.ts.map +1 -0
- package/{dist → dist-tsc}/raster-json-loaders/RasterJsonAsImageLoader.js +1 -1
- package/dist-tsc/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.d.ts +4 -0
- package/dist-tsc/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.d.ts.map +1 -0
- package/{dist → dist-tsc}/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.js +1 -1
- package/dist-tsc/raster-json-loaders/RasterJsonLoader.d.ts +6 -0
- package/dist-tsc/raster-json-loaders/RasterJsonLoader.d.ts.map +1 -0
- package/{dist → dist-tsc}/raster-json-loaders/RasterJsonLoader.js +3 -2
- package/dist-tsc/raster-json-loaders/index.d.ts +3 -0
- package/dist-tsc/raster-json-loaders/index.d.ts.map +1 -0
- package/{dist → dist-tsc}/raster-json-loaders/index.js +2 -2
- package/package.json +22 -15
- package/src/JsonSource.js +21 -0
- package/src/index.js +5 -0
- package/src/json-loaders/JsonLoader.js +64 -0
- package/src/json-loaders/JsonLoader.test.js +28 -0
- package/src/json-loaders/ObsSegmentationsJson.js +31 -0
- package/src/json-loaders/ObsSetsJson.js +54 -0
- package/{dist/json-loaders/ObsSetsJson.test.js → src/json-loaders/ObsSetsJson.test-old.js} +5 -2
- package/src/json-loaders/index.js +3 -0
- package/src/legacy-loaders/CellsJsonAsObsEmbedding.js +53 -0
- package/src/legacy-loaders/CellsJsonAsObsLabels.js +32 -0
- package/src/legacy-loaders/CellsJsonAsObsLocations.js +45 -0
- package/src/legacy-loaders/CellsJsonAsObsSegmentations.js +57 -0
- package/src/legacy-loaders/CellsJsonLoaders.test.js +68 -0
- package/src/legacy-loaders/ClustersJsonAsObsFeatureMatrix.js +55 -0
- package/src/legacy-loaders/ClustersJsonLoaders.test.js +33 -0
- package/src/legacy-loaders/GenesJsonAsObsFeatureMatrix.js +44 -0
- package/src/legacy-loaders/GenesJsonLoaders.test.js +33 -0
- package/src/legacy-loaders/MoleculesJsonAsObsLabels.js +38 -0
- package/src/legacy-loaders/MoleculesJsonAsObsLocations.js +49 -0
- package/src/legacy-loaders/MoleculesJsonLoaders.test.js +46 -0
- package/src/legacy-loaders/index.js +8 -0
- package/src/legacy-loaders/schemas/cells.js +13 -0
- package/src/legacy-loaders/schemas/clusters.js +7 -0
- package/src/legacy-loaders/schemas/fixtures/cells.bad.json +8 -0
- package/src/legacy-loaders/schemas/fixtures/cells.bad.message.json +11 -0
- package/src/legacy-loaders/schemas/fixtures/cells.good.json +29 -0
- package/src/legacy-loaders/schemas/fixtures/clusters.bad.json +9 -0
- package/src/legacy-loaders/schemas/fixtures/clusters.bad.message.json +13 -0
- package/src/legacy-loaders/schemas/fixtures/clusters.good.json +9 -0
- package/src/legacy-loaders/schemas/fixtures/genes.bad.json +6 -0
- package/src/legacy-loaders/schemas/fixtures/genes.bad.message.json +13 -0
- package/src/legacy-loaders/schemas/fixtures/genes.good.json +4 -0
- package/src/legacy-loaders/schemas/fixtures/molecules.bad.json +7 -0
- package/src/legacy-loaders/schemas/fixtures/molecules.bad.message.json +11 -0
- package/src/legacy-loaders/schemas/fixtures/molecules.good.json +7 -0
- package/src/legacy-loaders/schemas/fixtures/neighborhoods.bad.json +4 -0
- package/src/legacy-loaders/schemas/fixtures/neighborhoods.bad.message.json +11 -0
- package/src/legacy-loaders/schemas/fixtures/neighborhoods.good.json +4 -0
- package/src/legacy-loaders/schemas/genes.js +6 -0
- package/src/legacy-loaders/schemas/molecules.js +8 -0
- package/src/legacy-loaders/schemas/neighborhoods.js +10 -0
- package/src/raster-json-loaders/RasterJsonAsImageLoader.js +45 -0
- package/src/raster-json-loaders/RasterJsonAsObsSegmentationsLoader.js +46 -0
- package/src/raster-json-loaders/RasterJsonLoader.js +128 -0
- package/src/raster-json-loaders/index.js +2 -0
- package/dist/json-loaders/index.js +0 -3
- package/dist/legacy-loaders/schemas/cells.schema.json +0 -52
- package/dist/legacy-loaders/schemas/clusters.schema.json +0 -30
- package/dist/legacy-loaders/schemas/genes.schema.json +0 -27
- package/dist/legacy-loaders/schemas/molecules.schema.json +0 -20
- package/dist/legacy-loaders/schemas/neighborhoods.schema.json +0 -28
- package/dist/legacy-loaders/schemas/schema.test.js +0 -48
- /package/{dist → dist-tsc}/JsonSource.js +0 -0
- /package/{dist → dist-tsc}/json-loaders/ObsSetsJson.test-old.js +0 -0
- /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/cells.bad.json +0 -0
- /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/cells.good.json +0 -0
- /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/clusters.good.json +0 -0
- /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/genes.good.json +0 -0
- /package/{dist → dist-tsc}/legacy-loaders/schemas/fixtures/molecules.good.json +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tryUpgradeTreeToLatestSchema,
|
|
3
|
+
initializeCellSetColor,
|
|
4
|
+
nodeToSet,
|
|
5
|
+
treeToMembershipMap,
|
|
6
|
+
} from '@vitessce/sets-utils';
|
|
7
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
8
|
+
import { obsSetsSchema } from '@vitessce/schemas';
|
|
9
|
+
import JsonLoader from './JsonLoader.js';
|
|
10
|
+
|
|
11
|
+
export default class ObsSetsJsonLoader extends JsonLoader {
|
|
12
|
+
constructor(dataSource, params) {
|
|
13
|
+
super(dataSource, params);
|
|
14
|
+
|
|
15
|
+
this.schema = obsSetsSchema;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async load() {
|
|
19
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
20
|
+
if (payload instanceof AbstractLoaderError) {
|
|
21
|
+
return Promise.reject(payload);
|
|
22
|
+
}
|
|
23
|
+
const { data: rawData, url } = payload;
|
|
24
|
+
const datatype = this.fileType.endsWith('cell-sets.json') ? 'cell' : 'obs';
|
|
25
|
+
const [upgradedData] = tryUpgradeTreeToLatestSchema(rawData, datatype);
|
|
26
|
+
let obsIndex = [];
|
|
27
|
+
const coordinationValues = {
|
|
28
|
+
obsSetSelection: [],
|
|
29
|
+
obsSetColor: [],
|
|
30
|
+
};
|
|
31
|
+
let obsSetsMembership = new Map();
|
|
32
|
+
|
|
33
|
+
// Set up the initial coordination values.
|
|
34
|
+
if (upgradedData && upgradedData.tree.length >= 1) {
|
|
35
|
+
const { tree } = upgradedData;
|
|
36
|
+
obsSetsMembership = treeToMembershipMap(upgradedData);
|
|
37
|
+
const newAutoSetSelectionParentName = tree[0].name;
|
|
38
|
+
// Create a list of set paths to initally select.
|
|
39
|
+
const newAutoSetSelections = tree[0].children
|
|
40
|
+
.map(node => ([newAutoSetSelectionParentName, node.name]));
|
|
41
|
+
// Create a list of cell set objects with color mappings.
|
|
42
|
+
const newAutoSetColors = initializeCellSetColor(upgradedData, []);
|
|
43
|
+
coordinationValues.obsSetSelection = newAutoSetSelections;
|
|
44
|
+
coordinationValues.obsSetColor = newAutoSetColors;
|
|
45
|
+
|
|
46
|
+
obsIndex = nodeToSet(tree[0]).map(d => d[0]);
|
|
47
|
+
}
|
|
48
|
+
return Promise.resolve(new LoaderResult({
|
|
49
|
+
obsIndex,
|
|
50
|
+
obsSets: upgradedData,
|
|
51
|
+
obsSetsMembership,
|
|
52
|
+
}, url, coordinationValues));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export {};
|
|
2
1
|
// TODO(monorepo)
|
|
3
2
|
/*
|
|
3
|
+
import { LoaderResult } from '@vitessce/vit-s';
|
|
4
|
+
import ObsSetsJsonLoader from './ObsSetsJson';
|
|
5
|
+
import JsonSource from '../JsonSource';
|
|
6
|
+
|
|
4
7
|
const createLoader = (ClassDef, config, url) => {
|
|
5
8
|
const configWithUrl = {
|
|
6
9
|
...config,
|
|
@@ -25,4 +28,4 @@ describe('loaders/json-loaders/ObsSetsJson', () => {
|
|
|
25
28
|
});
|
|
26
29
|
});
|
|
27
30
|
});
|
|
28
|
-
*/
|
|
31
|
+
*/
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import { cellsSchema } from './schemas/cells.js';
|
|
3
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
4
|
+
|
|
5
|
+
export default class CellsJsonAsObsEmbeddingLoader extends JsonLoader {
|
|
6
|
+
constructor(dataSource, params) {
|
|
7
|
+
super(dataSource, params);
|
|
8
|
+
|
|
9
|
+
this.schema = cellsSchema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const { embeddingType } = this.coordinationValues;
|
|
17
|
+
const cellObjs = Object.values(data);
|
|
18
|
+
if (cellObjs.length > 0 && (
|
|
19
|
+
!cellObjs[0].mappings
|
|
20
|
+
|| !Array.isArray(cellObjs[0].mappings[embeddingType])
|
|
21
|
+
)) {
|
|
22
|
+
// The cells file does not contain this embedding.
|
|
23
|
+
this.cachedResult = null;
|
|
24
|
+
} else {
|
|
25
|
+
const obsIndex = Object.keys(data);
|
|
26
|
+
const obsEmbeddingX = Float32Array.from(
|
|
27
|
+
cellObjs.map(cellObj => cellObj.mappings[embeddingType][0]),
|
|
28
|
+
);
|
|
29
|
+
const obsEmbeddingY = Float32Array.from(
|
|
30
|
+
cellObjs.map(cellObj => cellObj.mappings[embeddingType][1]),
|
|
31
|
+
);
|
|
32
|
+
const obsEmbedding = {
|
|
33
|
+
data: [obsEmbeddingX, obsEmbeddingY],
|
|
34
|
+
shape: [2, obsEmbeddingX.length],
|
|
35
|
+
};
|
|
36
|
+
this.cachedResult = { obsIndex, obsEmbedding };
|
|
37
|
+
}
|
|
38
|
+
return this.cachedResult;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async load() {
|
|
42
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
43
|
+
if (payload instanceof AbstractLoaderError) {
|
|
44
|
+
return Promise.reject(payload);
|
|
45
|
+
}
|
|
46
|
+
const { data, url } = payload;
|
|
47
|
+
const result = this.loadFromCache(data);
|
|
48
|
+
return Promise.resolve(new LoaderResult(
|
|
49
|
+
result,
|
|
50
|
+
url,
|
|
51
|
+
));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import { cellsSchema } from './schemas/cells.js';
|
|
3
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
4
|
+
|
|
5
|
+
export default class CellsJsonAsObsLabelsLoader extends JsonLoader {
|
|
6
|
+
constructor(dataSource, params) {
|
|
7
|
+
super(dataSource, params);
|
|
8
|
+
|
|
9
|
+
this.schema = cellsSchema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const { obsLabelsType } = this.coordinationValues;
|
|
17
|
+
const obsIndex = Object.keys(data);
|
|
18
|
+
const obsLabels = Object.values(data).map(cellObj => cellObj.factors[obsLabelsType]);
|
|
19
|
+
this.cachedResult = { obsIndex, obsLabels };
|
|
20
|
+
return this.cachedResult;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async load() {
|
|
24
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
25
|
+
if (payload instanceof AbstractLoaderError) {
|
|
26
|
+
return Promise.reject(payload);
|
|
27
|
+
}
|
|
28
|
+
const { data, url } = payload;
|
|
29
|
+
const result = this.loadFromCache(data);
|
|
30
|
+
return Promise.resolve(new LoaderResult(result, url));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import { cellsSchema } from './schemas/cells.js';
|
|
3
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
4
|
+
|
|
5
|
+
export default class CellsJsonAsObsLocationsLoader extends JsonLoader {
|
|
6
|
+
constructor(dataSource, params) {
|
|
7
|
+
super(dataSource, params);
|
|
8
|
+
|
|
9
|
+
this.schema = cellsSchema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const cellObjs = Object.values(data);
|
|
17
|
+
if (cellObjs.length > 0 && !Array.isArray(cellObjs[0].xy)) {
|
|
18
|
+
// This cells file does not contain xy coordinates.
|
|
19
|
+
this.cachedResult = null;
|
|
20
|
+
} else {
|
|
21
|
+
const obsIndex = Object.keys(data);
|
|
22
|
+
const obsLocationsX = Float32Array.from(cellObjs.map(cellObj => cellObj.xy[0]));
|
|
23
|
+
const obsLocationsY = Float32Array.from(cellObjs.map(cellObj => cellObj.xy[1]));
|
|
24
|
+
const obsLocations = {
|
|
25
|
+
data: [obsLocationsX, obsLocationsY],
|
|
26
|
+
shape: [2, obsLocationsX.length],
|
|
27
|
+
};
|
|
28
|
+
this.cachedResult = { obsIndex, obsLocations };
|
|
29
|
+
}
|
|
30
|
+
return this.cachedResult;
|
|
31
|
+
}
|
|
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
|
+
return Promise.resolve(new LoaderResult(
|
|
41
|
+
result,
|
|
42
|
+
url,
|
|
43
|
+
));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import { DEFAULT_CELLS_LAYER, square } from '@vitessce/spatial-utils';
|
|
3
|
+
import { cellsSchema } from './schemas/cells.js';
|
|
4
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
5
|
+
|
|
6
|
+
export default class CellsJsonAsObsSegmentationsLoader extends JsonLoader {
|
|
7
|
+
constructor(dataSource, params) {
|
|
8
|
+
super(dataSource, params);
|
|
9
|
+
|
|
10
|
+
this.schema = cellsSchema;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
loadFromCache(data) {
|
|
14
|
+
if (this.cachedResult) {
|
|
15
|
+
return this.cachedResult;
|
|
16
|
+
}
|
|
17
|
+
const obsIndex = Object.keys(data);
|
|
18
|
+
const cellObjs = Object.values(data);
|
|
19
|
+
if (cellObjs.length > 0 && !Array.isArray(cellObjs[0].poly) && !Array.isArray(cellObjs[0].xy)) {
|
|
20
|
+
// This cells.json file does not have segmentations.
|
|
21
|
+
this.cachedResult = null;
|
|
22
|
+
} else {
|
|
23
|
+
let cellPolygons;
|
|
24
|
+
if (!Array.isArray(cellObjs[0].poly) || !cellObjs[0].poly?.length) {
|
|
25
|
+
// This cells.json file has xy positions but not segmentation polygons.
|
|
26
|
+
const radius = 50;
|
|
27
|
+
// If you want to use a different radius value,
|
|
28
|
+
// then create the polygons upstream and pass them in via .poly
|
|
29
|
+
cellPolygons = cellObjs.map(cellObj => square(cellObj.xy[0], cellObj.xy[1], radius));
|
|
30
|
+
} else {
|
|
31
|
+
cellPolygons = cellObjs.map(cellObj => cellObj.poly);
|
|
32
|
+
}
|
|
33
|
+
const obsSegmentations = {
|
|
34
|
+
data: cellPolygons,
|
|
35
|
+
shape: [cellPolygons.length, cellPolygons[0].length],
|
|
36
|
+
};
|
|
37
|
+
this.cachedResult = { obsIndex, obsSegmentations };
|
|
38
|
+
}
|
|
39
|
+
return this.cachedResult;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async load() {
|
|
43
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
44
|
+
if (payload instanceof AbstractLoaderError) {
|
|
45
|
+
return Promise.reject(payload);
|
|
46
|
+
}
|
|
47
|
+
const { data, url } = payload;
|
|
48
|
+
const result = this.loadFromCache(data);
|
|
49
|
+
const coordinationValues = {
|
|
50
|
+
spatialSegmentationLayer: DEFAULT_CELLS_LAYER,
|
|
51
|
+
};
|
|
52
|
+
return Promise.resolve(new LoaderResult({
|
|
53
|
+
...result,
|
|
54
|
+
obsSegmentationsType: 'polygon',
|
|
55
|
+
}, url, coordinationValues));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import CellsJsonAsObsEmbeddingLoader from './CellsJsonAsObsEmbedding.js';
|
|
3
|
+
import CellsJsonAsObsLabelsLoader from './CellsJsonAsObsLabels.js';
|
|
4
|
+
import CellsJsonAsObsSegmentationsLoader from './CellsJsonAsObsSegmentations.js';
|
|
5
|
+
import JsonSource from '../JsonSource.js';
|
|
6
|
+
|
|
7
|
+
const createLoader = (ClassDef, config, url) => {
|
|
8
|
+
const configWithUrl = {
|
|
9
|
+
...config,
|
|
10
|
+
url,
|
|
11
|
+
};
|
|
12
|
+
const source = new JsonSource(configWithUrl);
|
|
13
|
+
return new ClassDef(source, configWithUrl);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('loaders/cells-json-loaders', () => {
|
|
17
|
+
describe('CellsJsonAsObsEmbeddingLoader', () => {
|
|
18
|
+
it('can load obsEmbedding', async () => {
|
|
19
|
+
const loader = createLoader(CellsJsonAsObsEmbeddingLoader, {
|
|
20
|
+
fileType: 'obsEmbedding.cells.json',
|
|
21
|
+
coordinationValues: {
|
|
22
|
+
embeddingType: 'PCA',
|
|
23
|
+
},
|
|
24
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/cells.good.json');
|
|
25
|
+
const result = await loader.load();
|
|
26
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
27
|
+
const payload = result.data;
|
|
28
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsEmbedding']);
|
|
29
|
+
expect(payload.obsIndex).toEqual(['778']);
|
|
30
|
+
expect(Array.from(payload.obsEmbedding.data[0])).toEqual([1]);
|
|
31
|
+
expect(Array.from(payload.obsEmbedding.data[1])).toEqual([2]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('CellsJsonAsObsLabelsLoader', () => {
|
|
35
|
+
it('can load obsLabels', async () => {
|
|
36
|
+
const loader = createLoader(CellsJsonAsObsLabelsLoader, {
|
|
37
|
+
fileType: 'obsLabels.cells.json',
|
|
38
|
+
coordinationValues: {
|
|
39
|
+
obsLabelsType: 'cluster',
|
|
40
|
+
},
|
|
41
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/cells.good.json');
|
|
42
|
+
const result = await loader.load();
|
|
43
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
44
|
+
const payload = result.data;
|
|
45
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsLabels']);
|
|
46
|
+
expect(payload.obsIndex).toEqual(['778']);
|
|
47
|
+
expect(payload.obsLabels).toEqual(['Inhibitory CP']);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('CellsJsonAsObsSegmentationsLoader', () => {
|
|
51
|
+
it('can load obsSegmentations', async () => {
|
|
52
|
+
const loader = createLoader(CellsJsonAsObsSegmentationsLoader, {
|
|
53
|
+
fileType: 'obsSegmentations.cells.json',
|
|
54
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/cells.good.json');
|
|
55
|
+
const result = await loader.load();
|
|
56
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
57
|
+
const payload = result.data;
|
|
58
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsSegmentations', 'obsSegmentationsType']);
|
|
59
|
+
expect(payload.obsIndex).toEqual(['778']);
|
|
60
|
+
expect(payload.obsSegmentationsType).toEqual('polygon');
|
|
61
|
+
expect(payload.obsSegmentations.data[0]).toEqual([
|
|
62
|
+
[1, 2],
|
|
63
|
+
[3, 4],
|
|
64
|
+
[5, 6],
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { extent } from 'd3-array';
|
|
2
|
+
import { range } from 'lodash-es';
|
|
3
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
4
|
+
import { clustersSchema } from './schemas/clusters.js';
|
|
5
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
6
|
+
|
|
7
|
+
export default class ClustersJsonAsObsFeatureMatrixLoader extends JsonLoader {
|
|
8
|
+
constructor(dataSource, params) {
|
|
9
|
+
super(dataSource, params);
|
|
10
|
+
|
|
11
|
+
this.schema = clustersSchema;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
loadFromCache(data) {
|
|
15
|
+
if (this.cachedResult) {
|
|
16
|
+
return this.cachedResult;
|
|
17
|
+
}
|
|
18
|
+
const { rows: featureIndex, cols: obsIndex, matrix } = data;
|
|
19
|
+
const attrs = {
|
|
20
|
+
rows: obsIndex,
|
|
21
|
+
cols: featureIndex,
|
|
22
|
+
};
|
|
23
|
+
const shape = [attrs.rows.length, attrs.cols.length];
|
|
24
|
+
// Normalize values by converting to one-byte integers.
|
|
25
|
+
// Normalize for each gene (column) independently.
|
|
26
|
+
const normalizedMatrix = matrix.map((col) => {
|
|
27
|
+
const [min, max] = extent(col);
|
|
28
|
+
const normalize = d => Math.floor(((d - min) / (max - min)) * 255);
|
|
29
|
+
return col.map(normalize);
|
|
30
|
+
});
|
|
31
|
+
// Transpose the normalized matrix.
|
|
32
|
+
const tNormalizedMatrix = range(shape[0])
|
|
33
|
+
.map(i => range(shape[1]).map(j => normalizedMatrix[j][i]));
|
|
34
|
+
// Flatten the transposed matrix.
|
|
35
|
+
const normalizedFlatMatrix = tNormalizedMatrix.flat();
|
|
36
|
+
// Need to wrap the NestedArray to mock the HTTPStore-based array
|
|
37
|
+
// which returns promises.
|
|
38
|
+
const obsFeatureMatrix = { data: Uint8Array.from(normalizedFlatMatrix) };
|
|
39
|
+
this.cachedResult = { obsIndex, featureIndex, obsFeatureMatrix };
|
|
40
|
+
return this.cachedResult;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async load() {
|
|
44
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
45
|
+
if (payload instanceof AbstractLoaderError) {
|
|
46
|
+
return Promise.reject(payload);
|
|
47
|
+
}
|
|
48
|
+
const { data, url } = payload;
|
|
49
|
+
const result = this.loadFromCache(data);
|
|
50
|
+
return Promise.resolve(new LoaderResult(
|
|
51
|
+
result,
|
|
52
|
+
url,
|
|
53
|
+
));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import ClustersJsonAsObsFeatureMatrixLoader from './ClustersJsonAsObsFeatureMatrix.js';
|
|
3
|
+
import JsonSource from '../JsonSource.js';
|
|
4
|
+
|
|
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
|
+
|
|
14
|
+
describe('loaders/clusters-json-loaders', () => {
|
|
15
|
+
describe('ClustersJsonAsObsFeatureMatrixLoader', () => {
|
|
16
|
+
it('can load obsFeatureMatrix', async () => {
|
|
17
|
+
const loader = createLoader(ClustersJsonAsObsFeatureMatrixLoader, {
|
|
18
|
+
fileType: 'obsFeatureMatrix.clusters.json',
|
|
19
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/clusters.good.json');
|
|
20
|
+
const result = await loader.load();
|
|
21
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
22
|
+
const payload = result.data;
|
|
23
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'featureIndex', 'obsFeatureMatrix']);
|
|
24
|
+
expect(payload.obsIndex).toEqual(['3572', '1904', '1670']);
|
|
25
|
+
expect(payload.featureIndex).toEqual(['Lamp5', 'Sox10', 'Crhbp']);
|
|
26
|
+
expect(Array.from(payload.obsFeatureMatrix.data)).toEqual([
|
|
27
|
+
0, 0, 0,
|
|
28
|
+
127, 127, 127,
|
|
29
|
+
255, 255, 255,
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import { genesSchema } from './schemas/genes.js';
|
|
3
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
4
|
+
|
|
5
|
+
export default class GenesJsonAsObsFeatureMatrixLoader extends JsonLoader {
|
|
6
|
+
constructor(dataSource, params) {
|
|
7
|
+
super(dataSource, params);
|
|
8
|
+
|
|
9
|
+
this.schema = genesSchema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const cols = Object.keys(data);
|
|
17
|
+
const rows = (cols.length > 0 ? Object.keys(data[cols[0]].cells) : []);
|
|
18
|
+
|
|
19
|
+
const normalizedFlatMatrix = rows
|
|
20
|
+
.flatMap(cellId => cols.map(
|
|
21
|
+
geneId => (data[geneId].cells[cellId] / data[geneId].max) * 255,
|
|
22
|
+
));
|
|
23
|
+
// Need to wrap the NestedArray to mock the HTTPStore-based array
|
|
24
|
+
// which returns promises.
|
|
25
|
+
const featureIndex = cols;
|
|
26
|
+
const obsIndex = rows;
|
|
27
|
+
const obsFeatureMatrix = { data: Uint8Array.from(normalizedFlatMatrix) };
|
|
28
|
+
this.cachedResult = { obsIndex, featureIndex, obsFeatureMatrix };
|
|
29
|
+
return this.cachedResult;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async load() {
|
|
33
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
34
|
+
if (payload instanceof AbstractLoaderError) {
|
|
35
|
+
return Promise.reject(payload);
|
|
36
|
+
}
|
|
37
|
+
const { data, url } = payload;
|
|
38
|
+
const result = this.loadFromCache(data);
|
|
39
|
+
return Promise.resolve(new LoaderResult(
|
|
40
|
+
result,
|
|
41
|
+
url,
|
|
42
|
+
));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import GenesJsonAsObsFeatureMatrixLoader from './GenesJsonAsObsFeatureMatrix.js';
|
|
3
|
+
import JsonSource from '../JsonSource.js';
|
|
4
|
+
|
|
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
|
+
|
|
14
|
+
describe('loaders/genes-json-loaders', () => {
|
|
15
|
+
describe('GenesJsonAsObsFeatureMatrixLoader', () => {
|
|
16
|
+
it('can load obsFeatureMatrix', async () => {
|
|
17
|
+
const loader = createLoader(GenesJsonAsObsFeatureMatrixLoader, {
|
|
18
|
+
fileType: 'obsFeatureMatrix.genes.json',
|
|
19
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/genes.good.json');
|
|
20
|
+
const result = await loader.load();
|
|
21
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
22
|
+
const payload = result.data;
|
|
23
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'featureIndex', 'obsFeatureMatrix']);
|
|
24
|
+
expect(payload.obsIndex).toEqual(['778', '1409', '3642']);
|
|
25
|
+
expect(payload.featureIndex).toEqual(['Gad2', 'Slc32a1']);
|
|
26
|
+
expect(Array.from(payload.obsFeatureMatrix.data)).toEqual([
|
|
27
|
+
93, 213,
|
|
28
|
+
42, 135,
|
|
29
|
+
255, 255,
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { range, sum } from 'lodash-es';
|
|
2
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
3
|
+
import { moleculesSchema } from './schemas/molecules.js';
|
|
4
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
5
|
+
|
|
6
|
+
export default class MoleculesJsonAsObsLabelsLoader extends JsonLoader {
|
|
7
|
+
constructor(dataSource, params) {
|
|
8
|
+
super(dataSource, params);
|
|
9
|
+
|
|
10
|
+
this.schema = moleculesSchema;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
loadFromCache(data) {
|
|
14
|
+
if (this.cachedResult) {
|
|
15
|
+
return this.cachedResult;
|
|
16
|
+
}
|
|
17
|
+
const obsIndex = range(sum(Object.values(data).map(v => v.length))).map(i => String(i));
|
|
18
|
+
let obsLabels = [];
|
|
19
|
+
Object.entries(data).forEach(([gene, locations]) => {
|
|
20
|
+
obsLabels = [
|
|
21
|
+
...obsLabels,
|
|
22
|
+
...range(locations.length).map(() => gene),
|
|
23
|
+
];
|
|
24
|
+
});
|
|
25
|
+
this.cachedResult = { obsIndex, obsLabels };
|
|
26
|
+
return this.cachedResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async load() {
|
|
30
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
31
|
+
if (payload instanceof AbstractLoaderError) {
|
|
32
|
+
return Promise.reject(payload);
|
|
33
|
+
}
|
|
34
|
+
const { data, url } = payload;
|
|
35
|
+
const result = this.loadFromCache(data);
|
|
36
|
+
return Promise.resolve(new LoaderResult(result, url));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { range, sum } from 'lodash-es';
|
|
2
|
+
import { AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
3
|
+
import { DEFAULT_MOLECULES_LAYER } from '@vitessce/spatial-utils';
|
|
4
|
+
import { moleculesSchema } from './schemas/molecules.js';
|
|
5
|
+
import JsonLoader from '../json-loaders/JsonLoader.js';
|
|
6
|
+
|
|
7
|
+
export default class MoleculesJsonAsObsLocationsLoader extends JsonLoader {
|
|
8
|
+
constructor(dataSource, params) {
|
|
9
|
+
super(dataSource, params);
|
|
10
|
+
|
|
11
|
+
this.schema = moleculesSchema;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
loadFromCache(data) {
|
|
15
|
+
if (this.cachedResult) {
|
|
16
|
+
return this.cachedResult;
|
|
17
|
+
}
|
|
18
|
+
const moleculesValues = Object.values(data);
|
|
19
|
+
const obsIndex = range(sum(moleculesValues.map(v => v.length))).map(i => String(i));
|
|
20
|
+
const obsLocationsX = new Float32Array(obsIndex.length);
|
|
21
|
+
const obsLocationsY = new Float32Array(obsIndex.length);
|
|
22
|
+
let startAt = 0;
|
|
23
|
+
moleculesValues.forEach((locations) => {
|
|
24
|
+
obsLocationsX.set(locations.map(l => l[0]), startAt);
|
|
25
|
+
obsLocationsY.set(locations.map(l => l[1]), startAt);
|
|
26
|
+
startAt += locations.length;
|
|
27
|
+
});
|
|
28
|
+
const obsLocations = {
|
|
29
|
+
data: [obsLocationsX, obsLocationsY],
|
|
30
|
+
shape: [2, obsLocationsX.length],
|
|
31
|
+
};
|
|
32
|
+
this.cachedResult = { obsIndex, obsLocations };
|
|
33
|
+
return this.cachedResult;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async load() {
|
|
37
|
+
const payload = await super.load().catch(reason => Promise.resolve(reason));
|
|
38
|
+
if (payload instanceof AbstractLoaderError) {
|
|
39
|
+
return Promise.reject(payload);
|
|
40
|
+
}
|
|
41
|
+
const { data, url } = payload;
|
|
42
|
+
const result = this.loadFromCache(data);
|
|
43
|
+
const coordinationValues = {
|
|
44
|
+
// TODO: do this for anndata segmentation loader
|
|
45
|
+
spatialPointLayer: DEFAULT_MOLECULES_LAYER,
|
|
46
|
+
};
|
|
47
|
+
return Promise.resolve(new LoaderResult(result, url, coordinationValues));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
import MoleculesJsonAsObsLocationsLoader from './MoleculesJsonAsObsLocations.js';
|
|
3
|
+
import MoleculesJsonAsObsLabelsLoader from './MoleculesJsonAsObsLabels.js';
|
|
4
|
+
import JsonSource from '../JsonSource.js';
|
|
5
|
+
|
|
6
|
+
const createLoader = (ClassDef, config, url) => {
|
|
7
|
+
const configWithUrl = {
|
|
8
|
+
...config,
|
|
9
|
+
url,
|
|
10
|
+
};
|
|
11
|
+
const source = new JsonSource(configWithUrl);
|
|
12
|
+
return new ClassDef(source, configWithUrl);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('loaders/molecules-json-loaders', () => {
|
|
16
|
+
describe('MoleculesJsonAsObsLocationsLoader', () => {
|
|
17
|
+
it('can load obsLocations', async () => {
|
|
18
|
+
const loader = createLoader(MoleculesJsonAsObsLocationsLoader, {
|
|
19
|
+
fileType: 'obsLocations.molecules.json',
|
|
20
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/molecules.good.json');
|
|
21
|
+
const result = await loader.load();
|
|
22
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
23
|
+
const payload = result.data;
|
|
24
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsLocations']);
|
|
25
|
+
expect(payload.obsIndex).toEqual(['0', '1', '2']);
|
|
26
|
+
expect(Array.from(payload.obsLocations.data[0])).toEqual([27008.0, 8315.0, 18683.0]);
|
|
27
|
+
expect(Array.from(payload.obsLocations.data[1])).toEqual([949.0, 22747.0, 19476.0]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('MoleculesJsonAsObsLabelsLoader', () => {
|
|
31
|
+
it('can load obsLabels', async () => {
|
|
32
|
+
const loader = createLoader(MoleculesJsonAsObsLabelsLoader, {
|
|
33
|
+
fileType: 'obsLabels.molecules.json',
|
|
34
|
+
coordinationValues: {
|
|
35
|
+
obsLabelsType: 'gene',
|
|
36
|
+
},
|
|
37
|
+
}, 'http://localhost:51204/@fixtures/json-legacy/molecules.good.json');
|
|
38
|
+
const result = await loader.load();
|
|
39
|
+
expect(result).toBeInstanceOf(LoaderResult);
|
|
40
|
+
const payload = result.data;
|
|
41
|
+
expect(Object.keys(payload)).toEqual(['obsIndex', 'obsLabels']);
|
|
42
|
+
expect(payload.obsIndex).toEqual(['0', '1', '2']);
|
|
43
|
+
expect(payload.obsLabels).toEqual(['Klk6_Hybridization5', 'Klk6_Hybridization5', 'Klk6_Hybridization5']);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as CellsJsonAsObsEmbeddingLoader } from './CellsJsonAsObsEmbedding.js';
|
|
2
|
+
export { default as CellsJsonAsObsLabelsLoader } from './CellsJsonAsObsLabels.js';
|
|
3
|
+
export { default as CellsJsonAsObsLocationsLoader } from './CellsJsonAsObsLocations.js';
|
|
4
|
+
export { default as CellsJsonAsObsSegmentationsLoader } from './CellsJsonAsObsSegmentations.js';
|
|
5
|
+
export { default as ClustersJsonAsObsFeatureMatrixLoader } from './ClustersJsonAsObsFeatureMatrix.js';
|
|
6
|
+
export { default as GenesJsonAsObsFeatureMatrixLoader } from './GenesJsonAsObsFeatureMatrix.js';
|
|
7
|
+
export { default as MoleculesJsonAsObsLabelsLoader } from './MoleculesJsonAsObsLabels.js';
|
|
8
|
+
export { default as MoleculesJsonAsObsLocationsLoader } from './MoleculesJsonAsObsLocations.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const coordSchema = z.array(z.number()).length(2);
|
|
4
|
+
|
|
5
|
+
export const cellsSchema = z.record(
|
|
6
|
+
z.object({
|
|
7
|
+
xy: coordSchema,
|
|
8
|
+
genes: z.record(z.number()),
|
|
9
|
+
factors: z.record(z.string()),
|
|
10
|
+
poly: z.array(coordSchema),
|
|
11
|
+
mappings: z.record(coordSchema),
|
|
12
|
+
}).strict().partial(),
|
|
13
|
+
);
|