@vitessce/sets-utils 2.0.3-beta.0 → 3.0.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 (55) hide show
  1. package/dist/index.js +16700 -5
  2. package/dist-tsc/CellSetsZarrLoader.d.ts +2 -0
  3. package/dist-tsc/CellSetsZarrLoader.d.ts.map +1 -0
  4. package/{dist → dist-tsc}/CellSetsZarrLoader.js +9 -5
  5. package/dist-tsc/CellSetsZarrLoader.test.d.ts +2 -0
  6. package/dist-tsc/CellSetsZarrLoader.test.d.ts.map +1 -0
  7. package/{dist → dist-tsc}/CellSetsZarrLoader.test.js +10 -4
  8. package/dist-tsc/cell-set-utils.d.ts +204 -0
  9. package/dist-tsc/cell-set-utils.d.ts.map +1 -0
  10. package/{dist → dist-tsc}/cell-set-utils.js +28 -15
  11. package/dist-tsc/cell-set-utils.test.d.ts +2 -0
  12. package/dist-tsc/cell-set-utils.test.d.ts.map +1 -0
  13. package/dist-tsc/cell-set-utils.test.fixtures.d.ts +47 -0
  14. package/dist-tsc/cell-set-utils.test.fixtures.d.ts.map +1 -0
  15. package/{dist → dist-tsc}/cell-set-utils.test.js +76 -3
  16. package/dist-tsc/constants.d.ts +17 -0
  17. package/dist-tsc/constants.d.ts.map +1 -0
  18. package/{dist → dist-tsc}/constants.js +4 -15
  19. package/dist-tsc/index.d.ts +7 -0
  20. package/dist-tsc/index.d.ts.map +1 -0
  21. package/dist-tsc/index.js +6 -0
  22. package/dist-tsc/io.d.ts +47 -0
  23. package/dist-tsc/io.d.ts.map +1 -0
  24. package/{dist → dist-tsc}/io.js +25 -30
  25. package/dist-tsc/io.test.d.ts +2 -0
  26. package/dist-tsc/io.test.d.ts.map +1 -0
  27. package/{dist → dist-tsc}/io.test.js +1 -4
  28. package/dist-tsc/set-path-utils.d.ts +28 -0
  29. package/dist-tsc/set-path-utils.d.ts.map +1 -0
  30. package/dist-tsc/set-path-utils.js +133 -0
  31. package/dist-tsc/set-path-utils.test.d.ts +2 -0
  32. package/dist-tsc/set-path-utils.test.d.ts.map +1 -0
  33. package/dist-tsc/set-path-utils.test.js +210 -0
  34. package/dist-tsc/utils.d.ts +45 -0
  35. package/dist-tsc/utils.d.ts.map +1 -0
  36. package/{dist → dist-tsc}/utils.js +16 -9
  37. package/dist-tsc/utils.test.d.ts +2 -0
  38. package/dist-tsc/utils.test.d.ts.map +1 -0
  39. package/dist-tsc/utils.test.js +39 -0
  40. package/package.json +17 -9
  41. package/src/CellSetsZarrLoader.js +111 -0
  42. package/src/CellSetsZarrLoader.test.js +163 -0
  43. package/src/cell-set-utils.js +700 -0
  44. package/src/cell-set-utils.test.fixtures.js +71 -0
  45. package/src/cell-set-utils.test.js +277 -0
  46. package/src/constants.js +21 -0
  47. package/src/index.js +61 -0
  48. package/src/io.js +172 -0
  49. package/src/io.test.js +142 -0
  50. package/src/set-path-utils.js +155 -0
  51. package/src/set-path-utils.test.js +257 -0
  52. package/src/utils.js +160 -0
  53. package/src/utils.test.js +48 -0
  54. package/dist/hooks.js +0 -64
  55. /package/{dist → dist-tsc}/cell-set-utils.test.fixtures.js +0 -0
@@ -0,0 +1,2 @@
1
+ export function dataToCellSetsTree(data: any, options: any): object;
2
+ //# sourceMappingURL=CellSetsZarrLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetsZarrLoader.d.ts","sourceRoot":"","sources":["../src/CellSetsZarrLoader.js"],"names":[],"mappings":"AASA,oEAqGC"}
@@ -1,7 +1,9 @@
1
1
  import { InternMap } from 'internmap';
2
- import { treeInitialize, nodeAppendChild, } from './cell-set-utils';
3
- import { SETS_DATATYPE_OBS, } from './constants';
2
+ import { treeInitialize, nodeAppendChild, } from './cell-set-utils.js';
3
+ import { SETS_DATATYPE_OBS, } from './constants.js';
4
4
  export function dataToCellSetsTree(data, options) {
5
+ // obsIndex is an array of all cell IDs, for the purposes of set complement operations only.
6
+ // cellNames is per-cellSets arrays of cell IDs.
5
7
  const [cellNames, cellSets, cellSetScores] = data;
6
8
  const cellSetsTree = treeInitialize(SETS_DATATYPE_OBS);
7
9
  cellSets.forEach((cellSetIds, j) => {
@@ -14,7 +16,7 @@ export function dataToCellSetsTree(data, options) {
14
16
  // Multi-level case.
15
17
  // TODO: throw a warning if the levels are not in order coarser->finer.
16
18
  const levelSets = new InternMap([], JSON.stringify);
17
- cellNames.forEach((id, i) => {
19
+ cellNames[j].forEach((id, i) => {
18
20
  const classes = cellSetIds.map(col => col[i]);
19
21
  if (levelSets.has(classes)) {
20
22
  levelSets.get(classes).push([id, null]);
@@ -72,10 +74,12 @@ export function dataToCellSetsTree(data, options) {
72
74
  // eslint-disable-next-line no-return-assign
73
75
  uniqueCellSetIds.forEach(id => (clusters[id] = { name: id, set: [] }));
74
76
  if (cellSetScores[j]) {
75
- cellSetIds.forEach((id, i) => clusters[id].set.push([cellNames[i], cellSetScores[j][i]]));
77
+ cellSetIds
78
+ .forEach((id, i) => clusters[id].set.push([cellNames[j][i], cellSetScores[j][i]]));
76
79
  }
77
80
  else {
78
- cellSetIds.forEach((id, i) => clusters[id].set.push([cellNames[i], null]));
81
+ cellSetIds
82
+ .forEach((id, i) => clusters[id].set.push([cellNames[j][i], null]));
79
83
  }
80
84
  Object.values(clusters).forEach(
81
85
  // eslint-disable-next-line no-return-assign
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CellSetsZarrLoader.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellSetsZarrLoader.test.d.ts","sourceRoot":"","sources":["../src/CellSetsZarrLoader.test.js"],"names":[],"mappings":""}
@@ -1,8 +1,10 @@
1
- import { dataToCellSetsTree } from './CellSetsZarrLoader';
1
+ import { dataToCellSetsTree } from './CellSetsZarrLoader.js';
2
2
  describe('loaders/CellSetsZarrLoader', () => {
3
3
  it('dataToCellSetsTree constructs a hierarchy from an array of columns', async () => {
4
4
  const data = [
5
- ['cell_1', 'cell_2', 'cell_3', 'cell_4'],
5
+ [
6
+ ['cell_1', 'cell_2', 'cell_3', 'cell_4'],
7
+ ],
6
8
  [
7
9
  [
8
10
  ['Immune', 'Immune', 'Immune', 'Neuron'],
@@ -69,7 +71,9 @@ describe('loaders/CellSetsZarrLoader', () => {
69
71
  });
70
72
  it('dataToCellSetsTree creates a flat tree from a single column', async () => {
71
73
  const data = [
72
- ['cell_1', 'cell_2', 'cell_3', 'cell_4'],
74
+ [
75
+ ['cell_1', 'cell_2', 'cell_3', 'cell_4'],
76
+ ],
73
77
  [
74
78
  ['Immune', 'Immune', 'Immune', 'Neuron'],
75
79
  ],
@@ -107,7 +111,9 @@ describe('loaders/CellSetsZarrLoader', () => {
107
111
  });
108
112
  it('dataToCellSetsTree creates a flat tree from a single column with scores', async () => {
109
113
  const data = [
110
- ['cell_1', 'cell_2', 'cell_3', 'cell_4'],
114
+ [
115
+ ['cell_1', 'cell_2', 'cell_3', 'cell_4'],
116
+ ],
111
117
  [
112
118
  ['Immune', 'Immune', 'Immune', 'Neuron'],
113
119
  ],
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Get the set associated with a particular node.
3
+ * Recursive.
4
+ * @param {object} currNode A node object.
5
+ * @returns {array} The array representing the set associated with the node.
6
+ */
7
+ export function nodeToSet(currNode: object): array;
8
+ /**
9
+ * Get the height of a node (the number of levels to reach a leaf).
10
+ * @param {object} currNode A node object.
11
+ * @param {number} level The level that the height will be computed relative to. By default, 0.
12
+ * @returns {number} The height. If the node has a .children property,
13
+ * then the minimum value returned is 1.
14
+ */
15
+ export function nodeToHeight(currNode: object, level?: number): number;
16
+ /**
17
+ * Get the size associated with a particular node.
18
+ * Recursive.
19
+ * @param {object} currNode A node object.
20
+ * @returns {number} The length of all the node's children
21
+ */
22
+ export function getNodeLength(currNode: object): number;
23
+ /**
24
+ * Find a node with a matching name path, relative to the whole tree.
25
+ * @param {object} currTree A tree object.
26
+ * @param {string[]} targetNamePath The name path for the node of interest.
27
+ * @returns {object|null} A matching node object, or null if none is found.
28
+ */
29
+ export function treeFindNodeByNamePath(currTree: object, targetNamePath: string[]): object | null;
30
+ /**
31
+ * Transform a node object using a transform function.
32
+ * @param {object} node A node object.
33
+ * @param {function} predicate Returns true if a node matches a condition of interest.
34
+ * @param {function} transform Takes the node matching the predicate as input, returns
35
+ * a transformed version of the node.
36
+ * @param {array} transformedPaths This array parameter is mutated. The path of
37
+ * each transformed node is appended to this array.
38
+ * @param {string[]} The current path of the node being updated, used internally
39
+ * during recursion.
40
+ * @returns {object} The updated node.
41
+ */
42
+ export function nodeTransform(node: object, predicate: Function, transform: Function, transformedPaths: array, currPath: any): object;
43
+ /**
44
+ * Transform many node objects using a transform function.
45
+ * @param {object} node A node object.
46
+ * @param {function} predicate Returns true if a node matches a condition of interest.
47
+ * @param {function} transform Takes the node matching the predicate as input, returns
48
+ * a transformed version of the node.
49
+ * @param {array} transformedPaths This array parameter is mutated. The path of
50
+ * each transformed node is appended to this array.
51
+ * @param {string[]} The current path of the node being updated, used internally
52
+ * during recursion.
53
+ * @returns {object} The updated node.
54
+ */
55
+ export function nodeTransformAll(node: object, predicate: Function, transform: Function, transformedPaths: array, currPath: any): object;
56
+ /**
57
+ * Append a child to a parent node.
58
+ * @param {object} currNode A node object.
59
+ * @param {object} newChild The child node object.
60
+ * @returns {object} The updated node.
61
+ */
62
+ export function nodeAppendChild(currNode: object, newChild: object): object;
63
+ /**
64
+ * Prepend a child to a parent node.
65
+ * @param {object} currNode A node object.
66
+ * @param {object} newChild The child node object.
67
+ * @returns {object} The updated node.
68
+ */
69
+ export function nodePrependChild(currNode: object, newChild: object): object;
70
+ /**
71
+ * Insert a child to a parent node.
72
+ * @param {object} currNode A node object.
73
+ * @param {*} newChild The child node object.
74
+ * @param {*} insertIndex The index at which to insert the child.
75
+ * @returns {object} The updated node.
76
+ */
77
+ export function nodeInsertChild(currNode: object, newChild: any, insertIndex: any): object;
78
+ /**
79
+ * Get an array representing the union of the sets of checked nodes.
80
+ * @param {object} currTree A tree object.
81
+ * @returns {array} An array representing the union of the sets of checked nodes.
82
+ */
83
+ export function treeToUnion(currTree: object, checkedPaths: any): array;
84
+ /**
85
+ * Get an array representing the intersection of the sets of checked nodes.
86
+ * @param {object} currTree A tree object.
87
+ * @returns {array} An array representing the intersection of the sets of checked nodes.
88
+ */
89
+ export function treeToIntersection(currTree: object, checkedPaths: any): array;
90
+ /**
91
+ * Get an array representing the complement of the union of the sets of checked nodes.
92
+ * @param {object} currTree
93
+ * @returns {array} An array representing the complement of the
94
+ * union of the sets of checked nodes.
95
+ */
96
+ export function treeToComplement(currTree: object, checkedPaths: any, items: any): array;
97
+ /**
98
+ * Get an flattened array of descendants at a particular relative
99
+ * level of interest.
100
+ * @param {object} node A node object.
101
+ * @param {number} level The relative level of interest.
102
+ * 0 for this node's children, 1 for grandchildren, etc.
103
+ * @param {boolean} stopEarly Should a node be returned early if no children exist?
104
+ * @returns {object[]} An array of descendants at the specified level,
105
+ * where the level is relative to the node.
106
+ */
107
+ export function nodeToLevelDescendantNamePaths(node: object, level: number, prevPath: any, stopEarly?: boolean): object[];
108
+ /**
109
+ * Export the tree by clearing tree state and all node states.
110
+ * @param {object} currTree A tree object.
111
+ * @returns {object} Tree object with tree and node state removed.
112
+ */
113
+ export function treeExport(currTree: object, datatype: any): object;
114
+ /**
115
+ * Export the tree by clearing tree state and all node states,
116
+ * and filter so that only the level zero node of interest is included.
117
+ * @param {object} currTree A tree object.
118
+ * @param {string} nodePath The path of the node of interest.
119
+ * @param {string} dataType Datatype (i.e cell sets)
120
+ * @param {Array} cellSetColors Array of objects of cell set colors and paths
121
+ * @param {string} theme "light" or "dark" for the vitessce theme
122
+ * @returns {object} { treeToExport, nodeName }
123
+ * Tree with one level zero node, and with state removed.
124
+ */
125
+ export function treeExportLevelZeroNode(currTree: object, nodePath: string, datatype: any, cellSetColors: any[], theme: string): object;
126
+ /**
127
+ * Prepare the set of a node of interest for export.
128
+ * @param {object} currTree A tree object.
129
+ * @param {string} nodeKey The key of the node of interest.
130
+ * @returns {object} { setToExport, nodeName } The set as an array.
131
+ */
132
+ export function treeExportSet(currTree: object, nodePath: any): object;
133
+ /**
134
+ * Get an empty tree, with a default tree state.
135
+ * @param {string} datatype The type of sets that this tree contains.
136
+ * @returns {object} Empty tree.
137
+ */
138
+ export function treeInitialize(datatype: string): object;
139
+ /**
140
+ * For convenience, get an object with information required
141
+ * to render a node as a component.
142
+ * @param {object} node A node to be rendered.
143
+ * @returns {object} An object containing properties required
144
+ * by the TreeNode render functions.
145
+ */
146
+ export function nodeToRenderProps(node: object, path: any, cellSetColor: any): object;
147
+ /**
148
+ * Given a tree with state, get the cellIds and cellColors,
149
+ * based on the nodes currently marked as "visible".
150
+ * @param {object} currTree A tree object.
151
+ * @param {array} selectedNamePaths Array of arrays of strings,
152
+ * representing set "paths".
153
+ * @param {object[]} cellSetColor Array of objects with the
154
+ * properties `path` and `color`.
155
+ * @param {string} theme "light" or "dark" for the vitessce theme
156
+ * @returns {array} Tuple of [cellIds, cellColors]
157
+ * where cellIds is an array of strings,
158
+ * and cellColors is an object mapping cellIds to color [r,g,b] arrays.
159
+ */
160
+ export function treeToCellColorsBySetNames(currTree: object, selectedNamePaths: array, cellSetColor: object[], theme: string): array;
161
+ /**
162
+ * Given a tree with state, get an array of
163
+ * objects with cellIds and cellColors,
164
+ * based on the nodes currently marked as "visible".
165
+ * @param {object} currTree A tree object.
166
+ * @param {array} selectedNamePaths Array of arrays of strings,
167
+ * representing set "paths".
168
+ * @param {object[]} setColor Array of objects with the
169
+ * properties `path` and `color`
170
+ * @param {string} theme "light" or "dark" for the vitessce theme.
171
+ * @returns {object[]} Array of objects with properties
172
+ * `obsId`, `name`, and `color`.
173
+ */
174
+ export function treeToObjectsBySetNames(currTree: object, selectedNamePaths: array, setColor: object[], theme: string): object[];
175
+ export function treeToCellPolygonsBySetNames(currTree: any, obsIndex: any, obsEmbedding: any, selectedNamePaths: any, cellSetColor: any, theme: any): any[];
176
+ /**
177
+ * Given a tree with state, get the sizes of the
178
+ * sets currently marked as "visible".
179
+ * @param {object} currTree A tree object.
180
+ * @param {array} allNamePaths Array of all paths.
181
+ * @param {array} selectedNamePaths Array of arrays of strings,
182
+ * representing selected paths.
183
+ * @param {object[]} setColor Array of objects with the
184
+ * properties `path` and `color`.
185
+ * @param {string} theme "light" or "dark" for the vitessce theme
186
+ * @returns {object[]} Array of objects
187
+ * with the properties `name`, `size`, `key`,
188
+ * and `color`.
189
+ */
190
+ export function treeToSetSizesBySetNames(currTree: object, allNamePaths: array, selectedNamePaths: array, setColor: object[], theme: string): object[];
191
+ /**
192
+ * Find and remove a node from the descendants of the current node.
193
+ * @param {object} node A node to search on.
194
+ * @param {array} prevPath Path of the current node to be searched.
195
+ * @param {array} filterPath The path sought.
196
+ * @returns {object} A new node without a node at filterPath.
197
+ */
198
+ export function filterNode(node: object, prevPath: array, filterPath: array): object;
199
+ export function treeToExpectedCheckedLevel(currTree: any, checkedPaths: any): null;
200
+ export function treesConflict(cellSets: any, testCellSets: any): boolean;
201
+ export function initializeCellSetColor(cellSets: any, cellSetColor: any): any[];
202
+ export function getCellSetPolygons(params: any): any[];
203
+ export function treeToMembershipMap(currTree: any): Map<any, any>;
204
+ //# sourceMappingURL=cell-set-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-set-utils.d.ts","sourceRoot":"","sources":["../src/cell-set-utils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,oCAHW,MAAM,SAWhB;AAED;;;;;;GAMG;AACH,uCALW,MAAM,UACN,MAAM,GACJ,MAAM,CAUlB;AAED;;;;;GAKG;AACH,wCAHW,MAAM,GACJ,MAAM,CAUlB;AA2BD;;;;;GAKG;AACH,iDAJW,MAAM,kBACN,MAAM,EAAE,GACN,MAAM,GAAC,IAAI,CAUvB;AAED;;;;;;;;;;;GAWG;AACH,oCAVW,MAAM,qFAQJ,MAAM,CAwBlB;AAED;;;;;;;;;;;GAWG;AACH,uCAVW,MAAM,qFAQJ,MAAM,CAyBlB;AAED;;;;;GAKG;AACH,0CAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;;GAMG;AACH,0CALW,MAAM,oCAGJ,MAAM,CASlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,4BAQhB;AAED;;;;GAIG;AACH,6CAHW,MAAM,4BAQhB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,wCAOhB;AAED;;;;;;;;;GASG;AACH,qDAPW,MAAM,SACN,MAAM,6BAEN,OAAO,GACL,MAAM,EAAE,CAgBpB;AAED;;;;GAIG;AACH,qCAHW,MAAM,kBACJ,MAAM,CAQlB;AAED;;;;;;;;;;GAUG;AACH,kDARW,MAAM,YACN,MAAM,8CAGN,MAAM,GACJ,MAAM,CAqBlB;AAED;;;;;GAKG;AACH,wCAJW,MAAM,kBAEJ,MAAM,CAKlB;AAED;;;;GAIG;AACH,yCAHW,MAAM,GACJ,MAAM,CAQlB;AAED;;;;;;GAMG;AACH,wCAJW,MAAM,iCACJ,MAAM,CAelB;AAoBD;;;;;;;;;;;;GAYG;AACH,qDAVW,MAAM,0CAGN,MAAM,EAAE,SAER,MAAM,SAyBhB;AAED;;;;;;;;;;;;GAYG;AACH,kDATW,MAAM,sCAGN,MAAM,EAAE,SAER,MAAM,GACJ,MAAM,EAAE,CAsBpB;AAED,4JA2CC;AAED;;;;;;;;;;;;;GAaG;AACH,mDAXW,MAAM,2DAIN,MAAM,EAAE,SAER,MAAM,GACJ,MAAM,EAAE,CAuCpB;AAED;;;;;;GAMG;AACH,iCALW,MAAM,uCAGJ,MAAM,CAelB;AAED,mFAgBC;AAED,yEA2BC;AAED,gFA6BC;AAED,uDAeC;AAED,kEA0BC"}
@@ -1,14 +1,12 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- import uuidv4 from 'uuid/v4';
3
- import isNil from 'lodash/isNil';
4
- import isEqual from 'lodash/isEqual';
5
- import range from 'lodash/range';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { isNil, isEqual, range } from 'lodash-es';
6
4
  import { featureCollection as turfFeatureCollection, point as turfPoint } from '@turf/helpers';
7
5
  import centroid from '@turf/centroid';
8
6
  import concaveman from 'concaveman';
9
7
  import { getDefaultColor, PALETTE } from '@vitessce/utils';
10
- import { HIERARCHICAL_SCHEMAS, } from './constants';
11
- import { pathToKey } from './utils';
8
+ import { HIERARCHICAL_SCHEMAS, } from './constants.js';
9
+ import { pathToKey } from './utils.js';
12
10
  /**
13
11
  * Alias for the uuidv4 function to make code more readable.
14
12
  * @returns {string} UUID.
@@ -267,7 +265,7 @@ export function nodeToLevelDescendantNamePaths(node, level, prevPath, stopEarly
267
265
  */
268
266
  export function treeExport(currTree, datatype) {
269
267
  return {
270
- version: HIERARCHICAL_SCHEMAS[datatype].latestVersion,
268
+ version: HIERARCHICAL_SCHEMAS.latestVersion,
271
269
  datatype,
272
270
  tree: currTree.tree,
273
271
  };
@@ -319,7 +317,7 @@ export function treeExportSet(currTree, nodePath) {
319
317
  */
320
318
  export function treeInitialize(datatype) {
321
319
  return {
322
- version: HIERARCHICAL_SCHEMAS[datatype].latestVersion,
320
+ version: HIERARCHICAL_SCHEMAS.latestVersion,
323
321
  datatype,
324
322
  tree: [],
325
323
  };
@@ -465,8 +463,9 @@ export function treeToCellPolygonsBySetNames(currTree, obsIndex, obsEmbedding, s
465
463
  * Given a tree with state, get the sizes of the
466
464
  * sets currently marked as "visible".
467
465
  * @param {object} currTree A tree object.
466
+ * @param {array} allNamePaths Array of all paths.
468
467
  * @param {array} selectedNamePaths Array of arrays of strings,
469
- * representing set "paths".
468
+ * representing selected paths.
470
469
  * @param {object[]} setColor Array of objects with the
471
470
  * properties `path` and `color`.
472
471
  * @param {string} theme "light" or "dark" for the vitessce theme
@@ -474,20 +473,34 @@ export function treeToCellPolygonsBySetNames(currTree, obsIndex, obsEmbedding, s
474
473
  * with the properties `name`, `size`, `key`,
475
474
  * and `color`.
476
475
  */
477
- export function treeToSetSizesBySetNames(currTree, selectedNamePaths, setColor, theme) {
476
+ export function treeToSetSizesBySetNames(currTree, allNamePaths, selectedNamePaths, setColor, theme) {
478
477
  const sizes = [];
479
- selectedNamePaths.forEach((setNamePath) => {
480
- const node = treeFindNodeByNamePath(currTree, setNamePath);
478
+ /**
479
+ * Checks if a path is contained in an array of paths.
480
+ * @param {array} path Array of strings, which compose the path.
481
+ * @param {array} paths Array of arrays of strings, which compose paths.
482
+ * */
483
+ const contains = (path, paths) => paths.some(p => isEqual(p, path));
484
+ allNamePaths.forEach((clusterPath) => {
485
+ const node = treeFindNodeByNamePath(currTree, clusterPath);
481
486
  if (node) {
482
487
  const nodeSet = nodeToSet(node);
483
- const nodeColor = setColor?.find(d => isEqual(d.path, setNamePath))?.color
488
+ const nodeColor = setColor?.find(d => isEqual(d.path, clusterPath))?.color
484
489
  || getDefaultColor(theme);
485
- sizes.push({
490
+ const nodeProps = {
486
491
  key: generateKey(),
487
492
  name: node.name,
488
493
  size: nodeSet.length,
489
494
  color: nodeColor,
490
- });
495
+ setNamePath: clusterPath,
496
+ // used by the CellSetSizesPlot to determine if the bar should be grayed out
497
+ isGrayedOut: true,
498
+ };
499
+ // if the current path is selected, we need to show it
500
+ if (contains(clusterPath, selectedNamePaths)) {
501
+ nodeProps.isGrayedOut = false;
502
+ }
503
+ sizes.push(nodeProps);
491
504
  }
492
505
  });
493
506
  return sizes;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cell-set-utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-set-utils.test.d.ts","sourceRoot":"","sources":["../src/cell-set-utils.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ export namespace levelTwoNodeLeaf {
2
+ const name: string;
3
+ const set: (string | null)[][];
4
+ }
5
+ export namespace levelOneNode {
6
+ const name_1: string;
7
+ export { name_1 as name };
8
+ export const children: {
9
+ name: string;
10
+ set: (string | null)[][];
11
+ }[];
12
+ }
13
+ export namespace levelZeroNode {
14
+ const name_2: string;
15
+ export { name_2 as name };
16
+ const children_1: {
17
+ name: string;
18
+ children: {
19
+ name: string;
20
+ set: (string | null)[][];
21
+ }[];
22
+ }[];
23
+ export { children_1 as children };
24
+ }
25
+ export namespace tree {
26
+ const version: string;
27
+ const datatype: string;
28
+ const tree: {
29
+ name: string;
30
+ children: {
31
+ name: string;
32
+ children: ({
33
+ name: string;
34
+ set: (string | null)[][];
35
+ children?: undefined;
36
+ } | {
37
+ name: string;
38
+ children: {
39
+ name: string;
40
+ set: (string | null)[][];
41
+ }[];
42
+ set?: undefined;
43
+ })[];
44
+ }[];
45
+ }[];
46
+ }
47
+ //# sourceMappingURL=cell-set-utils.test.fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-set-utils.test.fixtures.d.ts","sourceRoot":"","sources":["../src/cell-set-utils.test.fixtures.js"],"names":[],"mappings":""}
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- import { cloneDeep } from 'lodash';
3
- import { nodeToRenderProps, nodeToSet, nodeToHeight, treeFindNodeByNamePath, nodeTransform, treeToUnion, treeToIntersection, treeToComplement, nodeToLevelDescendantNamePaths, treeExport, filterNode, } from './cell-set-utils';
4
- import { levelTwoNodeLeaf, levelZeroNode, tree, } from './cell-set-utils.test.fixtures';
2
+ import { cloneDeep } from 'lodash-es';
3
+ import { nodeToRenderProps, nodeToSet, nodeToHeight, treeFindNodeByNamePath, nodeTransform, treeToUnion, treeToIntersection, treeToComplement, nodeToLevelDescendantNamePaths, treeExport, filterNode, treeToSetSizesBySetNames, } from './cell-set-utils.js';
4
+ import { levelTwoNodeLeaf, levelZeroNode, tree, } from './cell-set-utils.test.fixtures.js';
5
5
  describe('Hierarchical sets cell-set-utils', () => {
6
6
  describe('Node rendering', () => {
7
7
  it('can get render properties for a node', () => {
@@ -68,6 +68,79 @@ describe('Hierarchical sets cell-set-utils', () => {
68
68
  expect(nodeTransformedWithoutPredicate.children[0].children[0].name).toEqual('Pericytes');
69
69
  });
70
70
  });
71
+ describe('Generate properties from paths', () => {
72
+ it('treeToSetSizesBySetNames where one bar is selected', () => {
73
+ const setColor = [
74
+ {
75
+ path: ['Cell Type Annotations', 'Vasculature', 'Endothelial'],
76
+ color: [255, 0, 0],
77
+ },
78
+ {
79
+ path: ['Cell Type Annotations', 'Vasculature'],
80
+ color: [68, 119, 170],
81
+ },
82
+ ];
83
+ const setSizes = treeToSetSizesBySetNames(tree, [['Cell Type Annotations', 'Vasculature', 'Endothelial'], ['Cell Type Annotations', 'Vasculature']], [['Cell Type Annotations', 'Vasculature', 'Endothelial']], setColor, 'dark');
84
+ expect(setSizes.length).toEqual(2);
85
+ expect(setSizes[0].name).toEqual('Endothelial');
86
+ expect(setSizes[0].size).toEqual(3);
87
+ expect(setSizes[0].color).toEqual([255, 0, 0]);
88
+ expect(setSizes[0].isGrayedOut).toEqual(false);
89
+ expect(setSizes[0].setNamePath).toEqual(['Cell Type Annotations', 'Vasculature', 'Endothelial']);
90
+ expect(setSizes[1].name).toEqual('Vasculature');
91
+ expect(setSizes[1].size).toEqual(9);
92
+ expect(setSizes[1].color).toEqual([68, 119, 170]);
93
+ expect(setSizes[1].isGrayedOut).toEqual(true);
94
+ });
95
+ it('treeToSetSizesBySetNames where nothing is selected', () => {
96
+ const setColor = [
97
+ {
98
+ path: ['Cell Type Annotations', 'Vasculature', 'Endothelial'],
99
+ color: [255, 0, 0],
100
+ },
101
+ {
102
+ path: ['Cell Type Annotations', 'Vasculature'],
103
+ color: [68, 119, 170],
104
+ },
105
+ ];
106
+ const setSizes = treeToSetSizesBySetNames(tree, [['Cell Type Annotations', 'Vasculature', 'Endothelial'], ['Cell Type Annotations', 'Vasculature']], [], setColor, 'dark');
107
+ expect(setSizes.length).toEqual(2);
108
+ expect(setSizes[0].name).toEqual('Endothelial');
109
+ expect(setSizes[0].size).toEqual(3);
110
+ expect(setSizes[0].color).toEqual([255, 0, 0]);
111
+ expect(setSizes[0].isGrayedOut).toEqual(true);
112
+ expect(setSizes[0].setNamePath).toEqual(['Cell Type Annotations', 'Vasculature', 'Endothelial']);
113
+ expect(setSizes[1].name).toEqual('Vasculature');
114
+ expect(setSizes[1].size).toEqual(9);
115
+ expect(setSizes[1].color).toEqual([68, 119, 170]);
116
+ expect(setSizes[1].isGrayedOut).toEqual(true);
117
+ expect(setSizes[1].setNamePath).toEqual(['Cell Type Annotations', 'Vasculature']);
118
+ });
119
+ it('treeToSetSizesBySetNames where selected paths are not part of all paths', () => {
120
+ const setColor = [
121
+ {
122
+ path: ['Cell Type Annotations', 'Vasculature', 'Endothelial'],
123
+ color: [255, 0, 0],
124
+ },
125
+ {
126
+ path: ['Cell Type Annotations', 'Vasculature'],
127
+ color: [68, 119, 170],
128
+ },
129
+ ];
130
+ const setSizes = treeToSetSizesBySetNames(tree, [['Cell Type Annotations', 'Vasculature', 'Endothelial'], ['Cell Type Annotations', 'Vasculature']], [['Louvain Clusters', '0'], ['Louvain Clusters', '1']], setColor, 'dark');
131
+ expect(setSizes.length).toEqual(2);
132
+ expect(setSizes[0].name).toEqual('Endothelial');
133
+ expect(setSizes[0].size).toEqual(3);
134
+ expect(setSizes[0].color).toEqual([255, 0, 0]);
135
+ expect(setSizes[0].isGrayedOut).toEqual(true);
136
+ expect(setSizes[0].setNamePath).toEqual(['Cell Type Annotations', 'Vasculature', 'Endothelial']);
137
+ expect(setSizes[1].name).toEqual('Vasculature');
138
+ expect(setSizes[1].size).toEqual(9);
139
+ expect(setSizes[1].color).toEqual([68, 119, 170]);
140
+ expect(setSizes[1].isGrayedOut).toEqual(true);
141
+ expect(setSizes[1].setNamePath).toEqual(['Cell Type Annotations', 'Vasculature']);
142
+ });
143
+ });
71
144
  describe('Get from tree', () => {
72
145
  it('Tree Union', () => {
73
146
  const union = treeToUnion(tree, [
@@ -0,0 +1,17 @@
1
+ export const FILE_EXTENSION_JSON: "json";
2
+ export const MIME_TYPE_JSON: "application/json";
3
+ export const FILE_EXTENSION_TABULAR: "csv";
4
+ export const MIME_TYPE_TABULAR: "text/csv";
5
+ export const SEPARATOR_TABULAR: ",";
6
+ export const NA_VALUE_TABULAR: "NA";
7
+ export const SETS_DATATYPE_OBS: "obs";
8
+ export namespace HIERARCHICAL_SCHEMAS {
9
+ export const latestVersion: string;
10
+ export { obsSetsSchema as schema };
11
+ }
12
+ export namespace TABULAR_SCHEMAS {
13
+ export { obsSetsTabularSchema as schema };
14
+ }
15
+ import { obsSetsSchema } from "@vitessce/schemas";
16
+ import { obsSetsTabularSchema } from "@vitessce/schemas";
17
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.js"],"names":[],"mappings":"AAEA,yCAA0C;AAC1C,gDAAiD;AAEjD,2CAA4C;AAC5C,2CAA4C;AAC5C,oCAAqC;AAGrC,oCAAqC;AAErC,sCAAuC"}
@@ -1,4 +1,4 @@
1
- import { obsSetsSchema, obsSetsTabularSchema } from '@vitessce/vit-s';
1
+ import { obsSetsSchema, obsSetsTabularSchema } from '@vitessce/schemas';
2
2
  export const FILE_EXTENSION_JSON = 'json';
3
3
  export const MIME_TYPE_JSON = 'application/json';
4
4
  export const FILE_EXTENSION_TABULAR = 'csv';
@@ -9,20 +9,9 @@ export const SEPARATOR_TABULAR = ',';
9
9
  export const NA_VALUE_TABULAR = 'NA';
10
10
  export const SETS_DATATYPE_OBS = 'obs';
11
11
  export const HIERARCHICAL_SCHEMAS = {
12
- cell: {
13
- latestVersion: '0.1.3',
14
- schema: obsSetsSchema,
15
- },
16
- obs: {
17
- latestVersion: '0.1.3',
18
- schema: obsSetsSchema,
19
- },
12
+ latestVersion: '0.1.3',
13
+ schema: obsSetsSchema,
20
14
  };
21
15
  export const TABULAR_SCHEMAS = {
22
- cell: {
23
- schema: obsSetsTabularSchema,
24
- },
25
- obs: {
26
- schema: obsSetsTabularSchema,
27
- },
16
+ schema: obsSetsTabularSchema,
28
17
  };
@@ -0,0 +1,7 @@
1
+ export { dataToCellSetsTree } from "./CellSetsZarrLoader.js";
2
+ export { treeToCellColorsBySetNames, treeToSetSizesBySetNames, treeToObjectsBySetNames, treeExportLevelZeroNode, treeExportSet, treeToExpectedCheckedLevel, nodeToLevelDescendantNamePaths, treeToIntersection, treeToUnion, treeToComplement, treeFindNodeByNamePath, treesConflict, nodeTransform, nodeAppendChild, nodePrependChild, nodeInsertChild, filterNode, treeInitialize, initializeCellSetColor, nodeToRenderProps, getCellSetPolygons, treeToMembershipMap, nodeToSet } from "./cell-set-utils.js";
3
+ export { findLongestCommonPath, filterPathsByExpansionAndSelection, findChangedHierarchy } from "./set-path-utils.js";
4
+ export { isEqualOrPrefix, tryRenamePath, PATH_SEP, setObsSelection, mergeObsSets, getNextNumberedNodeName, colorArrayToString, callbackOnKeyPress, getLevelTooltipText, pathToKey, getObsInfoFromDataWithinRange } from "./utils.js";
5
+ export { downloadForUser, handleExportJSON, handleExportTabular, tryUpgradeTreeToLatestSchema, handleImportJSON, handleImportTabular } from "./io.js";
6
+ export { FILE_EXTENSION_JSON, FILE_EXTENSION_TABULAR, SETS_DATATYPE_OBS, MIME_TYPE_JSON, MIME_TYPE_TABULAR } from "./constants.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export { treeToCellColorsBySetNames, treeToSetSizesBySetNames, treeToObjectsBySetNames, treeExportLevelZeroNode, treeExportSet, treeToExpectedCheckedLevel, nodeToLevelDescendantNamePaths, treeToIntersection, treeToUnion, treeToComplement, treeFindNodeByNamePath, treesConflict, nodeTransform, nodeAppendChild, nodePrependChild, nodeInsertChild, filterNode, treeInitialize, initializeCellSetColor, nodeToRenderProps, getCellSetPolygons, treeToMembershipMap, nodeToSet, } from './cell-set-utils.js';
2
+ export { findLongestCommonPath, filterPathsByExpansionAndSelection, findChangedHierarchy, } from './set-path-utils.js';
3
+ export { isEqualOrPrefix, tryRenamePath, PATH_SEP, setObsSelection, mergeObsSets, getNextNumberedNodeName, colorArrayToString, callbackOnKeyPress, getLevelTooltipText, pathToKey, getObsInfoFromDataWithinRange, } from './utils.js';
4
+ export { downloadForUser, handleExportJSON, handleExportTabular, tryUpgradeTreeToLatestSchema, handleImportJSON, handleImportTabular, } from './io.js';
5
+ export { FILE_EXTENSION_JSON, FILE_EXTENSION_TABULAR, SETS_DATATYPE_OBS, MIME_TYPE_JSON, MIME_TYPE_TABULAR, } from './constants.js';
6
+ export { dataToCellSetsTree, } from './CellSetsZarrLoader.js';