@sjcrh/proteinpaint-server 2.189.0 → 2.190.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.
Files changed (82) hide show
  1. package/package.json +9 -12
  2. package/routes/aiProjectAdmin.js +2 -28
  3. package/routes/aiProjectSelectedWSImages.js +2 -16
  4. package/routes/brainImaging.js +1 -15
  5. package/routes/brainImagingSamples.js +1 -15
  6. package/routes/burden.js +1 -15
  7. package/routes/correlationVolcano.js +1 -15
  8. package/routes/dataset.js +1 -16
  9. package/routes/deleteWSITileSelection.js +2 -12
  10. package/routes/dsdata.js +1 -19
  11. package/routes/gdc.grin2.list.js +1 -15
  12. package/routes/gdc.grin2.run.js +1 -15
  13. package/routes/gdc.maf.js +1 -15
  14. package/routes/gdc.mafBuild.js +1 -15
  15. package/routes/genesetEnrichment.js +129 -97
  16. package/routes/grin2.js +110 -79
  17. package/routes/saveWSIAnnotation.js +2 -13
  18. package/routes/termdb.DE.js +137 -54
  19. package/routes/termdb.categories.js +2 -16
  20. package/routes/termdb.chat.js +169 -1076
  21. package/routes/termdb.cluster.js +5 -16
  22. package/routes/termdb.config.js +12 -17
  23. package/routes/termdb.descrstats.js +2 -16
  24. package/routes/termdb.diffMeth.js +100 -21
  25. package/routes/termdb.geneRanking.js +139 -0
  26. package/routes/termdb.proteome.js +1 -15
  27. package/routes/termdb.runChart.js +16 -30
  28. package/routes/termdb.sampleScatter.js +7 -97
  29. package/routes/termdb.singleCellPlots.js +159 -0
  30. package/routes/termdb.singlecellSamples.js +6 -16
  31. package/routes/termdb.violinBox.js +1 -15
  32. package/routes/wsimages.js +1 -16
  33. package/src/app.js +3984 -4103
  34. package/routes/_template_.js +0 -33
  35. package/routes/aiProjectTrainModel.js +0 -68
  36. package/routes/alphaGenome.js +0 -41
  37. package/routes/alphaGenomeTypes.js +0 -36
  38. package/routes/dzimages.js +0 -55
  39. package/routes/gene2canonicalisoform.js +0 -37
  40. package/routes/genelookup.js +0 -32
  41. package/routes/genesetOverrepresentation.js +0 -49
  42. package/routes/genomes.js +0 -150
  43. package/routes/healthcheck.js +0 -35
  44. package/routes/hicdata.js +0 -74
  45. package/routes/hicgenome.js +0 -75
  46. package/routes/hicstat.js +0 -35
  47. package/routes/img.js +0 -46
  48. package/routes/isoformlst.js +0 -48
  49. package/routes/ntseq.js +0 -36
  50. package/routes/pdomain.js +0 -53
  51. package/routes/profile.barchart2.js +0 -114
  52. package/routes/profile.forms2.js +0 -107
  53. package/routes/profile.polar2.js +0 -101
  54. package/routes/profile.radar2.js +0 -112
  55. package/routes/profile.radarFacility2.js +0 -148
  56. package/routes/sampledzimages.js +0 -48
  57. package/routes/samplewsimages.js +0 -60
  58. package/routes/snp.js +0 -98
  59. package/routes/termdb.chat2.js +0 -217
  60. package/routes/termdb.chat3.js +0 -209
  61. package/routes/termdb.cohort.summary.js +0 -37
  62. package/routes/termdb.cohorts.js +0 -41
  63. package/routes/termdb.dapVolcano.js +0 -80
  64. package/routes/termdb.dmr.js +0 -93
  65. package/routes/termdb.filterTermValues.js +0 -89
  66. package/routes/termdb.isoformAvailability.js +0 -35
  67. package/routes/termdb.numericcategories.js +0 -46
  68. package/routes/termdb.percentile.js +0 -66
  69. package/routes/termdb.profileFormScores.js +0 -92
  70. package/routes/termdb.profileScores.js +0 -113
  71. package/routes/termdb.rootterm.js +0 -39
  72. package/routes/termdb.sampleImages.js +0 -63
  73. package/routes/termdb.singleSampleMutation.js +0 -75
  74. package/routes/termdb.singlecellDEgenes.js +0 -55
  75. package/routes/termdb.singlecellData.js +0 -39
  76. package/routes/termdb.termchildren.js +0 -42
  77. package/routes/termdb.termsbyids.js +0 -50
  78. package/routes/termdb.topMutatedGenes.js +0 -127
  79. package/routes/termdb.topTermsByType.js +0 -96
  80. package/routes/termdb.topVariablyExpressedGenes.js +0 -132
  81. package/routes/tileserver.js +0 -68
  82. package/routes/wsisamples.js +0 -71
@@ -1,66 +0,0 @@
1
- import { percentilePayload } from "#types/checkers";
2
- import { isNumericTerm } from "#shared/terms.js";
3
- import { getData } from "#src/termdb.matrix.js";
4
- import computePercentile from "#shared/compute.percentile.js";
5
- const api = {
6
- endpoint: "termdb/getpercentile",
7
- methods: {
8
- get: {
9
- ...percentilePayload,
10
- init
11
- },
12
- post: {
13
- ...percentilePayload,
14
- init
15
- }
16
- }
17
- };
18
- function init({ genomes }) {
19
- return async (req, res) => {
20
- const q = req.query;
21
- try {
22
- const g = genomes[req.query.genome];
23
- if (!g) throw "invalid genome name";
24
- const ds = g.datasets[req.query.dslabel];
25
- if (!ds) throw "invalid dataset name";
26
- await trigger_getpercentile(q, res, ds);
27
- } catch (e) {
28
- res.send({ error: e instanceof Error ? e.message : e });
29
- if (e instanceof Error && e.stack) console.log(e);
30
- }
31
- };
32
- }
33
- async function trigger_getpercentile(q, res, ds) {
34
- const term = q.term;
35
- if (!term) throw "term is missing";
36
- if (!isNumericTerm(term)) throw "not numeric term";
37
- const tw = { $id: "_", term, q: { mode: "continuous" } };
38
- const data = await getData({ filter: q.filter, filter0: q.filter0, terms: [tw], __protected__: q.__protected__ }, ds);
39
- if (data.error) throw data.error;
40
- const values = [];
41
- for (const key in data.samples) {
42
- const sample = data.samples[key];
43
- const v = sample[tw.$id];
44
- if (!v?.value) {
45
- continue;
46
- }
47
- const value = v.value;
48
- if (term.values && term.values[value] && term.values[value].uncomputable) {
49
- continue;
50
- }
51
- if (term.skip0forPercentile && value == 0) {
52
- continue;
53
- }
54
- values.push(Number(value));
55
- }
56
- const percentile_lst = q.getpercentile;
57
- const perc_values = [];
58
- for (const percentile of percentile_lst) {
59
- const perc_value = computePercentile(values, percentile);
60
- perc_values.push(perc_value);
61
- }
62
- res.send({ values: perc_values });
63
- }
64
- export {
65
- api
66
- };
@@ -1,92 +0,0 @@
1
- import { ProfileFormScoresPayload } from "#types/checkers";
2
- import { getScoresData } from "./termdb.profileScores.ts";
3
- const api = {
4
- endpoint: "termdb/profileFormScores",
5
- methods: {
6
- get: {
7
- ...ProfileFormScoresPayload,
8
- init
9
- },
10
- post: {
11
- ...ProfileFormScoresPayload,
12
- init
13
- }
14
- }
15
- };
16
- function init({ genomes }) {
17
- return async (req, res) => {
18
- try {
19
- const g = genomes[req.query.genome];
20
- if (!g) throw "invalid genome name";
21
- const ds = g.datasets?.[req.query.dslabel];
22
- const result = await getScoresDict(req.query, ds);
23
- res.send(result);
24
- } catch (e) {
25
- console.log(e);
26
- res.send({ status: "error", error: e.message || e });
27
- }
28
- };
29
- }
30
- async function getScoresDict(query, ds) {
31
- const terms = [...query.scoreTerms, query.facilityTW];
32
- if (query.scScoreTerms) terms.push(...query.scScoreTerms);
33
- const data = await getScoresData(query, ds, terms);
34
- const term2Score = {};
35
- for (const d of query.scoreTerms) {
36
- const getDictFunc = (sample) => getDict(d.$id, sample);
37
- const percents = getPercentsDict(getDictFunc, data.samples);
38
- term2Score[d.term.id] = percents;
39
- }
40
- if (query.scScoreTerms)
41
- for (const d of query.scScoreTerms) {
42
- const percents = getSCPercentsDict(d, data.samples);
43
- term2Score[d.term.id] = percents;
44
- }
45
- const { clientAuthResult, activeCohort } = query.__protected__;
46
- const isPublic = !clientAuthResult[activeCohort]?.role || clientAuthResult[activeCohort].role === "public";
47
- let hospital;
48
- if (!isPublic && data.sampleData) {
49
- const facilityValue = data.sampleData[query.facilityTW.$id];
50
- const termValue = query.facilityTW.term.values[facilityValue?.value];
51
- hospital = termValue?.label || termValue?.key;
52
- }
53
- return {
54
- term2Score,
55
- // Do not expose individual site IDs, names, or hospital to public-role users
56
- sites: isPublic ? [] : data.sites,
57
- hospital,
58
- n: data.sampleData ? 1 : data.samples.length
59
- };
60
- }
61
- function getDict(key, sample) {
62
- if (!sample[key]) return null;
63
- const termData = sample[key].value;
64
- return JSON.parse(termData);
65
- }
66
- function getPercentsDict(getDictFunc, samples) {
67
- const percentageDict = {};
68
- for (const sample of samples) {
69
- const percents = getDictFunc(sample);
70
- if (!percents) continue;
71
- for (const key in percents) {
72
- const value = percents[key];
73
- if (!percentageDict[key]) percentageDict[key] = 0;
74
- percentageDict[key] += value;
75
- }
76
- }
77
- return percentageDict;
78
- }
79
- function getSCPercentsDict(tw, samples) {
80
- if (!tw) throw "tw not defined";
81
- const percentageDict = {};
82
- for (const sample of samples) {
83
- const twData = sample[tw.$id];
84
- const key = twData?.value;
85
- if (!percentageDict[key]) percentageDict[key] = 0;
86
- percentageDict[key] += 1;
87
- }
88
- return percentageDict;
89
- }
90
- export {
91
- api
92
- };
@@ -1,113 +0,0 @@
1
- import { ProfileScoresPayload } from "#types/checkers";
2
- import { getData } from "../src/termdb.matrix.js";
3
- const api = {
4
- endpoint: "termdb/profileScores",
5
- methods: {
6
- get: {
7
- ...ProfileScoresPayload,
8
- init
9
- },
10
- post: {
11
- ...ProfileScoresPayload,
12
- init
13
- }
14
- }
15
- };
16
- function init({ genomes }) {
17
- return async (req, res) => {
18
- try {
19
- const g = genomes[req.query.genome];
20
- if (!g) throw "invalid genome name";
21
- const ds = g.datasets?.[req.query.dslabel];
22
- const result = await getScores(req.query, ds);
23
- res.send(result);
24
- } catch (e) {
25
- console.log(e);
26
- res.send({ status: "error", error: e.message || e });
27
- }
28
- };
29
- }
30
- async function getScoresData(query, ds, terms) {
31
- if (!query.filterByUserSites) query.__protected__.ignoredTermIds.push(query.facilityTW.term.id);
32
- const { clientAuthResult, activeCohort } = query.__protected__;
33
- const userSites = clientAuthResult[activeCohort].sites;
34
- const data = await getData(
35
- {
36
- terms,
37
- filter: query.filter,
38
- __protected__: query.__protected__
39
- },
40
- ds
41
- );
42
- if (data.error) throw data.error;
43
- const lst = Object.values(data.samples);
44
- let sites = lst.map((s) => {
45
- let label = query.facilityTW.term.values[s[query.facilityTW.$id].value]?.label || s[query.facilityTW.$id].value;
46
- if (label.length > 50) label = label.slice(0, 47) + "...";
47
- return {
48
- value: s[query.facilityTW.$id].value,
49
- label
50
- };
51
- });
52
- if (userSites) {
53
- sites = sites.filter((s) => userSites.includes(s.value));
54
- }
55
- sites.sort((a, b) => {
56
- return a.label.localeCompare(b.label);
57
- });
58
- const samples = Object.values(data.samples);
59
- let sampleData, site;
60
- if ("facilitySite" in query) {
61
- const facilitySite = query.facilitySite || sites[0].value;
62
- const index = lst.findIndex((s) => s[query.facilityTW.$id].value == facilitySite);
63
- sampleData = lst[index];
64
- site = sites.find((s) => s.value == facilitySite);
65
- } else if (sites.length == 1) {
66
- sampleData = data.samples[sites[0].value];
67
- site = sites[0];
68
- }
69
- return { samples, sampleData, sites, site };
70
- }
71
- async function getScores(query, ds) {
72
- const terms = [query.facilityTW];
73
- for (const term of query.scoreTerms) {
74
- terms.push(term.score);
75
- if (term.maxScore?.term) {
76
- terms.push(term.maxScore);
77
- }
78
- }
79
- const data = await getScoresData(query, ds, terms);
80
- const term2Score = {};
81
- for (const d of query.scoreTerms) {
82
- term2Score[d.score.term.id] = getPercentage(d, data.samples, data.sampleData);
83
- }
84
- const { clientAuthResult, activeCohort } = query.__protected__;
85
- const isPublic = !clientAuthResult[activeCohort]?.role || clientAuthResult[activeCohort].role === "public";
86
- return {
87
- term2Score,
88
- // Do not expose individual site IDs or names to public-role users
89
- sites: isPublic ? [] : data.sites,
90
- site: isPublic ? void 0 : data.site,
91
- n: data.sampleData ? 1 : data.samples.length
92
- };
93
- }
94
- function getPercentage(d, samples, sampleData) {
95
- if (!d) return null;
96
- const isAggregate = sampleData == null;
97
- if (isAggregate) {
98
- const scores = samples.filter((sample) => sample[d.score.$id]?.value).map((sample) => sample[d.score.$id].value / (sample[d.maxScore.$id]?.value || d.maxScore) * 100);
99
- scores.sort((s1, s2) => s1 - s2);
100
- const middle = Math.floor(scores.length / 2);
101
- const score = scores.length % 2 !== 0 ? scores[middle] : (scores[middle - 1] + scores[middle]) / 2;
102
- return Math.round(score);
103
- } else {
104
- const score = sampleData[d.score.$id]?.value;
105
- const maxScore = d.maxScore.term ? sampleData[d.maxScore.$id]?.value : d.maxScore;
106
- const percentage = score / maxScore * 100;
107
- return Math.round(percentage);
108
- }
109
- }
110
- export {
111
- api,
112
- getScoresData
113
- };
@@ -1,39 +0,0 @@
1
- import { rootTermPayload } from "#types/checkers";
2
- import { get_ds_tdb } from "#src/termdb.js";
3
- const api = {
4
- endpoint: "termdb/rootterm",
5
- methods: {
6
- get: {
7
- ...rootTermPayload,
8
- init
9
- },
10
- post: {
11
- ...rootTermPayload,
12
- init
13
- }
14
- }
15
- };
16
- function init({ genomes }) {
17
- return async (req, res) => {
18
- const q = req.query;
19
- try {
20
- const g = genomes[req.query.genome];
21
- if (!g) throw "invalid genome name";
22
- const [ds, tdb] = get_ds_tdb(g, q);
23
- if (!ds) throw "invalid dataset name";
24
- if (!tdb) throw "invalid termdb object";
25
- await trigger_rootterm(req, q, res, tdb);
26
- } catch (e) {
27
- res.send({ error: e instanceof Error ? e.message : e });
28
- if (e instanceof Error && e.stack) console.log(e);
29
- }
30
- };
31
- }
32
- async function trigger_rootterm(req, q, res, tdb) {
33
- const cohortValues = q.cohortValues ? q.cohortValues : "";
34
- const treeFilter = q.treeFilter ? q.treeFilter : "";
35
- res.send({ lst: await tdb.q.getRootTerms(req, cohortValues, treeFilter) });
36
- }
37
- export {
38
- api
39
- };
@@ -1,63 +0,0 @@
1
- import { termdbSampleImagesPayload } from "#types/checkers";
2
- import path from "path";
3
- import fs from "fs";
4
- import serverconfig from "#src/serverconfig.js";
5
- const api = {
6
- endpoint: "termdb/getSampleImages",
7
- methods: {
8
- get: {
9
- ...termdbSampleImagesPayload,
10
- init
11
- },
12
- post: {
13
- ...termdbSampleImagesPayload,
14
- init
15
- }
16
- }
17
- };
18
- function init({ genomes }) {
19
- return async (req, res) => {
20
- try {
21
- const q = req.query;
22
- const sampleId = q.sampleId;
23
- const genome = genomes[q.genome];
24
- if (!genome) throw "invalid genome";
25
- const ds = genome.datasets?.[q.dslabel];
26
- if (!ds) throw "invalid dslabel";
27
- const images = await ds.queries.images.getSampleImages({ sampleId });
28
- res.send({ images });
29
- } catch (e) {
30
- res.send({ status: "error", error: e.message || e });
31
- }
32
- };
33
- }
34
- function validate_query_getSampleImages(ds) {
35
- const q = ds.queries.images;
36
- if (!q) return;
37
- nativeValidateQuery(ds);
38
- }
39
- function nativeValidateQuery(ds) {
40
- ds.queries.images.getSampleImages = async (q) => {
41
- const folder = ds.queries.images.folder;
42
- const images = await getSampleImages(ds, folder, q.sampleId);
43
- return images;
44
- };
45
- }
46
- async function getSampleImages(ds, folder, sampleId) {
47
- const sql = `SELECT * FROM images WHERE sample = ${sampleId}`;
48
- const rows = ds.cohort.db.connection.prepare(sql).all();
49
- const images = [];
50
- for (const row of rows) {
51
- const file = path.join(serverconfig.tpmasterdir, folder, row.fileName);
52
- if (!fs.existsSync(file)) throw new Error(`File ${row.fileName} does not exist`);
53
- const data = await fs.promises.readFile(file);
54
- images.push({
55
- src: "data:image/jpeg;base64," + Buffer.from(data).toString("base64")
56
- });
57
- }
58
- return images;
59
- }
60
- export {
61
- api,
62
- validate_query_getSampleImages
63
- };
@@ -1,75 +0,0 @@
1
- import path from "path";
2
- import { read_file, file_is_readable, fileurl, illegalpath } from "#src/utils.js";
3
- import { termdbSingleSampleMutationPayload } from "#types/checkers";
4
- import { gdcValidate_query_singleSampleMutation } from "#src/mds3.gdc.js";
5
- const api = {
6
- endpoint: "termdb/singleSampleMutation",
7
- methods: {
8
- get: {
9
- ...termdbSingleSampleMutationPayload,
10
- init
11
- }
12
- }
13
- };
14
- function init({ genomes }) {
15
- return async (req, res) => {
16
- const q = req.query;
17
- let result;
18
- try {
19
- const g = genomes[q.genome];
20
- if (!g) throw "invalid genome name";
21
- const ds = g.datasets[q.dslabel];
22
- if (!ds) throw "invalid dataset name";
23
- if (!ds.queries?.singleSampleMutation) throw "not supported on this dataset";
24
- result = await ds.queries.singleSampleMutation.get(q);
25
- } catch (e) {
26
- if (e.stack) console.log(e.stack);
27
- result = {
28
- status: e.status || 400,
29
- error: e.message || e
30
- };
31
- }
32
- res.send(result);
33
- };
34
- }
35
- async function validate_query_singleSampleMutation(ds, genome) {
36
- const _q = ds.queries.singleSampleMutation;
37
- if (!_q) return;
38
- if (typeof _q.get == "function") {
39
- } else if (_q.src == "gdcapi") {
40
- gdcValidate_query_singleSampleMutation(ds, genome);
41
- } else if (_q.src == "native") {
42
- _q.get = async (q) => {
43
- let sample;
44
- {
45
- const vt = typeof q.sample;
46
- if (vt == "string") {
47
- if (q.sample == "") throw "sample is blank string";
48
- sample = q.sample;
49
- } else if (vt == "number") {
50
- sample = q.sample.toString();
51
- } else {
52
- throw "sample value is not string or number";
53
- }
54
- }
55
- if (illegalpath(sample)) throw "invalid sample name";
56
- const tmp = fileurl({
57
- query: {
58
- file: path.join(_q.folder, sample)
59
- }
60
- });
61
- if (tmp[0]) throw tmp[0];
62
- const file = tmp[1];
63
- if (!file) throw "no file returned";
64
- await file_is_readable(file);
65
- const data = await read_file(file);
66
- return { mlst: JSON.parse(data) };
67
- };
68
- } else {
69
- throw "unknown singleSampleMutation.src";
70
- }
71
- }
72
- export {
73
- api,
74
- validate_query_singleSampleMutation
75
- };
@@ -1,55 +0,0 @@
1
- import { termdbSingleCellDEgenesPayload } from "#types/checkers";
2
- import { gdc_validate_query_singleCell_DEgenes } from "#src/mds3.gdc.js";
3
- const api = {
4
- endpoint: "termdb/singlecellDEgenes",
5
- methods: {
6
- get: {
7
- ...termdbSingleCellDEgenesPayload,
8
- init
9
- },
10
- post: {
11
- ...termdbSingleCellDEgenesPayload,
12
- init
13
- }
14
- }
15
- };
16
- function init({ genomes }) {
17
- return async (req, res) => {
18
- const q = req.query;
19
- let result;
20
- try {
21
- const g = genomes[q.genome];
22
- if (!g) throw new Error("invalid genome name");
23
- const ds = g.datasets[q.dslabel];
24
- if (!ds) throw new Error("invalid dataset name");
25
- if (!ds.queries?.singleCell?.DEgenes || !ds.queries.singleCell.DEgenes.get)
26
- throw new Error("DE genes not supported on this dataset.");
27
- result = await ds.queries.singleCell.DEgenes.get(q);
28
- const isEmpty = !result || !result.data || (Array.isArray(result.data) ? result.data.length === 0 : !result.data.totalRows);
29
- if (isEmpty) {
30
- result = {
31
- status: 404,
32
- error: !result ? "No data found." : "No differentially expressed genes found."
33
- };
34
- }
35
- } catch (e) {
36
- if (e.stack) console.log(e.stack);
37
- result = {
38
- status: e.status || 400,
39
- error: e.message || e
40
- };
41
- }
42
- res.send(result);
43
- };
44
- }
45
- async function validate_query_singleCell_DEgenes(ds) {
46
- if (ds.queries.singleCell.DEgenes.src == "gdcapi") {
47
- gdc_validate_query_singleCell_DEgenes(ds);
48
- } else {
49
- throw new Error("unknown singleCell.DEgenes.src");
50
- }
51
- }
52
- export {
53
- api,
54
- validate_query_singleCell_DEgenes
55
- };
@@ -1,39 +0,0 @@
1
- import { termdbSingleCellDataPayload } from "#types/checkers";
2
- const api = {
3
- endpoint: "termdb/singlecellData",
4
- methods: {
5
- get: {
6
- ...termdbSingleCellDataPayload,
7
- init
8
- },
9
- post: {
10
- ...termdbSingleCellDataPayload,
11
- init
12
- }
13
- }
14
- };
15
- function init({ genomes }) {
16
- return async (req, res) => {
17
- const q = req.query;
18
- let result;
19
- try {
20
- const g = genomes[q.genome];
21
- if (!g) throw new Error("invalid genome name");
22
- const ds = g.datasets[q.dslabel];
23
- if (!ds) throw new Error("invalid dataset name");
24
- if (!ds.queries?.singleCell) throw new Error("no single cell data on this dataset");
25
- if (!ds.queries.singleCell.data?.get) throw new Error("dataset has no single cell data get() function");
26
- result = await ds.queries.singleCell.data.get(q);
27
- } catch (e) {
28
- if (e.stack) console.log(e);
29
- result = {
30
- status: e.status || 400,
31
- error: e.message || e
32
- };
33
- }
34
- res.send(result);
35
- };
36
- }
37
- export {
38
- api
39
- };
@@ -1,42 +0,0 @@
1
- import { termChildrenPayload } from "#types/checkers";
2
- import { copy_term, get_ds_tdb } from "#src/termdb.js";
3
- const api = {
4
- endpoint: "termdb/termchildren",
5
- methods: {
6
- get: {
7
- ...termChildrenPayload,
8
- init
9
- },
10
- post: {
11
- ...termChildrenPayload,
12
- init
13
- }
14
- }
15
- };
16
- function init({ genomes }) {
17
- return async (req, res) => {
18
- const q = req.query;
19
- try {
20
- const g = genomes[req.query.genome];
21
- if (!g) throw "invalid genome name";
22
- const [ds, tdb] = await get_ds_tdb(g, q);
23
- if (!ds) throw "invalid dataset name";
24
- if (!tdb) throw "invalid termdb object";
25
- const result = await trigger_children(req, q, tdb);
26
- res.send(result);
27
- } catch (e) {
28
- res.send({ error: e instanceof Error ? e.message : e });
29
- if (e instanceof Error && e.stack) console.log(e);
30
- }
31
- };
32
- }
33
- async function trigger_children(req, q, tdb) {
34
- if (!q.tid) throw "no parent term id";
35
- const cohortValues = q.cohortValues ? q.cohortValues : "";
36
- const treeFilter = q.treeFilter ? q.treeFilter : "";
37
- const terms = await tdb.q.getTermChildren(req, q.tid, cohortValues, treeFilter);
38
- return { lst: terms.map(copy_term) };
39
- }
40
- export {
41
- api
42
- };
@@ -1,50 +0,0 @@
1
- import { termsByIdsPayload } from "#types/checkers";
2
- import { copy_term } from "#src/termdb.js";
3
- const api = {
4
- endpoint: "termdb/termsbyids",
5
- methods: {
6
- get: {
7
- ...termsByIdsPayload,
8
- init
9
- },
10
- post: {
11
- ...termsByIdsPayload,
12
- init
13
- }
14
- }
15
- };
16
- function init({ genomes }) {
17
- return async (req, res) => {
18
- const q = req.query;
19
- try {
20
- const g = genomes[req.query.genome];
21
- if (!g) throw "invalid genome name";
22
- const ds = g.datasets[req.query.dslabel];
23
- if (!ds) throw "invalid dataset name";
24
- const tdb = ds.cohort.termdb;
25
- if (!tdb) throw "invalid termdb object";
26
- const results = await trigger_gettermsbyid(q, tdb);
27
- res.send(results);
28
- } catch (e) {
29
- res.send({ error: e instanceof Error ? e.message : e });
30
- if (e instanceof Error && e.stack) console.log(e);
31
- }
32
- };
33
- }
34
- async function trigger_gettermsbyid(q, tdb) {
35
- const terms = {};
36
- for (const id of q.ids) {
37
- const term = tdb.q.termjsonByOneid(id);
38
- if (term) {
39
- if (term.type == "categorical" && !term.values) {
40
- term.values = {};
41
- term.samplecount = {};
42
- }
43
- }
44
- terms[id] = term ? copy_term(term) : void 0;
45
- }
46
- return { terms };
47
- }
48
- export {
49
- api
50
- };