@vitessce/scatterplot-gating 2.0.2 → 2.0.3
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.244b5e4d.mjs +13 -0
- package/dist/index.2b98eb03.mjs +137724 -0
- package/dist/index.mjs +8 -0
- package/dist/jpeg.0c78cd80.mjs +840 -0
- package/dist/lerc.2aba4384.mjs +1943 -0
- package/dist/lzw.83308f93.mjs +128 -0
- package/dist/packbits.b29c602e.mjs +30 -0
- package/dist/pako.esm.4b234125.mjs +3940 -0
- package/dist/raw.7e14c8c2.mjs +12 -0
- package/dist/webimage.ed12ec5b.mjs +32 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +10 -10
- package/src/GatingScatterplotOptions.js +130 -0
- package/src/GatingSubscriber.js +460 -0
- package/src/index.js +1 -0
- package/dist/GatingScatterplotOptions.js +0 -56
- package/dist/GatingSubscriber.js +0 -211
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { B as BaseDecoder } from "./index.2b98eb03.mjs";
|
|
2
|
+
import "react";
|
|
3
|
+
import "@vitessce/vit-s";
|
|
4
|
+
import "react-dom";
|
|
5
|
+
class RawDecoder extends BaseDecoder {
|
|
6
|
+
decodeBlock(buffer) {
|
|
7
|
+
return buffer;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
RawDecoder as default
|
|
12
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { B as BaseDecoder } from "./index.2b98eb03.mjs";
|
|
2
|
+
import "react";
|
|
3
|
+
import "@vitessce/vit-s";
|
|
4
|
+
import "react-dom";
|
|
5
|
+
class WebImageDecoder extends BaseDecoder {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
if (typeof createImageBitmap === "undefined") {
|
|
9
|
+
throw new Error("Cannot decode WebImage as `createImageBitmap` is not available");
|
|
10
|
+
} else if (typeof document === "undefined" && typeof OffscreenCanvas === "undefined") {
|
|
11
|
+
throw new Error("Cannot decode WebImage as neither `document` nor `OffscreenCanvas` is not available");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async decode(fileDirectory, buffer) {
|
|
15
|
+
const blob = new Blob([buffer]);
|
|
16
|
+
const imageBitmap = await createImageBitmap(blob);
|
|
17
|
+
let canvas;
|
|
18
|
+
if (typeof document !== "undefined") {
|
|
19
|
+
canvas = document.createElement("canvas");
|
|
20
|
+
canvas.width = imageBitmap.width;
|
|
21
|
+
canvas.height = imageBitmap.height;
|
|
22
|
+
} else {
|
|
23
|
+
canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
|
|
24
|
+
}
|
|
25
|
+
const ctx = canvas.getContext("2d");
|
|
26
|
+
ctx.drawImage(imageBitmap, 0, 0);
|
|
27
|
+
return ctx.getImageData(0, 0, imageBitmap.width, imageBitmap.height).data.buffer;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
WebImageDecoder as default
|
|
32
|
+
};
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/scatterplot-gating",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -8,20 +8,21 @@
|
|
|
8
8
|
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "dist/index.
|
|
11
|
+
"main": "dist/index.mjs",
|
|
12
12
|
"files": [
|
|
13
|
-
"dist"
|
|
13
|
+
"dist",
|
|
14
|
+
"src"
|
|
14
15
|
],
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@material-ui/core": "~4.12.3",
|
|
17
18
|
"d3-array": "^2.4.0",
|
|
18
19
|
"lodash": "^4.17.21",
|
|
19
20
|
"plur": "^5.1.0",
|
|
20
|
-
"@vitessce/constants-internal": "2.0.
|
|
21
|
-
"@vitessce/scatterplot": "2.0.
|
|
22
|
-
"@vitessce/sets-utils": "2.0.
|
|
23
|
-
"@vitessce/utils": "2.0.
|
|
24
|
-
"@vitessce/vit-s": "2.0.
|
|
21
|
+
"@vitessce/constants-internal": "2.0.3",
|
|
22
|
+
"@vitessce/scatterplot": "2.0.3",
|
|
23
|
+
"@vitessce/sets-utils": "2.0.3",
|
|
24
|
+
"@vitessce/utils": "2.0.3",
|
|
25
|
+
"@vitessce/vit-s": "2.0.3"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"react": "^18.0.0",
|
|
@@ -32,8 +33,7 @@
|
|
|
32
33
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
|
-
"
|
|
36
|
-
"build": "tsc",
|
|
36
|
+
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
|
37
37
|
"test": "pnpm exec vitest --run -r ../../../ --dir ."
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import plur from 'plur';
|
|
3
|
+
import TableCell from '@material-ui/core/TableCell';
|
|
4
|
+
import TableRow from '@material-ui/core/TableRow';
|
|
5
|
+
import TextField from '@material-ui/core/TextField';
|
|
6
|
+
import { usePlotOptionsStyles, OptionSelect } from '@vitessce/vit-s';
|
|
7
|
+
import { capitalize } from '@vitessce/utils';
|
|
8
|
+
|
|
9
|
+
export default function GatingScatterplotOptions(props) {
|
|
10
|
+
const {
|
|
11
|
+
featureType,
|
|
12
|
+
gatingFeatureSelectionX,
|
|
13
|
+
setGatingFeatureSelectionX,
|
|
14
|
+
gatingFeatureSelectionY,
|
|
15
|
+
setGatingFeatureSelectionY,
|
|
16
|
+
gatingFeatureValueTransform,
|
|
17
|
+
setGatingFeatureValueTransform,
|
|
18
|
+
gatingFeatureValueTransformCoefficient,
|
|
19
|
+
setGatingFeatureValueTransformCoefficient,
|
|
20
|
+
geneSelectOptions,
|
|
21
|
+
transformOptions,
|
|
22
|
+
} = props;
|
|
23
|
+
|
|
24
|
+
const classes = usePlotOptionsStyles();
|
|
25
|
+
|
|
26
|
+
// Handlers for custom option field changes.
|
|
27
|
+
const handleGeneSelectChange = (event) => {
|
|
28
|
+
const { options } = event.target;
|
|
29
|
+
const newValues = [];
|
|
30
|
+
for (let i = 0, l = options.length; i < l; i += 1) {
|
|
31
|
+
if (options[i].selected) {
|
|
32
|
+
newValues.push(options[i].value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (newValues.length === 1
|
|
37
|
+
&& gatingFeatureSelectionX
|
|
38
|
+
&& !gatingFeatureSelectionY
|
|
39
|
+
&& newValues[0] !== gatingFeatureSelectionX) {
|
|
40
|
+
setGatingFeatureSelectionY(newValues[0]);
|
|
41
|
+
} else if (newValues.length <= 2) {
|
|
42
|
+
setGatingFeatureSelectionX(newValues[0]);
|
|
43
|
+
setGatingFeatureSelectionY(newValues[1]);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleTransformChange = (event) => {
|
|
48
|
+
setGatingFeatureValueTransform(event.target.value === '' ? null : event.target.value);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Feels a little hacky, but I think this is the best way to handle
|
|
52
|
+
// the limitations of the v4 material-ui number input.
|
|
53
|
+
const handleTransformCoefficientChange = (event) => {
|
|
54
|
+
const { value } = event.target;
|
|
55
|
+
if (!value) {
|
|
56
|
+
setGatingFeatureValueTransformCoefficient(value);
|
|
57
|
+
} else {
|
|
58
|
+
const newCoefficient = Number(value);
|
|
59
|
+
if (!Number.isNaN(newCoefficient) && newCoefficient >= 0) {
|
|
60
|
+
setGatingFeatureValueTransformCoefficient(value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<TableRow key="gene-option-row">
|
|
68
|
+
<TableCell className={classes.labelCell}>
|
|
69
|
+
{capitalize(plur(featureType, geneSelectOptions?.length))}
|
|
70
|
+
</TableCell>
|
|
71
|
+
<TableCell className={classes.inputCell}>
|
|
72
|
+
<OptionSelect
|
|
73
|
+
key="gating-gene-select"
|
|
74
|
+
multiple
|
|
75
|
+
className={classes.select}
|
|
76
|
+
value={[gatingFeatureSelectionX, gatingFeatureSelectionY].filter(v => v)}
|
|
77
|
+
onChange={handleGeneSelectChange}
|
|
78
|
+
inputProps={{
|
|
79
|
+
id: 'scatterplot-gene-select',
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
{geneSelectOptions.map(name => (
|
|
83
|
+
<option key={name} value={name}>
|
|
84
|
+
{name}
|
|
85
|
+
</option>
|
|
86
|
+
))}
|
|
87
|
+
</OptionSelect>
|
|
88
|
+
</TableCell>
|
|
89
|
+
</TableRow>
|
|
90
|
+
<TableRow key="transform-option-row">
|
|
91
|
+
<TableCell className={classes.labelCell}>
|
|
92
|
+
Transform
|
|
93
|
+
</TableCell>
|
|
94
|
+
<TableCell className={classes.inputCell}>
|
|
95
|
+
<OptionSelect
|
|
96
|
+
key="gating-transform-select"
|
|
97
|
+
className={classes.select}
|
|
98
|
+
value={gatingFeatureValueTransform === null ? '' : gatingFeatureValueTransform}
|
|
99
|
+
onChange={handleTransformChange}
|
|
100
|
+
inputProps={{
|
|
101
|
+
id: 'scatterplot-transform-select',
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
{transformOptions.map(opt => (
|
|
105
|
+
<option key={opt.name} value={opt.value === null ? '' : opt.value}>
|
|
106
|
+
{opt.name}
|
|
107
|
+
</option>
|
|
108
|
+
))}
|
|
109
|
+
</OptionSelect>
|
|
110
|
+
</TableCell>
|
|
111
|
+
</TableRow>
|
|
112
|
+
<TableRow key="transform-coefficient-option-row">
|
|
113
|
+
<TableCell className={classes.labelCell}>
|
|
114
|
+
Transform Coefficient
|
|
115
|
+
</TableCell>
|
|
116
|
+
<TableCell className={classes.inputCell}>
|
|
117
|
+
<TextField
|
|
118
|
+
label="Number"
|
|
119
|
+
type="number"
|
|
120
|
+
onChange={handleTransformCoefficientChange}
|
|
121
|
+
value={gatingFeatureValueTransformCoefficient}
|
|
122
|
+
InputLabelProps={{
|
|
123
|
+
shrink: true,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
</TableCell>
|
|
127
|
+
</TableRow>
|
|
128
|
+
</>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useState, useEffect, useCallback, useMemo,
|
|
3
|
+
} from 'react';
|
|
4
|
+
import plur from 'plur';
|
|
5
|
+
import { extent } from 'd3-array';
|
|
6
|
+
import isEqual from 'lodash/isEqual';
|
|
7
|
+
import {
|
|
8
|
+
capitalize, commaNumber,
|
|
9
|
+
getCellColors,
|
|
10
|
+
getValueTransformFunction, VALUE_TRANSFORM_OPTIONS,
|
|
11
|
+
} from '@vitessce/utils';
|
|
12
|
+
import {
|
|
13
|
+
TitleInfo,
|
|
14
|
+
useDeckCanvasSize, useReady, useUrls, useExpressionValueGetter,
|
|
15
|
+
useObsSetsData,
|
|
16
|
+
useFeatureSelection,
|
|
17
|
+
useObsFeatureMatrixIndices,
|
|
18
|
+
useCoordination,
|
|
19
|
+
useLoaders,
|
|
20
|
+
useSetComponentHover,
|
|
21
|
+
useSetComponentViewInfo,
|
|
22
|
+
registerPluginViewType,
|
|
23
|
+
} from '@vitessce/vit-s';
|
|
24
|
+
import { getCellSetPolygons, mergeObsSets, setObsSelection } from '@vitessce/sets-utils';
|
|
25
|
+
import {
|
|
26
|
+
Scatterplot, ScatterplotTooltipSubscriber, ScatterplotOptions,
|
|
27
|
+
getPointSizeDevicePixels,
|
|
28
|
+
getPointOpacity,
|
|
29
|
+
EmptyMessage,
|
|
30
|
+
} from '@vitessce/scatterplot';
|
|
31
|
+
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
|
32
|
+
import GatingScatterplotOptions from './GatingScatterplotOptions';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A subscriber component for the gating scatterplot.
|
|
36
|
+
* @param {object} props
|
|
37
|
+
* @param {number} props.uuid The unique identifier for this component.
|
|
38
|
+
* @param {string} props.theme The current theme name.
|
|
39
|
+
* @param {object} props.coordinationScopes The mapping from coordination types to coordination
|
|
40
|
+
* scopes.
|
|
41
|
+
* @param {boolean} props.disableTooltip Should the tooltip be disabled?
|
|
42
|
+
* @param {function} props.removeGridComponent The callback function to pass to TitleInfo,
|
|
43
|
+
* to call when the component has been removed from the grid.
|
|
44
|
+
* @param {number} props.averageFillDensity Override the average fill density calculation
|
|
45
|
+
* when using dynamic opacity mode.
|
|
46
|
+
*/
|
|
47
|
+
export function GatingSubscriber(props) {
|
|
48
|
+
const {
|
|
49
|
+
uuid,
|
|
50
|
+
coordinationScopes,
|
|
51
|
+
removeGridComponent,
|
|
52
|
+
theme,
|
|
53
|
+
disableTooltip = false,
|
|
54
|
+
title: titleOverride,
|
|
55
|
+
// Average fill density for dynamic opacity calculation.
|
|
56
|
+
averageFillDensity,
|
|
57
|
+
} = props;
|
|
58
|
+
|
|
59
|
+
const loaders = useLoaders();
|
|
60
|
+
const setComponentHover = useSetComponentHover();
|
|
61
|
+
const setComponentViewInfo = useSetComponentViewInfo(uuid);
|
|
62
|
+
|
|
63
|
+
// Get "props" from the coordination space.
|
|
64
|
+
const [{
|
|
65
|
+
dataset,
|
|
66
|
+
obsType,
|
|
67
|
+
featureType,
|
|
68
|
+
featureValueType,
|
|
69
|
+
embeddingZoom: zoom,
|
|
70
|
+
embeddingTargetX: targetX,
|
|
71
|
+
embeddingTargetY: targetY,
|
|
72
|
+
embeddingTargetZ: targetZ,
|
|
73
|
+
obsFilter: cellFilter,
|
|
74
|
+
obsHighlight: cellHighlight,
|
|
75
|
+
obsSetSelection: cellSetSelection,
|
|
76
|
+
obsSetColor: cellSetColor,
|
|
77
|
+
obsColorEncoding: cellColorEncoding,
|
|
78
|
+
additionalObsSets: additionalCellSets,
|
|
79
|
+
embeddingObsSetPolygonsVisible: cellSetPolygonsVisible,
|
|
80
|
+
embeddingObsSetLabelsVisible: cellSetLabelsVisible,
|
|
81
|
+
embeddingObsSetLabelSize: cellSetLabelSize,
|
|
82
|
+
embeddingObsRadius: cellRadiusFixed,
|
|
83
|
+
embeddingObsRadiusMode: cellRadiusMode,
|
|
84
|
+
embeddingObsOpacity: cellOpacityFixed,
|
|
85
|
+
embeddingObsOpacityMode: cellOpacityMode,
|
|
86
|
+
featureValueColormap: geneExpressionColormap,
|
|
87
|
+
featureValueColormapRange: geneExpressionColormapRange,
|
|
88
|
+
featureSelection: gatingFeatureSelectionColor,
|
|
89
|
+
featureValueTransform,
|
|
90
|
+
featureValueTransformCoefficient,
|
|
91
|
+
gatingFeatureSelectionX,
|
|
92
|
+
gatingFeatureSelectionY,
|
|
93
|
+
}, {
|
|
94
|
+
setEmbeddingZoom: setZoom,
|
|
95
|
+
setEmbeddingTargetX: setTargetX,
|
|
96
|
+
setEmbeddingTargetY: setTargetY,
|
|
97
|
+
setEmbeddingTargetZ: setTargetZ,
|
|
98
|
+
setObsFilter: setCellFilter,
|
|
99
|
+
setObsSetSelection: setCellSetSelection,
|
|
100
|
+
setObsHighlight: setCellHighlight,
|
|
101
|
+
setObsSetColor: setCellSetColor,
|
|
102
|
+
setObsColorEncoding: setCellColorEncoding,
|
|
103
|
+
setAdditionalObsSets: setAdditionalCellSets,
|
|
104
|
+
setEmbeddingObsSetPolygonsVisible: setCellSetPolygonsVisible,
|
|
105
|
+
setEmbeddingObsSetLabelsVisible: setCellSetLabelsVisible,
|
|
106
|
+
setEmbeddingObsSetLabelSize: setCellSetLabelSize,
|
|
107
|
+
setEmbeddingObsRadius: setCellRadiusFixed,
|
|
108
|
+
setEmbeddingObsRadiusMode: setCellRadiusMode,
|
|
109
|
+
setEmbeddingObsOpacity: setCellOpacityFixed,
|
|
110
|
+
setEmbeddingObsOpacityMode: setCellOpacityMode,
|
|
111
|
+
setFeatureValueColormap: setGeneExpressionColormap,
|
|
112
|
+
setFeatureValueColormapRange: setGeneExpressionColormapRange,
|
|
113
|
+
setFeatureValueTransform,
|
|
114
|
+
setFeatureValueTransformCoefficient,
|
|
115
|
+
setGatingFeatureSelectionX,
|
|
116
|
+
setGatingFeatureSelectionY,
|
|
117
|
+
}] = useCoordination(
|
|
118
|
+
COMPONENT_COORDINATION_TYPES[ViewType.GATING],
|
|
119
|
+
coordinationScopes,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const [urls, addUrl] = useUrls(loaders, dataset);
|
|
123
|
+
const [width, height, deckRef] = useDeckCanvasSize();
|
|
124
|
+
|
|
125
|
+
const title = useMemo(() => {
|
|
126
|
+
if (titleOverride) {
|
|
127
|
+
return titleOverride;
|
|
128
|
+
}
|
|
129
|
+
if (!(gatingFeatureSelectionX && gatingFeatureSelectionY)) {
|
|
130
|
+
return 'Gating';
|
|
131
|
+
}
|
|
132
|
+
return `Gating (${gatingFeatureSelectionX} vs ${gatingFeatureSelectionY})`;
|
|
133
|
+
}, [titleOverride, gatingFeatureSelectionX, gatingFeatureSelectionY]);
|
|
134
|
+
|
|
135
|
+
const featureSelectionX = useMemo(() => (
|
|
136
|
+
gatingFeatureSelectionX ? [gatingFeatureSelectionX] : null
|
|
137
|
+
), [gatingFeatureSelectionX]);
|
|
138
|
+
const featureSelectionY = useMemo(() => (
|
|
139
|
+
gatingFeatureSelectionY ? [gatingFeatureSelectionY] : null
|
|
140
|
+
), [gatingFeatureSelectionY]);
|
|
141
|
+
|
|
142
|
+
// Get data from loaders using the data hooks.
|
|
143
|
+
const [{ obsSets: cellSets }, obsSetsStatus] = useObsSetsData(
|
|
144
|
+
loaders, dataset, addUrl, false,
|
|
145
|
+
{ setObsSetSelection: setCellSetSelection, setObsSetColor: setCellSetColor },
|
|
146
|
+
{ obsSetSelection: cellSetSelection, obsSetColor: cellSetColor },
|
|
147
|
+
{ obsType },
|
|
148
|
+
);
|
|
149
|
+
// eslint-disable-next-line no-unused-vars
|
|
150
|
+
const [expressionDataColor, loadedColor, featureSelectionColorStatus] = useFeatureSelection(
|
|
151
|
+
loaders, dataset, false, gatingFeatureSelectionColor,
|
|
152
|
+
{ obsType, featureType, featureValueType },
|
|
153
|
+
);
|
|
154
|
+
// eslint-disable-next-line no-unused-vars
|
|
155
|
+
const [expressionDataX, loadedX, featureSelectionXStatus] = useFeatureSelection(
|
|
156
|
+
loaders, dataset, false, featureSelectionX,
|
|
157
|
+
{ obsType, featureType, featureValueType },
|
|
158
|
+
);
|
|
159
|
+
// eslint-disable-next-line no-unused-vars
|
|
160
|
+
const [expressionDataY, loadedY, featureSelectionYStatus] = useFeatureSelection(
|
|
161
|
+
loaders, dataset, false, featureSelectionY,
|
|
162
|
+
{ obsType, featureType, featureValueType },
|
|
163
|
+
);
|
|
164
|
+
const [{ obsIndex, featureIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(
|
|
165
|
+
loaders, dataset, addUrl, false,
|
|
166
|
+
{ obsType, featureType, featureValueType },
|
|
167
|
+
);
|
|
168
|
+
const cellsCount = obsIndex?.length || 0;
|
|
169
|
+
|
|
170
|
+
const isReady = useReady([
|
|
171
|
+
obsSetsStatus,
|
|
172
|
+
featureSelectionColorStatus,
|
|
173
|
+
featureSelectionXStatus,
|
|
174
|
+
featureSelectionYStatus,
|
|
175
|
+
matrixIndicesStatus,
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
// Generate a new cells object with a mapping added for the user selected genes.
|
|
179
|
+
const obsXY = useMemo(() => {
|
|
180
|
+
if (!(cellsCount && expressionDataX?.[0] && expressionDataY?.[0]
|
|
181
|
+
&& featureSelectionX && featureSelectionY
|
|
182
|
+
)) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Get transform coefficient for log and arcsinh
|
|
187
|
+
let coefficient = 1;
|
|
188
|
+
const parsedTransformCoefficient = Number(featureValueTransformCoefficient);
|
|
189
|
+
if (!Number.isNaN(parsedTransformCoefficient) && parsedTransformCoefficient > 0) {
|
|
190
|
+
coefficient = parsedTransformCoefficient;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Set transform function
|
|
194
|
+
const transformFunction = getValueTransformFunction(
|
|
195
|
+
featureValueTransform,
|
|
196
|
+
coefficient,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const obsX = new Float32Array(cellsCount);
|
|
200
|
+
const obsY = new Float32Array(cellsCount);
|
|
201
|
+
for (let i = 0; i < cellsCount; i += 1) {
|
|
202
|
+
obsX[i] = transformFunction(expressionDataX[0][i]);
|
|
203
|
+
obsY[i] = transformFunction(expressionDataY[0][i]);
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
data: [obsX, obsY],
|
|
207
|
+
shape: [2, cellsCount],
|
|
208
|
+
};
|
|
209
|
+
}, [cellsCount, expressionDataX, expressionDataY,
|
|
210
|
+
featureValueTransform, featureValueTransformCoefficient,
|
|
211
|
+
featureSelectionX, featureSelectionY,
|
|
212
|
+
]);
|
|
213
|
+
|
|
214
|
+
const [dynamicCellRadius, setDynamicCellRadius] = useState(cellRadiusFixed);
|
|
215
|
+
const [dynamicCellOpacity, setDynamicCellOpacity] = useState(cellOpacityFixed);
|
|
216
|
+
|
|
217
|
+
const mergedCellSets = useMemo(() => mergeObsSets(
|
|
218
|
+
cellSets, additionalCellSets,
|
|
219
|
+
), [cellSets, additionalCellSets]);
|
|
220
|
+
|
|
221
|
+
const setCellSelectionProp = useCallback((v) => {
|
|
222
|
+
setObsSelection(
|
|
223
|
+
v, additionalCellSets, cellSetColor,
|
|
224
|
+
setCellSetSelection, setAdditionalCellSets, setCellSetColor,
|
|
225
|
+
setCellColorEncoding,
|
|
226
|
+
);
|
|
227
|
+
}, [additionalCellSets, cellSetColor, setCellColorEncoding,
|
|
228
|
+
setAdditionalCellSets, setCellSetColor, setCellSetSelection]);
|
|
229
|
+
|
|
230
|
+
const cellColors = useMemo(() => getCellColors({
|
|
231
|
+
cellColorEncoding,
|
|
232
|
+
expressionData: expressionDataColor && expressionDataColor[0],
|
|
233
|
+
geneSelection: gatingFeatureSelectionColor,
|
|
234
|
+
cellSets: mergedCellSets,
|
|
235
|
+
cellSetSelection,
|
|
236
|
+
cellSetColor,
|
|
237
|
+
obsIndex,
|
|
238
|
+
theme,
|
|
239
|
+
}), [cellColorEncoding, gatingFeatureSelectionColor, mergedCellSets, theme,
|
|
240
|
+
cellSetSelection, cellSetColor, expressionDataColor, obsIndex]);
|
|
241
|
+
|
|
242
|
+
// cellSetPolygonCache is an array of tuples like [(key0, val0), (key1, val1), ...],
|
|
243
|
+
// where the keys are cellSetSelection arrays.
|
|
244
|
+
const [cellSetPolygonCache, setCellSetPolygonCache] = useState([]);
|
|
245
|
+
const cacheHas = (cache, key) => cache.findIndex(el => isEqual(el[0], key)) !== -1;
|
|
246
|
+
const cacheGet = (cache, key) => cache.find(el => isEqual(el[0], key))?.[1];
|
|
247
|
+
const cellSetPolygons = useMemo(() => {
|
|
248
|
+
if ((cellSetLabelsVisible || cellSetPolygonsVisible)
|
|
249
|
+
&& !cacheHas(cellSetPolygonCache, cellSetSelection)
|
|
250
|
+
&& mergedCellSets?.tree?.length
|
|
251
|
+
&& obsXY
|
|
252
|
+
&& obsIndex
|
|
253
|
+
&& cellSetColor?.length) {
|
|
254
|
+
const newCellSetPolygons = getCellSetPolygons({
|
|
255
|
+
obsIndex,
|
|
256
|
+
obsEmbedding: obsXY,
|
|
257
|
+
cellSets: mergedCellSets,
|
|
258
|
+
cellSetSelection,
|
|
259
|
+
cellSetColor,
|
|
260
|
+
theme,
|
|
261
|
+
});
|
|
262
|
+
setCellSetPolygonCache(cache => [...cache, [cellSetSelection, newCellSetPolygons]]);
|
|
263
|
+
return newCellSetPolygons;
|
|
264
|
+
}
|
|
265
|
+
return cacheGet(cellSetPolygonCache, cellSetSelection) || [];
|
|
266
|
+
}, [cellSetPolygonsVisible, cellSetPolygonCache, cellSetLabelsVisible, theme,
|
|
267
|
+
obsIndex, obsXY, mergedCellSets, cellSetSelection, cellSetColor]);
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
const cellSelection = useMemo(() => Array.from(cellColors.keys()), [cellColors]);
|
|
271
|
+
|
|
272
|
+
const [xRange, yRange, xExtent, yExtent, numCells] = useMemo(() => {
|
|
273
|
+
if (obsXY && obsXY.data && obsXY.shape) {
|
|
274
|
+
const cellCount = obsXY.shape[1];
|
|
275
|
+
const xE = extent(obsXY.data[0]);
|
|
276
|
+
const yE = extent(obsXY.data[1]);
|
|
277
|
+
const xR = xE[1] - xE[0];
|
|
278
|
+
const yR = yE[1] - yE[0];
|
|
279
|
+
return [xR, yR, xE, yE, cellCount];
|
|
280
|
+
}
|
|
281
|
+
return [null, null, null, null, null];
|
|
282
|
+
}, [obsXY]);
|
|
283
|
+
|
|
284
|
+
// After cells have loaded or changed,
|
|
285
|
+
// compute the cell radius scale based on the
|
|
286
|
+
// extents of the cell coordinates on the x/y axes.
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
if (xRange && yRange) {
|
|
289
|
+
const pointSizeDevicePixels = getPointSizeDevicePixels(
|
|
290
|
+
window.devicePixelRatio, zoom, xRange, yRange, width, height,
|
|
291
|
+
);
|
|
292
|
+
setDynamicCellRadius(pointSizeDevicePixels);
|
|
293
|
+
|
|
294
|
+
const nextCellOpacityScale = getPointOpacity(
|
|
295
|
+
zoom, xRange, yRange, width, height, numCells, averageFillDensity,
|
|
296
|
+
);
|
|
297
|
+
setDynamicCellOpacity(nextCellOpacityScale);
|
|
298
|
+
|
|
299
|
+
if (typeof targetX !== 'number' || typeof targetY !== 'number') {
|
|
300
|
+
const newTargetX = xExtent[0] + xRange / 2;
|
|
301
|
+
const newTargetY = yExtent[0] + yRange / 2;
|
|
302
|
+
const newZoom = Math.log2(Math.min(width / xRange, height / yRange));
|
|
303
|
+
setTargetX(newTargetX);
|
|
304
|
+
// Graphics rendering has the y-axis going south so we need to multiply by negative one.
|
|
305
|
+
setTargetY(-newTargetY);
|
|
306
|
+
setZoom(newZoom);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
310
|
+
}, [xRange, yRange, xExtent, yExtent, numCells,
|
|
311
|
+
width, height, zoom, averageFillDensity]);
|
|
312
|
+
|
|
313
|
+
const cellSelectionSet = useMemo(() => new Set(cellSelection), [cellSelection]);
|
|
314
|
+
const getCellIsSelected = useCallback((object, { index }) => (
|
|
315
|
+
(cellSelectionSet || new Set([])).has(obsIndex[index]) ? 1.0 : 0.0
|
|
316
|
+
), [cellSelectionSet, obsIndex]);
|
|
317
|
+
|
|
318
|
+
const cellRadius = (cellRadiusMode === 'manual' ? cellRadiusFixed : dynamicCellRadius);
|
|
319
|
+
const cellOpacity = (cellOpacityMode === 'manual' ? cellOpacityFixed : dynamicCellOpacity);
|
|
320
|
+
|
|
321
|
+
// Set up a getter function for gene expression values, to be used
|
|
322
|
+
// by the DeckGL layer to obtain values for instanced attributes.
|
|
323
|
+
const getExpressionValue = useExpressionValueGetter({
|
|
324
|
+
instanceObsIndex: obsIndex,
|
|
325
|
+
matrixObsIndex: obsIndex,
|
|
326
|
+
expressionData: expressionDataColor,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Puts the mapping values in the cell info tooltip.
|
|
330
|
+
const getObsInfo = useCallback((obsId) => {
|
|
331
|
+
const selectedTransformName = VALUE_TRANSFORM_OPTIONS.find(
|
|
332
|
+
o => o.value === featureValueTransform,
|
|
333
|
+
)?.name;
|
|
334
|
+
const genePrefix = featureValueTransform ? `${selectedTransformName} ` : '';
|
|
335
|
+
const obsIdx = obsIndex?.indexOf(obsId);
|
|
336
|
+
const obsInfo = { [`${capitalize(obsType)} ID`]: obsId };
|
|
337
|
+
if (gatingFeatureSelectionX && gatingFeatureSelectionY) {
|
|
338
|
+
obsInfo[genePrefix + gatingFeatureSelectionX] = obsXY.data[0][obsIdx];
|
|
339
|
+
obsInfo[genePrefix + gatingFeatureSelectionY] = obsXY.data[1][obsIdx];
|
|
340
|
+
}
|
|
341
|
+
return obsInfo;
|
|
342
|
+
}, [obsXY, obsIndex, featureValueTransform,
|
|
343
|
+
gatingFeatureSelectionX, gatingFeatureSelectionY, obsType,
|
|
344
|
+
]);
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<TitleInfo
|
|
348
|
+
title={title}
|
|
349
|
+
info={`${commaNumber(cellsCount)} ${plur(obsType, cellsCount)}`}
|
|
350
|
+
removeGridComponent={removeGridComponent}
|
|
351
|
+
urls={urls}
|
|
352
|
+
theme={theme}
|
|
353
|
+
isReady={isReady}
|
|
354
|
+
options={(
|
|
355
|
+
<ScatterplotOptions
|
|
356
|
+
observationsLabel={obsType}
|
|
357
|
+
cellRadius={cellRadiusFixed}
|
|
358
|
+
setCellRadius={setCellRadiusFixed}
|
|
359
|
+
cellRadiusMode={cellRadiusMode}
|
|
360
|
+
setCellRadiusMode={setCellRadiusMode}
|
|
361
|
+
cellOpacity={cellOpacityFixed}
|
|
362
|
+
setCellOpacity={setCellOpacityFixed}
|
|
363
|
+
cellOpacityMode={cellOpacityMode}
|
|
364
|
+
setCellOpacityMode={setCellOpacityMode}
|
|
365
|
+
cellSetLabelsVisible={cellSetLabelsVisible}
|
|
366
|
+
setCellSetLabelsVisible={setCellSetLabelsVisible}
|
|
367
|
+
cellSetLabelSize={cellSetLabelSize}
|
|
368
|
+
setCellSetLabelSize={setCellSetLabelSize}
|
|
369
|
+
cellSetPolygonsVisible={cellSetPolygonsVisible}
|
|
370
|
+
setCellSetPolygonsVisible={setCellSetPolygonsVisible}
|
|
371
|
+
cellColorEncoding={cellColorEncoding}
|
|
372
|
+
setCellColorEncoding={setCellColorEncoding}
|
|
373
|
+
geneExpressionColormap={geneExpressionColormap}
|
|
374
|
+
setGeneExpressionColormap={setGeneExpressionColormap}
|
|
375
|
+
geneExpressionColormapRange={geneExpressionColormapRange}
|
|
376
|
+
setGeneExpressionColormapRange={setGeneExpressionColormapRange}
|
|
377
|
+
>
|
|
378
|
+
<GatingScatterplotOptions
|
|
379
|
+
featureType={featureType}
|
|
380
|
+
gatingFeatureSelectionX={gatingFeatureSelectionX}
|
|
381
|
+
setGatingFeatureSelectionX={setGatingFeatureSelectionX}
|
|
382
|
+
gatingFeatureSelectionY={gatingFeatureSelectionY}
|
|
383
|
+
setGatingFeatureSelectionY={setGatingFeatureSelectionY}
|
|
384
|
+
gatingFeatureValueTransform={featureValueTransform}
|
|
385
|
+
setGatingFeatureValueTransform={(newValue) => {
|
|
386
|
+
setFeatureValueTransform(newValue);
|
|
387
|
+
setTargetX(null);
|
|
388
|
+
setTargetY(null);
|
|
389
|
+
setZoom(null);
|
|
390
|
+
}}
|
|
391
|
+
gatingFeatureValueTransformCoefficient={featureValueTransformCoefficient}
|
|
392
|
+
setGatingFeatureValueTransformCoefficient={setFeatureValueTransformCoefficient}
|
|
393
|
+
geneSelectOptions={featureIndex}
|
|
394
|
+
transformOptions={VALUE_TRANSFORM_OPTIONS}
|
|
395
|
+
/>
|
|
396
|
+
</ScatterplotOptions>
|
|
397
|
+
)}
|
|
398
|
+
>
|
|
399
|
+
<EmptyMessage
|
|
400
|
+
visible={!(gatingFeatureSelectionX && gatingFeatureSelectionY)}
|
|
401
|
+
message={`Select two ${plur(featureType, 2)} in the plot settings.`}
|
|
402
|
+
/>
|
|
403
|
+
<Scatterplot
|
|
404
|
+
ref={deckRef}
|
|
405
|
+
uuid={uuid}
|
|
406
|
+
theme={theme}
|
|
407
|
+
hideTools={!(gatingFeatureSelectionX && gatingFeatureSelectionY)}
|
|
408
|
+
viewState={{ zoom, target: [targetX, targetY, targetZ] }}
|
|
409
|
+
setViewState={({ zoom: newZoom, target }) => {
|
|
410
|
+
setZoom(newZoom);
|
|
411
|
+
setTargetX(target[0]);
|
|
412
|
+
setTargetY(target[1]);
|
|
413
|
+
setTargetZ(target[2] || 0);
|
|
414
|
+
}}
|
|
415
|
+
obsEmbeddingIndex={obsIndex}
|
|
416
|
+
obsEmbedding={obsXY}
|
|
417
|
+
cellFilter={cellFilter}
|
|
418
|
+
cellSelection={cellSelection}
|
|
419
|
+
cellHighlight={cellHighlight}
|
|
420
|
+
cellColors={cellColors}
|
|
421
|
+
cellSetPolygons={cellSetPolygons}
|
|
422
|
+
cellSetLabelSize={cellSetLabelSize}
|
|
423
|
+
cellSetLabelsVisible={cellSetLabelsVisible}
|
|
424
|
+
cellSetPolygonsVisible={cellSetPolygonsVisible}
|
|
425
|
+
setCellFilter={setCellFilter}
|
|
426
|
+
setCellSelection={setCellSelectionProp}
|
|
427
|
+
setCellHighlight={setCellHighlight}
|
|
428
|
+
cellRadius={cellRadius}
|
|
429
|
+
cellOpacity={cellOpacity}
|
|
430
|
+
cellColorEncoding={cellColorEncoding}
|
|
431
|
+
geneExpressionColormap={geneExpressionColormap}
|
|
432
|
+
geneExpressionColormapRange={geneExpressionColormapRange}
|
|
433
|
+
setComponentHover={() => {
|
|
434
|
+
setComponentHover(uuid);
|
|
435
|
+
}}
|
|
436
|
+
updateViewInfo={setComponentViewInfo}
|
|
437
|
+
getExpressionValue={getExpressionValue}
|
|
438
|
+
getCellIsSelected={getCellIsSelected}
|
|
439
|
+
|
|
440
|
+
/>
|
|
441
|
+
{!disableTooltip && (
|
|
442
|
+
<ScatterplotTooltipSubscriber
|
|
443
|
+
parentUuid={uuid}
|
|
444
|
+
obsHighlight={cellHighlight}
|
|
445
|
+
width={width}
|
|
446
|
+
height={height}
|
|
447
|
+
getObsInfo={getObsInfo}
|
|
448
|
+
/>
|
|
449
|
+
)}
|
|
450
|
+
</TitleInfo>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export function register() {
|
|
455
|
+
registerPluginViewType(
|
|
456
|
+
ViewType.GATING,
|
|
457
|
+
GatingSubscriber,
|
|
458
|
+
COMPONENT_COORDINATION_TYPES[ViewType.GATING],
|
|
459
|
+
);
|
|
460
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GatingSubscriber, register } from './GatingSubscriber';
|