@sjcrh/proteinpaint-server 2.44.0 → 2.46.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/dataset/clinvar.hg19.js +53 -52
  2. package/dataset/clinvar.hg38.js +74 -73
  3. package/dataset/clinvar.js +164 -47
  4. package/dataset/termdb.test.js +257 -0
  5. package/genome/CriGri.js +1859 -27
  6. package/genome/cgc.js +743 -7
  7. package/genome/danRer10.js +1108 -46
  8. package/genome/dm3.js +71 -44
  9. package/genome/dm6.js +1926 -45
  10. package/genome/galGal5.js +23522 -46
  11. package/genome/galGal6.js +512 -46
  12. package/genome/hg19.js +293 -198
  13. package/genome/hg38.js +472 -105
  14. package/genome/hg38.test.js +406 -40
  15. package/genome/hgvirus.js +45 -20
  16. package/genome/mm10.js +135 -67
  17. package/genome/mm9.js +116 -79
  18. package/genome/rn6.js +1002 -47
  19. package/package.json +31 -35
  20. package/routes/_template_.js +30 -0
  21. package/routes/burden.js +149 -0
  22. package/routes/dataset.js +266 -0
  23. package/routes/dsdata.js +127 -0
  24. package/routes/gdc.maf.js +120 -0
  25. package/routes/gdc.mafBuild.js +106 -0
  26. package/routes/gdc.topMutatedGenes.js +465 -0
  27. package/routes/gene2canonicalisoform.js +41 -0
  28. package/routes/genelookup.js +52 -0
  29. package/routes/genomes.js +144 -0
  30. package/routes/healthcheck.js +30 -0
  31. package/routes/hicdata.js +98 -0
  32. package/routes/hicstat.js +55 -0
  33. package/routes/isoformlst.js +57 -0
  34. package/routes/ntseq.js +43 -0
  35. package/routes/pdomain.js +61 -0
  36. package/routes/snp.js +107 -0
  37. package/routes/termdb.categories.js +209 -0
  38. package/routes/termdb.cluster.js +228 -0
  39. package/routes/termdb.cohort.summary.js +38 -0
  40. package/routes/termdb.cohorts.js +49 -0
  41. package/routes/termdb.config.js +201 -0
  42. package/routes/termdb.getdescrstats.js +102 -0
  43. package/routes/termdb.getnumericcategories.js +92 -0
  44. package/routes/termdb.getpercentile.js +108 -0
  45. package/routes/termdb.getrootterm.js +65 -0
  46. package/routes/termdb.gettermchildren.js +67 -0
  47. package/routes/termdb.singleSampleMutation.js +80 -0
  48. package/routes/termdb.singlecellData.js +46 -0
  49. package/routes/termdb.singlecellSamples.js +160 -0
  50. package/routes/termdb.termsbyids.js +59 -0
  51. package/routes/termdb.topVariablyExpressedGenes.js +171 -0
  52. package/routes/termdb.violin.js +77 -0
  53. package/src/app.js +41498 -0
  54. package/src/serverconfig.js +14 -8
  55. package/start.js +3 -3
  56. package/routes/README.md +0 -84
  57. package/routes/burden.ts +0 -143
  58. package/routes/gdc.maf.ts +0 -195
  59. package/routes/gdc.mafBuild.ts +0 -114
  60. package/routes/gdc.topMutatedGenes.ts +0 -586
  61. package/routes/genelookup.ts +0 -50
  62. package/routes/healthcheck.ts +0 -29
  63. package/routes/hicdata.ts +0 -111
  64. package/routes/hicstat.ts +0 -55
  65. package/routes/termdb.categories.ts +0 -245
  66. package/routes/termdb.cluster.ts +0 -248
  67. package/routes/termdb.getdescrstats.ts +0 -102
  68. package/routes/termdb.getnumericcategories.ts +0 -99
  69. package/routes/termdb.getpercentile.ts +0 -118
  70. package/routes/termdb.getrootterm.ts +0 -73
  71. package/routes/termdb.gettermchildren.ts +0 -82
  72. package/routes/termdb.singleSampleMutation.ts +0 -87
  73. package/routes/termdb.singlecellData.ts +0 -49
  74. package/routes/termdb.singlecellSamples.ts +0 -175
  75. package/routes/termdb.termsbyids.ts +0 -63
  76. package/routes/termdb.topVariablyExpressedGenes.ts +0 -214
  77. package/routes/termdb.violin.ts +0 -77
  78. package/server.js +0 -2
  79. package/server.js.map +0 -1
  80. package/shared/common.js +0 -1080
  81. package/shared/termdb.initbinconfig.js +0 -96
  82. package/shared/vcf.js +0 -629
@@ -0,0 +1,201 @@
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 { mayCopyFromCookie } from "#src/utils.js";
5
+ import { mayComputeTermtypeByCohort } from "#src/termdb.server.init.js";
6
+ const api = {
7
+ endpoint: "termdb/config",
8
+ methods: {
9
+ get: {
10
+ init,
11
+ request: {
12
+ typeId: "any"
13
+ },
14
+ response: {
15
+ typeId: "any"
16
+ }
17
+ }
18
+ }
19
+ };
20
+ function init({ genomes }) {
21
+ return async (req, res) => {
22
+ const q = req.query;
23
+ mayCopyFromCookie(q, req.cookies);
24
+ try {
25
+ const genome = genomes[q.genome];
26
+ if (!genome)
27
+ throw "invalid genome";
28
+ const [ds, tdb] = get_ds_tdb(genome, q);
29
+ return make(q, res, ds, genome);
30
+ } catch (e) {
31
+ res.send({ error: e.message || e });
32
+ if (e.stack)
33
+ console.log(e.stack);
34
+ else
35
+ console.log(e);
36
+ }
37
+ };
38
+ }
39
+ function make(q, res, ds, genome) {
40
+ const tdb = ds.cohort.termdb;
41
+ const c = {
42
+ selectCohort: tdb.selectCohort,
43
+ // optional
44
+ supportedChartTypes: tdb.q.getSupportedChartTypes(q.embedder),
45
+ hiddenChartTypes: ds.cohort.hiddenChartTypes,
46
+ renamedChartTypes: ds.cohort.renamedChartTypes,
47
+ allowedTermTypes: getAllowedTermTypes(ds),
48
+ termMatch2geneSet: tdb.termMatch2geneSet,
49
+ massSessionDuration: serverconfig.features.massSessionDuration || 30,
50
+ dataDownloadCatch: tdb.dataDownloadCatch,
51
+ matrix: tdb.matrix,
52
+ hierCluster: tdb.hierCluster,
53
+ mclass: tdb.mclass,
54
+ alwaysRefillCategoricalTermValues: tdb.alwaysRefillCategoricalTermValues,
55
+ isGeneSetTermdb: tdb.isGeneSetTermdb,
56
+ lollipop: tdb.lollipop,
57
+ urlTemplates: tdb.urlTemplates
58
+ };
59
+ if (tdb.chartConfigByType)
60
+ c.chartConfigByType = tdb.chartConfigByType;
61
+ if (tdb.multipleTestingCorrection)
62
+ c.multipleTestingCorrection = tdb.multipleTestingCorrection;
63
+ if (tdb.helpPages)
64
+ c.helpPages = tdb.helpPages;
65
+ if (tdb.minTimeSinceDx)
66
+ c.minTimeSinceDx = tdb.minTimeSinceDx;
67
+ if (tdb.timeUnit)
68
+ c.timeUnit = tdb.timeUnit;
69
+ if (tdb.cohortStartTimeMsg)
70
+ c.cohortStartTimeMsg = tdb.cohortStartTimeMsg;
71
+ if (tdb.displaySampleIds)
72
+ c.displaySampleIds = tdb.displaySampleIds;
73
+ if (tdb.logscaleBase2)
74
+ c.logscaleBase2 = tdb.logscaleBase2;
75
+ if (ds.assayAvailability)
76
+ c.assayAvailability = ds.assayAvailability;
77
+ if (ds.customTwQByType)
78
+ c.customTwQByType = ds.customTwQByType;
79
+ c.requiredAuth = authApi.getRequiredCredForDsEmbedder(q.dslabel, q.embedder);
80
+ addRestrictAncestries(c, tdb);
81
+ addScatterplots(c, ds);
82
+ addMatrixplots(c, ds);
83
+ addGenomicQueries(c, ds, genome);
84
+ res.send({ termdbConfig: c });
85
+ }
86
+ function addRestrictAncestries(c, tdb) {
87
+ if (!tdb.restrictAncestries)
88
+ return;
89
+ c.restrictAncestries = tdb.restrictAncestries.map((i) => {
90
+ return { name: i.name, tvs: i.tvs, PCcount: i.PCcount };
91
+ });
92
+ }
93
+ function addScatterplots(c, ds) {
94
+ if (!ds.cohort.scatterplots)
95
+ return;
96
+ c.scatterplots = ds.cohort.scatterplots.plots.map((p) => {
97
+ return {
98
+ name: p.name,
99
+ dimensions: p.dimensions,
100
+ colorTW: p.colorTW,
101
+ shapeTW: p.shapeTW,
102
+ colorColumn: p.colorColumn
103
+ };
104
+ });
105
+ }
106
+ function addMatrixplots(c, ds) {
107
+ if (!ds.cohort.matrixplots)
108
+ return;
109
+ c.matrixplots = ds.cohort.matrixplots.plots.map((p) => {
110
+ return { name: p.name };
111
+ });
112
+ }
113
+ function addGenomicQueries(c, ds, genome) {
114
+ const q = ds.queries;
115
+ if (!q)
116
+ return;
117
+ c.queries = {
118
+ defaultCoord: q.defaultCoord || genome.defaultcoord
119
+ };
120
+ const q2 = c.queries;
121
+ if (q.defaultBlock2GeneMode)
122
+ q2.defaultBlock2GeneMode = q.defaultBlock2GeneMode;
123
+ if (q.snvindel) {
124
+ q2.snvindel = {
125
+ allowSNPs: q.snvindel.allowSNPs
126
+ };
127
+ }
128
+ if (q.cnv) {
129
+ q2.cnv = {};
130
+ for (const k of [
131
+ "cnvMaxLength",
132
+ "cnvGainCutoff",
133
+ "cnvLossCutoff",
134
+ "absoluteValueRenderMax",
135
+ "gainColor",
136
+ "lossColor"
137
+ ]) {
138
+ if (k in q.cnv)
139
+ q2.cnv[k] = q.cnv[k];
140
+ }
141
+ }
142
+ if (q.topMutatedGenes)
143
+ q2.topMutatedGenes = q.topMutatedGenes;
144
+ if (q.topVariablyExpressedGenes)
145
+ q2.topVariablyExpressedGenes = q.topVariablyExpressedGenes;
146
+ if (q.singleSampleMutation) {
147
+ q2.singleSampleMutation = {
148
+ sample_id_key: q.singleSampleMutation.sample_id_key,
149
+ discoSkipChrM: q.singleSampleMutation.discoSkipChrM
150
+ };
151
+ }
152
+ if (q.singleSampleGenomeQuantification) {
153
+ q2.singleSampleGenomeQuantification = {};
154
+ for (const k in q.singleSampleGenomeQuantification) {
155
+ q2.singleSampleGenomeQuantification[k] = JSON.parse(JSON.stringify(q.singleSampleGenomeQuantification[k]));
156
+ delete q2.singleSampleGenomeQuantification[k].folder;
157
+ }
158
+ }
159
+ if (q.singleSampleGbtk) {
160
+ q2.singleSampleGbtk = {};
161
+ for (const k in q.singleSampleGbtk) {
162
+ q2.singleSampleGbtk[k] = JSON.parse(JSON.stringify(q.singleSampleGbtk[k]));
163
+ delete q2.singleSampleGbtk[k].folder;
164
+ }
165
+ }
166
+ if (q.rnaseqGeneCount) {
167
+ q2.rnaseqGeneCount = true;
168
+ }
169
+ if (q.singleCell) {
170
+ q2.singleCell = {
171
+ samples: {
172
+ firstColumnName: q.singleCell.samples.firstColumnName,
173
+ sampleColumns: q.singleCell.samples.sampleColumns,
174
+ experimentColumns: q.singleCell.samples.experimentColumns
175
+ },
176
+ data: {
177
+ sameLegend: q.singleCell.data.sameLegend,
178
+ refName: q.singleCell.data.refName
179
+ }
180
+ };
181
+ }
182
+ }
183
+ function getAllowedTermTypes(ds) {
184
+ mayComputeTermtypeByCohort(ds);
185
+ const typeSet = /* @__PURE__ */ new Set();
186
+ for (const r of ds.cohort.termdb.termtypeByCohort) {
187
+ if (r.type)
188
+ typeSet.add(r.type);
189
+ }
190
+ if (ds.cohort.termdb.allowedTermTypes) {
191
+ for (const t of ds.cohort.termdb.allowedTermTypes)
192
+ typeSet.add(t);
193
+ }
194
+ if (ds?.queries?.defaultBlock2GeneMode) {
195
+ typeSet.add("geneVariant");
196
+ }
197
+ return [...typeSet];
198
+ }
199
+ export {
200
+ api
201
+ };
@@ -0,0 +1,102 @@
1
+ import { get_rows_by_one_key } from "../src/termdb.sql.js";
2
+ import Summarystats from "../shared/descriptive.stats.js";
3
+ const api = {
4
+ endpoint: "termdb/descrstats",
5
+ methods: {
6
+ all: {
7
+ init,
8
+ request: {
9
+ typeId: "getdescrstatsRequest"
10
+ },
11
+ response: {
12
+ typeId: "getdescrstatsResponse"
13
+ },
14
+ examples: [
15
+ {
16
+ request: {
17
+ body: {
18
+ genome: "hg38-test",
19
+ dslabel: "TermdbTest",
20
+ embedder: "localhost",
21
+ tid: "hrtavg",
22
+ filter: {
23
+ type: "tvslst",
24
+ in: true,
25
+ join: "",
26
+ lst: [
27
+ {
28
+ tag: "cohortFilter",
29
+ type: "tvs",
30
+ tvs: {
31
+ term: {
32
+ name: "Cohort",
33
+ type: "categorical",
34
+ values: { ABC: { label: "ABC" }, XYZ: { label: "XYZ" } },
35
+ id: "subcohort",
36
+ isleaf: false,
37
+ groupsetting: { disabled: true }
38
+ },
39
+ values: [{ key: "ABC", label: "ABC" }]
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ }
45
+ },
46
+ response: {
47
+ header: { status: 200 }
48
+ }
49
+ }
50
+ ]
51
+ }
52
+ }
53
+ };
54
+ function init({ genomes }) {
55
+ return async (req, res) => {
56
+ const q = req.query;
57
+ try {
58
+ const g = genomes[req.query.genome];
59
+ if (!g)
60
+ throw "invalid genome name";
61
+ const ds = g.datasets[req.query.dslabel];
62
+ if (!ds)
63
+ throw "invalid dataset name";
64
+ const tdb = ds.cohort.termdb;
65
+ if (!tdb)
66
+ throw "invalid termdb object";
67
+ await trigger_getdescrstats(q, res, ds);
68
+ } catch (e) {
69
+ res.send({ error: e?.message || e });
70
+ if (e instanceof Error && e.stack)
71
+ console.log(e);
72
+ }
73
+ };
74
+ }
75
+ async function trigger_getdescrstats(q, res, ds) {
76
+ const term = ds.cohort.termdb.q.termjsonByOneid(q.tid);
77
+ if (!term)
78
+ throw "invalid termid";
79
+ if (term.type != "float" && term.type != "integer")
80
+ throw "not numerical term";
81
+ const rows = await get_rows_by_one_key({
82
+ ds,
83
+ key: q.tid,
84
+ filter: q.filter
85
+ });
86
+ const values = [];
87
+ for (const { value } of rows) {
88
+ if (term.values?.[value]?.uncomputable) {
89
+ continue;
90
+ }
91
+ if (q.settings?.violin?.unit === "log") {
92
+ if (value === 0) {
93
+ continue;
94
+ }
95
+ }
96
+ values.push(value);
97
+ }
98
+ res.send(Summarystats(values));
99
+ }
100
+ export {
101
+ api
102
+ };
@@ -0,0 +1,92 @@
1
+ import * as termdbsql from "#src/termdb.sql.js";
2
+ const api = {
3
+ endpoint: "termdb/numericcategories",
4
+ methods: {
5
+ get: {
6
+ init,
7
+ request: {
8
+ typeId: "getnumericcategoriesRequest"
9
+ },
10
+ response: {
11
+ typeId: "getnumericcategoriesResponse"
12
+ },
13
+ examples: [
14
+ {
15
+ request: {
16
+ body: {
17
+ genome: "hg38-test",
18
+ dslabel: "TermdbTest",
19
+ embedder: "localhost",
20
+ tid: "aaclassic_5",
21
+ filter: {
22
+ type: "tvslst",
23
+ in: true,
24
+ join: "",
25
+ lst: [
26
+ {
27
+ tag: "cohortFilter",
28
+ type: "tvs",
29
+ tvs: {
30
+ term: {
31
+ name: "Cohort",
32
+ type: "categorical",
33
+ values: { ABC: { label: "ABC" }, XYZ: { label: "XYZ" } },
34
+ id: "subcohort",
35
+ isleaf: false,
36
+ groupsetting: { disabled: true }
37
+ },
38
+ values: [{ key: "ABC", label: "ABC" }]
39
+ }
40
+ }
41
+ ]
42
+ }
43
+ }
44
+ },
45
+ response: {
46
+ header: { status: 200 }
47
+ }
48
+ }
49
+ ]
50
+ },
51
+ post: {
52
+ alternativeFor: "get",
53
+ init
54
+ }
55
+ }
56
+ };
57
+ function init({ genomes }) {
58
+ return async (req, res) => {
59
+ const q = req.query;
60
+ try {
61
+ const g = genomes[req.query.genome];
62
+ if (!g)
63
+ throw "invalid genome name";
64
+ const ds = g.datasets[req.query.dslabel];
65
+ if (!ds)
66
+ throw "invalid dataset name";
67
+ const tdb = ds.cohort.termdb;
68
+ if (!tdb)
69
+ throw "invalid termdb object";
70
+ await trigger_getnumericcategories(q, res, tdb, ds);
71
+ } catch (e) {
72
+ res.send({ error: e?.message || e });
73
+ if (e instanceof Error && e.stack)
74
+ console.log(e);
75
+ }
76
+ };
77
+ }
78
+ async function trigger_getnumericcategories(q, res, tdb, ds) {
79
+ if (!q.tid)
80
+ throw ".tid missing";
81
+ const term = tdb.q.termjsonByOneid(q.tid);
82
+ const arg = {
83
+ ds,
84
+ term_id: q.tid,
85
+ filter: q.filter
86
+ };
87
+ const lst = await termdbsql.get_summary_numericcategories(arg);
88
+ res.send({ lst });
89
+ }
90
+ export {
91
+ api
92
+ };
@@ -0,0 +1,108 @@
1
+ import * as termdbsql from "../src/termdb.sql.js";
2
+ import computePercentile from "../shared/compute.percentile.js";
3
+ const api = {
4
+ endpoint: "termdb/getpercentile",
5
+ methods: {
6
+ get: {
7
+ init,
8
+ request: {
9
+ typeId: "getpercentileRequest"
10
+ },
11
+ response: {
12
+ typeId: "getpercentileResponse"
13
+ },
14
+ examples: [
15
+ {
16
+ request: {
17
+ body: {
18
+ genome: "hg38-test",
19
+ dslabel: "TermdbTest",
20
+ embedder: "localhost",
21
+ getpercentile: [50],
22
+ tid: "agedx",
23
+ filter: {
24
+ type: "tvslst",
25
+ in: true,
26
+ join: "",
27
+ lst: [
28
+ {
29
+ tag: "cohortFilter",
30
+ type: "tvs",
31
+ tvs: {
32
+ term: {
33
+ name: "Cohort",
34
+ type: "categorical",
35
+ values: { ABC: { label: "ABC" }, XYZ: { label: "XYZ" } },
36
+ id: "subcohort",
37
+ isleaf: false,
38
+ groupsetting: { disabled: true }
39
+ },
40
+ values: [{ key: "ABC", label: "ABC" }]
41
+ }
42
+ }
43
+ ]
44
+ }
45
+ }
46
+ },
47
+ response: {
48
+ header: { status: 200 }
49
+ }
50
+ }
51
+ ]
52
+ },
53
+ post: {
54
+ alternativeFor: "get",
55
+ init
56
+ }
57
+ }
58
+ };
59
+ function init({ genomes }) {
60
+ return async (req, res) => {
61
+ const q = req.query;
62
+ try {
63
+ const g = genomes[req.query.genome];
64
+ if (!g)
65
+ throw "invalid genome name";
66
+ const ds = g.datasets[req.query.dslabel];
67
+ if (!ds)
68
+ throw "invalid dataset name";
69
+ await trigger_getpercentile(q, res, ds);
70
+ } catch (e) {
71
+ res.send({ error: e?.message || e });
72
+ if (e instanceof Error && e.stack)
73
+ console.log(e);
74
+ }
75
+ };
76
+ }
77
+ async function trigger_getpercentile(q, res, ds) {
78
+ const term = ds.cohort.termdb.q.termjsonByOneid(q.tid);
79
+ if (!term)
80
+ throw "invalid termid";
81
+ if (term.type != "float" && term.type != "integer")
82
+ throw "not numerical term";
83
+ const percentile_lst = q.getpercentile;
84
+ const perc_values = [];
85
+ const values = [];
86
+ const rows = await termdbsql.get_rows_by_one_key({
87
+ ds,
88
+ key: q.tid,
89
+ filter: q.filter ? typeof q.filter == "string" ? JSON.parse(q.filter) : q.filter : null
90
+ });
91
+ for (const { value } of rows) {
92
+ if (term.values && term.values[value] && term.values[value].uncomputable) {
93
+ continue;
94
+ }
95
+ if (term.skip0forPercentile && value == 0) {
96
+ continue;
97
+ }
98
+ values.push(Number(value));
99
+ }
100
+ for (const percentile of percentile_lst) {
101
+ const perc_value = computePercentile(values, percentile);
102
+ perc_values.push(perc_value);
103
+ }
104
+ res.send({ values: perc_values });
105
+ }
106
+ export {
107
+ api
108
+ };
@@ -0,0 +1,65 @@
1
+ import { get_ds_tdb } from "#src/termdb.js";
2
+ const api = {
3
+ endpoint: "termdb/rootterm",
4
+ methods: {
5
+ get: {
6
+ init,
7
+ request: {
8
+ typeId: "getroottermRequest"
9
+ },
10
+ response: {
11
+ typeId: "getroottermResponse"
12
+ },
13
+ examples: [
14
+ {
15
+ request: {
16
+ body: {
17
+ genome: "hg38-test",
18
+ dslabel: "TermdbTest",
19
+ embedder: "localhost",
20
+ default_rootterm: 1,
21
+ cohortValues: "ABC"
22
+ }
23
+ },
24
+ response: {
25
+ header: { status: 200 }
26
+ }
27
+ }
28
+ ]
29
+ },
30
+ post: {
31
+ alternativeFor: "get",
32
+ init
33
+ }
34
+ }
35
+ };
36
+ function init({ genomes }) {
37
+ return async (req, res) => {
38
+ const q = req.query;
39
+ const cohortValues = q.cohortValues ? q.cohortValues : "";
40
+ const treeFilter = q.treeFilter ? q.treeFilter : "";
41
+ try {
42
+ const g = genomes[req.query.genome];
43
+ if (!g)
44
+ throw "invalid genome name";
45
+ const [ds, tdb] = get_ds_tdb(g, q);
46
+ if (!ds)
47
+ throw "invalid dataset name";
48
+ if (!tdb)
49
+ throw "invalid termdb object";
50
+ await trigger_rootterm(q, res, tdb);
51
+ } catch (e) {
52
+ res.send({ error: e?.message || e });
53
+ if (e instanceof Error && e.stack)
54
+ console.log(e);
55
+ }
56
+ };
57
+ }
58
+ async function trigger_rootterm(q, res, tdb) {
59
+ const cohortValues = q.cohortValues ? q.cohortValues : "";
60
+ const treeFilter = q.treeFilter ? q.treeFilter : "";
61
+ res.send({ lst: await tdb.q.getRootTerms(cohortValues, treeFilter) });
62
+ }
63
+ export {
64
+ api
65
+ };
@@ -0,0 +1,67 @@
1
+ import { copy_term, get_ds_tdb } from "#src/termdb.js";
2
+ const api = {
3
+ endpoint: "termdb/termchildren",
4
+ methods: {
5
+ get: {
6
+ init,
7
+ request: {
8
+ typeId: "gettermchildrenRequest"
9
+ },
10
+ response: {
11
+ typeId: "gettermchildrenResponse"
12
+ },
13
+ examples: [
14
+ {
15
+ request: {
16
+ body: {
17
+ genome: "hg38-test",
18
+ dslabel: "TermdbTest",
19
+ embedder: "localhost",
20
+ get_children: 1,
21
+ cohortValues: "ABC",
22
+ tid: "GO:0000001"
23
+ }
24
+ },
25
+ response: {
26
+ header: { status: 200 }
27
+ }
28
+ }
29
+ ]
30
+ },
31
+ post: {
32
+ alternativeFor: "get",
33
+ init
34
+ }
35
+ }
36
+ };
37
+ function init({ genomes }) {
38
+ return async (req, res) => {
39
+ const q = req.query;
40
+ try {
41
+ const g = genomes[req.query.genome];
42
+ if (!g)
43
+ throw "invalid genome name";
44
+ const [ds, tdb] = await get_ds_tdb(g, q);
45
+ if (!ds)
46
+ throw "invalid dataset name";
47
+ if (!tdb)
48
+ throw "invalid termdb object";
49
+ await trigger_children(q, res, tdb);
50
+ } catch (e) {
51
+ res.send({ error: e?.message || e });
52
+ if (e instanceof Error && e.stack)
53
+ console.log(e);
54
+ }
55
+ };
56
+ }
57
+ async function trigger_children(q, res, tdb) {
58
+ if (!q.tid)
59
+ throw "no parent term id";
60
+ const cohortValues = q.cohortValues ? q.cohortValues : "";
61
+ const treeFilter = q.treeFilter ? q.treeFilter : "";
62
+ const terms = await tdb.q.getTermChildren(q.tid, cohortValues, treeFilter);
63
+ res.send({ lst: terms.map(copy_term) });
64
+ }
65
+ export {
66
+ api
67
+ };
@@ -0,0 +1,80 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { read_file } from "#src/utils.js";
4
+ import serverconfig from "#src/serverconfig.js";
5
+ import { gdcValidate_query_singleSampleMutation } from "#src/mds3.gdc.js";
6
+ const api = {
7
+ endpoint: "termdb/singleSampleMutation",
8
+ methods: {
9
+ get: {
10
+ init,
11
+ request: {
12
+ typeId: "TermdbSingleSampleMutationRequest"
13
+ },
14
+ response: {
15
+ typeId: "TermdbSingleSampleMutationResponse"
16
+ }
17
+ }
18
+ }
19
+ };
20
+ function init({ genomes }) {
21
+ return async (req, res) => {
22
+ const q = req.query;
23
+ let result;
24
+ try {
25
+ const g = genomes[q.genome];
26
+ if (!g)
27
+ throw "invalid genome name";
28
+ const ds = g.datasets[q.dslabel];
29
+ if (!ds)
30
+ throw "invalid dataset name";
31
+ if (!ds.queries?.singleSampleMutation)
32
+ throw "not supported on this dataset";
33
+ result = await ds.queries.singleSampleMutation.get(q);
34
+ } catch (e) {
35
+ if (e.stack)
36
+ 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_singleSampleMutation(ds, genome) {
46
+ const _q = ds.queries.singleSampleMutation;
47
+ if (!_q)
48
+ return;
49
+ if (_q.src == "gdcapi") {
50
+ gdcValidate_query_singleSampleMutation(ds, genome);
51
+ } else if (_q.src == "native") {
52
+ _q.get = async (q) => {
53
+ let fileName = q.sample;
54
+ if (ds.cohort?.termdb?.q?.sampleName2id) {
55
+ fileName = ds.cohort.termdb.q.sampleName2id(q.sample);
56
+ if (fileName == void 0) {
57
+ return [];
58
+ }
59
+ }
60
+ const file = path.join(serverconfig.tpmasterdir, _q.folder, fileName.toString());
61
+ try {
62
+ await fs.promises.stat(file);
63
+ } catch (e) {
64
+ if (e.code == "EACCES")
65
+ throw "cannot read file, permission denied";
66
+ if (e.code == "ENOENT")
67
+ throw "no data for this sample";
68
+ throw "failed to load data";
69
+ }
70
+ const data = await read_file(file);
71
+ return { mlst: JSON.parse(data) };
72
+ };
73
+ } else {
74
+ throw "unknown singleSampleMutation.src";
75
+ }
76
+ }
77
+ export {
78
+ api,
79
+ validate_query_singleSampleMutation
80
+ };