@sjcrh/proteinpaint-shared 2.111.0 → 2.112.1-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.111.0",
3
+ "version": "2.112.1-0",
4
4
  "description": "ProteinPaint code that is shared between server and client-side workspaces",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -2,7 +2,7 @@ import { roundValueAuto } from './roundValue.js'
2
2
 
3
3
  /* This file generates summary statistics on any given array of numbers*/
4
4
 
5
- export default function summaryStats(array) {
5
+ export function summaryStats(array) {
6
6
  //console.log("array:",array)
7
7
  let arr = array
8
8
  if (typeof array[0] == 'string') {
@@ -14,18 +14,12 @@ export default function summaryStats(array) {
14
14
  const sorted_arr = arr.sort((a, b) => a - b)
15
15
  const n = arr.length
16
16
 
17
- //compute mean
18
- function mean(arr) {
19
- if (arr.length === 0) throw new Error('No data provided')
20
- return arr.reduce((a, b) => a + b) / n
21
- }
22
-
23
17
  //compute median
24
18
  const median = computePercentile(sorted_arr, 50)
25
- const mean_arr = mean(sorted_arr)
26
- const squareDiffs = arr.map(x => (x - mean_arr) ** 2).reduce((a, b) => a + b, 0)
19
+ //compute mean
20
+ const mean = getMean(arr)
27
21
  // compute variance
28
- const variance = squareDiffs / (n - 1)
22
+ const variance = getVariance(sorted_arr)
29
23
  // compute standard deviation
30
24
  const stdDev = Math.sqrt(variance)
31
25
 
@@ -45,7 +39,7 @@ export default function summaryStats(array) {
45
39
  { id: 'min', label: 'Minimum', value: roundValueAuto(min, true) },
46
40
  { id: 'p25', label: '1st quartile', value: roundValueAuto(p25, true) },
47
41
  { id: 'median', label: 'Median', value: roundValueAuto(median, true) },
48
- { id: 'mean', label: 'Mean', value: roundValueAuto(mean(arr), true) },
42
+ { id: 'mean', label: 'Mean', value: roundValueAuto(mean, true) },
49
43
  { id: 'p75', label: '3rd quartile', value: roundValueAuto(p75, true) },
50
44
  { id: 'max', label: 'Maximum', value: roundValueAuto(max, true) },
51
45
  { id: 'SD', label: 'Standard deviation', value: roundValueAuto(stdDev, true) },
@@ -60,3 +54,18 @@ function computePercentile(values, percentile) {
60
54
  const value = Number.isInteger(index) ? (values[index] + values[index + 1]) / 2 : values[Math.ceil(index)]
61
55
  return value
62
56
  }
57
+
58
+ export function getMean(data) {
59
+ return data.reduce((sum, value) => sum + value, 0) / data.length
60
+ }
61
+
62
+ export function getVariance(data) {
63
+ const meanValue = getMean(data)
64
+ const squaredDifferences = data.map(value => Math.pow(value - meanValue, 2))
65
+ return squaredDifferences.reduce((sum, value) => sum + value, 0) / data.length
66
+ }
67
+
68
+ export function getStdDev(data) {
69
+ const variance = getVariance(data)
70
+ return Math.sqrt(variance)
71
+ }
package/src/roundValue.js CHANGED
@@ -22,10 +22,10 @@ export function roundValue(value, digits) {
22
22
  * TODO: Review digit logic.
23
23
  */
24
24
 
25
- export function roundValueAuto(value, format = false) {
25
+ export function roundValueAuto(value, format = false, defaultDigits = 2) {
26
26
  if (!value && value != 0) return value
27
27
  const dp = decimalPlacesUntilFirstNonZero(value)
28
- const digits = Math.abs(value) > 1 ? 2 : dp > 0 ? dp + 1 : 2
28
+ const digits = Math.abs(value) > 1 ? defaultDigits : dp > 0 ? dp + 1 : defaultDigits
29
29
  if (format) return formatValue(value, digits)
30
30
  return roundValue(value, digits)
31
31
  }
@@ -111,9 +111,10 @@ export function isUsableTerm(term, _usecase, termdbConfig, ds) {
111
111
  case 'profileForms':
112
112
  if (!term.isleaf) {
113
113
  const ancestors = term.id.split('__').length //depends on using the __ naming convension!
114
- if (ancestors == 2) {
114
+ if (ancestors == 3) {
115
+ // 3rd level term is a domain, we show the templates associated to this domain
115
116
  uses.add('plot')
116
- } else if (ancestors < 2) uses.add('branch')
117
+ } else if (ancestors < 3) uses.add('branch')
117
118
  }
118
119
  return uses
119
120