@sjcrh/proteinpaint-shared 2.178.1-0 → 2.180.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.178.1-0",
3
+ "version": "2.180.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",
@@ -1,4 +1,4 @@
1
- import { TermTypes, isNumericTerm } from './terms.js'
1
+ import { TermTypes, isNumericTerm, SINGLECELL_CELLTYPE, SINGLECELL_GENE_EXPRESSION } from './terms.js'
2
2
 
3
3
  export const graphableTypes = new Set([
4
4
  'categorical',
@@ -20,8 +20,8 @@ export const graphableTypes = new Set([
20
20
  TermTypes.DNA_METHYLATION,
21
21
  TermTypes.METABOLITE_INTENSITY,
22
22
  TermTypes.WHOLE_PROTEOME_ABUNDANCE,
23
- TermTypes.SINGLECELL_GENE_EXPRESSION,
24
- TermTypes.SINGLECELL_CELLTYPE,
23
+ SINGLECELL_GENE_EXPRESSION,
24
+ SINGLECELL_CELLTYPE,
25
25
  TermTypes.SNP,
26
26
  TermTypes.TERM_COLLECTION
27
27
  ])
@@ -114,14 +114,17 @@ export function isUsableTerm(term, _usecase, termdbConfig, ds) {
114
114
  uses.add('plot')
115
115
  }
116
116
  if (hasNumericChild(child_types)) uses.add('branch')
117
- } else if (usecase?.vocab?.type == 'singleCell') {
118
- /** TODO: Revisit this approach. Seems chaotic. */
119
- if (term.type && term.type.startsWith('singleCell')) {
120
- if (term.plot && term.plot == usecase.vocab?.config.name) {
121
- uses.add('plot')
122
- }
123
- }
124
- } else {
117
+ }
118
+ // Commenting out for now. May need later for another single
119
+ // cell term. Revisit logic at that time.
120
+ // else if (usecase?.specialCase?.type == 'singleCell') {
121
+ // if (term.type && term.type.startsWith('singleCell')) {
122
+ // if (term.plot && term.plot == usecase.specialCase?.config.name) {
123
+ // uses.add('plot')
124
+ // }
125
+ // }
126
+ // }
127
+ else {
125
128
  if (graphableTypes.has(term.type)) uses.add('plot')
126
129
  if (!term.isleaf) uses.add('branch')
127
130
  }
package/src/terms.js CHANGED
@@ -1,306 +1,309 @@
1
1
  import {
2
- dtgeneexpression,
3
- dtssgsea,
4
- dtdnamethylation,
5
- dtmetaboliteintensity,
6
- dtwholeproteomeabundance,
7
- TermTypeGroups,
8
- dtTerms
9
- } from './common.js'
10
-
11
- // moved TermTypeGroups to `server/src/common.js`, so now has to re-export
12
- export { TermTypeGroups } from './common.js'
13
-
14
- /*
15
- For datasets with multiple types of samples the ROOT_SAMPLE_TYPE is used to represent the root sample type, for example,
16
- the type patient, that has one or more samples associated to it. This should be the id used as sample_type, when generating the db to identify the root samples
17
- in sampleidmap or the terms annotating root samples in the terms table.
18
- The samples associated to a patient have annotations that are specific to a timepoint, for example, the age of the patient,
19
- the doses of the drugs the patient was taking at the time of the data collection, etc. These annotations are associated to a sample.
20
- */
21
- export const ROOT_SAMPLE_TYPE = 1
22
-
23
- //For datasets with one sample type the DEFAULT_SAMPLE_TYPE is used to represent the sample type
24
- export const DEFAULT_SAMPLE_TYPE = 2
25
-
26
- export const NumericModes = {
27
- continuous: 'continuous',
28
- discrete: 'discrete'
29
- }
30
-
31
- //Term types should be used gradually using these constants instead of hardcoding the values,
32
- // eg: type == TermTypes.CATEGORICAL instead of type == 'categorical'
33
- export const TermTypes = {
34
- GENE_VARIANT: 'geneVariant',
35
- GENE_EXPRESSION: 'geneExpression',
36
- SSGSEA: 'ssGSEA',
37
- DNA_METHYLATION: 'dnaMethylation',
38
- CATEGORICAL: 'categorical',
39
- INTEGER: 'integer',
40
- FLOAT: 'float',
41
- SNP: 'snp',
42
- SNP_LIST: 'snplst',
43
- SNP_LOCUS: 'snplocus',
44
- CONDITION: 'condition',
45
- SURVIVAL: 'survival',
46
- SAMPLELST: 'samplelst',
47
- METABOLITE_INTENSITY: 'metaboliteIntensity',
48
- WHOLE_PROTEOME_ABUNDANCE: 'wholeProteomeAbundance',
49
- SINGLECELL_GENE_EXPRESSION: 'singleCellGeneExpression',
50
- SINGLECELL_CELLTYPE: 'singleCellCellType',
51
- MULTIVALUE: 'multivalue',
52
- DATE: 'date',
53
- TERM_COLLECTION: 'termCollection'
54
- }
55
- export const dtTermTypes = new Set(dtTerms.map(t => t.type))
2
+ dtgeneexpression,
3
+ dtssgsea,
4
+ dtdnamethylation,
5
+ dtmetaboliteintensity,
6
+ dtwholeproteomeabundance,
7
+ TermTypeGroups,
8
+ dtTerms
9
+ } from "./common.js";
10
+ import { TermTypeGroups as TermTypeGroups2 } from "./common.js";
11
+ const ROOT_SAMPLE_TYPE = 1;
12
+ const DEFAULT_SAMPLE_TYPE = 2;
13
+ const NumericModes = {
14
+ continuous: "continuous",
15
+ discrete: "discrete"
16
+ };
17
+ const CATEGORICAL = "categorical";
18
+ const CONDITION = "condition";
19
+ const DATE = "date";
20
+ const DNA_METHYLATION = "dnaMethylation";
21
+ const FLOAT = "float";
22
+ const GENE_VARIANT = "geneVariant";
23
+ const GENE_EXPRESSION = "geneExpression";
24
+ const INTEGER = "integer";
25
+ const METABOLITE_INTENSITY = "metaboliteIntensity";
26
+ const MULTIVALUE = "multivalue";
27
+ const SAMPLELST = "samplelst";
28
+ const SINGLECELL_CELLTYPE = "singleCellCellType";
29
+ const SINGLECELL_GENE_EXPRESSION = "singleCellGeneExpression";
30
+ const SNP = "snp";
31
+ const SNP_LIST = "snplst";
32
+ const SNP_LOCUS = "snplocus";
33
+ const SSGSEA = "ssGSEA";
34
+ const SURVIVAL = "survival";
35
+ const TERM_COLLECTION = "termCollection";
36
+ const WHOLE_PROTEOME_ABUNDANCE = "wholeProteomeAbundance";
37
+ const TermTypes = {
38
+ GENE_VARIANT,
39
+ GENE_EXPRESSION,
40
+ SSGSEA,
41
+ DNA_METHYLATION,
42
+ CATEGORICAL,
43
+ INTEGER,
44
+ FLOAT,
45
+ SNP,
46
+ SNP_LIST,
47
+ SNP_LOCUS,
48
+ CONDITION,
49
+ SURVIVAL,
50
+ SAMPLELST,
51
+ METABOLITE_INTENSITY,
52
+ WHOLE_PROTEOME_ABUNDANCE,
53
+ SINGLECELL_CELLTYPE,
54
+ SINGLECELL_GENE_EXPRESSION,
55
+ MULTIVALUE,
56
+ DATE,
57
+ TERM_COLLECTION
58
+ };
59
+ const dtTermTypes = new Set(dtTerms.map((t) => t.type));
56
60
  for (const dtTermType of dtTermTypes) {
57
- TermTypes[dtTermType.toUpperCase()] = dtTermType
58
- }
59
-
60
- export const NUMERIC_DICTIONARY_TERM = 'numericDictTerm'
61
-
62
- export const TermTypes2Dt = {
63
- [TermTypes.GENE_EXPRESSION]: dtgeneexpression,
64
- [TermTypes.SSGSEA]: dtssgsea,
65
- [TermTypes.DNA_METHYLATION]: dtdnamethylation,
66
- [TermTypes.METABOLITE_INTENSITY]: dtmetaboliteintensity,
67
- [TermTypes.WHOLE_PROTEOME_ABUNDANCE]: dtwholeproteomeabundance
61
+ TermTypes[dtTermType.toUpperCase()] = dtTermType;
68
62
  }
69
-
70
- // maps term type to group (as is shown as toggles in search ui)
71
- export const typeGroup = {
72
- [TermTypes.CATEGORICAL]: TermTypeGroups.DICTIONARY_VARIABLES,
73
- [TermTypes.CONDITION]: TermTypeGroups.DICTIONARY_VARIABLES,
74
- [TermTypes.FLOAT]: TermTypeGroups.DICTIONARY_VARIABLES,
75
- [TermTypes.INTEGER]: TermTypeGroups.DICTIONARY_VARIABLES,
76
- [TermTypes.SAMPLELST]: TermTypeGroups.DICTIONARY_VARIABLES,
77
- [TermTypes.SURVIVAL]: TermTypeGroups.DICTIONARY_VARIABLES,
78
- [TermTypes.GENE_VARIANT]: TermTypeGroups.MUTATION_CNV_FUSION,
79
- [TermTypes.SNP]: TermTypeGroups.SNP,
80
- [TermTypes.SNP_LIST]: TermTypeGroups.SNP_LIST,
81
- [TermTypes.SNP_LOCUS]: TermTypeGroups.SNP_LOCUS,
82
- [TermTypes.GENE_EXPRESSION]: TermTypeGroups.GENE_EXPRESSION,
83
- [TermTypes.SSGSEA]: TermTypeGroups.SSGSEA,
84
- [TermTypes.DNA_METHYLATION]: TermTypeGroups.DNA_METHYLATION,
85
- [TermTypes.METABOLITE_INTENSITY]: TermTypeGroups.METABOLITE_INTENSITY,
86
- [TermTypes.WHOLE_PROTEOME_ABUNDANCE]: TermTypeGroups.WHOLE_PROTEOME_ABUNDANCE,
87
- [TermTypes.TERM_COLLECTION]: TermTypeGroups.TERM_COLLECTION,
88
- [TermTypes.SINGLECELL_CELLTYPE]: TermTypeGroups.SINGLECELL_CELLTYPE,
89
- [TermTypes.SINGLECELL_GENE_EXPRESSION]: TermTypeGroups.SINGLECELL_GENE_EXPRESSION
90
- }
91
-
92
- const nonDictTypes = new Set([
93
- TermTypes.SNP,
94
- TermTypes.SNP_LIST,
95
- TermTypes.SNP_LOCUS,
96
- TermTypes.GENE_EXPRESSION,
97
- TermTypes.SSGSEA,
98
- TermTypes.DNA_METHYLATION,
99
- TermTypes.GENE_VARIANT,
100
- TermTypes.METABOLITE_INTENSITY,
101
- TermTypes.WHOLE_PROTEOME_ABUNDANCE,
102
- TermTypes.SINGLECELL_GENE_EXPRESSION,
103
- TermTypes.SINGLECELL_CELLTYPE
104
- ])
63
+ const NUMERIC_DICTIONARY_TERM = "numericDictTerm";
64
+ const TermTypes2Dt = {
65
+ [GENE_EXPRESSION]: dtgeneexpression,
66
+ [SSGSEA]: dtssgsea,
67
+ [DNA_METHYLATION]: dtdnamethylation,
68
+ [METABOLITE_INTENSITY]: dtmetaboliteintensity,
69
+ [WHOLE_PROTEOME_ABUNDANCE]: dtwholeproteomeabundance
70
+ };
71
+ const typeGroup = {
72
+ [CATEGORICAL]: TermTypeGroups.DICTIONARY_VARIABLES,
73
+ [CONDITION]: TermTypeGroups.DICTIONARY_VARIABLES,
74
+ [FLOAT]: TermTypeGroups.DICTIONARY_VARIABLES,
75
+ [INTEGER]: TermTypeGroups.DICTIONARY_VARIABLES,
76
+ [SAMPLELST]: TermTypeGroups.DICTIONARY_VARIABLES,
77
+ [SURVIVAL]: TermTypeGroups.DICTIONARY_VARIABLES,
78
+ [DATE]: TermTypeGroups.DICTIONARY_VARIABLES,
79
+ [MULTIVALUE]: TermTypeGroups.DICTIONARY_VARIABLES,
80
+ [GENE_VARIANT]: TermTypeGroups.MUTATION_CNV_FUSION,
81
+ [SNP]: TermTypeGroups.SNP,
82
+ [SNP_LIST]: TermTypeGroups.SNP_LIST,
83
+ [SNP_LOCUS]: TermTypeGroups.SNP_LOCUS,
84
+ [GENE_EXPRESSION]: TermTypeGroups.GENE_EXPRESSION,
85
+ [SSGSEA]: TermTypeGroups.SSGSEA,
86
+ [DNA_METHYLATION]: TermTypeGroups.DNA_METHYLATION,
87
+ [METABOLITE_INTENSITY]: TermTypeGroups.METABOLITE_INTENSITY,
88
+ [WHOLE_PROTEOME_ABUNDANCE]: TermTypeGroups.WHOLE_PROTEOME_ABUNDANCE,
89
+ [TERM_COLLECTION]: TermTypeGroups.TERM_COLLECTION,
90
+ [SINGLECELL_CELLTYPE]: TermTypeGroups.SINGLECELL_CELLTYPE,
91
+ [SINGLECELL_GENE_EXPRESSION]: TermTypeGroups.SINGLECELL_GENE_EXPRESSION
92
+ };
93
+ const nonDictTypes = /* @__PURE__ */ new Set([
94
+ SNP,
95
+ SNP_LIST,
96
+ SNP_LOCUS,
97
+ GENE_EXPRESSION,
98
+ SSGSEA,
99
+ DNA_METHYLATION,
100
+ GENE_VARIANT,
101
+ METABOLITE_INTENSITY,
102
+ WHOLE_PROTEOME_ABUNDANCE,
103
+ SINGLECELL_CELLTYPE,
104
+ SINGLECELL_GENE_EXPRESSION
105
+ ]);
105
106
  for (const dtTermType of dtTermTypes) {
106
- nonDictTypes.add(TermTypes[dtTermType.toUpperCase()])
107
+ nonDictTypes.add(TermTypes[dtTermType.toUpperCase()]);
107
108
  }
108
-
109
- export const numericTypes = new Set([
110
- TermTypes.INTEGER,
111
- TermTypes.FLOAT,
112
- TermTypes.GENE_EXPRESSION,
113
- TermTypes.SSGSEA,
114
- TermTypes.DNA_METHYLATION,
115
- TermTypes.METABOLITE_INTENSITY,
116
- TermTypes.WHOLE_PROTEOME_ABUNDANCE,
117
- TermTypes.SINGLECELL_GENE_EXPRESSION,
118
- TermTypes.DATE
119
- ])
120
-
121
- // available termdb numeric table names used as anno_<term.type>,
122
- // for example anno_integer, anno_float, anno_date
123
- export const annoNumericTypes = new Set([TermTypes.INTEGER, TermTypes.FLOAT, TermTypes.DATE])
124
-
125
- const categoricalTypes = new Set([TermTypes.CATEGORICAL, TermTypes.SNP])
126
-
127
- const singleSampleTerms = new Set([TermTypes.SINGLECELL_CELLTYPE, TermTypes.SINGLECELL_GENE_EXPRESSION])
128
-
129
- export function isSingleSampleTerm(term) {
130
- if (!term) return false
131
- return singleSampleTerms.has(term.type)
109
+ const numericTypes = /* @__PURE__ */ new Set([
110
+ INTEGER,
111
+ FLOAT,
112
+ GENE_EXPRESSION,
113
+ SSGSEA,
114
+ DNA_METHYLATION,
115
+ METABOLITE_INTENSITY,
116
+ WHOLE_PROTEOME_ABUNDANCE,
117
+ SINGLECELL_GENE_EXPRESSION,
118
+ DATE
119
+ ]);
120
+ const annoNumericTypes = /* @__PURE__ */ new Set([INTEGER, FLOAT, DATE]);
121
+ const categoricalTypes = /* @__PURE__ */ new Set([CATEGORICAL, SNP]);
122
+ const singleCellTerms = /* @__PURE__ */ new Set([SINGLECELL_CELLTYPE, SINGLECELL_GENE_EXPRESSION]);
123
+ function isSingleCellTerm(term) {
124
+ if (!term) return false;
125
+ return singleCellTerms.has(term.type);
132
126
  }
133
- export function isNumericTerm(term) {
134
- if (!term) return false
135
- return numericTypes.has(term.type)
127
+ function isNumericTerm(term) {
128
+ if (!term) return false;
129
+ return numericTypes.has(term.type);
136
130
  }
137
- export function isCategoricalTerm(term) {
138
- if (!term) return false
139
- return categoricalTypes.has(term.type)
131
+ function isCategoricalTerm(term) {
132
+ if (!term) return false;
133
+ return categoricalTypes.has(term.type);
140
134
  }
141
-
142
- export function isDictionaryType(type) {
143
- return !isNonDictionaryType(type)
135
+ function isDictionaryType(type) {
136
+ return !isNonDictionaryType(type);
144
137
  }
145
-
146
- export function isNonDictionaryType(type) {
147
- if (!type) throw new Error('Type is not defined')
148
- return nonDictTypes.has(type)
138
+ function isNonDictionaryType(type) {
139
+ if (!type) throw new Error("Type is not defined");
140
+ return nonDictTypes.has(type);
149
141
  }
150
-
151
- export function equals(t1, t2) {
152
- if (!t1) throw new Error('First term is not defined ')
153
- if (!t2) throw new Error('Second term is not defined ')
154
- if (t1.type !== t2.type) return false //term types are different
155
- if (isDictionaryType(t1.type) && isDictionaryType(t2.type) && t1.type != TermTypes.SAMPLELST) return t1.id === t2.id
156
- switch (t1.type) {
157
- case TermTypes.GENE_EXPRESSION:
158
- return t1.gene == t2.gene
159
- case TermTypes.SSGSEA:
160
- return t1.id == t2.id
161
- case TermTypes.DNA_METHYLATION:
162
- return t1.chr == t2.chr && t1.start == t2.start && t1.stop == t2.stop
163
- case TermTypes.METABOLITE_INTENSITY:
164
- case TermTypes.WHOLE_PROTEOME_ABUNDANCE:
165
- return t1.name == t2.name
166
- case TermTypes.GENE_VARIANT:
167
- return t1.gene == t2.gene || (t1.chr == t2.chr && t1.start == t2.start && t1.stop == t2.stop)
168
-
169
- // TO DO: Add more cases
170
- // case TermTypes.SNP_LIST:
171
- // case TermTypes.SNP_LOCUS:
172
- // case TermTypes.SAMPLELST:
173
-
174
- default:
175
- return false
176
- }
142
+ function equals(t1, t2) {
143
+ if (!t1) throw new Error("First term is not defined ");
144
+ if (!t2) throw new Error("Second term is not defined ");
145
+ if (t1.type !== t2.type) return false;
146
+ if (isDictionaryType(t1.type) && isDictionaryType(t2.type) && t1.type != SAMPLELST) return t1.id === t2.id;
147
+ switch (t1.type) {
148
+ case GENE_EXPRESSION:
149
+ return t1.gene == t2.gene;
150
+ case SSGSEA:
151
+ return t1.id == t2.id;
152
+ case DNA_METHYLATION:
153
+ return t1.chr == t2.chr && t1.start == t2.start && t1.stop == t2.stop;
154
+ case METABOLITE_INTENSITY:
155
+ case WHOLE_PROTEOME_ABUNDANCE:
156
+ return t1.name == t2.name;
157
+ case GENE_VARIANT:
158
+ return t1.gene == t2.gene || t1.chr == t2.chr && t1.start == t2.start && t1.stop == t2.stop;
159
+ // TO DO: Add more cases
160
+ // case SNP_LIST:
161
+ // case SNP_LOCUS:
162
+ // case SAMPLELST:
163
+ default:
164
+ return false;
165
+ }
177
166
  }
178
-
179
- export function getBin(lst, value) {
180
- let bin = lst.findIndex(
181
- b => (b.startunbounded && value < b.stop) || (b.startunbounded && b.stopinclusive && value == b.stop)
182
- )
183
- if (bin == -1)
184
- bin = lst.findIndex(
185
- b => (b.stopunbounded && value > b.start) || (b.stopunbounded && b.startinclusive && value == b.start)
186
- )
187
- if (bin == -1)
188
- bin = lst.findIndex(
189
- b =>
190
- (value > b.start && value < b.stop) ||
191
- (b.startinclusive && value == b.start) ||
192
- (b.stopinclusive && value == b.stop)
193
- )
194
- return bin
167
+ function getBin(lst, value) {
168
+ let bin = lst.findIndex(
169
+ (b) => b.startunbounded && value < b.stop || b.startunbounded && b.stopinclusive && value == b.stop
170
+ );
171
+ if (bin == -1)
172
+ bin = lst.findIndex(
173
+ (b) => b.stopunbounded && value > b.start || b.stopunbounded && b.startinclusive && value == b.start
174
+ );
175
+ if (bin == -1)
176
+ bin = lst.findIndex(
177
+ (b) => value > b.start && value < b.stop || b.startinclusive && value == b.start || b.stopinclusive && value == b.stop
178
+ );
179
+ return bin;
195
180
  }
196
- //Terms may have a sample type associated to them, in datasets with multiple types of samples.
197
- //For example the gender is associated to the patient while the age is associated to the type sample. This function is used
198
- //for example when calling getData or getFilter, to return either the parent or the child samples, depending on the use case.
199
- export function getSampleType(term, ds) {
200
- if (!term) return null
201
- //non dict terms annotate only samples, eg: gene expression, metabolite intensity, gene variant.
202
- //Their sample type is the default sample type that may or may not have a parent type, depending on the dataset
203
- if (term.type && isNonDictionaryType(term.type)) return DEFAULT_SAMPLE_TYPE
204
- //dictionary terms may annotate different types of samples, eg: patient and sample or mouse and crop.
205
- if (term.id) return ds.cohort.termdb.term2SampleType.get(term.id)
206
- if (term.type == 'samplelst') {
207
- const key = Object.keys(term.values)[0]
208
- const sampleId = term.values[key].list[0]?.sampleId
209
- if (sampleId) return ds.sampleId2Type.get(Number(sampleId) || sampleId)
210
- else return DEFAULT_SAMPLE_TYPE
211
- }
212
- // samplelst or non dict terms
213
- return DEFAULT_SAMPLE_TYPE //later own term needs to know what type annotates based on the samples
181
+ function getSampleType(term, ds) {
182
+ if (!term) return null;
183
+ if (term.type && isNonDictionaryType(term.type)) return DEFAULT_SAMPLE_TYPE;
184
+ if (term.id) return ds.cohort.termdb.term2SampleType.get(term.id);
185
+ if (term.type == "samplelst") {
186
+ const key = Object.keys(term.values)[0];
187
+ const sampleId = term.values[key].list[0]?.sampleId;
188
+ if (sampleId) return ds.sampleId2Type.get(Number(sampleId) || sampleId);
189
+ else return DEFAULT_SAMPLE_TYPE;
190
+ }
191
+ return DEFAULT_SAMPLE_TYPE;
214
192
  }
215
-
216
- export function getParentType(types, ds) {
217
- if (Object.keys(ds.cohort.termdb.sampleTypes).length == 0) return null //dataset only has one type of sample
218
- const ids = Array.from(types)
219
- if (!ids || ids.length == 0) return null
220
- for (const id of ids) {
221
- const typeObj = ds.cohort.termdb.sampleTypes[id]
222
- if (!typeObj) continue
223
- if (typeObj.parent_id == null) return id //this is the root type
224
- //if my parent is in the list, then I am not the parent
225
- if (ids.includes(typeObj.parent_id)) continue
226
- else return typeObj.parent_id //my parent is not in the list, so I am the parent
227
- }
228
- return null //no parent found
193
+ function getParentType(types, ds) {
194
+ if (Object.keys(ds.cohort.termdb.sampleTypes).length == 0) return null;
195
+ const ids = Array.from(types);
196
+ if (!ids || ids.length == 0) return null;
197
+ for (const id of ids) {
198
+ const typeObj = ds.cohort.termdb.sampleTypes[id];
199
+ if (!typeObj) continue;
200
+ if (typeObj.parent_id == null) return id;
201
+ if (ids.includes(typeObj.parent_id)) continue;
202
+ else return typeObj.parent_id;
203
+ }
204
+ return null;
229
205
  }
230
-
231
- //Returns human readable label for each term type; label is just for printing and not computing
232
206
  const typeMap = {
233
- categorical: 'Categorical',
234
- condition: 'Condition',
235
- float: 'Numerical',
236
- integer: 'Numerical',
237
- geneExpression: 'Gene Expression',
238
- ssGSEA: 'Geneset Expression',
239
- dnaMethylation: 'DNA Methylation',
240
- geneVariant: 'Gene Variant',
241
- metaboliteIntensity: 'Metabolite Intensity',
242
- wholeProteomeAbundance: 'Whole Proteome Abundance',
243
- multiValue: 'Multi Value',
244
- singleCellGeneExpression: 'Single Cell, Gene Expression',
245
- singleCellCellType: 'Single Cell, Cell Type',
246
- snplocus: 'SNP Locus',
247
- snp: 'SNP',
248
- snplst: 'SNP List',
249
- numericDictTerm: 'Numeric Dictionary Term',
250
- termCollection: 'Term Collection'
251
- }
252
-
253
- export function termType2label(type) {
254
- return typeMap[type] || 'Unknown term type'
207
+ categorical: "Categorical",
208
+ condition: "Condition",
209
+ float: "Numerical",
210
+ integer: "Numerical",
211
+ geneExpression: "Gene Expression",
212
+ ssGSEA: "Geneset Expression",
213
+ dnaMethylation: "DNA Methylation",
214
+ geneVariant: "Gene Variant",
215
+ metaboliteIntensity: "Metabolite Intensity",
216
+ wholeProteomeAbundance: "Whole Proteome Abundance",
217
+ multivalue: "Multi Value",
218
+ singleCellGeneExpression: "Single Cell, Gene Expression",
219
+ singleCellCellType: "Single Cell, Cell Type",
220
+ snplocus: "SNP Locus",
221
+ snp: "SNP",
222
+ snplst: "SNP List",
223
+ numericDictTerm: "Numeric Dictionary Term",
224
+ termCollection: "Term Collection"
225
+ };
226
+ function termType2label(type) {
227
+ return typeMap[type] || "Unknown term type";
255
228
  }
256
-
257
- export function getDateFromNumber(value) {
258
- const year = Math.floor(value)
259
- const january1st = new Date(year, 0, 1)
260
- const totalDays = getDaysInYear(year)
261
- const time = Math.round((value - year) * totalDays) * oneDayTime
262
- const date = new Date(january1st.getTime() + time)
263
- return date
229
+ function getDateFromNumber(value) {
230
+ const year = Math.floor(value);
231
+ const january1st = new Date(year, 0, 1);
232
+ const totalDays = getDaysInYear(year);
233
+ const time = Math.round((value - year) * totalDays) * oneDayTime;
234
+ const date = new Date(january1st.getTime() + time);
235
+ return date;
264
236
  }
265
- /*
266
- Value is a decimal year.
267
- A decimal year is a way of expressing a date or time period as a year with a decimal part, where the decimal portion
268
- represents the fraction of the year that has elapsed.
269
- Example:
270
- 2025.0 represents the beginning of the year 2025.
271
- 2025.5 represents the middle of the year 2025.
272
- */
273
- const oneDayTime = 24 * 60 * 60 * 1000
274
-
275
- export function getDateStrFromNumber(value) {
276
- const date = getDateFromNumber(value)
277
-
278
- //Omit day to deidentify the patients
279
- return date.toLocaleDateString('en-US', {
280
- year: 'numeric',
281
- month: 'long'
282
- })
237
+ const oneDayTime = 24 * 60 * 60 * 1e3;
238
+ function getDateStrFromNumber(value) {
239
+ const date = getDateFromNumber(value);
240
+ return date.toLocaleDateString("en-US", {
241
+ year: "numeric",
242
+ month: "long"
243
+ });
283
244
  }
284
-
285
- //The value returned is a decimal year
286
- //A decimal year is a way of expressing a date or time period as a year with a decimal part, where the decimal portion
287
- //represents the fraction of the year that has elapsed.
288
- export function getNumberFromDateStr(str) {
289
- const date = new Date(str)
290
- return getNumberFromDate(date)
245
+ function getNumberFromDateStr(str) {
246
+ const date = new Date(str);
247
+ return getNumberFromDate(date);
291
248
  }
292
-
293
- export function getNumberFromDate(date) {
294
- const year = date.getFullYear()
295
- const january1st = new Date(year, 0, 1)
296
- const diffDays = (date - january1st) / oneDayTime
297
- const daysTotal = getDaysInYear(year)
298
- const decimal = diffDays / daysTotal
299
- return year + decimal
249
+ function getNumberFromDate(date) {
250
+ const year = date.getFullYear();
251
+ const january1st = new Date(year, 0, 1);
252
+ const diffDays = (date.getTime() - january1st.getTime()) / oneDayTime;
253
+ const daysTotal = getDaysInYear(year);
254
+ const decimal = diffDays / daysTotal;
255
+ return year + decimal;
300
256
  }
301
-
302
- export function getDaysInYear(year) {
303
- const isLeap = new Date(year, 1, 29).getMonth() === 1
304
- const days = isLeap ? 366 : 365
305
- return days
257
+ function getDaysInYear(year) {
258
+ const isLeap = new Date(year, 1, 29).getMonth() === 1;
259
+ const days = isLeap ? 366 : 365;
260
+ return days;
306
261
  }
262
+ export {
263
+ CATEGORICAL,
264
+ CONDITION,
265
+ DATE,
266
+ DEFAULT_SAMPLE_TYPE,
267
+ DNA_METHYLATION,
268
+ FLOAT,
269
+ GENE_EXPRESSION,
270
+ GENE_VARIANT,
271
+ INTEGER,
272
+ METABOLITE_INTENSITY,
273
+ MULTIVALUE,
274
+ NUMERIC_DICTIONARY_TERM,
275
+ NumericModes,
276
+ ROOT_SAMPLE_TYPE,
277
+ SAMPLELST,
278
+ SINGLECELL_CELLTYPE,
279
+ SINGLECELL_GENE_EXPRESSION,
280
+ SNP,
281
+ SNP_LIST,
282
+ SNP_LOCUS,
283
+ SSGSEA,
284
+ SURVIVAL,
285
+ TERM_COLLECTION,
286
+ TermTypeGroups2 as TermTypeGroups,
287
+ TermTypes,
288
+ TermTypes2Dt,
289
+ WHOLE_PROTEOME_ABUNDANCE,
290
+ annoNumericTypes,
291
+ dtTermTypes,
292
+ equals,
293
+ getBin,
294
+ getDateFromNumber,
295
+ getDateStrFromNumber,
296
+ getDaysInYear,
297
+ getNumberFromDate,
298
+ getNumberFromDateStr,
299
+ getParentType,
300
+ getSampleType,
301
+ isCategoricalTerm,
302
+ isDictionaryType,
303
+ isNonDictionaryType,
304
+ isNumericTerm,
305
+ isSingleCellTerm,
306
+ numericTypes,
307
+ termType2label,
308
+ typeGroup
309
+ };