@sjcrh/proteinpaint-server 2.57.0 → 2.58.0-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-server",
3
- "version": "2.57.0",
3
+ "version": "2.58.0-0",
4
4
  "type": "module",
5
5
  "description": "a genomics visualization tool for exploring a cohort's genotype and phenotype data",
6
6
  "main": "src/app.js",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@sjcrh/augen": "2.46.0",
64
- "@sjcrh/proteinpaint-rust": "2.55.0",
64
+ "@sjcrh/proteinpaint-rust": "2.58.0-0",
65
65
  "better-sqlite3": "^9.4.1",
66
66
  "body-parser": "^1.15.2",
67
67
  "canvas": "~2.11.2",
@@ -0,0 +1,56 @@
1
+ import { run_rust } from "@sjcrh/proteinpaint-rust";
2
+ const api = {
3
+ endpoint: "genesetOverrepresentation",
4
+ methods: {
5
+ all: {
6
+ init,
7
+ request: {
8
+ typeId: "genesetOverrepresentationRequest"
9
+ },
10
+ response: {
11
+ typeId: "genesetOverrepresentationResponse"
12
+ // will combine this with type checker
13
+ //valid: (t) => {}
14
+ }
15
+ }
16
+ }
17
+ };
18
+ function init({ genomes }) {
19
+ return async (req, res) => {
20
+ try {
21
+ const results = await run_genesetOverrepresentation_analysis(
22
+ req.query,
23
+ genomes
24
+ );
25
+ res.send(results);
26
+ } catch (e) {
27
+ res.send({ status: "error", error: e.message || e });
28
+ }
29
+ };
30
+ }
31
+ async function run_genesetOverrepresentation_analysis(q, genomes) {
32
+ if (!genomes[q.genome].termdbs)
33
+ throw "termdb database is not available for " + q.genome;
34
+ const gene_overrepresentation_input = {
35
+ sample_genes: q.sample_genes,
36
+ background_genes: q.background_genes,
37
+ db: genomes[q.genome].termdbs.msigdb.cohort.db.connection.name,
38
+ gene_set_group: q.geneSetGroup
39
+ };
40
+ const time1 = (/* @__PURE__ */ new Date()).valueOf();
41
+ const rust_output = await run_rust("genesetORA", JSON.stringify(gene_overrepresentation_input));
42
+ const time2 = (/* @__PURE__ */ new Date()).valueOf();
43
+ console.log("Time taken to run rust gene over representation pipeline:", time2 - time1, "ms");
44
+ let result;
45
+ for (const line of rust_output.split("\n")) {
46
+ if (line.startsWith("pathway_p_values:")) {
47
+ result = JSON.parse(line.replace("pathway_p_values:", ""));
48
+ } else {
49
+ console.log(line);
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+ export {
55
+ api
56
+ };
@@ -0,0 +1,93 @@
1
+ import { fileurl } from "#src/utils.js";
2
+ import { spawn } from "child_process";
3
+ import readline from "readline";
4
+ import serverconfig from "#src/serverconfig.js";
5
+ const api = {
6
+ endpoint: "hicgenome",
7
+ methods: {
8
+ get: {
9
+ init,
10
+ request: {
11
+ typeId: "HicdataRequest"
12
+ },
13
+ response: {
14
+ typeId: "HicdataResponse"
15
+ }
16
+ },
17
+ post: {
18
+ alternativeFor: "get",
19
+ init
20
+ }
21
+ }
22
+ };
23
+ function init() {
24
+ return async (req, res) => {
25
+ const data = [];
26
+ const erroutput = [];
27
+ const [e, file, isurl] = fileurl({ query: req.query });
28
+ if (e)
29
+ res.send({ error: "illegal file name" });
30
+ const matrixType = req.query.matrixType == "log(oe)" ? "oe" : req.query.matrixType ? req.query.matrixType : "observed";
31
+ const promises = req.query.chrlst.map((lead, i) => {
32
+ return req.query.chrlst.slice(0, i + 1).map((follow, j) => {
33
+ if (j <= i) {
34
+ return new Promise((resolve, reject) => {
35
+ const pos1 = req.query.nochr ? lead.replace("chr", "") : lead;
36
+ const pos2 = req.query.nochr ? follow.replace("chr", "") : follow;
37
+ const par = [
38
+ matrixType,
39
+ req.query.nmeth || "NONE",
40
+ file,
41
+ pos1,
42
+ pos2,
43
+ req.query.isfrag ? "FRAG" : "BP",
44
+ req.query.resolution
45
+ ];
46
+ const ps = spawn(serverconfig.hicstraw, par);
47
+ const rl = readline.createInterface({ input: ps.stdout });
48
+ const items = [];
49
+ let linenot3fields = 0;
50
+ let fieldnotnumerical = 0;
51
+ rl.on("line", (line) => {
52
+ const l = line.split(" ");
53
+ if (l.length != 3) {
54
+ linenot3fields++;
55
+ return;
56
+ }
57
+ const n1 = Number.parseInt(l[0]);
58
+ const n2 = Number.parseInt(l[1]);
59
+ const v = req.query.matrixType == "log(oe)" ? Math.log(Number.parseFloat(l[2])) : Number.parseFloat(l[2]);
60
+ if (Number.isNaN(n1) || Number.isNaN(n2) || Number.isNaN(v)) {
61
+ fieldnotnumerical++;
62
+ return;
63
+ }
64
+ if (req.query.mincutoff != void 0 && v <= req.query.mincutoff) {
65
+ return;
66
+ }
67
+ items.push([n1, n2, v]);
68
+ });
69
+ data.push({ items, lead, follow });
70
+ ps.stderr.on("data", (i2) => erroutput.push(`${lead} - ${follow}: `, i2));
71
+ ps.on("close", () => {
72
+ if (erroutput.length)
73
+ reject({ error: erroutput.join("") });
74
+ if (linenot3fields)
75
+ reject({ error: `${linenot3fields} lines have other than 3 fields` });
76
+ if (fieldnotnumerical)
77
+ reject(`${fieldnotnumerical} lines have non-numerical values in any of the 3 fields`);
78
+ resolve();
79
+ });
80
+ });
81
+ }
82
+ });
83
+ }).flat();
84
+ Promise.allSettled(promises).then(() => res.send({ data, error: erroutput.join("") })).catch((e2) => {
85
+ res.send({ error: e2?.message || e2 });
86
+ if (e2 instanceof Error && e2.stack)
87
+ console.log(e2);
88
+ });
89
+ };
90
+ }
91
+ export {
92
+ api
93
+ };
@@ -87,10 +87,23 @@ function init({ genomes }) {
87
87
  async function trigger_getcategories(q, res, tdb, ds, genome) {
88
88
  if (!q.tid)
89
89
  throw ".tid missing";
90
- const term = q.type == "geneVariant" ? { name: q.tid, type: "geneVariant", isleaf: true } : tdb.q.termjsonByOneid(q.tid);
90
+ let term;
91
+ if (q.type == "geneVariant") {
92
+ term = { id: q.name, name: q.name, type: "geneVariant", isleaf: true };
93
+ if (q.gene) {
94
+ term.gene = q.gene;
95
+ } else {
96
+ term.chr = q.chr;
97
+ term.start = q.start;
98
+ term.stop = q.stop;
99
+ }
100
+ } else {
101
+ term = tdb.q.termjsonByOneid(q.tid);
102
+ }
103
+ const tw = q.type == "geneVariant" ? { $id: q.gene || q.name || q.tid, term, q: { isAtomic: true } } : { $id: q.tid, id: q.tid, term, q: q.term1_q || getDefaultQ(term, q) };
91
104
  const arg = {
92
105
  filter: q.filter,
93
- terms: q.type == "geneVariant" ? [{ term, q: { isAtomic: true } }] : [{ id: q.tid, term, q: q.term1_q || getDefaultQ(term, q) }],
106
+ terms: [tw],
94
107
  currentGeneNames: q.currentGeneNames,
95
108
  // optional, from mds3 mayAddGetCategoryArgs()
96
109
  rglst: q.rglst
@@ -112,7 +125,8 @@ async function trigger_getcategories(q, res, tdb, ds, genome) {
112
125
  }
113
126
  const sampleCountedFor = /* @__PURE__ */ new Set();
114
127
  for (const [sampleId, sampleData] of Object.entries(samples)) {
115
- const values = sampleData[q.tid].values;
128
+ const key = tw.$id;
129
+ const values = sampleData[key].values;
116
130
  sampleCountedFor.clear();
117
131
  for (const value of values) {
118
132
  if (!dtClassMap.has(value.dt)) {
@@ -136,6 +136,7 @@ async function validate_query_geneExpression(ds, genome) {
136
136
  const q = ds.queries.geneExpression;
137
137
  if (!q)
138
138
  return;
139
+ q.gene2density = {};
139
140
  if (q.src == "gdcapi") {
140
141
  gdc_validate_query_geneExpression(ds, genome);
141
142
  return;
@@ -206,6 +206,8 @@ function getAllowedTermTypes(ds) {
206
206
  if (ds?.queries?.defaultBlock2GeneMode) {
207
207
  typeSet.add("geneVariant");
208
208
  }
209
+ if (ds?.queries?.geneExpression)
210
+ typeSet.add("geneExpression");
209
211
  return [...typeSet];
210
212
  }
211
213
  export {