@vitessce/utils 3.8.10 → 3.9.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.js +43 -2
- package/dist-tsc/expr.d.ts +7 -2
- package/dist-tsc/expr.d.ts.map +1 -1
- package/dist-tsc/expr.js +30 -3
- package/dist-tsc/index.d.ts +1 -1
- package/dist-tsc/index.d.ts.map +1 -1
- package/dist-tsc/index.js +1 -1
- package/package.json +2 -2
- package/src/expr.ts +39 -4
- package/src/index.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -893,6 +893,23 @@ class Pool {
|
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
895
|
}
|
|
896
|
+
function extent(values, valueof) {
|
|
897
|
+
let min;
|
|
898
|
+
let max;
|
|
899
|
+
{
|
|
900
|
+
for (const value of values) {
|
|
901
|
+
if (value != null) {
|
|
902
|
+
if (min === void 0) {
|
|
903
|
+
if (value >= value) min = max = value;
|
|
904
|
+
} else {
|
|
905
|
+
if (min > value) min = value;
|
|
906
|
+
if (max < value) max = value;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return [min, max];
|
|
912
|
+
}
|
|
896
913
|
function aggregateFeatureArrays(arrays, strategy) {
|
|
897
914
|
if (!arrays || arrays.length === 0) return null;
|
|
898
915
|
let targetArray;
|
|
@@ -928,7 +945,7 @@ function aggregateFeatureArrays(arrays, strategy) {
|
|
|
928
945
|
resultArray[i] /= numArrays;
|
|
929
946
|
}
|
|
930
947
|
}
|
|
931
|
-
return resultArray;
|
|
948
|
+
return Array.from(resultArray);
|
|
932
949
|
}
|
|
933
950
|
if (strategy === "difference") {
|
|
934
951
|
if (numArrays !== 2) {
|
|
@@ -941,10 +958,32 @@ function aggregateFeatureArrays(arrays, strategy) {
|
|
|
941
958
|
for (let i = 0; i < firstArrayLength; i++) {
|
|
942
959
|
resultArray[i] = arr0[i] - arr1[i];
|
|
943
960
|
}
|
|
944
|
-
return resultArray;
|
|
961
|
+
return Array.from(resultArray);
|
|
945
962
|
}
|
|
946
963
|
throw new Error(`Unknown aggregation strategy: ${strategy}`);
|
|
947
964
|
}
|
|
965
|
+
function normalizeAggregatedFeatureArray(values) {
|
|
966
|
+
if (!values || values.length === 0) {
|
|
967
|
+
return null;
|
|
968
|
+
}
|
|
969
|
+
const [min, max] = extent(values);
|
|
970
|
+
if (min == null || max == null) {
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
const ratio = max > min ? 255 / (max - min) : 1;
|
|
974
|
+
const normData = new Uint8Array(values.length);
|
|
975
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
976
|
+
const normalized = max > min ? Math.floor((values[i] - min) * ratio) : 0;
|
|
977
|
+
normData[i] = Number.isFinite(normalized) ? Math.max(0, Math.min(255, normalized)) : 0;
|
|
978
|
+
}
|
|
979
|
+
return { normData, extent: [min, max] };
|
|
980
|
+
}
|
|
981
|
+
function filterValidExpressionArrays(arrays) {
|
|
982
|
+
if (!arrays) {
|
|
983
|
+
return [];
|
|
984
|
+
}
|
|
985
|
+
return arrays.filter((arr) => arr && (Array.isArray(arr) || ArrayBuffer.isView(arr)) && arr.length > 0);
|
|
986
|
+
}
|
|
948
987
|
export {
|
|
949
988
|
COLORMAP_OPTIONS,
|
|
950
989
|
DEFAULT_DARK_COLOR,
|
|
@@ -970,6 +1009,7 @@ export {
|
|
|
970
1009
|
createDefaultUpdateTracksHover,
|
|
971
1010
|
createDefaultUpdateViewInfo,
|
|
972
1011
|
createPrefixedGetNextScopeNumeric,
|
|
1012
|
+
filterValidExpressionArrays,
|
|
973
1013
|
formatBytes,
|
|
974
1014
|
getDefaultColor,
|
|
975
1015
|
getDefaultForegroundColor,
|
|
@@ -979,6 +1019,7 @@ export {
|
|
|
979
1019
|
getNextScope,
|
|
980
1020
|
getNextScopeNumeric,
|
|
981
1021
|
getValueTransformFunction,
|
|
1022
|
+
normalizeAggregatedFeatureArray,
|
|
982
1023
|
pluralize,
|
|
983
1024
|
unnestMap
|
|
984
1025
|
};
|
package/dist-tsc/expr.d.ts
CHANGED
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
* - 'first', 'last', or number: Selects a specific array.
|
|
10
10
|
* - 'sum', 'mean': Mathematical aggregation.
|
|
11
11
|
* - 'difference': Subtracts the second array from the first (requires exactly 2 arrays).
|
|
12
|
-
* @returns {
|
|
12
|
+
* @returns {number[]|null} - The aggregated array or null on error/empty input.
|
|
13
13
|
*/
|
|
14
|
-
export declare function aggregateFeatureArrays(arrays: Array<Array<number>>, strategy: string | number): number[] |
|
|
14
|
+
export declare function aggregateFeatureArrays(arrays: Array<Array<number>>, strategy: string | number): number[] | null;
|
|
15
|
+
export declare function normalizeAggregatedFeatureArray(values: null | number[] | Float32Array | Float64Array): {
|
|
16
|
+
normData: Uint8Array;
|
|
17
|
+
extent: number[];
|
|
18
|
+
} | null;
|
|
19
|
+
export declare function filterValidExpressionArrays(arrays: null | Array<null | Array<number> | Float32Array | Float64Array>): (number[] | Float64Array | Float32Array | null)[];
|
|
15
20
|
//# sourceMappingURL=expr.d.ts.map
|
package/dist-tsc/expr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expr.d.ts","sourceRoot":"","sources":["../src/expr.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"expr.d.ts","sourceRoot":"","sources":["../src/expr.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAC5B,QAAQ,EAAE,MAAM,GAAG,MAAM,GACxB,MAAM,EAAE,GAAG,IAAI,CAoEjB;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY;;;SAkBtD;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,YAAY,GAAG,YAAY,CAAC,qDAUzE"}
|
package/dist-tsc/expr.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable prefer-destructuring */
|
|
2
|
+
import { extent } from 'd3-array';
|
|
2
3
|
/**
|
|
3
4
|
* Aggregates multiple arrays of numbers into a single array using a specified strategy.
|
|
4
5
|
*
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
* - 'first', 'last', or number: Selects a specific array.
|
|
11
12
|
* - 'sum', 'mean': Mathematical aggregation.
|
|
12
13
|
* - 'difference': Subtracts the second array from the first (requires exactly 2 arrays).
|
|
13
|
-
* @returns {
|
|
14
|
+
* @returns {number[]|null} - The aggregated array or null on error/empty input.
|
|
14
15
|
*/
|
|
15
16
|
export function aggregateFeatureArrays(arrays, strategy) {
|
|
16
17
|
if (!arrays || arrays.length === 0)
|
|
@@ -54,7 +55,7 @@ export function aggregateFeatureArrays(arrays, strategy) {
|
|
|
54
55
|
resultArray[i] /= numArrays;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
return resultArray;
|
|
58
|
+
return Array.from(resultArray);
|
|
58
59
|
}
|
|
59
60
|
if (strategy === 'difference') {
|
|
60
61
|
if (numArrays !== 2) {
|
|
@@ -67,7 +68,33 @@ export function aggregateFeatureArrays(arrays, strategy) {
|
|
|
67
68
|
for (let i = 0; i < firstArrayLength; i++) {
|
|
68
69
|
resultArray[i] = arr0[i] - arr1[i];
|
|
69
70
|
}
|
|
70
|
-
return resultArray;
|
|
71
|
+
return Array.from(resultArray);
|
|
71
72
|
}
|
|
72
73
|
throw new Error(`Unknown aggregation strategy: ${strategy}`);
|
|
73
74
|
}
|
|
75
|
+
export function normalizeAggregatedFeatureArray(values) {
|
|
76
|
+
if (!values || values.length === 0) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const [min, max] = extent(values);
|
|
80
|
+
if (min == null || max == null) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const ratio = max > min ? (255 / (max - min)) : 1;
|
|
84
|
+
const normData = new Uint8Array(values.length);
|
|
85
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
86
|
+
const normalized = max > min ? Math.floor((values[i] - min) * ratio) : 0;
|
|
87
|
+
normData[i] = Number.isFinite(normalized)
|
|
88
|
+
? Math.max(0, Math.min(255, normalized))
|
|
89
|
+
: 0;
|
|
90
|
+
}
|
|
91
|
+
return { normData, extent: [min, max] };
|
|
92
|
+
}
|
|
93
|
+
export function filterValidExpressionArrays(arrays) {
|
|
94
|
+
if (!arrays) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return arrays.filter(arr => (arr
|
|
98
|
+
&& (Array.isArray(arr) || ArrayBuffer.isView(arr))
|
|
99
|
+
&& arr.length > 0));
|
|
100
|
+
}
|
package/dist-tsc/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { commaNumber, capitalize, pluralize, cleanFeatureId, getLongestString, g
|
|
|
2
2
|
export { DEFAULT_DARK_COLOR, DEFAULT_LIGHT_COLOR, getDefaultColor, getDefaultForegroundColor, PALETTE, VIEWER_PALETTE, PATHOLOGY_PALETTE, LARGE_PATHOLOGY_PALETTE, COLORMAP_OPTIONS, DEFAULT_GL_OPTIONS, createDefaultUpdateStatus, createDefaultUpdateCellsSelection, createDefaultUpdateCellsHover, createDefaultUpdateGenesHover, createDefaultUpdateTracksHover, createDefaultUpdateViewInfo, createDefaultClearPleaseWait, copyUint8Array, asEsModule, formatBytes, } from './components.js';
|
|
3
3
|
export { getValueTransformFunction, VALUE_TRANSFORM_OPTIONS, } from './gating.js';
|
|
4
4
|
export { default as Pool } from './Pool.js';
|
|
5
|
-
export { aggregateFeatureArrays } from './expr.js';
|
|
5
|
+
export { aggregateFeatureArrays, normalizeAggregatedFeatureArray, filterValidExpressionArrays, } from './expr.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist-tsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,SAAS,GACV,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,SAAS,GACV,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,WAAW,CAAC"}
|
package/dist-tsc/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { commaNumber, capitalize, pluralize, cleanFeatureId, getLongestString, g
|
|
|
4
4
|
export { DEFAULT_DARK_COLOR, DEFAULT_LIGHT_COLOR, getDefaultColor, getDefaultForegroundColor, PALETTE, VIEWER_PALETTE, PATHOLOGY_PALETTE, LARGE_PATHOLOGY_PALETTE, COLORMAP_OPTIONS, DEFAULT_GL_OPTIONS, createDefaultUpdateStatus, createDefaultUpdateCellsSelection, createDefaultUpdateCellsHover, createDefaultUpdateGenesHover, createDefaultUpdateTracksHover, createDefaultUpdateViewInfo, createDefaultClearPleaseWait, copyUint8Array, asEsModule, formatBytes, } from './components.js';
|
|
5
5
|
export { getValueTransformFunction, VALUE_TRANSFORM_OPTIONS, } from './gating.js';
|
|
6
6
|
export { default as Pool } from './Pool.js';
|
|
7
|
-
export { aggregateFeatureArrays } from './expr.js';
|
|
7
|
+
export { aggregateFeatureArrays, normalizeAggregatedFeatureArray, filterValidExpressionArrays, } from './expr.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"author": "HIDIVE Lab at HMS",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"lz-string": "^1.4.4",
|
|
22
22
|
"pluralize": "^8.0.0",
|
|
23
23
|
"d3-array": "^2.4.0",
|
|
24
|
-
"@vitessce/globals": "3.
|
|
24
|
+
"@vitessce/globals": "3.9.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.mjs",
|
package/src/expr.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable prefer-destructuring */
|
|
2
|
+
import { extent } from 'd3-array';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Aggregates multiple arrays of numbers into a single array using a specified strategy.
|
|
@@ -11,12 +12,12 @@
|
|
|
11
12
|
* - 'first', 'last', or number: Selects a specific array.
|
|
12
13
|
* - 'sum', 'mean': Mathematical aggregation.
|
|
13
14
|
* - 'difference': Subtracts the second array from the first (requires exactly 2 arrays).
|
|
14
|
-
* @returns {
|
|
15
|
+
* @returns {number[]|null} - The aggregated array or null on error/empty input.
|
|
15
16
|
*/
|
|
16
17
|
export function aggregateFeatureArrays(
|
|
17
18
|
arrays: Array<Array<number>>,
|
|
18
19
|
strategy: string | number,
|
|
19
|
-
) {
|
|
20
|
+
): number[] | null {
|
|
20
21
|
if (!arrays || arrays.length === 0) return null;
|
|
21
22
|
|
|
22
23
|
// Check these first to avoid any setup overhead for simple lookups.
|
|
@@ -63,7 +64,7 @@ export function aggregateFeatureArrays(
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
return resultArray;
|
|
67
|
+
return Array.from(resultArray);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
if (strategy === 'difference') {
|
|
@@ -80,8 +81,42 @@ export function aggregateFeatureArrays(
|
|
|
80
81
|
resultArray[i] = arr0[i] - arr1[i];
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
return resultArray;
|
|
84
|
+
return Array.from(resultArray);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
throw new Error(`Unknown aggregation strategy: ${strategy}`);
|
|
87
88
|
}
|
|
89
|
+
|
|
90
|
+
export function normalizeAggregatedFeatureArray(
|
|
91
|
+
values: null | number[] | Float32Array | Float64Array,
|
|
92
|
+
) {
|
|
93
|
+
if (!values || values.length === 0) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const [min, max] = extent(values);
|
|
97
|
+
if (min == null || max == null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const ratio = max > min ? (255 / (max - min)) : 1;
|
|
101
|
+
const normData = new Uint8Array(values.length);
|
|
102
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
103
|
+
const normalized = max > min ? Math.floor((values[i] - min) * ratio) : 0;
|
|
104
|
+
normData[i] = Number.isFinite(normalized)
|
|
105
|
+
? Math.max(0, Math.min(255, normalized))
|
|
106
|
+
: 0;
|
|
107
|
+
}
|
|
108
|
+
return { normData, extent: [min, max] };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function filterValidExpressionArrays(
|
|
112
|
+
arrays: null | Array<null | Array<number> | Float32Array | Float64Array>,
|
|
113
|
+
) {
|
|
114
|
+
if (!arrays) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
return arrays.filter(arr => (
|
|
118
|
+
arr
|
|
119
|
+
&& (Array.isArray(arr) || ArrayBuffer.isView(arr))
|
|
120
|
+
&& arr.length > 0
|
|
121
|
+
));
|
|
122
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -40,4 +40,8 @@ export {
|
|
|
40
40
|
VALUE_TRANSFORM_OPTIONS,
|
|
41
41
|
} from './gating.js';
|
|
42
42
|
export { default as Pool } from './Pool.js';
|
|
43
|
-
export {
|
|
43
|
+
export {
|
|
44
|
+
aggregateFeatureArrays,
|
|
45
|
+
normalizeAggregatedFeatureArray,
|
|
46
|
+
filterValidExpressionArrays,
|
|
47
|
+
} from './expr.js';
|