@vitessce/sets-utils 2.0.2 → 2.0.3-beta.0

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.
Files changed (2) hide show
  1. package/dist/hooks.js +64 -0
  2. package/package.json +3 -3
package/dist/hooks.js ADDED
@@ -0,0 +1,64 @@
1
+ import { useMemo } from 'react';
2
+ import { getValueTransformFunction } from '@vitessce/utils';
3
+ import { treeToObjectsBySetNames, treeToSetSizesBySetNames } from './cell-set-utils';
4
+ import { mergeObsSets } from './utils';
5
+ /**
6
+ * Get expression data for the cells
7
+ * in the selected cell sets.
8
+ * @param {object} expressionMatrix
9
+ * @param {string[]} expressionMatrix.rows Cell IDs.
10
+ * @param {string[]} expressionMatrix.cols Gene names.
11
+ * @param {Uint8Array} expressionMatrix.matrix The
12
+ * flattened expression matrix as a typed array.
13
+ * @param {object} cellSets The cell sets from the dataset.
14
+ * @param {object} additionalCellSets The user-defined cell sets
15
+ * from the coordination space.
16
+ * @param {array} geneSelection Array of selected genes.
17
+ * @param {array} cellSetSelection Array of selected cell set paths.
18
+ * @param {object[]} cellSetColor Array of objects with properties
19
+ * @param {string|null} featureValueTransform The name of the
20
+ * feature value transform function.
21
+ * @param {number} featureValueTransformCoefficient A coefficient
22
+ * to be used in the transform function.
23
+ * @param {string} theme "light" or "dark" for the vitessce theme
24
+ * `path` and `color`.
25
+ */
26
+ export function useExpressionByCellSet(expressionData, obsIndex, cellSets, additionalCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient, theme) {
27
+ const mergedCellSets = useMemo(() => mergeObsSets(cellSets, additionalCellSets), [cellSets, additionalCellSets]);
28
+ // From the expression matrix and the list of selected genes / cell sets,
29
+ // generate the array of data points for the plot.
30
+ const [expressionArr, expressionMax] = useMemo(() => {
31
+ if (mergedCellSets && cellSetSelection
32
+ && geneSelection && geneSelection.length >= 1
33
+ && expressionData) {
34
+ const cellObjects = treeToObjectsBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme);
35
+ const firstGeneSelected = geneSelection[0];
36
+ // Create new cellColors map based on the selected gene.
37
+ let exprMax = -Infinity;
38
+ const cellIndices = {};
39
+ for (let i = 0; i < obsIndex.length; i += 1) {
40
+ cellIndices[obsIndex[i]] = i;
41
+ }
42
+ const exprValues = cellObjects.map((cell) => {
43
+ const cellIndex = cellIndices[cell.obsId];
44
+ const value = expressionData[0][cellIndex];
45
+ const normValue = value * 100 / 255;
46
+ const transformFunction = getValueTransformFunction(featureValueTransform, featureValueTransformCoefficient);
47
+ const transformedValue = transformFunction(normValue);
48
+ exprMax = Math.max(transformedValue, exprMax);
49
+ return { value: transformedValue, gene: firstGeneSelected, set: cell.name };
50
+ });
51
+ return [exprValues, exprMax];
52
+ }
53
+ return [null, null];
54
+ }, [expressionData, obsIndex, geneSelection, theme,
55
+ mergedCellSets, cellSetSelection, cellSetColor,
56
+ featureValueTransform, featureValueTransformCoefficient,
57
+ ]);
58
+ // From the cell sets hierarchy and the list of selected cell sets,
59
+ // generate the array of set sizes data points for the bar plot.
60
+ const setArr = useMemo(() => (mergedCellSets && cellSetSelection && cellSetColor
61
+ ? treeToSetSizesBySetNames(mergedCellSets, cellSetSelection, cellSetColor, theme)
62
+ : []), [mergedCellSets, cellSetSelection, cellSetColor, theme]);
63
+ return [expressionArr, setArr, expressionMax];
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/sets-utils",
3
- "version": "2.0.2",
3
+ "version": "2.0.3-beta.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -23,8 +23,8 @@
23
23
  "lodash": "^4.17.21",
24
24
  "tinycolor2": "^1.4.1",
25
25
  "uuid": "^3.3.2",
26
- "@vitessce/utils": "2.0.2",
27
- "@vitessce/vit-s": "2.0.2"
26
+ "@vitessce/utils": "2.0.3-beta.0",
27
+ "@vitessce/vit-s": "2.0.3-beta.0"
28
28
  },
29
29
  "scripts": {
30
30
  "start": "tsc --watch",