@sjcrh/proteinpaint-server 2.191.5 → 2.192.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.
@@ -53,7 +53,6 @@ if (!serverconfig.tabix) serverconfig.tabix = 'tabix'
53
53
  if (!serverconfig.samtools) serverconfig.samtools = 'samtools'
54
54
  if (!serverconfig.bcftools) serverconfig.bcftools = 'bcftools'
55
55
  if (!serverconfig.hicstraw) serverconfig.hicstraw = 'straw'
56
- if (!serverconfig.bigwigsummary) serverconfig.bigwigsummary = 'bigWigSummary'
57
56
  if (!serverconfig.bigBedToBed) serverconfig.bigBedToBed = 'bigBedToBed'
58
57
  if (!serverconfig.bigBedInfo) serverconfig.bigBedInfo = 'bigBedInfo'
59
58
  if (!serverconfig.bigBedNamedItems) serverconfig.bigBedNamedItems = 'bigBedNamedItems'
@@ -228,7 +227,6 @@ if (process.env.PP_MODE?.startsWith('container')) {
228
227
  tpmasterdir: '/home/root/pp/tp',
229
228
  cachedir: '/home/root/pp/cache',
230
229
  hicstraw: '/home/root/pp/tools/straw',
231
- bigwigsummary: '/home/root/pp/tools/bigWigSummary',
232
230
  bigBedToBed: '/home/root/pp/tools/bigBedToBed',
233
231
  bigBedNamedItems: '/home/root/pp/tools/bigBedNamedItems',
234
232
  bigBedInfo: '/home/root/pp/tools/bigBedInfo'
@@ -1,115 +0,0 @@
1
- import { getData } from "#src/termdb.matrix.js";
2
- import computePercentile from "#shared/compute.percentile.js";
3
- import { roundValueAuto } from "#shared/roundValue.js";
4
- function init({ genomes }) {
5
- return async (req, res) => {
6
- const q = req.query;
7
- try {
8
- const genome = genomes[req.query.genome];
9
- if (!genome) throw "invalid genome name";
10
- const ds = genome.datasets[req.query.dslabel];
11
- if (!ds) throw "invalid dataset name";
12
- const tdb = ds.cohort.termdb;
13
- if (!tdb) throw "invalid termdb object";
14
- if (!q.tw.$id) q.tw.$id = "_";
15
- const result = await trigger_getDescrStats(q, ds);
16
- res.send(result);
17
- } catch (e) {
18
- if (e instanceof Error && e.stack) console.log(e);
19
- const result = { error: e?.message || e };
20
- res.send(result);
21
- }
22
- };
23
- }
24
- async function trigger_getDescrStats(q, ds) {
25
- const data = await getData(
26
- {
27
- filter: q.filter,
28
- filter0: q.filter0,
29
- terms: [q.tw],
30
- __protected__: q.__protected__,
31
- __abortSignal: q.__abortSignal
32
- },
33
- ds
34
- );
35
- if (data.error) throw data.error;
36
- const values = [];
37
- for (const key in data.samples) {
38
- const sample = data.samples[key];
39
- const v = sample[q.tw.$id || ""];
40
- if (!v && v !== 0) {
41
- continue;
42
- }
43
- const value = v.value;
44
- if (q.tw.term.values?.[value]?.uncomputable) {
45
- continue;
46
- }
47
- if (q.logScale) {
48
- if (value === 0) {
49
- continue;
50
- }
51
- }
52
- values.push(Number(value));
53
- }
54
- const stats = getDescrStats(values);
55
- return stats;
56
- }
57
- function getDescrStats(values, showOutlierRange = false) {
58
- if (!values.length) {
59
- return {};
60
- }
61
- if (values.some((v) => !Number.isFinite(v))) throw new Error("non-numeric values found");
62
- const sorted_arr = values.sort((a, b) => a - b);
63
- const n = sorted_arr.length;
64
- const median = computePercentile(sorted_arr, 50, true);
65
- const mean = getMean(sorted_arr);
66
- const variance = getVariance(sorted_arr);
67
- const stdDev = Math.sqrt(variance);
68
- const p25 = computePercentile(sorted_arr, 25, true);
69
- const p75 = computePercentile(sorted_arr, 75, true);
70
- const IQR = p75 - p25;
71
- const min = sorted_arr[0];
72
- const max = sorted_arr[sorted_arr.length - 1];
73
- const outlierMin = p25 - 1.5 * IQR;
74
- const outlierMax = p75 + 1.5 * IQR;
75
- const stats = {
76
- total: { key: "total", label: "Total", value: n },
77
- min: { key: "min", label: "Minimum", value: min },
78
- p25: { key: "p25", label: "1st quartile", value: p25 },
79
- median: { key: "median", label: "Median", value: median },
80
- p75: { key: "p75", label: "3rd quartile", value: p75 },
81
- max: { key: "max", label: "Maximum", value: max },
82
- mean: { key: "mean", label: "Mean", value: mean },
83
- stdDev: { key: "stdDev", label: "Standard deviation", value: stdDev }
84
- //variance: { label: 'Variance', value: variance }, // not necessary to report, as it is just stdDev^2
85
- //iqr: { label: 'Inter-quartile range', value: IQR } // not necessary to report, as it is just p75-p25
86
- };
87
- if (showOutlierRange) {
88
- stats.outlierMin = { key: "outlierMin", label: "Outlier minimum", value: outlierMin };
89
- stats.outlierMax = { key: "outlierMax", label: "Outlier maximum", value: outlierMax };
90
- }
91
- for (const v of Object.values(stats)) {
92
- const rounded = roundValueAuto(v.value);
93
- v.value = rounded;
94
- }
95
- return stats;
96
- }
97
- function getMean(data) {
98
- return data.reduce((sum, value) => sum + value, 0) / data.length;
99
- }
100
- function getVariance(data) {
101
- const meanValue = getMean(data);
102
- const squaredDifferences = data.map((value) => Math.pow(value - meanValue, 2));
103
- return squaredDifferences.reduce((sum, value) => sum + value, 0) / (data.length - 1);
104
- }
105
- function getStdDev(data) {
106
- const variance = getVariance(data);
107
- return Math.sqrt(variance);
108
- }
109
- export {
110
- getDescrStats,
111
- getMean,
112
- getStdDev,
113
- getVariance,
114
- init
115
- };
@@ -1,434 +0,0 @@
1
- import { getData } from "#src/termdb.matrix.js";
2
- import path from "path";
3
- import serverconfig from "#src/serverconfig.js";
4
- import { schemeCategory20, getColors, mclass, dt2label, morigin, isNumericTerm } from "#shared";
5
- import { authApi } from "#src/auth.js";
6
- import { run_R } from "@sjcrh/proteinpaint-r";
7
- import { read_file } from "#src/utils.js";
8
- import { getDescrStats } from "./termdb.descrstats.ts";
9
- const refColor = "#F5F5DC";
10
- function init({ genomes }) {
11
- return async function(req, res) {
12
- try {
13
- const q = req.query;
14
- if (!q.genome || !q.dslabel) {
15
- throw new Error("Genome and dataset label are required for termdb/sampleScatter request.");
16
- }
17
- const g = genomes[q.genome];
18
- const ds = g.datasets[q.dslabel];
19
- let refSamples = [], cohortSamples;
20
- const terms = [];
21
- if (q.colorTW) terms.push(q.colorTW);
22
- if (q.shapeTW) terms.push(q.shapeTW);
23
- if (q.divideByTW) terms.push(q.divideByTW);
24
- if (q.scaleDotTW) terms.push(q.scaleDotTW);
25
- if (q.coordTWs) for (const tw of q.coordTWs) terms.push(tw);
26
- const data = await getData(
27
- { filter: q.filter, filter0: q.filter0, terms, __protected__: q.__protected__, __abortSignal: q.__abortSignal },
28
- ds,
29
- true
30
- // FIXME 3rd arg hardcoded to true
31
- );
32
- if (data.error) throw new Error(data.error);
33
- let result;
34
- if (q.coordTWs && q.coordTWs.length > 0) {
35
- const tmp = await getSampleCoordinatesByTerms(req, q, ds, data);
36
- cohortSamples = tmp[0];
37
- } else {
38
- if (!q.plotName) throw new Error("Neither plot name or coordinates where provided");
39
- if (typeof ds.cohort?.scatterplots?.get == "function") {
40
- const allowed = ds.cohort.scatterplots.get(q.__protected__?.clientAuthResult);
41
- if (!allowed?.find((i) => i.name == q.plotName)) throw new Error("No permission to display plot");
42
- }
43
- if (!Array.isArray(ds.cohort?.scatterplots?.plots)) throw new Error("not supported");
44
- const plot = ds.cohort.scatterplots.plots.find((p) => p.name == q.plotName);
45
- if (!plot) throw new Error(`plot not found with plotName ${q.plotName}`);
46
- const tmp = await getSamples(ds, plot);
47
- refSamples = tmp[0];
48
- cohortSamples = tmp[1];
49
- if (q.colorColumn) {
50
- let categories = new Set(refSamples.map((s) => s.category));
51
- categories = Array.from(categories);
52
- const colorMap = {};
53
- const k2c = getColors(categories.length);
54
- for (const category of categories) {
55
- const color = q.colorColumn.colorMap?.[category] || k2c(category);
56
- colorMap[category] = {
57
- sampleCount: refSamples.filter((s) => s.category == category).length,
58
- color,
59
- key: category
60
- };
61
- }
62
- const shapeMap = { Ref: { shape: 0, sampleCount: refSamples.length, key: "Ref" } };
63
- result = {
64
- Default: {
65
- samples: refSamples,
66
- colorLegend: Object.entries(colorMap),
67
- shapeLegend: Object.entries(shapeMap)
68
- }
69
- };
70
- }
71
- }
72
- const samples = [...cohortSamples, ...refSamples];
73
- let range;
74
- if (samples.length > 0) {
75
- if (q.excludeOutliers) {
76
- const ystats = getDescrStats(
77
- samples.map((s) => s.y),
78
- q.excludeOutliers
79
- );
80
- cohortSamples = cohortSamples.filter(
81
- (sample) => sample.y > ystats.outlierMin.value && sample.y < ystats.outlierMax.value
82
- );
83
- refSamples = refSamples.filter(
84
- (sample) => sample.y > ystats.outlierMin.value && sample.y < ystats.outlierMax.value
85
- );
86
- }
87
- const s0 = samples[0];
88
- const [xMin, xMax, yMin, yMax] = samples.reduce(
89
- (s, d) => [
90
- d.x < s[0] ? d.x : s[0],
91
- d.x > s[1] ? d.x : s[1],
92
- d.y < s[2] ? d.y : s[2],
93
- d.y > s[3] ? d.y : s[3]
94
- ],
95
- [s0.x, s0.x, s0.y, s0.y]
96
- );
97
- range = { xMin, xMax, yMin, yMax };
98
- }
99
- if (!result) result = await colorAndShapeSamples(refSamples, cohortSamples, data, q);
100
- res.send({ result, range });
101
- } catch (e) {
102
- if (e.stack) console.log(e.stack);
103
- res.send({ error: e.message || e });
104
- }
105
- };
106
- }
107
- async function getSamples(ds, plot) {
108
- if (!plot.filterableSamples) await loadFile(plot, ds);
109
- return [readSamples(plot.referenceSamples), readSamples(plot.filterableSamples)];
110
- function readSamples(samples) {
111
- const result = [];
112
- for (const i of JSON.parse(JSON.stringify(samples))) {
113
- result.push(i);
114
- }
115
- return result;
116
- }
117
- }
118
- async function colorAndShapeSamples(refSamples, cohortSamples, data, q) {
119
- const results = {};
120
- let fCount = 0;
121
- const hasTerms = Object.keys(data.samples).length > 0;
122
- for (const sample of cohortSamples) {
123
- const dbSample = data.samples[sample.sampleId.toString()];
124
- if (!dbSample && hasTerms) {
125
- fCount++;
126
- continue;
127
- }
128
- if (q.colorTW && !hasValue(dbSample, q.colorTW) || q.shapeTW && !hasValue(dbSample, q.shapeTW)) continue;
129
- let divideBy = "Default";
130
- if (q.divideByTW) {
131
- sample.z = 0;
132
- if (q.divideByTW.term.type == "geneVariant" && q.divideByTW.q.type == "values") {
133
- divideBy = getMutation(true, dbSample, q.divideByTW);
134
- if (divideBy == null) {
135
- divideBy = getMutation(false, dbSample, q.divideByTW);
136
- }
137
- } else {
138
- const field = q.divideByTW.$id;
139
- const key = dbSample[field]?.key;
140
- if (key == null) continue;
141
- if (q.divideByTW.q.mode != "continuous") divideBy = q.divideByTW.term.values?.[key]?.label || key;
142
- else sample.z = key;
143
- }
144
- }
145
- if (divideBy == null || divideBy == void 0) {
146
- console.log("divideBy is null/undefined for sample " + JSON.stringify(sample));
147
- continue;
148
- }
149
- if (!results[divideBy]) {
150
- const samples = refSamples.map((sample2) => ({ ...sample2, category: "Ref", shape: "Ref", z: 0 }));
151
- results[divideBy] = { samples, colorMap: {}, shapeMap: {} };
152
- }
153
- if (!q.divideByTW) sample.z = 0;
154
- if (!q.scaleDotTW) sample.scale = 1;
155
- else {
156
- const value = dbSample?.[q.scaleDotTW.$id]?.key;
157
- if (!value || !isComputable(q.scaleDotTW.term, value)) continue;
158
- sample.scale = value;
159
- }
160
- sample.cat_info = {};
161
- sample.hidden = {};
162
- if (!q.colorTW) {
163
- sample.category = "Default";
164
- } else {
165
- if (q.colorTW?.q?.mode === "continuous") {
166
- if (dbSample) sample.category = dbSample[q.colorTW.$id].value;
167
- } else processSample(dbSample, sample, q.colorTW, results[divideBy].colorMap, "category");
168
- }
169
- if (q.shapeTW) processSample(dbSample, sample, q.shapeTW, results[divideBy].shapeMap, "shape");
170
- else sample.shape = "Ref";
171
- results[divideBy].samples.push(sample);
172
- }
173
- if (fCount) console.log(fCount + " samples not in the database or filtered");
174
- let max = 0;
175
- for (const [_, result] of Object.entries(results)) max = Math.max(max, Object.keys(result.colorMap).length);
176
- const k2c = getColors(max);
177
- const scheme = schemeCategory20;
178
- for (const [_, result] of Object.entries(results)) {
179
- if (q.colorTW && q.colorTW.q.mode !== "continuous") {
180
- let i2 = 20;
181
- for (const [category, value] of Object.entries(result.colorMap)) {
182
- delete value["sampleIds"];
183
- let tvalue;
184
- if (q.colorTW.term.values?.[value.key]) {
185
- tvalue = q.colorTW.term.values?.[value.key];
186
- }
187
- if (tvalue && "color" in tvalue) {
188
- value.color = tvalue.color;
189
- } else if (isNumericTerm(q.colorTW.term)) {
190
- const term = data.refs.byTermId[q.colorTW.$id] || data.refs.byTermId[q.colorTW.term.id];
191
- const bins = term.bins;
192
- const bin = bins.find((bin2) => bin2.label == category);
193
- if (bin?.color) value.color = bin.color;
194
- else {
195
- value.color = scheme[i2 - 1];
196
- i2--;
197
- }
198
- } else if (!(q.colorTW.term.type == "geneVariant" && q.colorTW.q.type == "values")) {
199
- value.color = k2c(category);
200
- }
201
- }
202
- }
203
- let i = 0;
204
- const shapes = Object.entries(result.shapeMap).sort((a, b) => a[0].localeCompare(b[0]));
205
- for (const [_2, value] of shapes) {
206
- delete value["sampleIds"];
207
- if ("shape" in value) continue;
208
- if (q.shapeTW.term.values?.[value.key]?.shape != void 0)
209
- value.shape = q.shapeTW.term.values?.[value.key].shape;
210
- else value.shape = i;
211
- i++;
212
- }
213
- result.colorLegend = q.colorTW ? order(result.colorMap, q.colorTW, data.refs) : [["Default", { sampleCount: cohortSamples.length, color: "blue", key: "Default" }]];
214
- result.colorLegend.push([
215
- "Ref",
216
- {
217
- sampleCount: refSamples.length,
218
- color: q.colorTW?.term.values?.["Ref"] ? q.colorTW.term.values?.["Ref"].color : refColor,
219
- key: "Ref"
220
- }
221
- ]);
222
- result.shapeLegend = shapes;
223
- result.shapeLegend.push(["Ref", { sampleCount: refSamples.length, shape: 0, key: "Ref" }]);
224
- }
225
- return results;
226
- }
227
- function hasValue(dbSample, tw) {
228
- const key = tw && tw.$id !== void 0 ? dbSample?.[tw.$id]?.key : void 0;
229
- const hasKey = key !== void 0;
230
- return hasKey;
231
- }
232
- function processSample(dbSample, sample, tw, categoryMap, category) {
233
- let value = null;
234
- if (tw.term.type == "geneVariant" && tw.q["type"] == "values")
235
- assignGeneVariantValue(dbSample, sample, tw, categoryMap, category);
236
- else {
237
- value = dbSample?.[tw.$id]?.key;
238
- if (value == null) return;
239
- if (tw.term.values?.[value]?.label) {
240
- value = tw.term.values?.[value]?.label;
241
- sample.hidden[category] = tw.q.hiddenValues ? value in tw.q.hiddenValues : false;
242
- } else sample.hidden[category] = tw.q.hiddenValues ? dbSample?.[tw.$id]?.key in tw.q.hiddenValues : false;
243
- if (value) {
244
- sample[category] = value.toString();
245
- if (categoryMap[value] == void 0) categoryMap[value] = { sampleCount: 1, key: dbSample?.[tw.$id]?.key };
246
- else categoryMap[value].sampleCount++;
247
- }
248
- }
249
- }
250
- function assignGeneVariantValue(dbSample, sample, tw, categoryMap, category) {
251
- if (tw.term.type == "geneVariant") {
252
- const mutations = dbSample?.[tw.$id]?.values;
253
- sample.cat_info[category] = [];
254
- for (const mutation of mutations) {
255
- const class_info = mclass[mutation.class];
256
- const value = getCategory(mutation);
257
- sample.cat_info[category].push(mutation);
258
- let mapValue;
259
- if (categoryMap[value] == void 0) {
260
- const sampleIds = /* @__PURE__ */ new Set();
261
- sampleIds.add(dbSample.sample);
262
- mapValue = { color: class_info.color, sampleCount: 1, mutation, key: value, sampleIds };
263
- categoryMap[value] = mapValue;
264
- } else {
265
- mapValue = categoryMap[value];
266
- mapValue.sampleIds.add(dbSample.sample);
267
- mapValue.sampleCount = mapValue.sampleIds.size;
268
- }
269
- }
270
- sample[category] = getMutation(true, dbSample, tw) || getMutation(false, dbSample, tw);
271
- if (!sample[category]) sample[category] = getCategory(mutations[0]);
272
- sample.hidden[category] = tw.q.hiddenValues ? sample[category] in tw.q.hiddenValues : false;
273
- }
274
- }
275
- function getMutation(strict, dbSample, tw) {
276
- const mutations = dbSample?.[tw.$id]?.values;
277
- for (const [dt, _] of Object.entries(dt2label)) {
278
- const mutation = mutations.find((mutation2) => {
279
- const value2 = getCategory(mutation2);
280
- const visible = !(tw.q.hiddenValues && value2 in tw.q.hiddenValues);
281
- return mutation2.dt == dt && visible;
282
- });
283
- if (!mutation) continue;
284
- const notImportant = mutation.class == "WT" || mutation.class == "Blank";
285
- if (strict && notImportant) continue;
286
- const value = getCategory(mutation);
287
- return value;
288
- }
289
- }
290
- function getCategory(mutation) {
291
- const dt = mutation.dt;
292
- const class_info = mclass[mutation.class];
293
- const origin = morigin[mutation.origin]?.label;
294
- const dtlabel = origin ? `${origin[0]} ${dt2label[dt]}` : dt2label[dt];
295
- return `${class_info.label}, ${dtlabel}`;
296
- }
297
- function order(map, tw, refs) {
298
- const hasOrder = tw?.term?.values ? Object.keys(tw.term.values).some((key) => tw.term.values[key].order != void 0) : false;
299
- let entries = [];
300
- if (!tw || map.size == 0) return entries;
301
- entries = Object.entries(map);
302
- const term = refs?.byTermId[tw.$id] || refs?.byTermId[tw.term.id];
303
- if (hasOrder) {
304
- entries.sort((a, b) => {
305
- let v1, v2;
306
- for (const key in tw.term.values) {
307
- const value = tw.term.values[key];
308
- if (value.label && a[0] == value.label) v1 = value;
309
- else if (key == a[0]) v1 = value;
310
- if (value.label && b[0] == value.label) v2 = value;
311
- else if (key == b[0]) v2 = value;
312
- }
313
- if (v1?.order < v2?.order) return -1;
314
- else if (v1?.order > v2?.order) return 1;
315
- else if (v1 > v2) return 1;
316
- else if (v1 < v2) return -1;
317
- return 0;
318
- });
319
- } else if (term?.bins) {
320
- const bins = term.bins;
321
- entries.sort((a, b) => {
322
- const binA = bins.findIndex((bin) => bin.label == a[0]);
323
- const binB = bins.findIndex((bin) => bin.label == b[0]);
324
- if (binA == -1) return 1;
325
- if (binB == -1) return -1;
326
- return binA - binB;
327
- });
328
- } else {
329
- entries.sort((a, b) => a[0].localeCompare(b[0]));
330
- }
331
- return entries;
332
- }
333
- async function getSampleCoordinatesByTerms(req, q, ds, data) {
334
- if (!q.coordTWs || q.coordTWs.length == 0) return [[], data];
335
- const canDisplay = authApi.canDisplaySampleIds(req, ds);
336
- const samples = [];
337
- for (const sampleId in data.samples) {
338
- const values = data.samples[sampleId];
339
- const x = values[q.coordTWs[0].$id]?.value;
340
- let y = values[q.coordTWs[1]?.$id]?.value;
341
- if (y === void 0 && (q.chartType == "runchart" || q.chartType == "frequencyChart")) y = 0;
342
- const z = q.divideByTW ? values[q.divideByTW?.$id]?.value : 0;
343
- if (x == void 0 || y == void 0 || z == void 0) continue;
344
- if (!isComputable(q.coordTWs[0].term, x) || !isComputable(q.coordTWs[1]?.term, y) || !isComputable(q.divideByTW?.term, z)) {
345
- continue;
346
- }
347
- const sample = { sampleId, x: Number(x), y: Number(y), z: Number(z) };
348
- if (canDisplay) {
349
- sample.sample = data.refs.bySampleId[sampleId]?.label || sampleId;
350
- }
351
- samples.push(sample);
352
- }
353
- return [samples, data];
354
- }
355
- function isComputable(term, value) {
356
- if (!term) return true;
357
- return !term.values?.[value]?.uncomputable;
358
- }
359
- async function loadFile(p, ds) {
360
- const lines = (await read_file(path.join(serverconfig.tpmasterdir, p.file))).trim().split("\n");
361
- const xColumn = p.coordsColumns?.x || 1;
362
- const yColumn = p.coordsColumns?.y || 2;
363
- const headerFields = lines[0].split(" ");
364
- p.filterableSamples = [];
365
- p.referenceSamples = [];
366
- let invalidXY = 0;
367
- for (let i = 1; i < lines.length; i++) {
368
- const l = lines[i].trim().split(" ");
369
- const x = Number(l[xColumn]), y = Number(l[yColumn]);
370
- if (Number.isNaN(x) || Number.isNaN(y)) {
371
- invalidXY++;
372
- continue;
373
- }
374
- const sample = { sample: l[0], x, y };
375
- if (p.colorColumn) {
376
- sample["sampleId"] = l[0];
377
- sample.category = l[p.colorColumn.index];
378
- sample.shape = "Ref";
379
- sample.z = 0;
380
- }
381
- const id = ds.cohort.termdb.q.sampleName2id(l[0]);
382
- if (id == void 0) {
383
- if (headerFields[3]) {
384
- sample.info = {};
385
- for (let j = 3; j < headerFields.length; j++) {
386
- sample.info[headerFields[j]] = l[j];
387
- }
388
- }
389
- p.referenceSamples.push(sample);
390
- } else {
391
- sample["sampleId"] = id;
392
- p.filterableSamples.push(sample);
393
- }
394
- }
395
- console.log(
396
- p.name + " (prebuilt scatter):",
397
- p.filterableSamples.length,
398
- "lines,",
399
- p.referenceSamples.length,
400
- "reference cases,",
401
- invalidXY,
402
- "lines with invalid X/Y values"
403
- );
404
- }
405
- async function mayInitiateScatterplots(ds) {
406
- if (ds.scatterplots) {
407
- ds.cohort.scatterplots = ds.scatterplots;
408
- delete ds.scatterplots;
409
- }
410
- if (!ds.cohort.scatterplots) return;
411
- if (typeof ds.cohort.scatterplots.get == "function") {
412
- }
413
- if (!Array.isArray(ds.cohort.scatterplots.plots)) throw new Error("cohort.scatterplots.plots is not array");
414
- for (const p of ds.cohort.scatterplots.plots) {
415
- if (!p.name) throw new Error(".name missing from one of scatterplots.plots[]");
416
- if (p.file) {
417
- } else {
418
- throw new Error("unknown data source of one of scatterplots.plots[]");
419
- }
420
- }
421
- }
422
- async function trigger_getLowessCurve(q, res) {
423
- const data = q.coords;
424
- const result = JSON.parse(await run_R("lowess.R", JSON.stringify(data)));
425
- const lowessCurve = [];
426
- for (const [i, x] of Object.entries(result.x)) lowessCurve.push([x, result.y[i]]);
427
- return res.send(lowessCurve);
428
- }
429
- export {
430
- init,
431
- mayInitiateScatterplots,
432
- refColor,
433
- trigger_getLowessCurve
434
- };