@vitessce/statistical-plots 2.0.3-beta.0 → 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/index.mjs +76191 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +10 -10
- package/src/CellSetExpressionPlot.js +278 -0
- package/src/CellSetExpressionPlotOptions.js +75 -0
- package/src/CellSetExpressionPlotSubscriber.js +228 -0
- package/src/CellSetSizesPlot.js +96 -0
- package/src/CellSetSizesPlotSubscriber.js +105 -0
- package/{dist → src}/ExpressionHistogram.js +42 -26
- package/src/ExpressionHistogramSubscriber.js +118 -0
- package/src/index.js +6 -0
- package/src/styles.js +9 -0
- package/dist/CellSetExpressionPlot.js +0 -248
- package/dist/CellSetExpressionPlotOptions.js +0 -32
- package/dist/CellSetExpressionPlotSubscriber.js +0 -111
- package/dist/CellSetSizesPlot.js +0 -77
- package/dist/CellSetSizesPlotSubscriber.js +0 -44
- package/dist/DotPlot.js +0 -110
- package/dist/DotPlotSubscriber.js +0 -126
- package/dist/ExpressionHistogramSubscriber.js +0 -63
- package/dist/styles.js +0 -8
@@ -1,32 +0,0 @@
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
-
import React from 'react';
|
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, OptionsContainer, OptionSelect } from '@vitessce/vit-s';
|
7
|
-
export default function CellSetExpressionPlotOptions(props) {
|
8
|
-
const { featureValueTransform, setFeatureValueTransform, featureValueTransformCoefficient, setFeatureValueTransformCoefficient, transformOptions, } = props;
|
9
|
-
const classes = usePlotOptionsStyles();
|
10
|
-
const handleTransformChange = (event) => {
|
11
|
-
setFeatureValueTransform(event.target.value === '' ? null : event.target.value);
|
12
|
-
};
|
13
|
-
// Feels a little hacky, but I think this is the best way to handle
|
14
|
-
// the limitations of the v4 material-ui number input.
|
15
|
-
const handleTransformCoefficientChange = (event) => {
|
16
|
-
const { value } = event.target;
|
17
|
-
if (!value) {
|
18
|
-
setFeatureValueTransformCoefficient(value);
|
19
|
-
}
|
20
|
-
else {
|
21
|
-
const newCoefficient = Number(value);
|
22
|
-
if (!Number.isNaN(newCoefficient) && newCoefficient >= 0) {
|
23
|
-
setFeatureValueTransformCoefficient(value);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
};
|
27
|
-
return (_jsxs(OptionsContainer, { children: [_jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Transform" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(OptionSelect, { className: classes.select, value: featureValueTransform === null ? '' : featureValueTransform, onChange: handleTransformChange, inputProps: {
|
28
|
-
id: 'scatterplot-transform-select',
|
29
|
-
}, children: transformOptions.map(opt => (_jsx("option", { value: opt.value === null ? '' : opt.value, children: opt.name }, opt.name))) }, "gating-transform-select") })] }), _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Transform Coefficient" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(TextField, { label: "Number", type: "number", onChange: handleTransformCoefficientChange, value: featureValueTransformCoefficient, InputLabelProps: {
|
30
|
-
shrink: true,
|
31
|
-
} }) })] }, "transform-coefficient-option-row")] }));
|
32
|
-
}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
-
import React, { useMemo } from 'react';
|
3
|
-
import { TitleInfo, useCoordination, useLoaders, useUrls, useReady, useGridItemSize, useFeatureSelection, useObsSetsData, useObsFeatureMatrixIndices, useFeatureLabelsData, registerPluginViewType, } from '@vitessce/vit-s';
|
4
|
-
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
5
|
-
import { VALUE_TRANSFORM_OPTIONS, capitalize, getValueTransformFunction } from '@vitessce/utils';
|
6
|
-
import { treeToObjectsBySetNames, treeToSetSizesBySetNames, mergeObsSets } from '@vitessce/sets-utils';
|
7
|
-
import CellSetExpressionPlotOptions from './CellSetExpressionPlotOptions';
|
8
|
-
import CellSetExpressionPlot from './CellSetExpressionPlot';
|
9
|
-
import { useStyles } from './styles';
|
10
|
-
/**
|
11
|
-
* Get expression data for the cells
|
12
|
-
* in the selected cell sets.
|
13
|
-
* @param {object} expressionMatrix
|
14
|
-
* @param {string[]} expressionMatrix.rows Cell IDs.
|
15
|
-
* @param {string[]} expressionMatrix.cols Gene names.
|
16
|
-
* @param {Uint8Array} expressionMatrix.matrix The
|
17
|
-
* flattened expression matrix as a typed array.
|
18
|
-
* @param {object} cellSets The cell sets from the dataset.
|
19
|
-
* @param {object} additionalCellSets The user-defined cell sets
|
20
|
-
* from the coordination space.
|
21
|
-
* @param {array} geneSelection Array of selected genes.
|
22
|
-
* @param {array} cellSetSelection Array of selected cell set paths.
|
23
|
-
* @param {object[]} cellSetColor Array of objects with properties
|
24
|
-
* @param {string|null} featureValueTransform The name of the
|
25
|
-
* feature value transform function.
|
26
|
-
* @param {number} featureValueTransformCoefficient A coefficient
|
27
|
-
* to be used in the transform function.
|
28
|
-
* @param {string} theme "light" or "dark" for the vitessce theme
|
29
|
-
* `path` and `color`.
|
30
|
-
*/
|
31
|
-
export function useExpressionByCellSet(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, theme) {
|
32
|
-
const mergedCellSets = useMemo(() => mergeObsSets(cellSets, additionalCellSets), [cellSets, additionalCellSets]);
|
33
|
-
// From the expression matrix and the list of selected genes / cell sets,
|
34
|
-
// generate the array of data points for the plot.
|
35
|
-
const [expressionArr, expressionMax] = useMemo(() => {
|
36
|
-
if (mergedCellSets && cellSetSelection
|
37
|
-
&& geneSelection && geneSelection.length >= 1
|
38
|
-
&& expressionData) {
|
39
|
-
const cellObjects = treeToObjectsBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme);
|
40
|
-
const firstGeneSelected = geneSelection[0];
|
41
|
-
// Create new cellColors map based on the selected gene.
|
42
|
-
let exprMax = -Infinity;
|
43
|
-
const cellIndices = {};
|
44
|
-
for (let i = 0; i < obsIndex.length; i += 1) {
|
45
|
-
cellIndices[obsIndex[i]] = i;
|
46
|
-
}
|
47
|
-
const exprValues = cellObjects.map((cell) => {
|
48
|
-
const cellIndex = cellIndices[cell.obsId];
|
49
|
-
const value = expressionData[0][cellIndex];
|
50
|
-
const normValue = value * 100 / 255;
|
51
|
-
const transformFunction = getValueTransformFunction(featureValueTransform, featureValueTransformCoefficient);
|
52
|
-
const transformedValue = transformFunction(normValue);
|
53
|
-
exprMax = Math.max(transformedValue, exprMax);
|
54
|
-
return { value: transformedValue, gene: firstGeneSelected, set: cell.name };
|
55
|
-
});
|
56
|
-
return [exprValues, exprMax];
|
57
|
-
}
|
58
|
-
return [null, null];
|
59
|
-
}, [expressionData, obsIndex, geneSelection, theme,
|
60
|
-
mergedCellSets, cellSetSelection, cellSetColor,
|
61
|
-
featureValueTransform, featureValueTransformCoefficient,
|
62
|
-
]);
|
63
|
-
// From the cell sets hierarchy and the list of selected cell sets,
|
64
|
-
// generate the array of set sizes data points for the bar plot.
|
65
|
-
const setArr = useMemo(() => (mergedCellSets && cellSetSelection && cellSetColor
|
66
|
-
? treeToSetSizesBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme)
|
67
|
-
: []), [mergedCellSets, cellSetSelection, cellSetColor, theme]);
|
68
|
-
return [expressionArr, setArr, expressionMax];
|
69
|
-
}
|
70
|
-
/**
|
71
|
-
* A subscriber component for `CellSetExpressionPlot`,
|
72
|
-
* which listens for gene selection updates and
|
73
|
-
* `GRID_RESIZE` events.
|
74
|
-
* @param {object} props
|
75
|
-
* @param {function} props.removeGridComponent The grid component removal function.
|
76
|
-
* @param {object} props.coordinationScopes An object mapping coordination
|
77
|
-
* types to coordination scopes.
|
78
|
-
* @param {string} props.theme The name of the current Vitessce theme.
|
79
|
-
*/
|
80
|
-
export function CellSetExpressionPlotSubscriber(props) {
|
81
|
-
const { coordinationScopes, removeGridComponent, theme, } = props;
|
82
|
-
const classes = useStyles();
|
83
|
-
const loaders = useLoaders();
|
84
|
-
// Get "props" from the coordination space.
|
85
|
-
const [{ dataset, obsType, featureType, featureValueType, featureSelection: geneSelection, featureValueTransform, featureValueTransformCoefficient, obsSetSelection: cellSetSelection, obsSetColor: cellSetColor, additionalObsSets: additionalCellSets, }, { setFeatureValueTransform, setFeatureValueTransformCoefficient, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.OBS_SET_FEATURE_VALUE_DISTRIBUTION], coordinationScopes);
|
86
|
-
const [width, height, containerRef] = useGridItemSize();
|
87
|
-
const [urls, addUrl] = useUrls(loaders, dataset);
|
88
|
-
const transformOptions = VALUE_TRANSFORM_OPTIONS;
|
89
|
-
// Get data from loaders using the data hooks.
|
90
|
-
// eslint-disable-next-line no-unused-vars
|
91
|
-
const [expressionData, loadedFeatureSelection, featureSelectionStatus] = useFeatureSelection(loaders, dataset, false, geneSelection, { obsType, featureType, featureValueType });
|
92
|
-
// TODO: support multiple feature labels using featureLabelsType coordination values.
|
93
|
-
const [{ featureLabelsMap }, featureLabelsStatus] = useFeatureLabelsData(loaders, dataset, addUrl, false, {}, {}, { featureType });
|
94
|
-
const [{ obsIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(loaders, dataset, addUrl, false, { obsType, featureType, featureValueType });
|
95
|
-
const [{ obsSets: cellSets }, obsSetsStatus] = useObsSetsData(loaders, dataset, addUrl, true, {}, {}, { obsType });
|
96
|
-
const isReady = useReady([
|
97
|
-
featureSelectionStatus,
|
98
|
-
matrixIndicesStatus,
|
99
|
-
obsSetsStatus,
|
100
|
-
featureLabelsStatus,
|
101
|
-
]);
|
102
|
-
const [expressionArr, setArr, expressionMax] = useExpressionByCellSet(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, theme);
|
103
|
-
const firstGeneSelected = geneSelection && geneSelection.length >= 1
|
104
|
-
? (featureLabelsMap?.get(geneSelection[0]) || geneSelection[0])
|
105
|
-
: null;
|
106
|
-
const selectedTransformName = transformOptions.find(o => o.value === featureValueTransform)?.name;
|
107
|
-
return (_jsx(TitleInfo, { title: `Expression by ${capitalize(obsType)} Set${(firstGeneSelected ? ` (${firstGeneSelected})` : '')}`, removeGridComponent: removeGridComponent, urls: urls, theme: theme, isReady: isReady, options: (_jsx(CellSetExpressionPlotOptions, { featureValueTransform: featureValueTransform, setFeatureValueTransform: setFeatureValueTransform, featureValueTransformCoefficient: featureValueTransformCoefficient, setFeatureValueTransformCoefficient: setFeatureValueTransformCoefficient, transformOptions: transformOptions })), children: _jsx("div", { ref: containerRef, className: classes.vegaContainer, children: expressionArr ? (_jsx(CellSetExpressionPlot, { domainMax: expressionMax, colors: setArr, data: expressionArr, theme: theme, width: width, height: height, obsType: obsType, featureValueType: featureValueType, featureValueTransformName: selectedTransformName })) : (_jsxs("span", { children: ["Select a ", featureType, "."] })) }) }));
|
108
|
-
}
|
109
|
-
export function register() {
|
110
|
-
registerPluginViewType(ViewType.OBS_SET_FEATURE_VALUE_DISTRIBUTION, CellSetExpressionPlotSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.OBS_SET_FEATURE_VALUE_DISTRIBUTION]);
|
111
|
-
}
|
package/dist/CellSetSizesPlot.js
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import React from 'react';
|
3
|
-
import clamp from 'lodash/clamp';
|
4
|
-
import { VegaPlot, VEGA_THEMES } from '@vitessce/vega';
|
5
|
-
import { colorArrayToString } from '@vitessce/sets-utils';
|
6
|
-
import { capitalize } from '@vitessce/utils';
|
7
|
-
/**
|
8
|
-
* Cell set sizes displayed as a bar chart,
|
9
|
-
* implemented with the VegaPlot component.
|
10
|
-
* @param {object} props
|
11
|
-
* @param {object[]} props.data The set size data, an array
|
12
|
-
* of objects with properties `name`, `key`, `color`, and `size`.
|
13
|
-
* @param {string} props.theme The name of the current Vitessce theme.
|
14
|
-
* @param {number} props.width The container width.
|
15
|
-
* @param {number} props.height The container height.
|
16
|
-
* @param {number} props.marginRight The size of the margin
|
17
|
-
* on the right side of the plot, to account for the vega menu button.
|
18
|
-
* By default, 90.
|
19
|
-
* @param {number} props.marginBottom The size of the margin
|
20
|
-
* on the bottom of the plot, to account for long x-axis labels.
|
21
|
-
* By default, 120.
|
22
|
-
* @param {number} props.keyLength The length of the `key` property of
|
23
|
-
* each data point. Assumes all key strings have the same length.
|
24
|
-
* By default, 36.
|
25
|
-
*/
|
26
|
-
export default function CellSetSizesPlot(props) {
|
27
|
-
const { data: rawData, theme, width, height, marginRight = 90, marginBottom = 120, keyLength = 36, obsType, } = props;
|
28
|
-
// Add a property `keyName` which concatenates the key and the name,
|
29
|
-
// which is both unique and can easily be converted
|
30
|
-
// back to the name by taking a substring.
|
31
|
-
// Add a property `colorString` which contains the `[r, g, b]` color
|
32
|
-
// after converting to a color hex string.
|
33
|
-
const data = rawData.map(d => ({
|
34
|
-
...d,
|
35
|
-
keyName: d.key + d.name,
|
36
|
-
colorString: colorArrayToString(d.color),
|
37
|
-
}));
|
38
|
-
// Manually set the color scale so that Vega-Lite does
|
39
|
-
// not choose the colors automatically.
|
40
|
-
const colors = {
|
41
|
-
domain: data.map(d => d.key),
|
42
|
-
range: data.map(d => d.colorString),
|
43
|
-
};
|
44
|
-
// Get an array of keys for sorting purposes.
|
45
|
-
const keys = data.map(d => d.keyName);
|
46
|
-
const spec = {
|
47
|
-
mark: { type: 'bar' },
|
48
|
-
encoding: {
|
49
|
-
x: {
|
50
|
-
field: 'keyName',
|
51
|
-
type: 'nominal',
|
52
|
-
axis: { labelExpr: `substring(datum.label, ${keyLength})` },
|
53
|
-
title: 'Cell Set',
|
54
|
-
sort: keys,
|
55
|
-
},
|
56
|
-
y: {
|
57
|
-
field: 'size',
|
58
|
-
type: 'quantitative',
|
59
|
-
title: `${capitalize(obsType)} Set Size`,
|
60
|
-
},
|
61
|
-
color: {
|
62
|
-
field: 'key',
|
63
|
-
type: 'nominal',
|
64
|
-
scale: colors,
|
65
|
-
legend: null,
|
66
|
-
},
|
67
|
-
tooltip: {
|
68
|
-
field: 'size',
|
69
|
-
type: 'quantitative',
|
70
|
-
},
|
71
|
-
},
|
72
|
-
width: clamp(width - marginRight, 10, Infinity),
|
73
|
-
height: clamp(height - marginBottom, 10, Infinity),
|
74
|
-
config: VEGA_THEMES[theme],
|
75
|
-
};
|
76
|
-
return (_jsx(VegaPlot, { data: data, spec: spec }));
|
77
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import React, { useMemo } from 'react';
|
3
|
-
import { TitleInfo, useCoordination, useLoaders, useUrls, useReady, useGridItemSize, useObsSetsData, registerPluginViewType, } from '@vitessce/vit-s';
|
4
|
-
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
5
|
-
import { mergeObsSets, treeToSetSizesBySetNames } from '@vitessce/sets-utils';
|
6
|
-
import { capitalize } from '@vitessce/utils';
|
7
|
-
import CellSetSizesPlot from './CellSetSizesPlot';
|
8
|
-
import { useStyles } from './styles';
|
9
|
-
/**
|
10
|
-
* A subscriber component for `CellSetSizePlot`,
|
11
|
-
* which listens for cell sets data updates and
|
12
|
-
* `GRID_RESIZE` events.
|
13
|
-
* @param {object} props
|
14
|
-
* @param {function} props.removeGridComponent The grid component removal function.
|
15
|
-
* @param {function} props.onReady The function to call when the subscriptions
|
16
|
-
* have been made.
|
17
|
-
* @param {string} props.theme The name of the current Vitessce theme.
|
18
|
-
* @param {string} props.title The component title.
|
19
|
-
*/
|
20
|
-
export function CellSetSizesPlotSubscriber(props) {
|
21
|
-
const { coordinationScopes, removeGridComponent, theme, title: titleOverride, } = props;
|
22
|
-
const classes = useStyles();
|
23
|
-
const loaders = useLoaders();
|
24
|
-
// Get "props" from the coordination space.
|
25
|
-
const [{ dataset, obsType, obsSetSelection: cellSetSelection, obsSetColor: cellSetColor, additionalObsSets: additionalCellSets, }, { setObsSetSelection: setCellSetSelection, setObsSetColor: setCellSetColor, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.OBS_SET_SIZES], coordinationScopes);
|
26
|
-
const title = titleOverride || `${capitalize(obsType)} Set Sizes`;
|
27
|
-
const [width, height, containerRef] = useGridItemSize();
|
28
|
-
const [urls, addUrl] = useUrls(loaders, dataset);
|
29
|
-
// Get data from loaders using the data hooks.
|
30
|
-
const [{ obsSets: cellSets }, obsSetsStatus] = useObsSetsData(loaders, dataset, addUrl, true, { setObsSetSelection: setCellSetSelection, setObsSetColor: setCellSetColor }, { obsSetSelection: cellSetSelection, obsSetColor: cellSetColor }, { obsType });
|
31
|
-
const isReady = useReady([
|
32
|
-
obsSetsStatus,
|
33
|
-
]);
|
34
|
-
const mergedCellSets = useMemo(() => mergeObsSets(cellSets, additionalCellSets), [cellSets, additionalCellSets]);
|
35
|
-
// From the cell sets hierarchy and the list of selected cell sets,
|
36
|
-
// generate the array of set sizes data points for the bar plot.
|
37
|
-
const data = useMemo(() => (mergedCellSets && cellSetSelection && cellSetColor
|
38
|
-
? treeToSetSizesBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme)
|
39
|
-
: []), [mergedCellSets, cellSetSelection, cellSetColor, theme]);
|
40
|
-
return (_jsx(TitleInfo, { title: title, removeGridComponent: removeGridComponent, urls: urls, theme: theme, isReady: isReady, children: _jsx("div", { ref: containerRef, className: classes.vegaContainer, children: _jsx(CellSetSizesPlot, { data: data, theme: theme, width: width, height: height, obsType: obsType }) }) }));
|
41
|
-
}
|
42
|
-
export function register() {
|
43
|
-
registerPluginViewType(ViewType.OBS_SET_SIZES, CellSetSizesPlotSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.OBS_SET_SIZES]);
|
44
|
-
}
|
package/dist/DotPlot.js
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import React from 'react';
|
3
|
-
import clamp from 'lodash/clamp';
|
4
|
-
import { VegaPlot, VEGA_THEMES } from '@vitessce/vega';
|
5
|
-
import { capitalize } from '@vitessce/utils';
|
6
|
-
import plur from 'plur';
|
7
|
-
/**
|
8
|
-
* Gene expression histogram displayed as a bar chart,
|
9
|
-
* implemented with the VegaPlot component.
|
10
|
-
* @param {object} props
|
11
|
-
* @param {object[]} props.data The expression data, an array
|
12
|
-
* of objects with properties `value`, `gene`, and `set`.
|
13
|
-
* @param {number} props.domainMax The maximum gene expression value.
|
14
|
-
* @param {object[]} props.colors An object for each
|
15
|
-
* cell set, with properties `name` and `color`.
|
16
|
-
* @param {string} props.theme The name of the current Vitessce theme.
|
17
|
-
* @param {number} props.width The container width.
|
18
|
-
* @param {number} props.height The container height.
|
19
|
-
* @param {number} props.marginRight The size of the margin
|
20
|
-
* on the right side of the plot, to account for the vega menu button.
|
21
|
-
* By default, 90.
|
22
|
-
* @param {number} props.marginBottom The size of the margin
|
23
|
-
* on the bottom of the plot, to account for long x-axis labels.
|
24
|
-
* Default is allowing the component to automatically determine the margin.
|
25
|
-
* @param {string|null} props.featureValueTransformName A name
|
26
|
-
* for the feature value transformation function.
|
27
|
-
*/
|
28
|
-
export default function DotPlot(props) {
|
29
|
-
const { data: rawData, theme, width, height, marginRight, marginBottom, obsType, keyLength = 36, featureType, featureValueType, featureValueTransformName, } = props;
|
30
|
-
// Add a property `keyGroup` and `keyFeature` which concatenates the key and the name,
|
31
|
-
// which is both unique and can easily be converted
|
32
|
-
// back to the name by taking a substring.
|
33
|
-
const data = rawData.map(d => ({
|
34
|
-
...d,
|
35
|
-
keyGroup: d.groupKey + d.group,
|
36
|
-
keyFeature: d.featureKey + d.feature,
|
37
|
-
}));
|
38
|
-
// Get the max characters in an axis label for autsizing the bottom margin.
|
39
|
-
const maxCharactersForGroup = data.reduce((acc, val) => {
|
40
|
-
// eslint-disable-next-line no-param-reassign
|
41
|
-
acc = acc === undefined || val.group.length > acc ? val.group.length : acc;
|
42
|
-
return acc;
|
43
|
-
}, 0);
|
44
|
-
const maxCharactersForFeature = data.reduce((acc, val) => {
|
45
|
-
// eslint-disable-next-line no-param-reassign
|
46
|
-
acc = acc === undefined || val.feature.length > acc ? val.feature.length : acc;
|
47
|
-
return acc;
|
48
|
-
}, 0);
|
49
|
-
// Use a square-root term because the angle of the labels is 45 degrees (see below)
|
50
|
-
// so the perpendicular distance to the bottom of the labels is proportional to the
|
51
|
-
// square root of the length of the labels along the imaginary hypotenuse.
|
52
|
-
// 30 is an estimate of the pixel size of a given character and seems to work well.
|
53
|
-
const autoMarginVertical = marginBottom
|
54
|
-
|| 30 + Math.sqrt(maxCharactersForFeature / 2) * 30;
|
55
|
-
const autoMarginHorizontal = marginRight
|
56
|
-
|| 30 + Math.sqrt(maxCharactersForGroup / 2) * 30;
|
57
|
-
const plotWidth = clamp(width - autoMarginHorizontal - 120, 10, Infinity);
|
58
|
-
const plotHeight = clamp(height - autoMarginVertical, 10, Infinity);
|
59
|
-
// Get an array of keys for sorting purposes.
|
60
|
-
const groupKeys = data.map(d => d.keyGroup);
|
61
|
-
const featureKeys = data.map(d => d.keyFeature);
|
62
|
-
const meanTransform = (featureValueTransformName && featureValueTransformName !== 'None')
|
63
|
-
// Mean Log-Transformed Normalized Expression
|
64
|
-
? [`Mean ${featureValueTransformName}-transformed`, `normalized ${featureValueType}`, 'in set']
|
65
|
-
// Mean Normalized Expression
|
66
|
-
: ['Mean normalized', `${featureValueType} in set`];
|
67
|
-
const spec = {
|
68
|
-
mark: { type: 'circle' },
|
69
|
-
encoding: {
|
70
|
-
x: {
|
71
|
-
field: 'keyFeature',
|
72
|
-
type: 'nominal',
|
73
|
-
axis: { labelExpr: `substring(datum.label, ${keyLength})` },
|
74
|
-
title: capitalize(featureType),
|
75
|
-
sort: featureKeys,
|
76
|
-
},
|
77
|
-
y: {
|
78
|
-
field: 'keyGroup',
|
79
|
-
type: 'nominal',
|
80
|
-
axis: { labelExpr: `substring(datum.label, ${keyLength})` },
|
81
|
-
title: `${capitalize(obsType)} Set`,
|
82
|
-
sort: groupKeys,
|
83
|
-
},
|
84
|
-
color: {
|
85
|
-
field: 'meanExpInGroup',
|
86
|
-
type: 'quantitative',
|
87
|
-
title: meanTransform,
|
88
|
-
scale: {
|
89
|
-
scheme: 'plasma',
|
90
|
-
},
|
91
|
-
legend: {
|
92
|
-
direction: 'horizontal',
|
93
|
-
tickCount: 2,
|
94
|
-
},
|
95
|
-
},
|
96
|
-
size: {
|
97
|
-
field: 'fracPosInGroup',
|
98
|
-
type: 'quantitative',
|
99
|
-
title: [`Fraction of ${plur(obsType, 2)}`, 'in set'],
|
100
|
-
legend: {
|
101
|
-
symbolFillColor: 'white',
|
102
|
-
},
|
103
|
-
},
|
104
|
-
},
|
105
|
-
width: plotWidth,
|
106
|
-
height: plotHeight,
|
107
|
-
config: VEGA_THEMES[theme],
|
108
|
-
};
|
109
|
-
return (_jsx(VegaPlot, { data: data, spec: spec }));
|
110
|
-
}
|
@@ -1,126 +0,0 @@
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
-
import React, { useMemo } from 'react';
|
3
|
-
import { TitleInfo, useCoordination, useLoaders, useUrls, useReady, useGridItemSize, useFeatureSelection, useObsSetsData, useObsFeatureMatrixIndices, useFeatureLabelsData, registerPluginViewType, } from '@vitessce/vit-s';
|
4
|
-
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
5
|
-
import { VALUE_TRANSFORM_OPTIONS, getValueTransformFunction } from '@vitessce/utils';
|
6
|
-
import { treeToObsIndicesBySetNames, mergeObsSets } from '@vitessce/sets-utils';
|
7
|
-
import { mean } from 'd3-array';
|
8
|
-
import uuidv4 from 'uuid/v4';
|
9
|
-
import CellSetExpressionPlotOptions from './CellSetExpressionPlotOptions';
|
10
|
-
import DotPlot from './DotPlot';
|
11
|
-
import { useStyles } from './styles';
|
12
|
-
/**
|
13
|
-
* Get expression data for the cells
|
14
|
-
* in the selected cell sets.
|
15
|
-
* @param {object} expressionMatrix
|
16
|
-
* @param {string[]} expressionMatrix.rows Cell IDs.
|
17
|
-
* @param {string[]} expressionMatrix.cols Gene names.
|
18
|
-
* @param {Uint8Array} expressionMatrix.matrix The
|
19
|
-
* flattened expression matrix as a typed array.
|
20
|
-
* @param {object} cellSets The cell sets from the dataset.
|
21
|
-
* @param {object} additionalCellSets The user-defined cell sets
|
22
|
-
* from the coordination space.
|
23
|
-
* @param {array} geneSelection Array of selected genes.
|
24
|
-
* @param {array} cellSetSelection Array of selected cell set paths.
|
25
|
-
* @param {object[]} cellSetColor Array of objects with properties
|
26
|
-
* @param {string|null} featureValueTransform The name of the
|
27
|
-
* feature value transform function.
|
28
|
-
* @param {number} featureValueTransformCoefficient A coefficient
|
29
|
-
* to be used in the transform function.
|
30
|
-
* @param {string} theme "light" or "dark" for the vitessce theme
|
31
|
-
* `path` and `color`.
|
32
|
-
*/
|
33
|
-
export function useExpressionSummaries(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, posThreshold, featureLabelsMap) {
|
34
|
-
const mergedCellSets = useMemo(() => mergeObsSets(cellSets, additionalCellSets), [cellSets, additionalCellSets]);
|
35
|
-
// From the expression matrix and the list of selected genes / cell sets,
|
36
|
-
// generate the array of data points for the plot.
|
37
|
-
const [resultArr, meanExpressionMax] = useMemo(() => {
|
38
|
-
if (mergedCellSets && cellSetSelection
|
39
|
-
&& geneSelection && geneSelection.length >= 1
|
40
|
-
&& expressionData && expressionData.length === geneSelection.length) {
|
41
|
-
let exprMax = -Infinity;
|
42
|
-
const result = [];
|
43
|
-
const cellIndices = {};
|
44
|
-
for (let i = 0; i < obsIndex.length; i += 1) {
|
45
|
-
cellIndices[obsIndex[i]] = i;
|
46
|
-
}
|
47
|
-
const setObjects = treeToObsIndicesBySetNames(mergedCellSets, cellSetSelection, cellIndices);
|
48
|
-
geneSelection.forEach((featureName, featureI) => {
|
49
|
-
const featureKey = uuidv4();
|
50
|
-
let numPos = 0;
|
51
|
-
setObjects.forEach((setObj) => {
|
52
|
-
const exprValues = setObj.indices.map((cellIndex) => {
|
53
|
-
const value = expressionData[featureI][cellIndex];
|
54
|
-
const normValue = value * 100 / 255;
|
55
|
-
const transformFunction = getValueTransformFunction(featureValueTransform, featureValueTransformCoefficient);
|
56
|
-
const transformedValue = transformFunction(normValue);
|
57
|
-
if (transformedValue > posThreshold) {
|
58
|
-
numPos += 1;
|
59
|
-
}
|
60
|
-
return transformedValue;
|
61
|
-
});
|
62
|
-
const exprMean = mean(exprValues);
|
63
|
-
const fracPos = numPos / setObj.size;
|
64
|
-
result.push({
|
65
|
-
key: uuidv4(),
|
66
|
-
featureKey,
|
67
|
-
groupKey: setObj.key,
|
68
|
-
group: setObj.name,
|
69
|
-
feature: featureLabelsMap?.get(featureName) || featureName,
|
70
|
-
meanExpInGroup: exprMean,
|
71
|
-
fracPosInGroup: fracPos,
|
72
|
-
});
|
73
|
-
exprMax = Math.max(exprMean, exprMax);
|
74
|
-
});
|
75
|
-
});
|
76
|
-
return [result, exprMax];
|
77
|
-
}
|
78
|
-
return [null, null];
|
79
|
-
}, [expressionData, obsIndex, geneSelection,
|
80
|
-
mergedCellSets, cellSetSelection,
|
81
|
-
featureValueTransform, featureValueTransformCoefficient,
|
82
|
-
posThreshold, featureLabelsMap,
|
83
|
-
]);
|
84
|
-
return [resultArr, meanExpressionMax];
|
85
|
-
}
|
86
|
-
/**
|
87
|
-
* A subscriber component for `DotPlot`,
|
88
|
-
* which listens for gene selection updates and
|
89
|
-
* `GRID_RESIZE` events.
|
90
|
-
* @param {object} props
|
91
|
-
* @param {function} props.removeGridComponent The grid component removal function.
|
92
|
-
* @param {object} props.coordinationScopes An object mapping coordination
|
93
|
-
* types to coordination scopes.
|
94
|
-
* @param {string} props.theme The name of the current Vitessce theme.
|
95
|
-
*/
|
96
|
-
export function DotPlotSubscriber(props) {
|
97
|
-
const { coordinationScopes, removeGridComponent, theme, title = 'Dot Plot', posThreshold = 0, } = props;
|
98
|
-
const classes = useStyles();
|
99
|
-
const loaders = useLoaders();
|
100
|
-
// Get "props" from the coordination space.
|
101
|
-
const [{ dataset, obsType, featureType, featureValueType, featureSelection: geneSelection, featureValueTransform, featureValueTransformCoefficient, obsSetSelection: cellSetSelection, obsSetColor: cellSetColor, additionalObsSets: additionalCellSets,
|
102
|
-
// TODO: coordination type for mean expression colormap
|
103
|
-
}, { setFeatureValueTransform, setFeatureValueTransformCoefficient, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.DOT_PLOT], coordinationScopes);
|
104
|
-
const [width, height, containerRef] = useGridItemSize();
|
105
|
-
const [urls, addUrl] = useUrls(loaders, dataset);
|
106
|
-
const transformOptions = VALUE_TRANSFORM_OPTIONS;
|
107
|
-
// Get data from loaders using the data hooks.
|
108
|
-
// eslint-disable-next-line no-unused-vars
|
109
|
-
const [expressionData, loadedFeatureSelection, featureSelectionStatus] = useFeatureSelection(loaders, dataset, false, geneSelection, { obsType, featureType, featureValueType });
|
110
|
-
// TODO: support multiple feature labels using featureLabelsType coordination values.
|
111
|
-
const [{ featureLabelsMap }, featureLabelsStatus] = useFeatureLabelsData(loaders, dataset, addUrl, false, {}, {}, { featureType });
|
112
|
-
const [{ obsIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(loaders, dataset, addUrl, false, { obsType, featureType, featureValueType });
|
113
|
-
const [{ obsSets: cellSets }, obsSetsStatus] = useObsSetsData(loaders, dataset, addUrl, true, {}, {}, { obsType });
|
114
|
-
const isReady = useReady([
|
115
|
-
featureSelectionStatus,
|
116
|
-
matrixIndicesStatus,
|
117
|
-
obsSetsStatus,
|
118
|
-
featureLabelsStatus,
|
119
|
-
]);
|
120
|
-
const [resultArr, meanExpressionMax] = useExpressionSummaries(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, posThreshold, featureLabelsMap);
|
121
|
-
const selectedTransformName = transformOptions.find(o => o.value === featureValueTransform)?.name;
|
122
|
-
return (_jsx(TitleInfo, { title: title, removeGridComponent: removeGridComponent, urls: urls, theme: theme, isReady: isReady, options: (_jsx(CellSetExpressionPlotOptions, { featureValueTransform: featureValueTransform, setFeatureValueTransform: setFeatureValueTransform, featureValueTransformCoefficient: featureValueTransformCoefficient, setFeatureValueTransformCoefficient: setFeatureValueTransformCoefficient, transformOptions: transformOptions })), children: _jsx("div", { ref: containerRef, className: classes.vegaContainer, children: resultArr ? (_jsx(DotPlot, { domainMax: meanExpressionMax, data: resultArr, theme: theme, width: width, height: height, obsType: obsType, featureType: featureType, featureValueType: featureValueType, featureValueTransformName: selectedTransformName })) : (_jsxs("span", { children: ["Select at least one ", featureType, "."] })) }) }));
|
123
|
-
}
|
124
|
-
export function register() {
|
125
|
-
registerPluginViewType(ViewType.DOT_PLOT, DotPlotSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.DOT_PLOT]);
|
126
|
-
}
|
@@ -1,63 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import React, { useMemo } from 'react';
|
3
|
-
import { sum } from 'd3-array';
|
4
|
-
import { TitleInfo, useCoordination, useLoaders, useUrls, useReady, useGridItemSize, useObsFeatureMatrixData, useFeatureSelection, registerPluginViewType, } from '@vitessce/vit-s';
|
5
|
-
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
6
|
-
import ExpressionHistogram from './ExpressionHistogram';
|
7
|
-
import { useStyles } from './styles';
|
8
|
-
/**
|
9
|
-
* A subscriber component for `ExpressionHistogram`,
|
10
|
-
* which listens for gene selection updates and
|
11
|
-
* `GRID_RESIZE` events.
|
12
|
-
* @param {object} props
|
13
|
-
* @param {function} props.removeGridComponent The grid component removal function.
|
14
|
-
* @param {object} props.coordinationScopes An object mapping coordination
|
15
|
-
* types to coordination scopes.
|
16
|
-
* @param {string} props.theme The name of the current Vitessce theme.
|
17
|
-
*/
|
18
|
-
export function ExpressionHistogramSubscriber(props) {
|
19
|
-
const { coordinationScopes, removeGridComponent, theme, } = props;
|
20
|
-
const classes = useStyles();
|
21
|
-
const loaders = useLoaders();
|
22
|
-
// Get "props" from the coordination space.
|
23
|
-
const [{ dataset, obsType, featureType, featureValueType, featureSelection: geneSelection, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_VALUE_HISTOGRAM], coordinationScopes);
|
24
|
-
const [width, height, containerRef] = useGridItemSize();
|
25
|
-
const [urls, addUrl] = useUrls(loaders, dataset);
|
26
|
-
// Get data from loaders using the data hooks.
|
27
|
-
const [{ obsIndex, featureIndex, obsFeatureMatrix }, matrixStatus] = useObsFeatureMatrixData(loaders, dataset, addUrl, true, {}, {}, { obsType, featureType, featureValueType });
|
28
|
-
// eslint-disable-next-line no-unused-vars
|
29
|
-
const [expressionData, loadedFeatureSelection, featureSelectionStatus] = useFeatureSelection(loaders, dataset, false, geneSelection, { obsType, featureType, featureValueType });
|
30
|
-
const isReady = useReady([
|
31
|
-
matrixStatus,
|
32
|
-
featureSelectionStatus,
|
33
|
-
]);
|
34
|
-
const firstGeneSelected = geneSelection && geneSelection.length >= 1
|
35
|
-
? geneSelection[0]
|
36
|
-
: null;
|
37
|
-
// From the expression matrix and the list of selected genes,
|
38
|
-
// generate the array of data points for the histogram.
|
39
|
-
const data = useMemo(() => {
|
40
|
-
if (firstGeneSelected && obsFeatureMatrix && expressionData) {
|
41
|
-
// Create new cellColors map based on the selected gene.
|
42
|
-
return Array.from(expressionData[0]).map((_, index) => {
|
43
|
-
const value = expressionData[0][index];
|
44
|
-
const normValue = value * 100 / 255;
|
45
|
-
return { value: normValue, gene: firstGeneSelected };
|
46
|
-
});
|
47
|
-
}
|
48
|
-
if (obsFeatureMatrix) {
|
49
|
-
const numGenes = featureIndex.length;
|
50
|
-
return obsIndex.map((cellId, cellIndex) => {
|
51
|
-
const values = obsFeatureMatrix.data
|
52
|
-
.subarray(cellIndex * numGenes, (cellIndex + 1) * numGenes);
|
53
|
-
const sumValue = sum(values) * 100 / 255;
|
54
|
-
return { value: sumValue, gene: null };
|
55
|
-
});
|
56
|
-
}
|
57
|
-
return null;
|
58
|
-
}, [obsIndex, featureIndex, obsFeatureMatrix, firstGeneSelected, expressionData]);
|
59
|
-
return (_jsx(TitleInfo, { title: `Expression Histogram${(firstGeneSelected ? ` (${firstGeneSelected})` : '')}`, removeGridComponent: removeGridComponent, urls: urls, theme: theme, isReady: isReady, children: _jsx("div", { ref: containerRef, className: classes.vegaContainer, children: _jsx(ExpressionHistogram, { geneSelection: geneSelection, data: data, theme: theme, width: width, height: height }) }) }));
|
60
|
-
}
|
61
|
-
export function register() {
|
62
|
-
registerPluginViewType(ViewType.FEATURE_VALUE_HISTOGRAM, ExpressionHistogramSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_VALUE_HISTOGRAM]);
|
63
|
-
}
|