@sjcrh/proteinpaint-shared 2.87.1 → 2.95.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/package.json +1 -1
- package/src/common.js +22 -0
- package/src/descriptive.stats.js +9 -9
- package/src/roundValue.js +46 -7
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -282,6 +282,9 @@ mclass[mclasssv] = {
|
|
|
282
282
|
key: mclasssv
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
// "CNV_amp" represents "CNV Gain" and is used in both 2-category and 5-category CNV data representation
|
|
286
|
+
// "CNV_amplification" represents CNV amplification and is used in 5-category CNV
|
|
287
|
+
// "CNV_amp" have to stay as-is since it may be hardcoded in lots of data beyond portal code.
|
|
285
288
|
export const mclasscnvgain = 'CNV_amp'
|
|
286
289
|
mclass[mclasscnvgain] = {
|
|
287
290
|
label: 'Copy number gain',
|
|
@@ -300,6 +303,25 @@ mclass[mclasscnvloss] = {
|
|
|
300
303
|
key: mclasscnvloss
|
|
301
304
|
}
|
|
302
305
|
|
|
306
|
+
// mclasscnvAmp is next level above mclasscnvgain and is used in 5-category CNV data
|
|
307
|
+
export const mclasscnvAmp = 'CNV_amplification'
|
|
308
|
+
mclass[mclasscnvAmp] = {
|
|
309
|
+
label: 'Copy number amplification',
|
|
310
|
+
color: '#900000',
|
|
311
|
+
dt: dtcnv,
|
|
312
|
+
desc: 'Copy number amplification',
|
|
313
|
+
key: mclasscnvAmp
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export const mclasscnvHomozygousDel = 'CNV_homozygous_deletion'
|
|
317
|
+
mclass[mclasscnvHomozygousDel] = {
|
|
318
|
+
label: 'Copy number homozygous deletion',
|
|
319
|
+
color: '#00457C',
|
|
320
|
+
dt: dtcnv,
|
|
321
|
+
desc: 'Copy number homozygous deletion',
|
|
322
|
+
key: mclasscnvHomozygousDel
|
|
323
|
+
}
|
|
324
|
+
|
|
303
325
|
export const mclasscnvloh = 'CNV_loh'
|
|
304
326
|
mclass[mclasscnvloh] = { label: 'LOH', color: '#12EDFC', dt: dtcnv, desc: 'Loss of heterozygosity', key: mclasscnvloh }
|
|
305
327
|
|
package/src/descriptive.stats.js
CHANGED
|
@@ -42,15 +42,15 @@ export default function summaryStats(array) {
|
|
|
42
42
|
return {
|
|
43
43
|
values: [
|
|
44
44
|
{ id: 'total', label: 'Total', value: n },
|
|
45
|
-
{ id: 'min', label: 'Minimum', value: roundValueAuto(min) },
|
|
46
|
-
{ id: 'p25', label: '1st quartile', value: roundValueAuto(p25) },
|
|
47
|
-
{ id: 'median', label: 'Median', value: roundValueAuto(median) },
|
|
48
|
-
{ id: 'mean', label: 'Mean', value: roundValueAuto(mean(arr)) },
|
|
49
|
-
{ id: 'p75', label: '3rd quartile', value: roundValueAuto(p75) },
|
|
50
|
-
{ id: 'max', label: 'Maximum', value: roundValueAuto(max) },
|
|
51
|
-
{ id: 'SD', label: 'Standard deviation', value: roundValueAuto(stdDev) },
|
|
52
|
-
{ id: 'variance', label: 'Variance', value: roundValueAuto(variance) },
|
|
53
|
-
{ id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(IQR) }
|
|
45
|
+
{ id: 'min', label: 'Minimum', value: roundValueAuto(min, true) },
|
|
46
|
+
{ id: 'p25', label: '1st quartile', value: roundValueAuto(p25, true) },
|
|
47
|
+
{ id: 'median', label: 'Median', value: roundValueAuto(median, true) },
|
|
48
|
+
{ id: 'mean', label: 'Mean', value: roundValueAuto(mean(arr), true) },
|
|
49
|
+
{ id: 'p75', label: '3rd quartile', value: roundValueAuto(p75, true) },
|
|
50
|
+
{ id: 'max', label: 'Maximum', value: roundValueAuto(max, true) },
|
|
51
|
+
{ id: 'SD', label: 'Standard deviation', value: roundValueAuto(stdDev, true) },
|
|
52
|
+
{ id: 'variance', label: 'Variance', value: roundValueAuto(variance, true) },
|
|
53
|
+
{ id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(IQR, true) }
|
|
54
54
|
]
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/roundValue.js
CHANGED
|
@@ -11,19 +11,22 @@ digits: number of digits to round to
|
|
|
11
11
|
export function roundValue(value, digits) {
|
|
12
12
|
const v = Number(value)
|
|
13
13
|
if (Number.isInteger(v)) return v
|
|
14
|
-
|
|
15
|
-
if (abs < 1 || abs > 9999) {
|
|
16
|
-
//Number() reverts positive values less than 10^21 to a whole number
|
|
17
|
-
return abs > 9999 ? v.toPrecision(digits) : Number(v.toPrecision(digits))
|
|
18
|
-
}
|
|
14
|
+
if (Math.abs(v) < 1) return Number(v.toPrecision(digits))
|
|
19
15
|
return Number(v.toFixed(digits))
|
|
20
16
|
}
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
/** Rounds numbers to the appropriate decimal point
|
|
19
|
+
* if format is true, returns either a number or string in
|
|
20
|
+
* scientific notation.
|
|
21
|
+
*
|
|
22
|
+
* TODO: Review digit logic.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function roundValueAuto(value, format = false) {
|
|
23
26
|
if (!value && value != 0) return value
|
|
24
27
|
const dp = decimalPlacesUntilFirstNonZero(value)
|
|
25
28
|
const digits = Math.abs(value) > 1 ? 2 : dp > 0 ? dp + 1 : 2
|
|
26
|
-
|
|
29
|
+
if (format) return formatValue(value, digits)
|
|
27
30
|
return roundValue(value, digits)
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -52,3 +55,39 @@ export function decimalPlacesUntilFirstNonZero(number) {
|
|
|
52
55
|
|
|
53
56
|
return decimalPlaces
|
|
54
57
|
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
simple logic to return a number close to original while rounding up decimals.
|
|
61
|
+
supplements roundValueAuto which rounds 12345 to 1.2e4 which is only suitable for human quick glance but not subsequent computing
|
|
62
|
+
|
|
63
|
+
TODO:
|
|
64
|
+
10000 and 10001 to 1e4
|
|
65
|
+
0.00001 to 1e-5
|
|
66
|
+
1.00001 to 1
|
|
67
|
+
*/
|
|
68
|
+
export function roundValue2(value) {
|
|
69
|
+
if (!Number.isFinite(value)) return value // not a number
|
|
70
|
+
if (Number.isInteger(value)) return value // is integer, do not convert
|
|
71
|
+
const abs = Math.abs(value)
|
|
72
|
+
if (abs > 100) return Math.round(value) // 12345.1234 to 12345 (compared to 1.2e4 from roundValueAuto)
|
|
73
|
+
if (abs > 10) return Number(value.toFixed(1)) // 99.1234 to 99.1
|
|
74
|
+
if (abs > 1) return Number(value.toFixed(2)) // 9.1234 to 9.12
|
|
75
|
+
if (abs > 0.1) return Number(value.toFixed(3)) // 0.12345 to 0.123
|
|
76
|
+
if (abs > 0.01) return Number(value.toFixed(4)) // 0.012345 to 0.0123
|
|
77
|
+
return value // as is
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Use to return displayed values in scientific notation
|
|
81
|
+
* Do not use for values intended for calculation later.
|
|
82
|
+
*/
|
|
83
|
+
export function formatValue(value, digits) {
|
|
84
|
+
const v = Number(value)
|
|
85
|
+
if (Number.isInteger(v)) return v
|
|
86
|
+
const abs = Math.abs(v)
|
|
87
|
+
if (abs < 1 || abs > 9999) {
|
|
88
|
+
//Number() reverts positive values less than 10^21 to a whole number
|
|
89
|
+
//To return the value in scientific notation, use toPrecision without Number()
|
|
90
|
+
return abs > 9999 ? v.toPrecision(digits) : Number(v.toPrecision(digits))
|
|
91
|
+
}
|
|
92
|
+
return Number(v.toFixed(digits))
|
|
93
|
+
}
|