@sjcrh/proteinpaint-shared 2.169.0 → 2.170.1

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.169.0",
3
+ "version": "2.170.1",
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/common.js CHANGED
@@ -1323,9 +1323,7 @@ const dtTerms_temp = [
1323
1323
  isleaf: true,
1324
1324
  type: 'dtsnvindel',
1325
1325
  dt: dtsnvindel,
1326
- values: Object.fromEntries(
1327
- mutationClasses.filter(key => key != 'Blank' && key != 'WT').map(key => [key, { label: mclass[key].label }])
1328
- )
1326
+ values: {}
1329
1327
  },
1330
1328
  {
1331
1329
  id: 'cnv',
@@ -1335,7 +1333,7 @@ const dtTerms_temp = [
1335
1333
  isleaf: true,
1336
1334
  type: 'dtcnv',
1337
1335
  dt: dtcnv,
1338
- values: Object.fromEntries(CNVClasses.map(key => [key, { label: mclass[key].label }]))
1336
+ values: {}
1339
1337
  },
1340
1338
  {
1341
1339
  id: 'fusion',
@@ -1345,7 +1343,7 @@ const dtTerms_temp = [
1345
1343
  isleaf: true,
1346
1344
  type: 'dtfusion',
1347
1345
  dt: dtfusionrna,
1348
- values: { [mclassfusionrna]: { label: mclass[mclassfusionrna].label } }
1346
+ values: {}
1349
1347
  },
1350
1348
  {
1351
1349
  id: 'sv',
@@ -1355,7 +1353,7 @@ const dtTerms_temp = [
1355
1353
  isleaf: true,
1356
1354
  type: 'dtsv',
1357
1355
  dt: dtsv,
1358
- values: { [mclasssv]: { label: mclass[mclasssv].label } }
1356
+ values: {}
1359
1357
  }
1360
1358
  ]
1361
1359
  // add origin annotations to dt terms
@@ -15,8 +15,9 @@ import { encode } from './urljson.js'
15
15
  init{headers?, body?}
16
16
  - first two arguments are same as native fetch
17
17
  */
18
- export async function ezFetch(_url, init = {}) {
19
- const url = mayAdjustRequest(_url, init)
18
+ export async function ezFetch(_url, init = {}, opts = {}) {
19
+ const url = opts.autoMethod ? mayAdjustRequest(_url, init) : _url
20
+ if (typeof init.body === 'object') init.body = JSON.stringify(init.body)
20
21
 
21
22
  return fetch(url, init).then(async r => {
22
23
  const response = await processResponse(r)
@@ -73,6 +74,9 @@ export async function processResponse(r) {
73
74
  if (ct.startsWith('multipart/form-data')) return processFormData(r)
74
75
  else throw `cannot handle response content-type: '${ct}'`
75
76
  }
77
+ if (ct == 'application/x-ndjson-nestedkey') {
78
+ return processNDJSON_nestedKey(r)
79
+ }
76
80
  // call blob() as catch-all
77
81
  // https://developer.mozilla.org/en-US/docs/Web/API/Response
78
82
  return r.blob()
@@ -115,6 +119,44 @@ export async function processFormData(res) {
115
119
  }
116
120
  }
117
121
 
122
+ async function processNDJSON_nestedKey(r) {
123
+ // 1. Pipe through TextDecoder to convert bytes to text
124
+ const stream = r.body.pipeThrough(new TextDecoderStream())
125
+ const reader = stream.getReader()
126
+ let rootObj = {}
127
+
128
+ let buffer = ''
129
+
130
+ while (true) {
131
+ const { value, done } = await reader.read()
132
+ if (done) break
133
+
134
+ // 2. Add new chunk to buffer
135
+ buffer += value
136
+
137
+ // 3. Split by newline
138
+ let parts = buffer.split('\n')
139
+
140
+ // 4. Keep the last partial line in the buffer
141
+ buffer = parts.pop()
142
+
143
+ // 5. Process complete lines
144
+ for (const line of parts) {
145
+ if (line.trim()) {
146
+ const [keys, data] = JSON.parse(line) //; console.log(143, keys, data) // Process JSON data
147
+ if (!keys.length) rootObj = data
148
+ else {
149
+ const lastKey = keys.pop()
150
+ let target = rootObj
151
+ for (const k of keys) target = target[k]
152
+ target[lastKey] = data
153
+ }
154
+ }
155
+ }
156
+ }
157
+ return rootObj
158
+ }
159
+
118
160
  // key: request object reference or conputed string dataName
119
161
  // value: fetch promise or response
120
162
  const dataCache = new Map()
@@ -145,6 +187,7 @@ const maxNumOfDataKeys = 360
145
187
  - if not provided, then a string cache data key will be computed from the request url, body, headers
146
188
  */
147
189
  export async function memFetch(url, init, opts = {}) {
190
+ if (typeof init.body === 'object') init.body = JSON.stringify(init.body)
148
191
  const dataKey = opts.q || (await getDataName(url, init))
149
192
  let result = dataCache.get(dataKey)
150
193
 
@@ -161,8 +204,13 @@ export async function memFetch(url, init, opts = {}) {
161
204
  fetch(url, init).then(async r => {
162
205
  const response = await processResponse(r)
163
206
  if (!r.ok) {
164
- console.log(response)
165
- throw 'memFetch error ' + r.status
207
+ console.trace(response)
208
+ throw (
209
+ 'memFetch error ' +
210
+ r.status +
211
+ ': ' +
212
+ (typeof response == 'object' ? response.message || response.error : response)
213
+ )
166
214
  }
167
215
  // to-do: support opt.freeze to enforce deep freeze of data.json()
168
216
  dataCache.set(dataKey, response)
package/src/index.js CHANGED
@@ -9,6 +9,7 @@ export * from './filter.js'
9
9
  export * from './hash.js'
10
10
  export * from './helpers.js'
11
11
  export * from './joinUrl.js'
12
+ export * from './manhattan.js'
12
13
  export * from './mds3tk.js'
13
14
  export * from './roundValue.js'
14
15
  export * from './termdb.bins.js'
@@ -0,0 +1,3 @@
1
+ // Contains shared constants for Manhattan plots
2
+ // This constant defines the log cutoff for q-values in Manhattan plots before scaling the y-axis.
3
+ export const MANHATTAN_LOG_QVALUE_CUTOFF = 40
@@ -20,7 +20,8 @@ export const graphableTypes = new Set([
20
20
  TermTypes.METABOLITE_INTENSITY,
21
21
  TermTypes.SINGLECELL_GENE_EXPRESSION,
22
22
  TermTypes.SINGLECELL_CELLTYPE,
23
- TermTypes.SNP
23
+ TermTypes.SNP,
24
+ TermTypes.TERM_COLLECTION
24
25
  ])
25
26
 
26
27
  /*