-
Notifications
You must be signed in to change notification settings - Fork 35
/
SpatialDataObsSpotsLoader.js
87 lines (79 loc) · 2.47 KB
/
SpatialDataObsSpotsLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
LoaderResult, AbstractTwoStepLoader, AbstractLoaderError,
} from '@vitessce/vit-s';
import { CoordinationLevel as CL } from '@vitessce/config';
function getCoordsPath(path) {
return `${path}/coords`;
}
function getRadiusPath(path) {
return `${path}/radius`;
}
/**
* Loader for embedding arrays located in anndata.zarr stores.
*/
export default class SpatialDataObsSpotsLoader extends AbstractTwoStepLoader {
/**
* Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
* @returns {Promise} A promise for an array of columns.
*/
loadSpots() {
const { path, dims = [0, 1] } = this.options;
if (this.locations) {
return this.locations;
}
if (!this.locations) {
this.locations = this.dataSource.loadNumericForDims(getCoordsPath(path), dims);
return this.locations;
}
this.locations = Promise.resolve(null);
return this.locations;
}
loadRadius() {
const { path } = this.options;
if (this.radius) {
return this.radius;
}
if (!this.radius) {
this.radius = this.dataSource.loadNumeric(getRadiusPath(path));
return this.radius;
}
this.radius = Promise.resolve(null);
return this.radius;
}
async load() {
const { path, tablePath } = this.options;
const superResult = await super.load().catch(reason => Promise.resolve(reason));
if (superResult instanceof AbstractLoaderError) {
return Promise.reject(superResult);
}
return Promise.all([
this.dataSource.loadObsIndex(getCoordsPath(path), tablePath),
this.loadSpots(),
this.loadRadius(),
]).then(([obsIndex, obsSpots, obsRadius]) => {
const spatialSpotRadius = obsRadius?.data?.[0];
const coordinationValues = {
spotLayer: CL({
obsType: 'spot',
// obsColorEncoding: 'spatialLayerColor',
// spatialLayerColor: [255, 255, 255],
spatialLayerVisible: true,
spatialLayerOpacity: 1.0,
spatialSpotRadius,
// TODO: spatialSpotRadiusUnit: 'µm' or 'um'
// after resolving https://github.com/vitessce/vitessce/issues/1760
// featureValueColormapRange: [0, 1],
// obsHighlight: null,
// obsSetColor: null,
// obsSetSelection: null,
// additionalObsSets: null,
}),
};
return Promise.resolve(new LoaderResult(
{ obsIndex, obsSpots },
null,
coordinationValues,
));
});
}
}