@vitessce/statistical-plots 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.
@@ -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
- }
@@ -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
- }
@@ -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
- }
package/dist/styles.js DELETED
@@ -1,8 +0,0 @@
1
- import { makeStyles } from '@material-ui/core/styles';
2
- export const useStyles = makeStyles(() => ({
3
- vegaContainer: {
4
- display: 'flex',
5
- flex: '1 1 auto',
6
- overflow: 'hidden',
7
- },
8
- }));