@sjcrh/proteinpaint-server 2.63.5 → 2.64.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/genome/hg38.test.js +12 -0
- package/package.json +1 -1
- package/routes/genesetEnrichment.js +107 -0
- package/routes/termdb.config.js +1 -1
- package/src/app.js +790 -532
- package/src/serverconfig.js +1 -0
- package/utils/gsea.py +75 -0
- /package/routes/{hicdata.genome.js → hicgenome.js} +0 -0
package/genome/hg38.test.js
CHANGED
|
@@ -4,6 +4,18 @@ const genome = {
|
|
|
4
4
|
genedb: {
|
|
5
5
|
dbfile: "anno/genes.hg38.test.db"
|
|
6
6
|
},
|
|
7
|
+
termdbs: {
|
|
8
|
+
msigdb: {
|
|
9
|
+
label: "MSigDB",
|
|
10
|
+
cohort: {
|
|
11
|
+
db: { file: "files/hg38/TermdbTest/msigdb/db" },
|
|
12
|
+
// nest file under TermdbTest since the folder is auto symlinked
|
|
13
|
+
termdb: {
|
|
14
|
+
isGeneSetTermdb: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
7
19
|
tracks: [
|
|
8
20
|
{
|
|
9
21
|
__isgene: true,
|
package/package.json
CHANGED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
import serverconfig from "../src/serverconfig.js";
|
|
5
|
+
const api = {
|
|
6
|
+
endpoint: "genesetEnrichment",
|
|
7
|
+
methods: {
|
|
8
|
+
all: {
|
|
9
|
+
init,
|
|
10
|
+
request: {
|
|
11
|
+
typeId: "genesetEnrichmentRequest"
|
|
12
|
+
},
|
|
13
|
+
response: {
|
|
14
|
+
typeId: "genesetEnrichmentResponse"
|
|
15
|
+
// will combine this with type checker
|
|
16
|
+
//valid: (t) => {}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function init({ genomes }) {
|
|
22
|
+
return async (req, res) => {
|
|
23
|
+
try {
|
|
24
|
+
const results = await run_genesetEnrichment_analysis(req.query, genomes);
|
|
25
|
+
res.send(results);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
res.send({ status: "error", error: e.message || e });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async function run_genesetEnrichment_analysis(q, genomes) {
|
|
32
|
+
if (!genomes[q.genome].termdbs)
|
|
33
|
+
throw "termdb database is not available for " + q.genome;
|
|
34
|
+
const genesetenrichment_input = {
|
|
35
|
+
genes: q.genes,
|
|
36
|
+
fold_change: q.fold_change,
|
|
37
|
+
db: genomes[q.genome].termdbs.msigdb.cohort.db.connection.name,
|
|
38
|
+
// For now msigdb has been added, but later databases other than msigdb may be used
|
|
39
|
+
gene_set_group: q.geneSetGroup
|
|
40
|
+
};
|
|
41
|
+
const gsea_output = await run_gsea(
|
|
42
|
+
`${serverconfig.binpath}/utils/gsea.py`,
|
|
43
|
+
"/" + JSON.stringify(genesetenrichment_input)
|
|
44
|
+
// "/" is needed for python to accept the bracket "{" as a bracket
|
|
45
|
+
);
|
|
46
|
+
let result;
|
|
47
|
+
for (const line of gsea_output.split("\n")) {
|
|
48
|
+
if (line.startsWith("result: ")) {
|
|
49
|
+
result = JSON.parse(line.replace("result: ", ""));
|
|
50
|
+
} else {
|
|
51
|
+
console.log(line);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
async function run_gsea(path2, data) {
|
|
57
|
+
try {
|
|
58
|
+
await fs.promises.stat(path2);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw `${path2} does not exist`;
|
|
61
|
+
}
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const _stdout = [];
|
|
64
|
+
const _stderr = [];
|
|
65
|
+
const sp = spawn(serverconfig.python, [path2]);
|
|
66
|
+
if (data) {
|
|
67
|
+
try {
|
|
68
|
+
const input = data.endsWith("\n") ? data : data + "\n";
|
|
69
|
+
Readable.from(input).pipe(sp.stdin);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
sp.kill();
|
|
72
|
+
let errmsg = e;
|
|
73
|
+
const stderr = _stderr.join("").trim();
|
|
74
|
+
if (stderr)
|
|
75
|
+
errmsg += `
|
|
76
|
+
python stderr: ${stderr}`;
|
|
77
|
+
reject(errmsg);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
sp.stdout.on("data", (data2) => _stdout.push(data2));
|
|
81
|
+
sp.stderr.on("data", (data2) => _stderr.push(data2));
|
|
82
|
+
sp.on("error", (err) => reject(err));
|
|
83
|
+
sp.on("close", (code) => {
|
|
84
|
+
const stdout = _stdout.join("").trim();
|
|
85
|
+
const stderr = _stderr.join("").trim();
|
|
86
|
+
if (code !== 0) {
|
|
87
|
+
let errmsg = `python process exited with non-zero status code=${code}`;
|
|
88
|
+
if (stdout)
|
|
89
|
+
errmsg += `
|
|
90
|
+
python stdout: ${stdout}`;
|
|
91
|
+
if (stderr)
|
|
92
|
+
errmsg += `
|
|
93
|
+
python stderr: ${stderr}`;
|
|
94
|
+
reject(errmsg);
|
|
95
|
+
}
|
|
96
|
+
if (stderr) {
|
|
97
|
+
const errmsg = `python process emitted standard error
|
|
98
|
+
python stderr: ${stderr}`;
|
|
99
|
+
reject(errmsg);
|
|
100
|
+
}
|
|
101
|
+
resolve(stdout);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
api
|
|
107
|
+
};
|
package/routes/termdb.config.js
CHANGED
|
@@ -42,7 +42,7 @@ function make(q, res, ds, genome) {
|
|
|
42
42
|
const c = {
|
|
43
43
|
selectCohort: tdb.selectCohort,
|
|
44
44
|
// optional
|
|
45
|
-
supportedChartTypes: tdb.q
|
|
45
|
+
supportedChartTypes: tdb.q?.getSupportedChartTypes(q.embedder),
|
|
46
46
|
hiddenChartTypes: ds.cohort.hiddenChartTypes,
|
|
47
47
|
renamedChartTypes: ds.cohort.renamedChartTypes,
|
|
48
48
|
allowedTermTypes: getAllowedTermTypes(ds),
|