@vitessce/statistical-plots 2.0.3 → 3.0.1
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/{index.mjs → index.js} +20520 -10837
- package/dist-tsc/CellSetExpressionPlot.d.ts +33 -0
- package/dist-tsc/CellSetExpressionPlot.d.ts.map +1 -0
- package/dist-tsc/CellSetExpressionPlot.js +248 -0
- package/dist-tsc/CellSetExpressionPlotOptions.d.ts +2 -0
- package/dist-tsc/CellSetExpressionPlotOptions.d.ts.map +1 -0
- package/dist-tsc/CellSetExpressionPlotOptions.js +30 -0
- package/dist-tsc/CellSetExpressionPlotSubscriber.d.ts +16 -0
- package/dist-tsc/CellSetExpressionPlotSubscriber.d.ts.map +1 -0
- package/dist-tsc/CellSetExpressionPlotSubscriber.js +111 -0
- package/dist-tsc/CellSetSizesPlot.d.ts +29 -0
- package/dist-tsc/CellSetSizesPlot.d.ts.map +1 -0
- package/dist-tsc/CellSetSizesPlot.js +149 -0
- package/dist-tsc/CellSetSizesPlotSubscriber.d.ts +18 -0
- package/dist-tsc/CellSetSizesPlotSubscriber.d.ts.map +1 -0
- package/dist-tsc/CellSetSizesPlotSubscriber.js +75 -0
- package/dist-tsc/ExpressionHistogram.d.ts +34 -0
- package/dist-tsc/ExpressionHistogram.d.ts.map +1 -0
- package/dist-tsc/ExpressionHistogram.js +93 -0
- package/dist-tsc/ExpressionHistogramSubscriber.d.ts +16 -0
- package/dist-tsc/ExpressionHistogramSubscriber.d.ts.map +1 -0
- package/dist-tsc/ExpressionHistogramSubscriber.js +72 -0
- package/dist-tsc/index.d.ts +7 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +6 -6
- package/dist-tsc/styles.d.ts +2 -0
- package/dist-tsc/styles.d.ts.map +1 -0
- package/dist-tsc/styles.js +8 -0
- package/package.json +21 -12
- package/src/CellSetExpressionPlot.js +3 -3
- package/src/CellSetExpressionPlotOptions.js +1 -3
- package/src/CellSetExpressionPlotSubscriber.js +19 -23
- package/src/CellSetSizesPlot.js +90 -13
- package/src/CellSetSizesPlotSubscriber.js +69 -25
- package/src/ExpressionHistogram.js +58 -3
- package/src/ExpressionHistogramSubscriber.js +43 -21
- package/src/index.js +6 -6
- package/src/styles.js +1 -1
package/src/CellSetSizesPlot.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import clamp from 'lodash
|
1
|
+
import React, { useCallback } from 'react';
|
2
|
+
import { clamp } from 'lodash-es';
|
3
3
|
import { VegaPlot, VEGA_THEMES } from '@vitessce/vega';
|
4
4
|
import { colorArrayToString } from '@vitessce/sets-utils';
|
5
|
-
import { capitalize } from '@vitessce/utils';
|
5
|
+
import { capitalize, getDefaultColor } from '@vitessce/utils';
|
6
6
|
|
7
7
|
/**
|
8
8
|
* Cell set sizes displayed as a bar chart,
|
@@ -33,6 +33,7 @@ export default function CellSetSizesPlot(props) {
|
|
33
33
|
marginBottom = 120,
|
34
34
|
keyLength = 36,
|
35
35
|
obsType,
|
36
|
+
onBarSelect,
|
36
37
|
} = props;
|
37
38
|
|
38
39
|
// Add a property `keyName` which concatenates the key and the name,
|
@@ -46,18 +47,53 @@ export default function CellSetSizesPlot(props) {
|
|
46
47
|
colorString: colorArrayToString(d.color),
|
47
48
|
}));
|
48
49
|
|
49
|
-
// Manually set the color scale so that Vega-Lite does
|
50
|
-
// not choose the colors automatically.
|
51
|
-
const colors = {
|
52
|
-
domain: data.map(d => d.key),
|
53
|
-
range: data.map(d => d.colorString),
|
54
|
-
};
|
55
|
-
|
56
50
|
// Get an array of keys for sorting purposes.
|
57
51
|
const keys = data.map(d => d.keyName);
|
58
52
|
|
53
|
+
const colorScale = {
|
54
|
+
// Manually set the color scale so that Vega-Lite does
|
55
|
+
// not choose the colors automatically.
|
56
|
+
domain: data.map(d => d.key),
|
57
|
+
range: data.map((d) => {
|
58
|
+
const [r, g, b] = !d.isGrayedOut ? d.color : getDefaultColor(theme);
|
59
|
+
return `rgba(${r}, ${g}, ${b}, 1)`;
|
60
|
+
}),
|
61
|
+
};
|
62
|
+
const captializedObsType = capitalize(obsType);
|
63
|
+
|
59
64
|
const spec = {
|
60
|
-
mark: { type: 'bar' },
|
65
|
+
mark: { type: 'bar', stroke: 'black', cursor: 'pointer' },
|
66
|
+
params: [
|
67
|
+
{
|
68
|
+
name: 'highlight',
|
69
|
+
select: {
|
70
|
+
type: 'point',
|
71
|
+
on: 'mouseover',
|
72
|
+
},
|
73
|
+
},
|
74
|
+
{
|
75
|
+
name: 'select',
|
76
|
+
select: 'point',
|
77
|
+
},
|
78
|
+
{
|
79
|
+
name: 'bar_select',
|
80
|
+
select: {
|
81
|
+
type: 'point',
|
82
|
+
on: 'click[event.shiftKey === false]',
|
83
|
+
fields: ['setNamePath', 'isGrayedOut'],
|
84
|
+
empty: 'none',
|
85
|
+
},
|
86
|
+
},
|
87
|
+
{
|
88
|
+
name: 'shift_bar_select',
|
89
|
+
select: {
|
90
|
+
type: 'point',
|
91
|
+
on: 'click[event.shiftKey]',
|
92
|
+
fields: ['setNamePath', 'isGrayedOut'],
|
93
|
+
empty: 'none',
|
94
|
+
},
|
95
|
+
},
|
96
|
+
],
|
61
97
|
encoding: {
|
62
98
|
x: {
|
63
99
|
field: 'keyName',
|
@@ -69,28 +105,69 @@ export default function CellSetSizesPlot(props) {
|
|
69
105
|
y: {
|
70
106
|
field: 'size',
|
71
107
|
type: 'quantitative',
|
72
|
-
title: `${
|
108
|
+
title: `${captializedObsType} Set Size`,
|
73
109
|
},
|
74
110
|
color: {
|
75
111
|
field: 'key',
|
76
112
|
type: 'nominal',
|
77
|
-
scale:
|
113
|
+
scale: colorScale,
|
78
114
|
legend: null,
|
79
115
|
},
|
80
116
|
tooltip: {
|
81
117
|
field: 'size',
|
82
118
|
type: 'quantitative',
|
83
119
|
},
|
120
|
+
fillOpacity: {
|
121
|
+
condition: {
|
122
|
+
param: 'select',
|
123
|
+
value: 1,
|
124
|
+
},
|
125
|
+
value: 0.3,
|
126
|
+
},
|
127
|
+
strokeWidth: {
|
128
|
+
condition: [
|
129
|
+
{
|
130
|
+
param: 'select',
|
131
|
+
empty: false,
|
132
|
+
value: 1,
|
133
|
+
},
|
134
|
+
{
|
135
|
+
param: 'highlight',
|
136
|
+
empty: false,
|
137
|
+
value: 2,
|
138
|
+
},
|
139
|
+
],
|
140
|
+
value: 0,
|
141
|
+
},
|
84
142
|
},
|
85
143
|
width: clamp(width - marginRight, 10, Infinity),
|
86
144
|
height: clamp(height - marginBottom, 10, Infinity),
|
87
145
|
config: VEGA_THEMES[theme],
|
88
146
|
};
|
89
147
|
|
148
|
+
const handleSignal = (name, value) => {
|
149
|
+
if (name === 'bar_select') {
|
150
|
+
onBarSelect(value.setNamePath, value.isGrayedOut[0]);
|
151
|
+
} else if (name === 'shift_bar_select') {
|
152
|
+
const isGrayedOut = false;
|
153
|
+
const selectOnlyEnabled = true;
|
154
|
+
onBarSelect(value.setNamePath, isGrayedOut, selectOnlyEnabled);
|
155
|
+
}
|
156
|
+
};
|
157
|
+
|
158
|
+
const signalListeners = { bar_select: handleSignal, shift_bar_select: handleSignal };
|
159
|
+
const getTooltipText = useCallback(item => ({
|
160
|
+
[`${captializedObsType} Set`]: item.datum.name,
|
161
|
+
[`${captializedObsType} Set Size`]: item.datum.size,
|
162
|
+
}
|
163
|
+
), [captializedObsType]);
|
164
|
+
|
90
165
|
return (
|
91
166
|
<VegaPlot
|
92
167
|
data={data}
|
93
168
|
spec={spec}
|
169
|
+
signalListeners={signalListeners}
|
170
|
+
getTooltipText={getTooltipText}
|
94
171
|
/>
|
95
172
|
);
|
96
173
|
}
|
@@ -1,16 +1,18 @@
|
|
1
|
-
import React, { useMemo } from 'react';
|
1
|
+
import React, { useMemo, useState } from 'react';
|
2
2
|
import {
|
3
3
|
TitleInfo,
|
4
4
|
useCoordination, useLoaders,
|
5
5
|
useUrls, useReady, useGridItemSize,
|
6
6
|
useObsSetsData,
|
7
|
-
registerPluginViewType,
|
8
7
|
} from '@vitessce/vit-s';
|
8
|
+
import { isEqual } from 'lodash-es';
|
9
9
|
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
10
|
-
import {
|
10
|
+
import {
|
11
|
+
mergeObsSets, treeToSetSizesBySetNames, filterPathsByExpansionAndSelection, findChangedHierarchy,
|
12
|
+
} from '@vitessce/sets-utils';
|
11
13
|
import { capitalize } from '@vitessce/utils';
|
12
|
-
import CellSetSizesPlot from './CellSetSizesPlot';
|
13
|
-
import { useStyles } from './styles';
|
14
|
+
import CellSetSizesPlot from './CellSetSizesPlot.js';
|
15
|
+
import { useStyles } from './styles.js';
|
14
16
|
|
15
17
|
/**
|
16
18
|
* A subscriber component for `CellSetSizePlot`,
|
@@ -42,6 +44,7 @@ export function CellSetSizesPlotSubscriber(props) {
|
|
42
44
|
obsSetSelection: cellSetSelection,
|
43
45
|
obsSetColor: cellSetColor,
|
44
46
|
additionalObsSets: additionalCellSets,
|
47
|
+
obsSetExpansion: cellSetExpansion,
|
45
48
|
}, {
|
46
49
|
setObsSetSelection: setCellSetSelection,
|
47
50
|
setObsSetColor: setCellSetColor,
|
@@ -50,30 +53,78 @@ export function CellSetSizesPlotSubscriber(props) {
|
|
50
53
|
const title = titleOverride || `${capitalize(obsType)} Set Sizes`;
|
51
54
|
|
52
55
|
const [width, height, containerRef] = useGridItemSize();
|
53
|
-
|
56
|
+
|
57
|
+
// the name of the hierarchy that was clicked on last
|
58
|
+
const [currentHierarchy, setCurrentHierarchy] = useState([]);
|
59
|
+
// the previous cell set that was selected
|
60
|
+
const [prevCellSetSelection, setPrevCellSetSelection] = useState([]);
|
54
61
|
|
55
62
|
// Get data from loaders using the data hooks.
|
56
|
-
const [{ obsSets: cellSets }, obsSetsStatus] = useObsSetsData(
|
57
|
-
loaders, dataset,
|
63
|
+
const [{ obsSets: cellSets }, obsSetsStatus, obsSetsUrls] = useObsSetsData(
|
64
|
+
loaders, dataset, true,
|
58
65
|
{ setObsSetSelection: setCellSetSelection, setObsSetColor: setCellSetColor },
|
59
66
|
{ obsSetSelection: cellSetSelection, obsSetColor: cellSetColor },
|
60
67
|
{ obsType },
|
61
68
|
);
|
62
|
-
const isReady = useReady([
|
63
|
-
|
64
|
-
]);
|
69
|
+
const isReady = useReady([obsSetsStatus]);
|
70
|
+
const urls = useUrls([obsSetsUrls]);
|
65
71
|
|
66
72
|
const mergedCellSets = useMemo(
|
67
73
|
() => mergeObsSets(cellSets, additionalCellSets),
|
68
74
|
[cellSets, additionalCellSets],
|
69
75
|
);
|
70
76
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
const data = useMemo(() => {
|
78
|
+
if (cellSetSelection && cellSetColor && mergedCellSets && cellSets) {
|
79
|
+
let newHierarchy = currentHierarchy;
|
80
|
+
|
81
|
+
if (cellSetSelection) {
|
82
|
+
const changedHierarchy = findChangedHierarchy(prevCellSetSelection, cellSetSelection);
|
83
|
+
setPrevCellSetSelection(cellSetSelection);
|
84
|
+
|
85
|
+
if (changedHierarchy) {
|
86
|
+
setCurrentHierarchy(changedHierarchy);
|
87
|
+
newHierarchy = changedHierarchy;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
const cellSetPaths = filterPathsByExpansionAndSelection(
|
92
|
+
mergedCellSets,
|
93
|
+
newHierarchy,
|
94
|
+
cellSetExpansion,
|
95
|
+
cellSetSelection,
|
96
|
+
);
|
97
|
+
|
98
|
+
if (mergedCellSets && cellSets && cellSetSelection && cellSetColor) {
|
99
|
+
return treeToSetSizesBySetNames(
|
100
|
+
mergedCellSets,
|
101
|
+
cellSetPaths,
|
102
|
+
cellSetSelection,
|
103
|
+
cellSetColor,
|
104
|
+
theme,
|
105
|
+
);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
return [];
|
109
|
+
}, [
|
110
|
+
mergedCellSets,
|
111
|
+
cellSetSelection,
|
112
|
+
cellSetExpansion,
|
113
|
+
cellSetColor,
|
114
|
+
theme,
|
115
|
+
]);
|
116
|
+
|
117
|
+
const onBarSelect = (setNamePath, wasGrayedOut, selectOnlyEnabled = false) => {
|
118
|
+
if (selectOnlyEnabled) {
|
119
|
+
setCellSetSelection([setNamePath]);
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
if (!wasGrayedOut) {
|
123
|
+
setCellSetSelection(cellSetSelection.filter(d => !isEqual(d, setNamePath)));
|
124
|
+
} else if (wasGrayedOut) {
|
125
|
+
setCellSetSelection([...cellSetSelection, setNamePath]);
|
126
|
+
}
|
127
|
+
};
|
77
128
|
|
78
129
|
return (
|
79
130
|
<TitleInfo
|
@@ -86,6 +137,7 @@ export function CellSetSizesPlotSubscriber(props) {
|
|
86
137
|
<div ref={containerRef} className={classes.vegaContainer}>
|
87
138
|
<CellSetSizesPlot
|
88
139
|
data={data}
|
140
|
+
onBarSelect={onBarSelect}
|
89
141
|
theme={theme}
|
90
142
|
width={width}
|
91
143
|
height={height}
|
@@ -95,11 +147,3 @@ export function CellSetSizesPlotSubscriber(props) {
|
|
95
147
|
</TitleInfo>
|
96
148
|
);
|
97
149
|
}
|
98
|
-
|
99
|
-
export function register() {
|
100
|
-
registerPluginViewType(
|
101
|
-
ViewType.OBS_SET_SIZES,
|
102
|
-
CellSetSizesPlotSubscriber,
|
103
|
-
COMPONENT_COORDINATION_TYPES[ViewType.OBS_SET_SIZES],
|
104
|
-
);
|
105
|
-
}
|
@@ -1,7 +1,14 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import clamp from 'lodash
|
1
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
2
|
+
import { clamp, debounce } from 'lodash-es';
|
3
3
|
import { VegaPlot, VEGA_THEMES } from '@vitessce/vega';
|
4
4
|
|
5
|
+
/**
|
6
|
+
* We use debounce, so that onSelect is called only after the user has finished the selection.
|
7
|
+
* Due to vega-lite limitations, we cannot use the vega-lite signals to implement this.
|
8
|
+
* See this issue: https://github.com/vega/vega-lite/issues/5728
|
9
|
+
* See this for reference on what is supported: https://vega.github.io/vega-lite/docs/selection.html
|
10
|
+
*/
|
11
|
+
|
5
12
|
/**
|
6
13
|
* Gene expression histogram displayed as a bar chart,
|
7
14
|
* implemented with the VegaPlot component.
|
@@ -29,14 +36,18 @@ export default function ExpressionHistogram(props) {
|
|
29
36
|
height,
|
30
37
|
marginRight = 90,
|
31
38
|
marginBottom = 50,
|
39
|
+
onSelect,
|
32
40
|
} = props;
|
33
41
|
|
42
|
+
const [selectedRanges, setSelectedRanges] = useState([]);
|
43
|
+
|
34
44
|
const xTitle = geneSelection && geneSelection.length >= 1
|
35
45
|
? 'Normalized Expression Value'
|
36
46
|
: 'Total Normalized Transcript Count';
|
37
47
|
|
38
48
|
const spec = {
|
39
|
-
|
49
|
+
data: { values: data },
|
50
|
+
mark: 'bar',
|
40
51
|
encoding: {
|
41
52
|
x: {
|
42
53
|
field: 'value',
|
@@ -50,15 +61,59 @@ export default function ExpressionHistogram(props) {
|
|
50
61
|
title: 'Number of Cells',
|
51
62
|
},
|
52
63
|
color: { value: 'gray' },
|
64
|
+
opacity: {
|
65
|
+
condition: { selection: 'brush', value: 1 },
|
66
|
+
value: 0.7,
|
67
|
+
},
|
53
68
|
},
|
69
|
+
params: [
|
70
|
+
{
|
71
|
+
name: 'brush',
|
72
|
+
select: { type: 'interval', encodings: ['x'] },
|
73
|
+
},
|
74
|
+
],
|
54
75
|
width: clamp(width - marginRight, 10, Infinity),
|
55
76
|
height: clamp(height - marginBottom, 10, Infinity),
|
56
77
|
config: VEGA_THEMES[theme],
|
57
78
|
};
|
58
79
|
|
80
|
+
|
81
|
+
const handleSignal = (name, value) => {
|
82
|
+
if (name === 'brush') {
|
83
|
+
setSelectedRanges(value.value);
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
89
|
+
const debouncedOnSelect = useCallback(debounce((ranges, latestOnSelect) => {
|
90
|
+
latestOnSelect(ranges);
|
91
|
+
// We set a debounce timer of 1000ms: the assumption here is that the user has
|
92
|
+
// finished the selection when there's been no mouse movement on the histogram for a second.
|
93
|
+
// We do not pass any dependencies for the useCallback
|
94
|
+
// since we only want to define the debounced function once (on the initial render).
|
95
|
+
}, 1000), []);
|
96
|
+
|
97
|
+
useEffect(() => {
|
98
|
+
if (!selectedRanges || selectedRanges.length === 0) return () => {};
|
99
|
+
|
100
|
+
// Call the debounced function instead of directly calling onSelect
|
101
|
+
debouncedOnSelect(selectedRanges, onSelect);
|
102
|
+
|
103
|
+
// Clean up the debounce timer when the component unmounts or the dependency changes
|
104
|
+
return () => {
|
105
|
+
debouncedOnSelect.cancel();
|
106
|
+
};
|
107
|
+
// We only want to call the debounced function when the selectedRanges changes.
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
109
|
+
}, [selectedRanges]);
|
110
|
+
|
111
|
+
const signalListeners = { brush: handleSignal };
|
112
|
+
|
59
113
|
return (
|
60
114
|
<VegaPlot
|
61
115
|
data={data}
|
116
|
+
signalListeners={signalListeners}
|
62
117
|
spec={spec}
|
63
118
|
/>
|
64
119
|
);
|
@@ -1,16 +1,17 @@
|
|
1
|
-
import React, {
|
1
|
+
import React, {
|
2
|
+
useMemo, useCallback,
|
3
|
+
} from 'react';
|
2
4
|
import { sum } from 'd3-array';
|
3
5
|
import {
|
4
6
|
TitleInfo,
|
5
7
|
useCoordination, useLoaders,
|
6
8
|
useUrls, useReady, useGridItemSize,
|
7
9
|
useObsFeatureMatrixData, useFeatureSelection,
|
8
|
-
registerPluginViewType,
|
9
10
|
} from '@vitessce/vit-s';
|
10
11
|
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
11
|
-
import
|
12
|
-
import
|
13
|
-
|
12
|
+
import { setObsSelection, getObsInfoFromDataWithinRange } from '@vitessce/sets-utils';
|
13
|
+
import ExpressionHistogram from './ExpressionHistogram.js';
|
14
|
+
import { useStyles } from './styles.js';
|
14
15
|
/**
|
15
16
|
* A subscriber component for `ExpressionHistogram`,
|
16
17
|
* which listens for gene selection updates and
|
@@ -38,17 +39,25 @@ export function ExpressionHistogramSubscriber(props) {
|
|
38
39
|
featureType,
|
39
40
|
featureValueType,
|
40
41
|
featureSelection: geneSelection,
|
42
|
+
additionalObsSets: additionalCellSets,
|
43
|
+
obsSetColor: cellSetColor,
|
44
|
+
}, {
|
45
|
+
setAdditionalObsSets: setAdditionalCellSets,
|
46
|
+
setObsSetColor: setCellSetColor,
|
47
|
+
setObsColorEncoding: setCellColorEncoding,
|
48
|
+
setObsSetSelection: setCellSetSelection,
|
41
49
|
}] = useCoordination(
|
42
50
|
COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_VALUE_HISTOGRAM],
|
43
51
|
coordinationScopes,
|
44
52
|
);
|
45
53
|
|
46
54
|
const [width, height, containerRef] = useGridItemSize();
|
47
|
-
const [urls, addUrl] = useUrls(loaders, dataset);
|
48
55
|
|
49
56
|
// Get data from loaders using the data hooks.
|
50
|
-
const [
|
51
|
-
|
57
|
+
const [
|
58
|
+
{ obsIndex, featureIndex, obsFeatureMatrix }, matrixStatus, matrixUrls,
|
59
|
+
] = useObsFeatureMatrixData(
|
60
|
+
loaders, dataset, true, {}, {},
|
52
61
|
{ obsType, featureType, featureValueType },
|
53
62
|
);
|
54
63
|
// eslint-disable-next-line no-unused-vars
|
@@ -60,6 +69,9 @@ export function ExpressionHistogramSubscriber(props) {
|
|
60
69
|
matrixStatus,
|
61
70
|
featureSelectionStatus,
|
62
71
|
]);
|
72
|
+
const urls = useUrls([
|
73
|
+
matrixUrls,
|
74
|
+
]);
|
63
75
|
|
64
76
|
const firstGeneSelected = geneSelection && geneSelection.length >= 1
|
65
77
|
? geneSelection[0]
|
@@ -69,11 +81,12 @@ export function ExpressionHistogramSubscriber(props) {
|
|
69
81
|
// generate the array of data points for the histogram.
|
70
82
|
const data = useMemo(() => {
|
71
83
|
if (firstGeneSelected && obsFeatureMatrix && expressionData) {
|
72
|
-
|
73
|
-
|
74
|
-
|
84
|
+
return obsIndex.map((cellId, cellIndex) => {
|
85
|
+
const value = expressionData[0][cellIndex];
|
86
|
+
// Create new cellColors map based on the selected gene.
|
75
87
|
const normValue = value * 100 / 255;
|
76
|
-
|
88
|
+
const newItem = { value: normValue, gene: firstGeneSelected, cellId };
|
89
|
+
return newItem;
|
77
90
|
});
|
78
91
|
}
|
79
92
|
if (obsFeatureMatrix) {
|
@@ -82,12 +95,28 @@ export function ExpressionHistogramSubscriber(props) {
|
|
82
95
|
const values = obsFeatureMatrix.data
|
83
96
|
.subarray(cellIndex * numGenes, (cellIndex + 1) * numGenes);
|
84
97
|
const sumValue = sum(values) * 100 / 255;
|
85
|
-
|
98
|
+
const newItem = { value: sumValue, gene: null, cellId };
|
99
|
+
return newItem;
|
86
100
|
});
|
87
101
|
}
|
88
102
|
return null;
|
89
103
|
}, [obsIndex, featureIndex, obsFeatureMatrix, firstGeneSelected, expressionData]);
|
90
104
|
|
105
|
+
const onSelect = useCallback((value) => {
|
106
|
+
const geneName = firstGeneSelected ? [firstGeneSelected, 'values'].join(' ') : 'transcript count';
|
107
|
+
|
108
|
+
const selectedCellIds = getObsInfoFromDataWithinRange(value, data);
|
109
|
+
setObsSelection(
|
110
|
+
selectedCellIds, additionalCellSets, cellSetColor,
|
111
|
+
setCellSetSelection, setAdditionalCellSets, setCellSetColor,
|
112
|
+
setCellColorEncoding,
|
113
|
+
'Selection ',
|
114
|
+
`: based on ${geneName} in range [${value[0].toFixed(1)}, ${value[1].toFixed(1)}] `,
|
115
|
+
);
|
116
|
+
}, [additionalCellSets, cellSetColor, data, setAdditionalCellSets,
|
117
|
+
setCellColorEncoding, setCellSetColor, setCellSetSelection, firstGeneSelected,
|
118
|
+
]);
|
119
|
+
|
91
120
|
return (
|
92
121
|
<TitleInfo
|
93
122
|
title={`Expression Histogram${(firstGeneSelected ? ` (${firstGeneSelected})` : '')}`}
|
@@ -99,6 +128,7 @@ export function ExpressionHistogramSubscriber(props) {
|
|
99
128
|
<div ref={containerRef} className={classes.vegaContainer}>
|
100
129
|
<ExpressionHistogram
|
101
130
|
geneSelection={geneSelection}
|
131
|
+
onSelect={onSelect}
|
102
132
|
data={data}
|
103
133
|
theme={theme}
|
104
134
|
width={width}
|
@@ -108,11 +138,3 @@ export function ExpressionHistogramSubscriber(props) {
|
|
108
138
|
</TitleInfo>
|
109
139
|
);
|
110
140
|
}
|
111
|
-
|
112
|
-
export function register() {
|
113
|
-
registerPluginViewType(
|
114
|
-
ViewType.FEATURE_VALUE_HISTOGRAM,
|
115
|
-
ExpressionHistogramSubscriber,
|
116
|
-
COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_VALUE_HISTOGRAM],
|
117
|
-
);
|
118
|
-
}
|
package/src/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export { CellSetExpressionPlotSubscriber
|
2
|
-
export { CellSetSizesPlotSubscriber
|
3
|
-
export { ExpressionHistogramSubscriber
|
4
|
-
export { default as CellSetSizesPlot } from './CellSetSizesPlot';
|
5
|
-
export { default as CellSetExpressionPlot } from './CellSetExpressionPlot';
|
6
|
-
export { default as ExpressionHistogram } from './ExpressionHistogram';
|
1
|
+
export { CellSetExpressionPlotSubscriber } from './CellSetExpressionPlotSubscriber.js';
|
2
|
+
export { CellSetSizesPlotSubscriber } from './CellSetSizesPlotSubscriber.js';
|
3
|
+
export { ExpressionHistogramSubscriber } from './ExpressionHistogramSubscriber.js';
|
4
|
+
export { default as CellSetSizesPlot } from './CellSetSizesPlot.js';
|
5
|
+
export { default as CellSetExpressionPlot } from './CellSetExpressionPlot.js';
|
6
|
+
export { default as ExpressionHistogram } from './ExpressionHistogram.js';
|
package/src/styles.js
CHANGED