@sjcrh/proteinpaint-server 2.198.0 → 2.200.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.
@@ -1,120 +0,0 @@
1
- import { dtTermTypes } from '#shared/terms.js'
2
-
3
- /*
4
- f{}
5
- filter object
6
- returns a GDC filter object, or null if no filter
7
-
8
- GDC filter: https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/
9
- */
10
- export function filter2GDCfilter(f, level = 0) {
11
- // gdc filter that will be returned
12
- let obj = {
13
- op: f.join || 'and',
14
- content: []
15
- }
16
- if (!Array.isArray(f.lst)) throw new Error('filter.lst[] not array')
17
- if (f.in === false) throw `negation of nested filters is not supported`
18
-
19
- for (const item of f.lst) {
20
- if (item.type != 'tvs') {
21
- const f = filter2GDCfilter(item, level + 1)
22
- if (f) obj.content.push(f)
23
- continue
24
- }
25
- if (!item.tvs) throw new Error('item.tvs missing')
26
- if (!item.tvs.term) throw new Error('item.tvs.term missing')
27
- if (dtTermTypes.has(item.tvs.term.type)) {
28
- if (level > 0) throw new Error(`geneVariant filters are only supported at the root level of a nested filter`)
29
- // geneVariant/dt term filtering will be performed during post-processing
30
- // (see mayFilterByGeneVariant() in server/src/mds3.init.js)
31
- continue
32
- }
33
- if (item.tvs.term.type == 'geneExpression') {
34
- if (level > 0) throw new Error(`gene expression filters are only supported at the root level of a nested filter`)
35
- // geneExpression term filtering will be performed during post-processing (see mayFilterByExpression() in server/src/mds3.gdc.js)
36
- continue
37
- }
38
- if (item.tvs.term.type == 'survival') {
39
- if (level > 0) throw new Error(`survival filters are only supported at the root level of a nested filter`)
40
- // survival term filtering will be performed during post-processing (see mayFilterBySurvival() in server/src/mds3.gdc.js)
41
- continue
42
- }
43
-
44
- // sometimes, numeric filters have a values entry
45
- if (item.tvs.values && !item.tvs.ranges) {
46
- // categorical
47
- const f = {
48
- op: item.tvs.isnot ? '!=' : 'in',
49
- content: {
50
- field: mayChangeCase2Cases(item.tvs.term),
51
- value: item.tvs.values.map(i => i.key)
52
- }
53
- }
54
- obj.content.push(f)
55
- continue
56
- }
57
- if (item.tvs.ranges) {
58
- let f
59
- if (!item.tvs.ranges.length) throw new Error('item.tvs.ranges[] is empty')
60
- if (item.tvs.ranges.length == 1) {
61
- const range = item.tvs.ranges[0]
62
- f = range2GDCrange(range, item)
63
- } else {
64
- f = { op: 'or', content: [] }
65
- for (const range of item.tvs.ranges) {
66
- f.content.push(range2GDCrange(range, item))
67
- }
68
- }
69
- //if (item.tvs.isnot) f = { op: '!=', content: f }
70
- obj.content.push(f)
71
- continue
72
- }
73
- throw new Error('unknown tvs structure when converting to gdc filter')
74
- }
75
- //if (!level) console.log(JSON.stringify(obj, null, ' '))
76
- return obj.content.length ? obj : null
77
- }
78
-
79
- /*
80
- input: case.disease_type
81
- output: cases.disease_type
82
-
83
- when a term id begins with "case"
84
- for the term to be used as a field in filter,
85
- it must be written as "cases"
86
- */
87
- function mayChangeCase2Cases(t) {
88
- const s = t.id || t.name
89
- const l = s.split('.')
90
- if (l[0] == 'case') l[0] = 'cases'
91
- return l.join('.')
92
- }
93
-
94
- function range2GDCrange(range, item) {
95
- if (range.startunbounded) {
96
- return {
97
- op: range.stopinclusive ? (item.tvs.isnot ? '>' : '<=') : item.tvs.isnot ? '>=' : '<',
98
- content: { field: mayChangeCase2Cases(item.tvs.term), value: range.stop }
99
- }
100
- }
101
- if (range.stopunbounded) {
102
- return {
103
- op: range.startinclusive ? (item.tvs.isnot ? '<' : '>=') : item.tvs.isnot ? '<=' : '>',
104
- content: { field: mayChangeCase2Cases(item.tvs.term), value: range.start }
105
- }
106
- }
107
- return {
108
- op: 'and',
109
- content: [
110
- {
111
- op: range.startinclusive ? (item.tvs.isnot ? '<' : '>=') : item.tvs.isnot ? '>=' : '>',
112
- content: { field: mayChangeCase2Cases(item.tvs.term), value: range.start }
113
- },
114
- {
115
- op: range.stopinclusive ? (item.tvs.isnot ? '>' : '<=') : item.tvs.isnot ? '<=' : '<',
116
- content: { field: mayChangeCase2Cases(item.tvs.term), value: range.stop }
117
- }
118
- ]
119
- }
120
- }