@sjcrh/proteinpaint-shared 2.166.0 → 2.167.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/mds3tk.js +48 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.166.0",
3
+ "version": "2.167.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,4 +1,4 @@
1
- import { dtcnv } from './common.js'
1
+ import { dtcnv, dtsnvindel, dtsv, dtfusionrna } from './common.js'
2
2
 
3
3
  // this script should contain mds3 track-related stuff shared between client and backend
4
4
 
@@ -49,3 +49,50 @@ export function summarize_mclass(mlst) {
49
49
  }
50
50
  return [...m2c].sort((i, j) => j[1] - i[1])
51
51
  }
52
+
53
+ /*
54
+ ssmid is not specific for ssm, it covers all alterations
55
+ gdc ssm are identified by a specific uuid, thus the design
56
+ */
57
+ export function guessSsmid(ssmid) {
58
+ const l = ssmid.split(ssmIdFieldsSeparator)
59
+ if (l.length == 4) {
60
+ const [chr, tmp, ref, alt] = l
61
+ const pos = Number(tmp)
62
+ if (Number.isNaN(pos)) throw 'ssmid snvindel pos not integer'
63
+ return { dt: dtsnvindel, l: [chr, pos, ref, alt] }
64
+ }
65
+ if (l.length == 5) {
66
+ // cnv. if type=cat, _value is blank string
67
+ const [chr, _start, _stop, _class, _value] = l
68
+ const start = Number(_start),
69
+ stop = Number(_stop),
70
+ value = _value == '' ? null : Number(_value)
71
+ if (Number.isNaN(start) || Number.isNaN(stop)) throw 'ssmid cnv start/stop not integer'
72
+ return { dt: dtcnv, l: [chr, start, stop, _class, value] }
73
+ }
74
+ if (l.length == 6) {
75
+ if (l[3] == '+' || l[3] == '-') {
76
+ // sv/fusion
77
+ const [_dt, chr, _pos, strand, _pi, _mname] = l
78
+
79
+ // mname is encoded in case it contains comma (and is same as ssmIdFieldsSeparator)
80
+ const mname = decodeURIComponent(_mname)
81
+ const dt = Number(_dt)
82
+ if (dt != dtsv && dt != dtfusionrna) throw 'ssmid dt not sv/fusion'
83
+ const pos = Number(_pos)
84
+ if (Number.isNaN(pos)) throw 'ssmid svfusion position not integer'
85
+ const pairlstIdx = Number(_pi)
86
+ if (Number.isNaN(pairlstIdx)) throw 'ssmid pairlstIdx not integer'
87
+ return { dt, l: [dt, chr, pos, strand, pairlstIdx, mname] }
88
+ }
89
+ // cnv with sample
90
+ const [chr, _start, _stop, _class, _value, sample] = l
91
+ const start = Number(_start),
92
+ stop = Number(_stop),
93
+ value = _value == '' ? null : Number(_value) // if cnv not using value, must avoid `Number('')=0`
94
+ if (Number.isNaN(start) || Number.isNaN(stop)) throw 'ssmid cnv start/stop not integer'
95
+ return { dt: dtcnv, l: [chr, start, stop, _class, value, sample] }
96
+ }
97
+ throw 'unknown ssmid'
98
+ }