@sjcrh/proteinpaint-shared 2.83.0 → 2.85.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 +3 -1
- package/src/helpers.js +13 -3
- package/src/termdb.bins.js +19 -19
- package/src/urljson.js +1 -3
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1293,5 +1293,7 @@ export const colorScaleMap = {
|
|
|
1293
1293
|
blueBlackYellow: {
|
|
1294
1294
|
domain: [0, 0.17, 0.33, 0.5, 0.67, 0.83, 1],
|
|
1295
1295
|
range: ['#0000FF', '#0000CC', '#000099', '#202020', '#999900', '#CCCC00', '#FFFF00']
|
|
1296
|
-
}
|
|
1296
|
+
},
|
|
1297
|
+
// when hierCluster z-score transformation is not performed, should use two-color scale
|
|
1298
|
+
whiteRed: { domain: [0, 1], range: ['white', 'red'] }
|
|
1297
1299
|
}
|
package/src/helpers.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
2
|
this is a helper file with a collection of functions to be used in backend and client side code. Here is a list.
|
|
3
3
|
|
|
4
|
-
1. isNumeric(n)
|
|
5
|
-
2.
|
|
4
|
+
1. isNumeric(n)
|
|
5
|
+
2. strictNumeric(n)
|
|
6
|
+
2. convertUnits
|
|
6
7
|
3. TODO - move computepercentile, roundValue, etc here?
|
|
7
8
|
*/
|
|
8
9
|
|
|
10
|
+
// checks whether given argument n is Numeric, with option to cast from string
|
|
9
11
|
export function isNumeric(n) {
|
|
10
|
-
|
|
12
|
+
const v = typeof n != 'string' || n === '' ? n : Number(n)
|
|
13
|
+
const f = parseFloat(n)
|
|
14
|
+
return !isNaN(f) && Number.isFinite(v) && v === f
|
|
11
15
|
}
|
|
12
16
|
|
|
17
|
+
// like isNumeric but does not cast from string
|
|
18
|
+
export function isStrictNumeric(n) {
|
|
19
|
+
return typeof n === 'number' && Number.isFinite(n)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// converts a value from a unit to another unit
|
|
13
23
|
export function convertUnits(v, fromUnit, toUnit, scaleFactor, compact) {
|
|
14
24
|
// do floor() on toUnit
|
|
15
25
|
// do ceil() on fromUnit, in case v is decimal (from violin range selection) and to keep showing integer fromUnit
|
package/src/termdb.bins.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { format } from 'd3-format'
|
|
2
2
|
import { getColors } from './common.js'
|
|
3
|
-
import {
|
|
3
|
+
import { isStrictNumeric, convertUnits } from './helpers.js'
|
|
4
4
|
|
|
5
5
|
export default function validate_bins(binconfig) {
|
|
6
6
|
// Number.isFinite('1') returns false, which is desired
|
|
@@ -35,14 +35,14 @@ export default function validate_bins(binconfig) {
|
|
|
35
35
|
if (!('stop' in bin)) {
|
|
36
36
|
throw `a custom first bin must define a bin.stop value`
|
|
37
37
|
}
|
|
38
|
-
if (!
|
|
38
|
+
if (!isStrictNumeric(bin.stop)) {
|
|
39
39
|
throw `a custom first bin.stop value should be numeric`
|
|
40
40
|
}
|
|
41
41
|
} else if (bin == last_bin) {
|
|
42
42
|
if (!('start' in bin)) {
|
|
43
43
|
throw `a custom last bin must define a bin.start value`
|
|
44
44
|
}
|
|
45
|
-
if (!
|
|
45
|
+
if (!isStrictNumeric(bin.start)) {
|
|
46
46
|
throw `a custom last bin.start must be numeric`
|
|
47
47
|
}
|
|
48
48
|
if ('stopunbounded' in bin && !bin.stopunbounded) {
|
|
@@ -53,8 +53,8 @@ export default function validate_bins(binconfig) {
|
|
|
53
53
|
throw 'a custom last bin must not set a bin.stop value'
|
|
54
54
|
}
|
|
55
55
|
} else {
|
|
56
|
-
if (!
|
|
57
|
-
if (!
|
|
56
|
+
if (!isStrictNumeric(bin.start)) throw 'bin.start must be numeric for a non-first bin'
|
|
57
|
+
if (!isStrictNumeric(bin.stop)) throw 'bin.stop must be numeric for a non-last bin'
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
} else if (bc.type == 'regular-bin') {
|
|
@@ -156,19 +156,19 @@ summaryfxn (percentiles)=> return {min, max, pX, pY, ...}
|
|
|
156
156
|
? maxCeil // in order to include the max value in the last bin
|
|
157
157
|
: bc.last_bin.stop_percentile
|
|
158
158
|
? summary['p' + bc.last_bin.stop_percentile]
|
|
159
|
-
: isNumeric(bc.last_bin.stop) && bc.last_bin.stop <= summary.max
|
|
159
|
+
: isNumeric(bc.last_bin.stop) && bc.last_bin.stop <= summary.max // '0.0088' < 0.0088
|
|
160
160
|
? bc.last_bin.stop
|
|
161
161
|
: maxCeil // in order to include the max value in the last bin
|
|
162
|
-
last_start =
|
|
162
|
+
last_start = isStrictNumeric(bc.last_bin.start_percentile)
|
|
163
163
|
? summary['p' + bc.last_bin.start_percentile]
|
|
164
|
-
:
|
|
164
|
+
: isStrictNumeric(bc.last_bin.start)
|
|
165
165
|
? bc.last_bin.start
|
|
166
166
|
: undefined
|
|
167
167
|
last_stop = bc.last_bin.stopunbounded
|
|
168
168
|
? null
|
|
169
169
|
: bc.last_bin.stop_percentile
|
|
170
170
|
? summary['p' + bc.last_bin.stop_percentile]
|
|
171
|
-
:
|
|
171
|
+
: isStrictNumeric(bc.last_bin.stop)
|
|
172
172
|
? bc.last_bin.stop
|
|
173
173
|
: null
|
|
174
174
|
} else if (bc.lst) {
|
|
@@ -181,9 +181,9 @@ summaryfxn (percentiles)=> return {min, max, pX, pY, ...}
|
|
|
181
181
|
last_stop = maxCeil
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
const numericMax =
|
|
185
|
-
const numericLastStart =
|
|
186
|
-
const numericLastStop =
|
|
184
|
+
const numericMax = isStrictNumeric(max)
|
|
185
|
+
const numericLastStart = isStrictNumeric(last_start)
|
|
186
|
+
const numericLastStop = isStrictNumeric(last_stop)
|
|
187
187
|
|
|
188
188
|
if (!numericMax && !numericLastStart) return [] //throw 'unable to compute the last bin start or stop'
|
|
189
189
|
|
|
@@ -191,16 +191,16 @@ summaryfxn (percentiles)=> return {min, max, pX, pY, ...}
|
|
|
191
191
|
let currBin = {
|
|
192
192
|
startunbounded: bc.first_bin.startunbounded,
|
|
193
193
|
start: bc.first_bin.startunbounded ? undefined : min,
|
|
194
|
-
stop:
|
|
194
|
+
stop: isStrictNumeric(bc.first_bin.stop_percentile)
|
|
195
195
|
? +summary['p' + bc.first_bin.stop_percentile]
|
|
196
|
-
:
|
|
196
|
+
: isStrictNumeric(bc.first_bin.stop)
|
|
197
197
|
? +bc.first_bin.stop
|
|
198
198
|
: min + bc.bin_size,
|
|
199
199
|
startinclusive: bc.startinclusive,
|
|
200
200
|
stopinclusive: bc.stopinclusive
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
if (!
|
|
203
|
+
if (!isStrictNumeric(currBin.stop)) throw 'the computed first_bin.stop is non-numeric' + currBin.stop
|
|
204
204
|
const maxNumBins = 100 // harcoded limit for now to not stress sqlite
|
|
205
205
|
|
|
206
206
|
while ((numericMax && currBin.stop <= max) || (currBin.startunbounded && !bins.length) || currBin.stopunbounded) {
|
|
@@ -372,10 +372,10 @@ export function get_bin_range_equation(bin, binconfig) {
|
|
|
372
372
|
export function target_percentiles(binconfig) {
|
|
373
373
|
const percentiles = []
|
|
374
374
|
const f = binconfig.first_bin
|
|
375
|
-
if (f &&
|
|
376
|
-
if (f &&
|
|
375
|
+
if (f && isStrictNumeric(f.start_percentile)) percentiles.push(f.start_percentile)
|
|
376
|
+
if (f && isStrictNumeric(f.stop_percentile)) percentiles.push(f.stop_percentile)
|
|
377
377
|
const l = binconfig.last_bin
|
|
378
|
-
if (l &&
|
|
379
|
-
if (l &&
|
|
378
|
+
if (l && isStrictNumeric(l.start_percentile)) percentiles.push(l.start_percentile)
|
|
379
|
+
if (l && isStrictNumeric(l.stop_percentile)) percentiles.push(l.stop_percentile)
|
|
380
380
|
return percentiles
|
|
381
381
|
}
|
package/src/urljson.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNumeric } from "./helpers.js";
|
|
1
2
|
const reserved = ["false", "true", "null", "undefined"];
|
|
2
3
|
const delimiters = ['"', "{", "["];
|
|
3
4
|
function encode(rawObject) {
|
|
@@ -23,9 +24,6 @@ function decode(query) {
|
|
|
23
24
|
}
|
|
24
25
|
return query;
|
|
25
26
|
}
|
|
26
|
-
function isNumeric(d) {
|
|
27
|
-
return !isNaN(parseFloat(d)) && isFinite(d) && d !== "";
|
|
28
|
-
}
|
|
29
27
|
export {
|
|
30
28
|
decode,
|
|
31
29
|
encode
|