@sjcrh/proteinpaint-server 2.190.2 → 2.191.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,347 +0,0 @@
1
- import serverconfig from "#src/serverconfig.js";
2
- import { authApi } from "#src/auth.js";
3
- import { get_ds_tdb } from "#src/termdb.js";
4
- import {
5
- TermTypeGroups,
6
- SINGLECELL_CELLTYPE,
7
- GENE_EXPRESSION,
8
- ISOFORM_EXPRESSION,
9
- METABOLITE_INTENSITY,
10
- PROTEOME_ABUNDANCE,
11
- SINGLECELL_GENE_EXPRESSION,
12
- DNA_METHYLATION,
13
- SSGSEA
14
- } from "#shared/terms.js";
15
- function init({ genomes }) {
16
- return async (req, res) => {
17
- const q = req.query;
18
- try {
19
- const genome = genomes[q.genome];
20
- if (!genome) throw "invalid genome";
21
- const [ds] = get_ds_tdb(genome, q);
22
- return make(q, req, res, ds, genome);
23
- } catch (e) {
24
- res.send({ error: e.message || e });
25
- if (e.stack) console.log(e.stack);
26
- else console.log(e);
27
- }
28
- };
29
- }
30
- function make(q, req, res, ds, genome) {
31
- const tdb = ds.cohort.termdb;
32
- const c = {
33
- selectCohort: getSelectCohort(ds, req),
34
- supportedChartTypes: tdb.q?.getSupportedChartTypes(req),
35
- renamedChartTypes: ds.cohort.renamedChartTypes,
36
- allowedTermTypes: getDsAllowedTermTypes(ds),
37
- massSessionDuration: serverconfig.features.massSessionDuration || 30,
38
- dataDownloadCatch: tdb.dataDownloadCatch,
39
- matrix: tdb.matrix,
40
- hierCluster: tdb.hierCluster,
41
- numericDictTermCluster: tdb.numericDictTermCluster,
42
- mclass: tdb.mclass,
43
- alwaysRefillCategoricalTermValues: tdb.alwaysRefillCategoricalTermValues,
44
- isGeneSetTermdb: tdb.isGeneSetTermdb,
45
- lollipop: tdb.lollipop,
46
- urlTemplates: tdb.urlTemplates,
47
- title: "title" in ds.cohort ? ds.cohort.title : { text: ds.label },
48
- massNav: ds.cohort.massNav,
49
- tracks: tdb.tracks,
50
- sampleTypes: ds.cohort.termdb.sampleTypes,
51
- hasSampleAncestry: ds.cohort.termdb.hasSampleAncestry,
52
- defaultChartType: ds.cohort.defaultChartType,
53
- invalidTokenErrorHandling: tdb.invalidTokenErrorHandling,
54
- colorMap: tdb.colorMap,
55
- defaultTw4correlationPlot: tdb.defaultTw4correlationPlot,
56
- authFilter: req.query.filter
57
- };
58
- if (tdb.plotConfigByCohort) c.plotConfigByCohort = structuredClone(tdb.plotConfigByCohort);
59
- if (tdb.multipleTestingCorrection) c.multipleTestingCorrection = tdb.multipleTestingCorrection;
60
- if (tdb.helpPages) c.helpPages = tdb.helpPages;
61
- if (tdb.minTimeSinceDx) c.minTimeSinceDx = tdb.minTimeSinceDx;
62
- if (tdb.timeUnit) c.timeUnit = tdb.timeUnit;
63
- if (tdb.cohortStartTimeMsg) c.cohortStartTimeMsg = tdb.cohortStartTimeMsg;
64
- if (tdb.hasAncestry) c.hasAncestry = tdb.hasAncestry;
65
- if (tdb.logscaleBase2) c.logscaleBase2 = tdb.logscaleBase2;
66
- if (tdb.useCasesExcluded) c.useCasesExcluded = tdb.useCasesExcluded;
67
- if (tdb.excludedTermtypeByTarget) c.excludedTermtypeByTarget = tdb.excludedTermtypeByTarget;
68
- if (tdb.survival) c.survival = tdb.survival;
69
- if (tdb.regression) c.regression = tdb.regression;
70
- if (tdb.uiLabels) c.uiLabels = tdb.uiLabels;
71
- if (tdb.termCollections) c.termCollections = tdb.termCollections;
72
- if (ds.assayAvailability) c.assayAvailability = ds.assayAvailability;
73
- if (ds.cohort.correlationVolcano) c.correlationVolcano = ds.cohort.correlationVolcano;
74
- if (ds.cohort.boxplots) c.boxplots = ds.cohort.boxplots;
75
- if (tdb.maxGeneVariantGeneSetSize) c.maxGeneVariantGeneSetSize = tdb.maxGeneVariantGeneSetSize;
76
- if (tdb.maxAnnoTermsPerClientRequest) c.maxAnnoTermsPerClientRequest = tdb.maxAnnoTermsPerClientRequest;
77
- addRestrictAncestries(c, tdb);
78
- addMatrixplots(c, ds);
79
- addNonDictionaryQueries(c, ds, genome);
80
- c.requiredAuth = authApi.getRequiredCredForDsEmbedder(q.dslabel, q.embedder);
81
- const info = authApi.getNonsensitiveInfo(req);
82
- c.clientAuthResult = info?.clientAuthResult || {};
83
- if (tdb.displaySampleIds) c.displaySampleIds = tdb.displaySampleIds(c.clientAuthResult);
84
- c.authFilter = req.query.filter;
85
- addScatterplots(c, ds, info);
86
- tdb.pruneTermdbConfig?.(c, q, ds);
87
- res.send({ termdbConfig: c });
88
- }
89
- function addRestrictAncestries(c, tdb) {
90
- if (!tdb.restrictAncestries) return;
91
- c.restrictAncestries = tdb.restrictAncestries.map((i) => {
92
- return { name: i.name, tvs: i.tvs, PCcount: i.PCcount };
93
- });
94
- }
95
- function addScatterplots(c, ds, info) {
96
- if (!ds.cohort.scatterplots) return;
97
- if (ds.cohort.scatterplots.get) {
98
- c.scatterplots = ds.cohort.scatterplots.get(info?.clientAuthResult);
99
- return;
100
- }
101
- c.scatterplots = ds.cohort.scatterplots.plots.map((p) => {
102
- return {
103
- name: p.name,
104
- dimensions: p.dimensions,
105
- colorTW: p.colorTW,
106
- shapeTW: p.shapeTW,
107
- colorColumn: p.colorColumn,
108
- sampleType: p.sampleType,
109
- coordsColumns: p.coordsColumns,
110
- settings: { sampleScatter: p.settings },
111
- //the client settings are under sampleScatter so we add it here to avoid adding it in the dataset
112
- sampleCategory: p.sampleCategory
113
- };
114
- });
115
- }
116
- function addMatrixplots(c, ds) {
117
- if (!ds.cohort.matrixplots) return;
118
- c.matrixplots = ds.cohort.matrixplots.plots.map((p) => {
119
- return { name: p.name };
120
- });
121
- }
122
- function addNonDictionaryQueries(c, ds, genome) {
123
- const q = ds.queries;
124
- if (!q) return;
125
- c.queries = {
126
- defaultCoord: q.defaultCoord || genome.defaultcoord,
127
- gbRestrictMode: q.gbRestrictMode
128
- };
129
- const q2 = c.queries;
130
- if (q.snvindel) {
131
- q2.snvindel = {
132
- allowSNPs: q.snvindel.allowSNPs,
133
- // details{} lists default method for computing variants, can be modified and is part of state
134
- // some of the stuff here are to provide user-selectable choices
135
- // e.g. computing methods, info fields, populations.
136
- details: q.snvindel.details,
137
- populations: q.snvindel.populations,
138
- mafFilter: q.snvindel.mafFilter
139
- };
140
- if (q.snvindel.byisoform?.processTwsInOneQuery) q2.snvindel.byisoform = { processTwsInOneQuery: true };
141
- }
142
- if (q.svfusion) {
143
- q2.svfusion = { dtLst: q.svfusion.dtLst };
144
- }
145
- if (q.cnv) {
146
- q2.cnv = {};
147
- for (const k of [
148
- "cnvMaxLength",
149
- "cnvGainCutoff",
150
- "cnvLossCutoff",
151
- "cnvCutoffsByGene",
152
- "absoluteValueRenderMax",
153
- "gainColor",
154
- "lossColor",
155
- "requiresHardcodeCnvOnlyFlag"
156
- ]) {
157
- if (k in q.cnv) q2.cnv[k] = q.cnv[k];
158
- }
159
- }
160
- if (q.geneCnv) {
161
- }
162
- if (q.topMutatedGenes) q2.topMutatedGenes = q.topMutatedGenes;
163
- if (q.topVariablyExpressedGenes) q2.topVariablyExpressedGenes = q.topVariablyExpressedGenes;
164
- if (q.singleSampleMutation) {
165
- q2.singleSampleMutation = {
166
- sample_id_key: q.singleSampleMutation.sample_id_key,
167
- discoPlot: q.singleSampleMutation.discoPlot
168
- };
169
- }
170
- if (q.singleSampleGenomeQuantification) {
171
- q2.singleSampleGenomeQuantification = {};
172
- for (const k in q.singleSampleGenomeQuantification) {
173
- q2.singleSampleGenomeQuantification[k] = JSON.parse(JSON.stringify(q.singleSampleGenomeQuantification[k]));
174
- delete q2.singleSampleGenomeQuantification[k].folder;
175
- }
176
- }
177
- if (q.geneExpression) {
178
- q2.geneExpression = { unit: q.geneExpression.unit };
179
- }
180
- if (q.isoformExpression) {
181
- q2.isoformExpression = { unit: q.isoformExpression.unit };
182
- }
183
- if (q.proteome) {
184
- q2.proteome = {};
185
- if (q.proteome.organisms) {
186
- q2.proteome.organisms = {};
187
- for (const organism in q.proteome.organisms) {
188
- q2.proteome.organisms[organism] = {};
189
- const orgSrc = q.proteome.organisms[organism];
190
- if (orgSrc.overlayTerm) {
191
- q2.proteome.organisms[organism].overlayTerm = JSON.parse(JSON.stringify(orgSrc.overlayTerm));
192
- }
193
- if (orgSrc.genomeName) {
194
- q2.proteome.organisms[organism].genomeName = orgSrc.genomeName;
195
- }
196
- if (orgSrc.assays) {
197
- q2.proteome.organisms[organism].assays = {};
198
- for (const assay in orgSrc.assays) {
199
- q2.proteome.organisms[organism].assays[assay] = {};
200
- if (orgSrc.assays[assay].cohorts) {
201
- q2.proteome.organisms[organism].assays[assay].cohorts = {};
202
- for (const cohort in orgSrc.assays[assay].cohorts) {
203
- q2.proteome.organisms[organism].assays[assay].cohorts[cohort] = {};
204
- const src = orgSrc.assays[assay].cohorts[cohort];
205
- if ("controlFilter" in src) {
206
- q2.proteome.organisms[organism].assays[assay].cohorts[cohort].controlFilter = JSON.parse(
207
- JSON.stringify(src.controlFilter)
208
- );
209
- }
210
- if ("caseFilter" in src) {
211
- q2.proteome.organisms[organism].assays[assay].cohorts[cohort].caseFilter = JSON.parse(
212
- JSON.stringify(src.caseFilter)
213
- );
214
- }
215
- if (src.DAPfile) {
216
- q2.proteome.organisms[organism].assays[assay].cohorts[cohort].DAPfile = true;
217
- }
218
- }
219
- }
220
- }
221
- }
222
- }
223
- }
224
- }
225
- if (q.geneRanking) {
226
- q2.geneRanking = {
227
- rankings: Object.fromEntries(Object.keys(q.geneRanking.rankings).map((k) => [k, true])),
228
- modalities: q.geneRanking.modalities,
229
- description: q.geneRanking.description,
230
- appName: q.geneRanking.appName
231
- };
232
- }
233
- if (q.dnaMethylation) {
234
- q2.dnaMethylation = { unit: q.dnaMethylation.unit };
235
- if (q.dnaMethylation.promoter) {
236
- q2.dnaMethylation.promoter = { unit: q.dnaMethylation.promoter.unit };
237
- }
238
- }
239
- if (q.ld) {
240
- q2.ld = structuredClone(q.ld);
241
- }
242
- if (q.trackLst) {
243
- q2.trackLst = q.trackLst;
244
- }
245
- if (q.chat) {
246
- q2.chat = {};
247
- }
248
- if (q.alphaGenome) q2.alphaGenome = q.alphaGenome;
249
- if (q.NIdata && serverconfig.features.showBrainImaging) {
250
- q2.NIdata = {};
251
- for (const k in q.NIdata) {
252
- q2.NIdata[k] = JSON.parse(JSON.stringify(q.NIdata[k]));
253
- }
254
- }
255
- if (q.DZImages && serverconfig.features.showDZImages) {
256
- q2.DZImages = {
257
- type: q.DZImages.type
258
- };
259
- }
260
- if (q.WSImages && serverconfig.features.showWSImages) {
261
- q2.WSImages = {
262
- type: q.WSImages.type
263
- };
264
- }
265
- if (q.singleSampleGbtk) {
266
- q2.singleSampleGbtk = {};
267
- for (const k in q.singleSampleGbtk) {
268
- q2.singleSampleGbtk[k] = JSON.parse(JSON.stringify(q.singleSampleGbtk[k]));
269
- delete q2.singleSampleGbtk[k].folder;
270
- }
271
- }
272
- if (q.rnaseqGeneCount) {
273
- q2.rnaseqGeneCount = true;
274
- }
275
- if (q.singleCell) {
276
- q2.singleCell = {
277
- samples: {
278
- sampleColumns: q.singleCell.samples.sampleColumns,
279
- experimentColumns: q.singleCell.samples.experimentColumns,
280
- extraSampleTabLabel: q.singleCell.samples.extraSampleTabLabel
281
- },
282
- images: q.singleCell.images,
283
- data: {
284
- sameLegend: q.singleCell.data.sameLegend,
285
- refName: q.singleCell.data.refName,
286
- settings: q.singleCell.data.settings,
287
- plots: q.singleCell.data.plots.map((p) => {
288
- return { name: p.name, colorColumns: p.colorColumns, selected: p.selected };
289
- })
290
- }
291
- };
292
- if (q.singleCell.geneExpression) {
293
- q2.singleCell.geneExpression = {
294
- unit: q.singleCell.geneExpression?.unit
295
- };
296
- }
297
- if (q.singleCell.DEgenes) {
298
- q2.singleCell.DEgenes = { termId: q.singleCell.DEgenes.termId };
299
- }
300
- if (q.singleCell?.terms?.length) {
301
- if (!c.termType2terms) c.termType2terms = {};
302
- c.termType2terms[TermTypeGroups.SINGLECELL_CELLTYPE] = q.singleCell.terms;
303
- }
304
- }
305
- if (q.images) {
306
- q2.images = {};
307
- }
308
- }
309
- function getDsAllowedTermTypes(ds) {
310
- const typeSet = /* @__PURE__ */ new Set();
311
- for (const r of ds.cohort.termdb.termtypeByCohort) {
312
- if (r.termType) typeSet.add(r.termType);
313
- }
314
- if (ds.cohort.termdb.allowedTermTypes) {
315
- for (const t of ds.cohort.termdb.allowedTermTypes) typeSet.add(t);
316
- }
317
- if (ds.queries?.geneExpression) typeSet.add(GENE_EXPRESSION);
318
- if (ds.queries?.isoformExpression) typeSet.add(ISOFORM_EXPRESSION);
319
- if (ds.queries?.metaboliteIntensity) typeSet.add(METABOLITE_INTENSITY);
320
- if (ds.queries?.proteome) typeSet.add(PROTEOME_ABUNDANCE);
321
- if (ds.queries?.ssGSEA) typeSet.add(SSGSEA);
322
- if (ds.queries?.dnaMethylation) typeSet.add(DNA_METHYLATION);
323
- if (ds.queries?.singleCell) {
324
- typeSet.add(SINGLECELL_CELLTYPE);
325
- if (ds.queries.singleCell?.geneExpression) typeSet.add(SINGLECELL_GENE_EXPRESSION);
326
- }
327
- if (ds.cohort.termdb.termCollections?.length) typeSet.add("termCollection");
328
- return [...typeSet];
329
- }
330
- function getSelectCohort(ds, req) {
331
- if (!ds.cohort.termdb.selectCohort) return;
332
- const copy = Object.assign({}, ds.cohort.termdb.selectCohort);
333
- if (ds.cohort.termdb.selectCohort.descriptionByUser) {
334
- copy.description = ds.cohort.termdb.selectCohort.descriptionByUser(authApi.getNonsensitiveInfo(req));
335
- delete copy.descriptionByUser;
336
- } else if (ds.cohort.termdb.selectCohort.descriptionByCohortBasedOnUserRole) {
337
- copy.descriptionByCohort = ds.cohort.termdb.selectCohort.descriptionByCohortBasedOnUserRole(
338
- authApi.getNonsensitiveInfo(req)
339
- );
340
- delete copy.descriptionByCohortBasedOnUserRole;
341
- }
342
- return copy;
343
- }
344
- export {
345
- getDsAllowedTermTypes,
346
- init
347
- };