@vitessce/sets-utils 2.0.3 → 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.
- package/dist/{index.mjs → index.js} +9301 -7998
- package/dist-tsc/CellSetsZarrLoader.d.ts +2 -0
- package/dist-tsc/CellSetsZarrLoader.d.ts.map +1 -0
- package/dist-tsc/CellSetsZarrLoader.js +91 -0
- package/dist-tsc/CellSetsZarrLoader.test.d.ts +2 -0
- package/dist-tsc/CellSetsZarrLoader.test.d.ts.map +1 -0
- package/dist-tsc/CellSetsZarrLoader.test.js +154 -0
- package/dist-tsc/cell-set-utils.d.ts +204 -0
- package/dist-tsc/cell-set-utils.d.ts.map +1 -0
- package/dist-tsc/cell-set-utils.js +630 -0
- package/dist-tsc/cell-set-utils.test.d.ts +2 -0
- package/dist-tsc/cell-set-utils.test.d.ts.map +1 -0
- package/dist-tsc/cell-set-utils.test.fixtures.d.ts +47 -0
- package/dist-tsc/cell-set-utils.test.fixtures.d.ts.map +1 -0
- package/dist-tsc/cell-set-utils.test.fixtures.js +68 -0
- package/dist-tsc/cell-set-utils.test.js +185 -0
- package/dist-tsc/constants.d.ts +17 -0
- package/dist-tsc/constants.d.ts.map +1 -0
- package/dist-tsc/constants.js +17 -0
- package/dist-tsc/index.d.ts +7 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +6 -5
- package/dist-tsc/io.d.ts +47 -0
- package/dist-tsc/io.d.ts.map +1 -0
- package/dist-tsc/io.js +159 -0
- package/dist-tsc/io.test.d.ts +2 -0
- package/dist-tsc/io.test.d.ts.map +1 -0
- package/dist-tsc/io.test.js +124 -0
- package/dist-tsc/set-path-utils.d.ts +28 -0
- package/dist-tsc/set-path-utils.d.ts.map +1 -0
- package/dist-tsc/set-path-utils.js +133 -0
- package/dist-tsc/set-path-utils.test.d.ts +2 -0
- package/dist-tsc/set-path-utils.test.d.ts.map +1 -0
- package/dist-tsc/set-path-utils.test.js +210 -0
- package/dist-tsc/utils.d.ts +45 -0
- package/dist-tsc/utils.d.ts.map +1 -0
- package/dist-tsc/utils.js +139 -0
- package/dist-tsc/utils.test.d.ts +2 -0
- package/dist-tsc/utils.test.d.ts.map +1 -0
- package/dist-tsc/utils.test.js +39 -0
- package/package.json +16 -8
- package/src/CellSetsZarrLoader.js +2 -2
- package/src/CellSetsZarrLoader.test.js +1 -1
- package/src/cell-set-utils.js +33 -16
- package/src/cell-set-utils.test.js +105 -4
- package/src/constants.js +4 -15
- package/src/index.js +11 -5
- package/src/io.js +25 -35
- package/src/io.test.js +1 -4
- package/src/set-path-utils.js +155 -0
- package/src/set-path-utils.test.js +257 -0
- package/src/utils.js +20 -9
- package/src/utils.test.js +48 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { handleImportJSON, handleExportJSON, handleImportTabular, handleExportTabular, } from './io.js';
|
|
2
|
+
const treeV012 = {
|
|
3
|
+
version: '0.1.2',
|
|
4
|
+
tree: [
|
|
5
|
+
{
|
|
6
|
+
name: 'Clustering Algorithm',
|
|
7
|
+
children: [
|
|
8
|
+
{
|
|
9
|
+
name: 'Cluster A',
|
|
10
|
+
color: [255, 0, 0],
|
|
11
|
+
set: ['cell_243', 'cell_271', 'cell_247', 'cell_248'],
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
const treeV013 = {
|
|
18
|
+
version: '0.1.3',
|
|
19
|
+
tree: [
|
|
20
|
+
{
|
|
21
|
+
name: 'Clustering Algorithm',
|
|
22
|
+
children: [
|
|
23
|
+
{
|
|
24
|
+
name: 'Cluster A',
|
|
25
|
+
color: [255, 0, 0],
|
|
26
|
+
set: [
|
|
27
|
+
['cell_243', null],
|
|
28
|
+
['cell_271', null],
|
|
29
|
+
['cell_247', null],
|
|
30
|
+
['cell_248', null],
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
const treeV013WithPredictionScores = {
|
|
38
|
+
version: '0.1.3',
|
|
39
|
+
tree: [
|
|
40
|
+
{
|
|
41
|
+
name: 'Clustering Algorithm',
|
|
42
|
+
children: [
|
|
43
|
+
{
|
|
44
|
+
name: 'Cluster A',
|
|
45
|
+
color: [255, 0, 0],
|
|
46
|
+
set: [
|
|
47
|
+
['cell_243', 0.5],
|
|
48
|
+
['cell_271', 0.6],
|
|
49
|
+
['cell_247', 0.12345],
|
|
50
|
+
['cell_248', 0],
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
const treeV012AsJson = JSON.stringify(treeV012);
|
|
58
|
+
const treeV013AsJson = JSON.stringify(treeV013);
|
|
59
|
+
const treeV013WithPredictionScoresAsJson = JSON.stringify(treeV013WithPredictionScores);
|
|
60
|
+
const expectedExportedJson = `data:application/json;charset=utf-8,${encodeURIComponent(treeV013AsJson)}`;
|
|
61
|
+
const expectedExportedJsonWithPredictionScores = `data:application/json;charset=utf-8,${encodeURIComponent(treeV013WithPredictionScoresAsJson)}`;
|
|
62
|
+
const treeV012AsCsv = `"groupName","setName","setColor","obsId"
|
|
63
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_243"
|
|
64
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_271"
|
|
65
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_247"
|
|
66
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_248"`;
|
|
67
|
+
const treeV013AsCsv = `"groupName","setName","setColor","obsId","predictionScore"
|
|
68
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_243","NA"
|
|
69
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_271","NA"
|
|
70
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_247","NA"
|
|
71
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_248","NA"`;
|
|
72
|
+
const expectedExportedTabular = `data:text/csv;charset=utf-8,${encodeURIComponent(treeV013AsCsv)}`;
|
|
73
|
+
const treeV013WithPredictionScoresAsCsv = `"groupName","setName","setColor","obsId","predictionScore"
|
|
74
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_243",0.5
|
|
75
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_271",0.6
|
|
76
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_247",0.12345
|
|
77
|
+
"Clustering Algorithm","Cluster A","#ff0000","cell_248",0`;
|
|
78
|
+
const expectedExportedTabularWithPredictionScores = `data:text/csv;charset=utf-8,${encodeURIComponent(treeV013WithPredictionScoresAsCsv)}`;
|
|
79
|
+
describe('io.js', () => {
|
|
80
|
+
describe('importing sets', () => {
|
|
81
|
+
it('can import cell sets from a JSON file v0.1.2', () => {
|
|
82
|
+
const importedTree = handleImportJSON(treeV012AsJson, 'cell');
|
|
83
|
+
expect(importedTree).toEqual(treeV013);
|
|
84
|
+
});
|
|
85
|
+
it('can import cell sets from a JSON file v0.1.3', () => {
|
|
86
|
+
const importedTree = handleImportJSON(treeV013AsJson, 'cell');
|
|
87
|
+
expect(importedTree).toEqual(treeV013);
|
|
88
|
+
});
|
|
89
|
+
it('can import cell sets from a JSON file v0.1.3 with prediction scores', () => {
|
|
90
|
+
const importedTree = handleImportJSON(treeV013WithPredictionScoresAsJson, 'cell');
|
|
91
|
+
expect(importedTree).toEqual(treeV013WithPredictionScores);
|
|
92
|
+
});
|
|
93
|
+
it('can import cell sets from a CSV file v0.1.2', () => {
|
|
94
|
+
const importedTree = handleImportTabular(treeV012AsCsv, 'cell');
|
|
95
|
+
expect(importedTree).toEqual(treeV013);
|
|
96
|
+
});
|
|
97
|
+
it('can import cell sets from a CSV file v0.1.3', () => {
|
|
98
|
+
const importedTree = handleImportTabular(treeV013AsCsv, 'cell');
|
|
99
|
+
expect(importedTree).toEqual(treeV013);
|
|
100
|
+
});
|
|
101
|
+
it('can import cell sets from a CSV file v0.1.3 with prediction scores', () => {
|
|
102
|
+
const importedTree = handleImportTabular(treeV013WithPredictionScoresAsCsv, 'cell');
|
|
103
|
+
expect(importedTree).toEqual(treeV013WithPredictionScores);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('exporting sets', () => {
|
|
107
|
+
it('can export sets to a JSON file v0.1.3', () => {
|
|
108
|
+
const dataString = handleExportJSON(treeV013);
|
|
109
|
+
expect(dataString).toEqual(expectedExportedJson);
|
|
110
|
+
});
|
|
111
|
+
it('can export sets to a JSON file v0.1.3 with prediction scores', () => {
|
|
112
|
+
const dataString = handleExportJSON(treeV013WithPredictionScores);
|
|
113
|
+
expect(dataString).toEqual(expectedExportedJsonWithPredictionScores);
|
|
114
|
+
});
|
|
115
|
+
it('can export sets to a CSV file v0.1.3', () => {
|
|
116
|
+
const dataString = handleExportTabular(treeV013);
|
|
117
|
+
expect(dataString).toEqual(expectedExportedTabular);
|
|
118
|
+
});
|
|
119
|
+
it('can export sets to a CSV file v0.1.3 with prediction scores', () => {
|
|
120
|
+
const dataString = handleExportTabular(treeV013WithPredictionScores);
|
|
121
|
+
expect(dataString).toEqual(expectedExportedTabularWithPredictionScores);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a path that belongs to cellSetSelection and is the longest path
|
|
3
|
+
* found in at least one of the paths in arrOfPaths.
|
|
4
|
+
* @param {array of paths} arrOfPaths contains all paths we are interested in
|
|
5
|
+
* @param {array of paths} cellSetSelection contains the paths of the selected cell sets
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function findLongestCommonPath(arrOfPaths: any, cellSetSelection: any): any[];
|
|
9
|
+
/**
|
|
10
|
+
* Generates paths by doing DFS of tree and filters out the ones that are irrelevant.
|
|
11
|
+
* Filtering is based on the hierarchy, currently expanded and currently selected cell sets.
|
|
12
|
+
* @param {object} tree The current tree.
|
|
13
|
+
* @param {string[]} hierarchy Array of level-zero set names, like
|
|
14
|
+
* `['Louvain Clustering']`.
|
|
15
|
+
* @param {array} cellSetExpansion An array of cell set paths that are expanded.
|
|
16
|
+
* @param {array} cellSetSelection An array of cell set paths that are selected.
|
|
17
|
+
* @returns An array of paths that should be displayed.
|
|
18
|
+
*/
|
|
19
|
+
export function filterPathsByExpansionAndSelection(mergedCellSets: any, hierarchy: string[], cellSetExpansion: array, cellSetSelection: array): any;
|
|
20
|
+
/**
|
|
21
|
+
* Finds the hierarchy, where cell sets were most recently selected/deselected.
|
|
22
|
+
* @param {array} lastSelection All selected cell sets prior to the modification.
|
|
23
|
+
* @param {array} currentSelection All cell sets that are currently selected.
|
|
24
|
+
* @returns The name of the hierarchy, within which the most recent change occured.
|
|
25
|
+
* If nothing changed, returns 0.
|
|
26
|
+
*/
|
|
27
|
+
export function findChangedHierarchy(prevSelectedPaths: any, currSelectedPaths: any): any;
|
|
28
|
+
//# sourceMappingURL=set-path-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-path-utils.d.ts","sourceRoot":"","sources":["../src/set-path-utils.js"],"names":[],"mappings":"AAoDA;;;;;;GAMG;AACH,qFAeC;AAED;;;;;;;;;GASG;AACH,mFANW,MAAM,EAAE,yDA2ClB;AAED;;;;;;GAMG;AACH,0FAsBC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
/**
|
|
3
|
+
* Depth-first search of cell set tree, starting from node.
|
|
4
|
+
* @param {*} node The node to start from.
|
|
5
|
+
* @param {*} currentPath The current path.
|
|
6
|
+
* @param {*} paths Accumulated paths so far.
|
|
7
|
+
* @returns all paths from node to leaves.
|
|
8
|
+
*/
|
|
9
|
+
function getPaths(node, currentPath = [], paths = []) {
|
|
10
|
+
if (node.children) {
|
|
11
|
+
node.children.forEach((child) => {
|
|
12
|
+
const newPath = [...currentPath, child.name];
|
|
13
|
+
paths.push(newPath);
|
|
14
|
+
getPaths(child, newPath, paths);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return paths;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Finds either the longest subset or the longest superset of path in
|
|
21
|
+
* arrOfPaths.
|
|
22
|
+
* @param {array} arrOfPaths An array of paths.
|
|
23
|
+
* @param {array} path An array of strings, representing a path.
|
|
24
|
+
* @param {boolean} isSubset A boolean flag that indicates whether we are
|
|
25
|
+
* looking for the longest subset (true) or the longest superset (false).
|
|
26
|
+
* @returns {array} The longest subset or superset of path in arrOfPaths.
|
|
27
|
+
*/
|
|
28
|
+
function findLongestPath(arrOfPaths, path, isSubset) {
|
|
29
|
+
if (Array.isArray(arrOfPaths)) {
|
|
30
|
+
let longest = null;
|
|
31
|
+
let longestLength = 0;
|
|
32
|
+
arrOfPaths.forEach((subArray) => {
|
|
33
|
+
const matchCount = subArray.filter((v, i) => v === path[i]).length;
|
|
34
|
+
if (matchCount === (isSubset ? subArray.length : path.length)
|
|
35
|
+
&& subArray.length > longestLength) {
|
|
36
|
+
longest = subArray;
|
|
37
|
+
longestLength = subArray.length;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (longestLength > 0) {
|
|
41
|
+
return longest;
|
|
42
|
+
}
|
|
43
|
+
if (isSubset) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns a path that belongs to cellSetSelection and is the longest path
|
|
51
|
+
* found in at least one of the paths in arrOfPaths.
|
|
52
|
+
* @param {array of paths} arrOfPaths contains all paths we are interested in
|
|
53
|
+
* @param {array of paths} cellSetSelection contains the paths of the selected cell sets
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export function findLongestCommonPath(arrOfPaths, cellSetSelection) {
|
|
57
|
+
let maxCount = 0;
|
|
58
|
+
let commonPath = [];
|
|
59
|
+
cellSetSelection.forEach((currentCellSet) => {
|
|
60
|
+
// Find the longest common path
|
|
61
|
+
const longestPath = findLongestPath(arrOfPaths, currentCellSet, false);
|
|
62
|
+
if (longestPath.length > maxCount) {
|
|
63
|
+
maxCount = longestPath.length;
|
|
64
|
+
commonPath = currentCellSet;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return commonPath;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generates paths by doing DFS of tree and filters out the ones that are irrelevant.
|
|
71
|
+
* Filtering is based on the hierarchy, currently expanded and currently selected cell sets.
|
|
72
|
+
* @param {object} tree The current tree.
|
|
73
|
+
* @param {string[]} hierarchy Array of level-zero set names, like
|
|
74
|
+
* `['Louvain Clustering']`.
|
|
75
|
+
* @param {array} cellSetExpansion An array of cell set paths that are expanded.
|
|
76
|
+
* @param {array} cellSetSelection An array of cell set paths that are selected.
|
|
77
|
+
* @returns An array of paths that should be displayed.
|
|
78
|
+
*/
|
|
79
|
+
export function filterPathsByExpansionAndSelection(mergedCellSets, hierarchy, cellSetExpansion, cellSetSelection) {
|
|
80
|
+
const paths = getPaths({ children: mergedCellSets.tree });
|
|
81
|
+
// returns true if path is contained in allPaths, false otherwise
|
|
82
|
+
const contains = (allPaths, path) => allPaths?.some(p => isEqual(p, path));
|
|
83
|
+
return paths.filter((clusterPath) => {
|
|
84
|
+
// clusterPath is a parent of some selected cell set and is expanded. We should discard it.
|
|
85
|
+
if (contains(cellSetExpansion, clusterPath))
|
|
86
|
+
return false;
|
|
87
|
+
// clusterPath is not selected. Now we need to determine if we should keep it.
|
|
88
|
+
if (!contains(cellSetSelection, clusterPath)) {
|
|
89
|
+
/* This line checks if the longest super set of clusterPath in cellSetSelection is longer
|
|
90
|
+
than clusterPath itself. If true, it means clusterPath is a parent of some selected cell
|
|
91
|
+
set but not expanded and we should discard it. */
|
|
92
|
+
if (findLongestPath(cellSetSelection, clusterPath, false).length > clusterPath.length) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (cellSetExpansion) {
|
|
96
|
+
// the clusterPath is too deep in the tree. We should discard it.
|
|
97
|
+
if (cellSetExpansion.length === 0 && clusterPath.length > 2)
|
|
98
|
+
return false;
|
|
99
|
+
const longestSubset = findLongestPath(cellSetExpansion, clusterPath, true);
|
|
100
|
+
// another case of the clusterPath being deep in the tree. We should discard it.
|
|
101
|
+
if (cellSetExpansion.length > 0 && longestSubset.length + 1 < clusterPath.length) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return clusterPath[0] === hierarchy[0];
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Finds the hierarchy, where cell sets were most recently selected/deselected.
|
|
111
|
+
* @param {array} lastSelection All selected cell sets prior to the modification.
|
|
112
|
+
* @param {array} currentSelection All cell sets that are currently selected.
|
|
113
|
+
* @returns The name of the hierarchy, within which the most recent change occured.
|
|
114
|
+
* If nothing changed, returns 0.
|
|
115
|
+
*/
|
|
116
|
+
export function findChangedHierarchy(prevSelectedPaths, currSelectedPaths) {
|
|
117
|
+
const unselectedPaths = prevSelectedPaths.filter(prevPath => !currSelectedPaths.find(currPath => isEqual(currPath, prevPath)));
|
|
118
|
+
const newlySelectedPaths = currSelectedPaths.filter(currPath => !prevSelectedPaths.find(prevPath => isEqual(currPath, prevPath)));
|
|
119
|
+
// nothing was selected or unselected, therefore hierarchy stays the same
|
|
120
|
+
if (unselectedPaths.length === 0 && newlySelectedPaths.length === 0) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
/*
|
|
124
|
+
* Picks the first path from newlySelectedPathsStr, if there is one,
|
|
125
|
+
* otherwise from unselectedPathsStr.
|
|
126
|
+
* This is going to be used as the new hierarchy.
|
|
127
|
+
*/
|
|
128
|
+
const changedPath = newlySelectedPaths.length > 0
|
|
129
|
+
? newlySelectedPaths[0] : unselectedPaths[0];
|
|
130
|
+
// we assume that the last element of a path is the leaf node.
|
|
131
|
+
// As leaf nodes do not hold hierarchy information, we can remove it.
|
|
132
|
+
return changedPath.slice(0, -1);
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-path-utils.test.d.ts","sourceRoot":"","sources":["../src/set-path-utils.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { filterPathsByExpansionAndSelection, findChangedHierarchy } from './set-path-utils.js';
|
|
2
|
+
describe('Tests for findChangedHierarchy', () => {
|
|
3
|
+
it('Computes correct new hierarchy after new selection', () => {
|
|
4
|
+
const prevSelectedPaths = [
|
|
5
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
6
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
7
|
+
];
|
|
8
|
+
const currSelectedPaths = [
|
|
9
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
10
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
11
|
+
['Cell Type Annotations', 'Vasculature', 'Endothelial'],
|
|
12
|
+
];
|
|
13
|
+
const changedHierarchy = findChangedHierarchy(prevSelectedPaths, currSelectedPaths);
|
|
14
|
+
expect(changedHierarchy).toEqual(['Cell Type Annotations', 'Vasculature']);
|
|
15
|
+
});
|
|
16
|
+
it('Computes correct hierarchy after unselecting', () => {
|
|
17
|
+
const prevSelectedPaths = [
|
|
18
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
19
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
20
|
+
];
|
|
21
|
+
const currSelectedPaths = [
|
|
22
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
23
|
+
];
|
|
24
|
+
const changedHierarchy = findChangedHierarchy(prevSelectedPaths, currSelectedPaths);
|
|
25
|
+
expect(changedHierarchy).toEqual(['Louvain Clustering']);
|
|
26
|
+
});
|
|
27
|
+
it('Computes correct hierarchy after select only', () => {
|
|
28
|
+
const prevSelectedPaths = [
|
|
29
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
30
|
+
['Louvain Clustering', 'Cluster 2'],
|
|
31
|
+
['Louvain Clustering', 'Cluster 3'],
|
|
32
|
+
['Louvain Clustering', 'Cluster 4'],
|
|
33
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
34
|
+
];
|
|
35
|
+
const currSelectedPaths = [
|
|
36
|
+
['Cell Type Annotations', 'Vasculature'],
|
|
37
|
+
];
|
|
38
|
+
const changedHierarchy = findChangedHierarchy(prevSelectedPaths, currSelectedPaths);
|
|
39
|
+
expect(changedHierarchy).toEqual(['Cell Type Annotations']);
|
|
40
|
+
});
|
|
41
|
+
it('Returns null when hierarchy was not changed', () => {
|
|
42
|
+
const prevSelectedPaths = [
|
|
43
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
44
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
45
|
+
];
|
|
46
|
+
const currSelectedPaths = [
|
|
47
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
48
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
49
|
+
];
|
|
50
|
+
const changedHierarchy = findChangedHierarchy(prevSelectedPaths, currSelectedPaths);
|
|
51
|
+
expect(changedHierarchy).toEqual(null);
|
|
52
|
+
});
|
|
53
|
+
it('Works when nothing was previously selected', () => {
|
|
54
|
+
const prevSelectedPaths = [];
|
|
55
|
+
const currSelectedPaths = [
|
|
56
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
57
|
+
];
|
|
58
|
+
const changedHierarchy = findChangedHierarchy(prevSelectedPaths, currSelectedPaths);
|
|
59
|
+
expect(changedHierarchy).toEqual(['Louvain Clustering']);
|
|
60
|
+
});
|
|
61
|
+
it('Works when nothing is selected', () => {
|
|
62
|
+
const prevSelectedPaths = [
|
|
63
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
64
|
+
];
|
|
65
|
+
const currSelectedPaths = [];
|
|
66
|
+
const changedHierarchy = findChangedHierarchy(prevSelectedPaths, currSelectedPaths);
|
|
67
|
+
expect(changedHierarchy).toEqual(['Louvain Clustering']);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('Tests for filterPathsByExpansionAndSelection', () => {
|
|
71
|
+
const tree = {
|
|
72
|
+
version: '0.1.3',
|
|
73
|
+
datatype: 'cell',
|
|
74
|
+
tree: [
|
|
75
|
+
{
|
|
76
|
+
name: 'Louvain Clustering',
|
|
77
|
+
children: [
|
|
78
|
+
{
|
|
79
|
+
name: 'Cluster 1',
|
|
80
|
+
set: [['cell_1', null], ['cell_2', null], ['cell_3', null]],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'Cluster 2',
|
|
84
|
+
set: [['cell_4', null], ['cell_5', null]],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'Cluster 3',
|
|
88
|
+
set: [['cell_6', null], ['cell_7', null]],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'Cluster 4',
|
|
92
|
+
set: [['cell_8', null], ['cell_9', null], ['cell_10', null]],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Cell Type Annotations',
|
|
98
|
+
children: [
|
|
99
|
+
{
|
|
100
|
+
name: 'Vasculature',
|
|
101
|
+
children: [
|
|
102
|
+
{
|
|
103
|
+
name: 'Pericytes',
|
|
104
|
+
set: [['cell_1', null], ['cell_2', null], ['cell_3', null]],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'Endothelial',
|
|
108
|
+
set: [['cell_3', null], ['cell_4', null], ['cell_5', null]],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'Epithelial',
|
|
112
|
+
children: [
|
|
113
|
+
{
|
|
114
|
+
name: 'Squamous',
|
|
115
|
+
set: [['cell_5', null], ['cell_6', null], ['cell_7', null]],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'Immune',
|
|
123
|
+
set: [['cell_8', null], ['cell_9', null], ['cell_10', null]],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
it('Generates correct cell set paths when expanded', () => {
|
|
130
|
+
const hierarchy = ['Louvain Clustering'];
|
|
131
|
+
const cellSetExpansion = [
|
|
132
|
+
['Louvain Clustering'],
|
|
133
|
+
];
|
|
134
|
+
const cellSetSelection = [
|
|
135
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
136
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
137
|
+
];
|
|
138
|
+
const cellSetPaths = filterPathsByExpansionAndSelection(tree, hierarchy, cellSetExpansion, cellSetSelection);
|
|
139
|
+
expect(cellSetPaths).toEqual([
|
|
140
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
141
|
+
['Louvain Clustering', 'Cluster 2'],
|
|
142
|
+
['Louvain Clustering', 'Cluster 3'],
|
|
143
|
+
['Louvain Clustering', 'Cluster 4'],
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
it('Generates correct cell set paths when not expanded and no nested hierarchy', () => {
|
|
147
|
+
const hierarchy = ['Louvain Clustering'];
|
|
148
|
+
const cellSetExpansion = [];
|
|
149
|
+
const cellSetSelection = [
|
|
150
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
151
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
152
|
+
];
|
|
153
|
+
const cellSetPaths = filterPathsByExpansionAndSelection(tree, hierarchy, cellSetExpansion, cellSetSelection);
|
|
154
|
+
expect(cellSetPaths).toEqual([
|
|
155
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
156
|
+
['Louvain Clustering', 'Cluster 2'],
|
|
157
|
+
['Louvain Clustering', 'Cluster 3'],
|
|
158
|
+
['Louvain Clustering', 'Cluster 4'],
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
it('Generates correct cell set paths when expanded and nested hierarchy', () => {
|
|
162
|
+
const hierarchy = ['Cell Type Annotations'];
|
|
163
|
+
const cellSetExpansion = [
|
|
164
|
+
['Cell Type Annotations', 'Vasculature'],
|
|
165
|
+
];
|
|
166
|
+
const cellSetSelection = [
|
|
167
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
168
|
+
['Louvain Clustering', 'Cluster 2'],
|
|
169
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
170
|
+
];
|
|
171
|
+
const cellSetPaths = filterPathsByExpansionAndSelection(tree, hierarchy, cellSetExpansion, cellSetSelection);
|
|
172
|
+
expect(cellSetPaths).toEqual([
|
|
173
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
174
|
+
['Cell Type Annotations', 'Vasculature', 'Endothelial'],
|
|
175
|
+
['Cell Type Annotations', 'Vasculature', 'Epithelial'],
|
|
176
|
+
]);
|
|
177
|
+
});
|
|
178
|
+
it('Generates correct cell set paths when not expanded and nested hierarchy', () => {
|
|
179
|
+
const hierarchy = ['Cell Type Annotations'];
|
|
180
|
+
const cellSetExpansion = [
|
|
181
|
+
['Cell Type Annotations'],
|
|
182
|
+
];
|
|
183
|
+
const cellSetSelection = [
|
|
184
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
185
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
186
|
+
];
|
|
187
|
+
const cellSetPaths = filterPathsByExpansionAndSelection(tree, hierarchy, cellSetExpansion, cellSetSelection);
|
|
188
|
+
expect(cellSetPaths).toEqual([
|
|
189
|
+
['Cell Type Annotations', 'Vasculature', 'Pericytes'],
|
|
190
|
+
['Cell Type Annotations', 'Immune'],
|
|
191
|
+
]);
|
|
192
|
+
});
|
|
193
|
+
it('Uses paths in cellSetSelection when cellSetExpansion is null', () => {
|
|
194
|
+
const hierarchy = ['Louvain Clustering'];
|
|
195
|
+
const cellSetExpansion = null;
|
|
196
|
+
const cellSetSelection = [
|
|
197
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
198
|
+
['Louvain Clustering', 'Cluster 2'],
|
|
199
|
+
['Louvain Clustering', 'Cluster 3'],
|
|
200
|
+
['Louvain Clustering', 'Cluster 4'],
|
|
201
|
+
];
|
|
202
|
+
const cellSetPaths = filterPathsByExpansionAndSelection(tree, hierarchy, cellSetExpansion, cellSetSelection);
|
|
203
|
+
expect(cellSetPaths).toEqual([
|
|
204
|
+
['Louvain Clustering', 'Cluster 1'],
|
|
205
|
+
['Louvain Clustering', 'Cluster 2'],
|
|
206
|
+
['Louvain Clustering', 'Cluster 3'],
|
|
207
|
+
['Louvain Clustering', 'Cluster 4'],
|
|
208
|
+
]);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a callback function based on a keypress event.
|
|
3
|
+
* @param {object} event The event from onKeyPress
|
|
4
|
+
* @param {string} key The key identifier to match.
|
|
5
|
+
* @param {Function} callback The function to execute.
|
|
6
|
+
*/
|
|
7
|
+
export function callbackOnKeyPress(event: object, key: string, callback: Function): void;
|
|
8
|
+
/**
|
|
9
|
+
* Convert an array of [r, g, b] numbers to a hex color.
|
|
10
|
+
* @param {number[]} rgbArray The color [r, g, b] array.
|
|
11
|
+
* @returns {string} The hex color as a string.
|
|
12
|
+
*/
|
|
13
|
+
export function colorArrayToString(rgbArray: number[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a string color representation to an array of [r,g,b].
|
|
16
|
+
* @param {string} colorString The color as a string.
|
|
17
|
+
* @returns {number[]} The color as an array.
|
|
18
|
+
*/
|
|
19
|
+
export function colorStringToArray(colorString: string): number[];
|
|
20
|
+
/**
|
|
21
|
+
* Get a string of help text for coloring a particular hierarchy level.
|
|
22
|
+
* @param {integer} i The level. 1 for cluster, 2 for subcluster, etc.
|
|
23
|
+
* @returns {string} The tooltip text for coloring the level.
|
|
24
|
+
*/
|
|
25
|
+
export function getLevelTooltipText(i: integer): string;
|
|
26
|
+
export function isEqualOrPrefix(targetPath: any, testPath: any): any;
|
|
27
|
+
export function tryRenamePath(targetPath: any, testPath: any, nextTargetPath: any): any;
|
|
28
|
+
export function pathToKey(path: any): any;
|
|
29
|
+
export function getNextNumberedNodeName(nodes: any, prefix: any, suffix: any): string;
|
|
30
|
+
/**
|
|
31
|
+
* Create a new selected cell set based on a cell selection.
|
|
32
|
+
* @param {string[]} cellSelection An array of cell IDs.
|
|
33
|
+
* @param {object[]} additionalCellSets The previous array of user-defined cell sets.
|
|
34
|
+
* @param {function} setCellSetSelection The setter function for cell set selections.
|
|
35
|
+
* @param {function} setAdditionalCellSets The setter function for user-defined cell sets.
|
|
36
|
+
*/
|
|
37
|
+
export function setObsSelection(cellSelection: string[], additionalCellSets: object[], cellSetColor: any, setCellSetSelection: Function, setAdditionalCellSets: Function, setCellSetColor: any, setCellColorEncoding: any, prefix?: string, suffix?: string): void;
|
|
38
|
+
export function mergeObsSets(cellSets: any, additionalCellSets: any): {
|
|
39
|
+
version: string;
|
|
40
|
+
datatype: string;
|
|
41
|
+
tree: any[];
|
|
42
|
+
};
|
|
43
|
+
export function getObsInfoFromDataWithinRange(range: any, data: any): any;
|
|
44
|
+
export const PATH_SEP: "___";
|
|
45
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,0CAJW,MAAM,OACN,MAAM,4BAQhB;AAED;;;;GAIG;AACH,6CAHW,MAAM,EAAE,GACN,MAAM,CAIlB;AAED;;;;GAIG;AACH,gDAHW,MAAM,GACJ,MAAM,EAAE,CAKpB;AAED;;;;GAIG;AACH,iDAFa,MAAM,CASlB;AAED,qEAKC;AAED,wFAKC;AAID,0CAEC;AAID,sFAUC;AAED;;;;;;GAMG;AACH,+CALW,MAAM,EAAE,sBACR,MAAM,EAAE,8KA+ClB;AAED;;;;EASC;AAED,0EAQC;AA3FD,6BAA8B"}
|