@sjcrh/proteinpaint-shared 2.180.0 → 2.180.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.
@@ -1,29 +1,34 @@
1
- import { TermTypes, isNumericTerm, SINGLECELL_CELLTYPE, SINGLECELL_GENE_EXPRESSION } from './terms.js'
1
+ import {
2
+ TermTypes,
3
+ isNumericTerm,
4
+ SINGLECELL_CELLTYPE,
5
+ SINGLECELL_GENE_EXPRESSION,
6
+ } from "./terms.js"
2
7
 
3
8
  export const graphableTypes = new Set([
4
- 'categorical',
5
- 'integer',
6
- 'float',
7
- 'condition',
8
- 'survival',
9
- 'snplst',
10
- 'snplocus',
11
- 'geneVariant',
12
- 'samplelst',
13
- 'geneExpression',
14
- 'dtcnv',
15
- 'dtsnvindel',
16
- 'dtfusion',
17
- 'dtsv',
18
- 'date',
9
+ "categorical",
10
+ "integer",
11
+ "float",
12
+ "condition",
13
+ "survival",
14
+ "snplst",
15
+ "snplocus",
16
+ "geneVariant",
17
+ "samplelst",
18
+ "geneExpression",
19
+ "dtcnv",
20
+ "dtsnvindel",
21
+ "dtfusion",
22
+ "dtsv",
23
+ "date",
19
24
  TermTypes.SSGSEA,
20
25
  TermTypes.DNA_METHYLATION,
21
26
  TermTypes.METABOLITE_INTENSITY,
22
- TermTypes.WHOLE_PROTEOME_ABUNDANCE,
27
+ TermTypes.PROTEOME_ABUNDANCE,
23
28
  SINGLECELL_GENE_EXPRESSION,
24
29
  SINGLECELL_CELLTYPE,
25
30
  TermTypes.SNP,
26
- TermTypes.TERM_COLLECTION
31
+ TermTypes.TERM_COLLECTION,
27
32
  ])
28
33
 
29
34
  /*
@@ -68,7 +73,7 @@ export function isUsableTerm(term, _usecase, termdbConfig, ds) {
68
73
  const usecase = _usecase || {}
69
74
 
70
75
  // may apply dataset specific override filter for a use case
71
- if (typeof ds?.usecase?.[usecase.target] == 'function') {
76
+ if (typeof ds?.usecase?.[usecase.target] == "function") {
72
77
  return ds.usecase[usecase.target](term, usecase)
73
78
  }
74
79
 
@@ -79,41 +84,41 @@ export function isUsableTerm(term, _usecase, termdbConfig, ds) {
79
84
  const child_types = term.child_types || []
80
85
  // default handling
81
86
  switch (usecase.target) {
82
- case 'barchart':
83
- case 'violin':
84
- case 'boxplot':
85
- case 'summary':
86
- if (term.type && term.type !== 'survival') uses.add('plot')
87
- if (hasAllowedChildTypes(child_types, ['survival'])) uses.add('branch')
87
+ case "barchart":
88
+ case "violin":
89
+ case "boxplot":
90
+ case "summary":
91
+ if (term.type && term.type !== "survival") uses.add("plot")
92
+ if (hasAllowedChildTypes(child_types, ["survival"])) uses.add("branch")
88
93
  return uses
89
94
 
90
- case 'summaryInput':
91
- if (usecase.detail === 'term2' || usecase.detail == 'term0') {
92
- if (term.type && term.type !== 'survival') uses.add('plot')
93
- if (hasAllowedChildTypes(child_types, ['survival'])) uses.add('branch')
95
+ case "summaryInput":
96
+ if (usecase.detail === "term2" || usecase.detail == "term0") {
97
+ if (term.type && term.type !== "survival") uses.add("plot")
98
+ if (hasAllowedChildTypes(child_types, ["survival"])) uses.add("branch")
94
99
  return uses
95
100
  } else {
96
- if (graphableTypes.has(term.type)) uses.add('plot')
97
- if (!term.isleaf) uses.add('branch')
101
+ if (graphableTypes.has(term.type)) uses.add("plot")
102
+ if (!term.isleaf) uses.add("branch")
98
103
  return uses
99
104
  }
100
105
 
101
- case 'matrix':
102
- if (term.type) uses.add('plot')
103
- if (!term.isleaf) uses.add('branch')
106
+ case "matrix":
107
+ if (term.type) uses.add("plot")
108
+ if (!term.isleaf) uses.add("branch")
104
109
  return uses
105
110
 
106
- case 'table':
107
- if (usecase.detail == 'term') uses.add('plot')
108
- if (child_types.length > 1) uses.add('branch')
111
+ case "table":
112
+ if (usecase.detail == "term") uses.add("plot")
113
+ if (child_types.length > 1) uses.add("branch")
109
114
  return uses
110
115
 
111
- case 'sampleScatter':
112
- if (usecase.detail == 'numeric') {
116
+ case "sampleScatter":
117
+ if (usecase.detail == "numeric") {
113
118
  if (isNumericTerm(term)) {
114
- uses.add('plot')
119
+ uses.add("plot")
115
120
  }
116
- if (hasNumericChild(child_types)) uses.add('branch')
121
+ if (hasNumericChild(child_types)) uses.add("branch")
117
122
  }
118
123
  // Commenting out for now. May need later for another single
119
124
  // cell term. Revisit logic at that time.
@@ -125,49 +130,38 @@ export function isUsableTerm(term, _usecase, termdbConfig, ds) {
125
130
  // }
126
131
  // }
127
132
  else {
128
- if (graphableTypes.has(term.type)) uses.add('plot')
129
- if (!term.isleaf) uses.add('branch')
133
+ if (graphableTypes.has(term.type)) uses.add("plot")
134
+ if (!term.isleaf) uses.add("branch")
130
135
  }
131
136
  return uses
132
- case 'runChart2':
133
- if (usecase.detail == 'date' || usecase.detail == 'xtw') {
134
- if (term.type == 'date') {
135
- uses.add('plot')
137
+ case "runChart2":
138
+ if (usecase.detail == "date" || usecase.detail == "xtw") {
139
+ if (term.type == "date") {
140
+ uses.add("plot")
136
141
  }
137
- if (child_types.includes('date')) uses.add('branch')
138
- } else if (usecase.detail == 'numeric') {
139
- if (isNumericTerm(term) && term.type != 'date') {
140
- uses.add('plot')
142
+ if (child_types.includes("date")) uses.add("branch")
143
+ } else if (usecase.detail == "numeric") {
144
+ if (isNumericTerm(term) && term.type != "date") {
145
+ uses.add("plot")
141
146
  }
142
- if (hasNumericChild(child_types)) uses.add('branch')
147
+ if (hasNumericChild(child_types)) uses.add("branch")
143
148
  } else {
144
- if (graphableTypes.has(term.type)) uses.add('plot')
145
- if (!term.isleaf) uses.add('branch')
146
- }
147
- return uses
148
- case 'numericDictTermCluster':
149
- if (!usecase.detail?.exclude?.includes(term.id)) {
150
- if (isNumericTerm(term)) {
151
- uses.add('plot')
152
- }
153
- if (hasNumericChild(child_types)) {
154
- uses.add('branch')
155
- }
149
+ if (graphableTypes.has(term.type)) uses.add("plot")
150
+ if (!term.isleaf) uses.add("branch")
156
151
  }
157
152
  return uses
158
-
159
- case 'termCollections':
160
- if (usecase.detail?.termIds?.includes(term.id)) uses.add('plot')
161
- if (usecase.detail?.branchIds?.includes(term.id)) uses.add('branch')
153
+ case "termCollections":
154
+ if (usecase.detail?.termIds?.includes(term.id)) uses.add("plot")
155
+ if (usecase.detail?.branchIds?.includes(term.id)) uses.add("branch")
162
156
  return uses
163
157
 
164
- case 'profileForms':
158
+ case "profileForms":
165
159
  if (!term.isleaf) {
166
- const ancestors = term.id.split('__').length //depends on using the __ naming convension!
160
+ const ancestors = term.id.split("__").length //depends on using the __ naming convension!
167
161
  if (ancestors == 3) {
168
162
  // 3rd level term is a domain, we show the templates associated to this domain
169
- uses.add('plot')
170
- } else if (ancestors < 3) uses.add('branch')
163
+ uses.add("plot")
164
+ } else if (ancestors < 3) uses.add("branch")
171
165
  }
172
166
  return uses
173
167
 
@@ -176,87 +170,102 @@ export function isUsableTerm(term, _usecase, termdbConfig, ds) {
176
170
  // if (usecase.detail === 'term2' && hasNumericChild(child_types)) uses.add('branch')
177
171
  // return uses
178
172
 
179
- case 'cuminc':
180
- if (usecase.detail == 'term') {
181
- if (term.type == 'condition') uses.add('plot')
182
- if (child_types.includes('condition')) uses.add('branch')
173
+ case "cuminc":
174
+ if (usecase.detail == "term") {
175
+ if (term.type == "condition") uses.add("plot")
176
+ if (child_types.includes("condition")) uses.add("branch")
183
177
  return uses
184
178
  }
185
- if (usecase.detail === 'term2' || usecase.detail == 'term0') {
186
- if (term.type && term.type != 'condition' && term.type != 'survival') uses.add('plot')
187
- if (hasAllowedChildTypes(child_types, ['condition', 'survival'])) uses.add('branch')
179
+ if (usecase.detail === "term2" || usecase.detail == "term0") {
180
+ if (term.type && term.type != "condition" && term.type != "survival")
181
+ uses.add("plot")
182
+ if (hasAllowedChildTypes(child_types, ["condition", "survival"]))
183
+ uses.add("branch")
188
184
  return uses
189
185
  }
190
186
  return uses
191
187
 
192
- case 'survival':
193
- if (usecase.detail == 'term') {
194
- if (term.type == 'survival') uses.add('plot')
195
- if (child_types.includes('survival')) uses.add('branch')
188
+ case "survival":
189
+ if (usecase.detail == "term") {
190
+ if (term.type == "survival") uses.add("plot")
191
+ if (child_types.includes("survival")) uses.add("branch")
196
192
  return uses
197
193
  }
198
- if (usecase.detail === 'term2' || usecase.detail == 'term0') {
199
- if (term.type && term.type != 'survival') uses.add('plot')
200
- if (hasAllowedChildTypes(child_types, ['survival'])) uses.add('branch')
194
+ if (usecase.detail === "term2" || usecase.detail == "term0") {
195
+ if (term.type && term.type != "survival") uses.add("plot")
196
+ if (hasAllowedChildTypes(child_types, ["survival"])) uses.add("branch")
201
197
  return uses
202
198
  }
203
199
  return uses
204
200
 
205
- case 'regression':
206
- if (usecase.detail == 'outcome') {
207
- if (usecase.regressionType == 'linear') {
208
- if (term.type == 'float' || term.type == 'integer') uses.add('plot')
209
- if (hasNumericChild(child_types)) uses.add('branch')
201
+ case "regression":
202
+ if (usecase.detail == "outcome") {
203
+ if (usecase.regressionType == "linear") {
204
+ if (term.type == "float" || term.type == "integer") uses.add("plot")
205
+ if (hasNumericChild(child_types)) uses.add("branch")
210
206
  return uses
211
207
  }
212
- if (usecase.regressionType == 'logistic') {
213
- if (term.type && term.type != 'survival') uses.add('plot')
214
- if (hasAllowedChildTypes(child_types, ['survival'])) uses.add('branch')
208
+ if (usecase.regressionType == "logistic") {
209
+ if (term.type && term.type != "survival") uses.add("plot")
210
+ if (hasAllowedChildTypes(child_types, ["survival"]))
211
+ uses.add("branch")
215
212
  return uses
216
- } else if (usecase.regressionType == 'cox') {
217
- if (term.type == 'condition' || term.type == 'survival') uses.add('plot')
218
- if (child_types.includes('condition') || child_types.includes('survival')) uses.add('branch')
213
+ } else if (usecase.regressionType == "cox") {
214
+ if (term.type == "condition" || term.type == "survival")
215
+ uses.add("plot")
216
+ if (
217
+ child_types.includes("condition") ||
218
+ child_types.includes("survival")
219
+ )
220
+ uses.add("branch")
219
221
  return uses
220
222
  }
221
223
  }
222
224
 
223
- if (usecase.detail == 'independent') {
224
- if (term.type == 'float' || term.type == 'integer' || term.type == 'categorical' || term.type == 'samplelst')
225
- uses.add('plot')
226
- if (hasChildTypes(child_types, ['categorical', 'float', 'integer'])) uses.add('branch')
225
+ if (usecase.detail == "independent") {
226
+ if (
227
+ term.type == "float" ||
228
+ term.type == "integer" ||
229
+ term.type == "categorical" ||
230
+ term.type == "samplelst"
231
+ )
232
+ uses.add("plot")
233
+ if (hasChildTypes(child_types, ["categorical", "float", "integer"]))
234
+ uses.add("branch")
227
235
  return uses
228
236
  }
229
237
  return uses
230
238
 
231
- case 'filter': {
239
+ case "filter": {
232
240
  // apply "exlst" to other targets as needed
233
241
  const exlst = termdbConfig?.excludedTermtypeByTarget?.filter
234
242
  if (exlst) {
235
- if (graphableTypes.has(term.type) && !exlst.includes(term.type)) uses.add('plot')
236
- if (child_types.find(t => !exlst.includes(t))) uses.add('branch') // there's a non-excluded child type, allow branch to show
243
+ if (graphableTypes.has(term.type) && !exlst.includes(term.type))
244
+ uses.add("plot")
245
+ if (child_types.find((t) => !exlst.includes(t))) uses.add("branch") // there's a non-excluded child type, allow branch to show
237
246
  return uses
238
247
  }
239
248
  // no specific rule for filter. use default rules
240
- if (graphableTypes.has(term.type)) uses.add('plot')
241
- if (!term.isleaf) uses.add('branch')
249
+ if (graphableTypes.has(term.type)) uses.add("plot")
250
+ if (!term.isleaf) uses.add("branch")
242
251
  return uses
243
252
  }
244
253
 
245
- case 'correlationVolcano':
246
- if (usecase.detail == 'numeric') {
254
+ case "correlationVolcano":
255
+ if (usecase.detail == "numeric") {
247
256
  if (isNumericTerm(term)) {
248
- uses.add('plot')
257
+ uses.add("plot")
249
258
  }
250
- if (hasNumericChild(child_types)) uses.add('branch')
259
+ if (hasNumericChild(child_types)) uses.add("branch")
251
260
  } else {
252
- if (graphableTypes.has(term.type)) uses.add('plot')
253
- if (!term.isleaf) uses.add('branch')
261
+ if (graphableTypes.has(term.type)) uses.add("plot")
262
+ if (!term.isleaf) uses.add("branch")
254
263
  }
255
264
  return uses
256
265
 
257
266
  default:
258
- if (graphableTypes.has(term.type)) uses.add('plot')
259
- if (!term.isleaf) uses.add('branch')
267
+ if (graphableTypes.has(term.type)) uses.add("plot")
268
+ if (!term.isleaf) uses.add("branch")
260
269
  return uses
261
270
  }
262
271
  }
@@ -272,14 +281,14 @@ function hasAllowedChildTypes(child_types, excluded_types) {
272
281
  // no excluded types
273
282
  return true
274
283
  }
275
- if (child_types.some(type => !excluded_types.includes(type))) {
284
+ if (child_types.some((type) => !excluded_types.includes(type))) {
276
285
  // at least one child type is not excluded
277
286
  return true
278
287
  }
279
288
  }
280
289
 
281
290
  function hasNumericChild(child_types) {
282
- return child_types.includes('float') || child_types.includes('integer')
291
+ return child_types.includes("float") || child_types.includes("integer")
283
292
  }
284
293
 
285
294
  function hasChildTypes(child_types, expected_types) {