@sjcrh/proteinpaint-shared 2.119.0 → 2.121.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/README.md CHANGED
@@ -38,5 +38,9 @@ keep doing this until a dev script or another approach can take care of the `.js
38
38
  ## Test
39
39
 
40
40
  ```sh
41
+ # run all tests
41
42
  npm test
43
+
44
+ # run one script
45
+ node test/mds3tk.unit.spec.js
42
46
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.119.0",
3
+ "version": "2.121.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",
package/src/mds3tk.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { dtcnv } from './common.js'
2
+
1
3
  // this script should contain mds3 track-related stuff shared between client and backend
2
4
 
3
5
  /*
@@ -14,3 +16,36 @@ svfusion: dt + chr + pos + strand + pairlstidx + mname
14
16
  the separator must avoid conflicting with characters from gene names, and can be changed based on needs
15
17
  */
16
18
  export const ssmIdFieldsSeparator = '__'
19
+
20
+ /*
21
+ input: array of mixture of ssm, svfusion and cnv
22
+
23
+ output: sorted array. each element: [ class/dt, count of m ]
24
+ */
25
+ export function summarize_mclass(mlst) {
26
+ const m2c = new Map() // k: mclass, v: {}
27
+ const cnvs = []
28
+ for (const m of mlst) {
29
+ if (m.dt == dtcnv) {
30
+ cnvs.push(m)
31
+ continue // process cnv later
32
+ }
33
+ // snvindel has m.class=str, svfusion has only dt=int
34
+ const key = m.class || m.dt
35
+ m2c.set(key, 1 + (m2c.get(key) || 0))
36
+ }
37
+
38
+ if (cnvs.length) {
39
+ if (Number.isFinite(cnvs[0].value)) {
40
+ // first cnv uses numeric value (assumes all the same). record by dt
41
+ m2c.set(dtcnv, cnvs.length)
42
+ } else {
43
+ // cnv not numeric and uses class; record by each class
44
+ for (const c of cnvs) {
45
+ if (!c.class) continue // should not happen
46
+ m2c.set(c.class, 1 + (m2c.get(c.class) || 0))
47
+ }
48
+ }
49
+ }
50
+ return [...m2c].sort((i, j) => j[1] - i[1])
51
+ }