@sjcrh/proteinpaint-server 2.65.0 → 2.66.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 +2 -2
- package/routes/termdb.categories.js +3 -0
- package/routes/termdb.cluster.js +6 -2
- package/routes/termdb.config.js +6 -1
- package/routes/termdb.singlecellSamples.js +30 -46
- package/routes/termdb.topVariablyExpressedGenes.js +12 -12
- package/src/app.js +358 -275
- package/utils/getGeneFromMatrix.R +40 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjcrh/proteinpaint-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.66.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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"postpack": "./dedupjs.sh",
|
|
28
28
|
"dedup": "./dedupjs.sh",
|
|
29
29
|
"//todo": "refactor or deprecate the scripts below",
|
|
30
|
-
"pretest": "tsc
|
|
30
|
+
"pretest": "tsc && ./test/pretest.js",
|
|
31
31
|
"prepare": "ts-patch install",
|
|
32
32
|
"pretest:type": "npm run checkers",
|
|
33
33
|
"pretest:integration": "tsc --esModuleInterop genome/*.ts dataset/*.ts",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getOrderedLabels } from "#src/termdb.barchart.js";
|
|
2
2
|
import { getData } from "#src/termdb.matrix.js";
|
|
3
|
+
import { TermTypes } from "#shared/terms.js";
|
|
3
4
|
const api = {
|
|
4
5
|
endpoint: "termdb/categories",
|
|
5
6
|
methods: {
|
|
@@ -195,6 +196,8 @@ function getDefaultQ(term, q) {
|
|
|
195
196
|
}
|
|
196
197
|
if (term.type == "geneVariant")
|
|
197
198
|
return {};
|
|
199
|
+
if (term.type == TermTypes.SINGLECELL_CELLTYPE)
|
|
200
|
+
return {};
|
|
198
201
|
throw "unknown term type";
|
|
199
202
|
}
|
|
200
203
|
export {
|
package/routes/termdb.cluster.js
CHANGED
|
@@ -53,8 +53,12 @@ function init({ genomes }) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
async function getResult(q, ds) {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
let _q = q;
|
|
57
|
+
if (q.dataType == TermTypes.GENE_EXPRESSION) {
|
|
58
|
+
_q = JSON.parse(JSON.stringify(q));
|
|
59
|
+
_q.forClusteringAnalysis = true;
|
|
60
|
+
}
|
|
61
|
+
const { term2sample2value, byTermId, bySampleId } = await ds.queries[q.dataType].get(_q);
|
|
58
62
|
if (term2sample2value.size == 0)
|
|
59
63
|
throw "no data";
|
|
60
64
|
if (term2sample2value.size == 1) {
|
package/routes/termdb.config.js
CHANGED
|
@@ -191,6 +191,10 @@ function addNonDictionaryQueries(c, ds, genome) {
|
|
|
191
191
|
q2.rnaseqGeneCount = true;
|
|
192
192
|
}
|
|
193
193
|
if (q.singleCell) {
|
|
194
|
+
const plots = "plots" in q.singleCell.data ? q.singleCell.data.plots.map((p) => ({
|
|
195
|
+
name: p.name,
|
|
196
|
+
colorColumn: p.colorColumn.name
|
|
197
|
+
})) : [];
|
|
194
198
|
q2.singleCell = {
|
|
195
199
|
samples: {
|
|
196
200
|
firstColumnName: q.singleCell.samples.firstColumnName,
|
|
@@ -199,7 +203,8 @@ function addNonDictionaryQueries(c, ds, genome) {
|
|
|
199
203
|
},
|
|
200
204
|
data: {
|
|
201
205
|
sameLegend: q.singleCell.data.sameLegend,
|
|
202
|
-
refName: q.singleCell.data.refName
|
|
206
|
+
refName: q.singleCell.data.refName,
|
|
207
|
+
plots
|
|
203
208
|
}
|
|
204
209
|
};
|
|
205
210
|
if (q.singleCell.geneExpression) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { read_file } from "#src/utils.js";
|
|
4
|
+
import run_R from "#src/run_R.js";
|
|
5
5
|
import serverconfig from "#src/serverconfig.js";
|
|
6
6
|
import { gdc_validate_query_singleCell_samples, gdc_validate_query_singleCell_data } from "#src/mds3.gdc.js";
|
|
7
7
|
const api = {
|
|
@@ -104,19 +104,25 @@ function validateDataNative(D, ds) {
|
|
|
104
104
|
if (ds.queries.singleCell.geneExpression && q.gene) {
|
|
105
105
|
geneExpMap = await ds.queries.singleCell.geneExpression.get({ sample: q.sample, gene: q.gene });
|
|
106
106
|
}
|
|
107
|
+
const file2Lines = {};
|
|
107
108
|
for (const plot of D.plots) {
|
|
109
|
+
if (!q.plots.includes(plot.name))
|
|
110
|
+
continue;
|
|
108
111
|
const tsvfile = path.join(serverconfig.tpmasterdir, plot.folder, q.sample + plot.fileSuffix);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
if (!file2Lines[tsvfile]) {
|
|
113
|
+
try {
|
|
114
|
+
await fs.promises.stat(tsvfile);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
if (e.code == "ENOENT") {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (e.code == "EACCES")
|
|
120
|
+
throw "cannot read file, permission denied";
|
|
121
|
+
throw "failed to load sc data file";
|
|
114
122
|
}
|
|
115
|
-
|
|
116
|
-
throw "cannot read file, permission denied";
|
|
117
|
-
throw "failed to load sc data file";
|
|
123
|
+
file2Lines[tsvfile] = (await read_file(tsvfile)).trim().split("\n");
|
|
118
124
|
}
|
|
119
|
-
const lines =
|
|
125
|
+
const lines = file2Lines[tsvfile];
|
|
120
126
|
const cells = [];
|
|
121
127
|
for (let i = 1; i < lines.length; i++) {
|
|
122
128
|
const l = lines[i].split(" ");
|
|
@@ -148,47 +154,25 @@ function validateDataNative(D, ds) {
|
|
|
148
154
|
};
|
|
149
155
|
}
|
|
150
156
|
function validateGeneExpressionNative(G) {
|
|
157
|
+
G.sample2gene2expressionBins = {};
|
|
151
158
|
G.get = async (q) => {
|
|
152
|
-
const
|
|
159
|
+
const rdsfile = path.join(serverconfig.tpmasterdir, G.folder, q.sample + ".rds");
|
|
160
|
+
try {
|
|
161
|
+
await fs.promises.stat(rdsfile);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
return {};
|
|
164
|
+
}
|
|
165
|
+
let out;
|
|
153
166
|
try {
|
|
154
|
-
|
|
167
|
+
out = JSON.parse(
|
|
168
|
+
await run_R(path.join(serverconfig.binpath, "utils", "getGeneFromMatrix.R"), null, [rdsfile, q.gene])
|
|
169
|
+
);
|
|
155
170
|
} catch (e) {
|
|
156
|
-
|
|
171
|
+
return {};
|
|
157
172
|
}
|
|
158
|
-
|
|
159
|
-
if (header.length == 0)
|
|
160
|
-
throw "blank header line";
|
|
161
|
-
return await grepMatrix4geneExpression(tsvfile, q.gene, header);
|
|
173
|
+
return out;
|
|
162
174
|
};
|
|
163
175
|
}
|
|
164
|
-
function grepMatrix4geneExpression(tsvfile, gene, header) {
|
|
165
|
-
return new Promise((resolve, reject) => {
|
|
166
|
-
const cp = spawn("grep", ["-m", "1", gene + " ", tsvfile]);
|
|
167
|
-
const out = [], err = [];
|
|
168
|
-
cp.stdout.on("data", (d) => out.push(d));
|
|
169
|
-
cp.stderr.on("data", (d) => err.push(d));
|
|
170
|
-
cp.on("close", () => {
|
|
171
|
-
const e = err.join("");
|
|
172
|
-
if (e)
|
|
173
|
-
reject(e);
|
|
174
|
-
const cell2value = {};
|
|
175
|
-
const line = out.join("").trim();
|
|
176
|
-
if (!line) {
|
|
177
|
-
resolve(cell2value);
|
|
178
|
-
}
|
|
179
|
-
const l = line.split(" ");
|
|
180
|
-
if (l.length != header.length)
|
|
181
|
-
reject(`number of fields differ between data line and header: ${l.length} ${header.length}`);
|
|
182
|
-
for (let i = 1; i < l.length; i++) {
|
|
183
|
-
const v = Number(l[i]);
|
|
184
|
-
if (Number.isNaN(v))
|
|
185
|
-
continue;
|
|
186
|
-
cell2value[header[i]] = v;
|
|
187
|
-
}
|
|
188
|
-
resolve(cell2value);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
176
|
export {
|
|
193
177
|
api,
|
|
194
178
|
validate_query_singleCell
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { gdcGetCasesWithExpressionDataFromCohort } from "../src/mds3.gdc.js";
|
|
2
1
|
import path from "path";
|
|
3
2
|
import { run_rust } from "@sjcrh/proteinpaint-rust";
|
|
4
3
|
import got from "got";
|
|
5
4
|
import serverconfig from "#src/serverconfig.js";
|
|
6
5
|
import { get_samples } from "#src/termdb.sql.js";
|
|
6
|
+
import { makeFilter } from "#src/mds3.gdc.js";
|
|
7
7
|
const api = {
|
|
8
8
|
endpoint: "termdb/topVariablyExpressedGenes",
|
|
9
9
|
methods: {
|
|
@@ -106,21 +106,20 @@ async function computeGenes4nativeDs(q, ds, matrixFile, samples) {
|
|
|
106
106
|
function gdcValidateQuery(ds, genome) {
|
|
107
107
|
ds.queries.topVariablyExpressedGenes.getGenes = async (q) => {
|
|
108
108
|
if (serverconfig.features.gdcGenes) {
|
|
109
|
-
console.log(
|
|
109
|
+
console.log(
|
|
110
|
+
"!!GDC!! using serverconfig.features.gdcGenes[] but not live api query. only use this on DEV and never on PROD!"
|
|
111
|
+
);
|
|
110
112
|
return serverconfig.features.gdcGenes;
|
|
111
113
|
}
|
|
112
|
-
if (!ds.__gdc.doneCaching)
|
|
114
|
+
if (!ds.__gdc.doneCaching) {
|
|
113
115
|
throw "The server has not finished caching the case IDs: try again in about 2 minutes.";
|
|
114
|
-
const caseLst = await gdcGetCasesWithExpressionDataFromCohort(q, ds);
|
|
115
|
-
if (caseLst.length == 0) {
|
|
116
|
-
return [];
|
|
117
116
|
}
|
|
118
117
|
const { host, headers } = ds.getHostHeaders(q);
|
|
119
118
|
const url = path.join(host.geneExp, "/gene_expression/gene_selection");
|
|
120
119
|
try {
|
|
121
120
|
const response = await got.post(url, {
|
|
122
121
|
headers,
|
|
123
|
-
body: JSON.stringify(getGeneSelectionArg(q
|
|
122
|
+
body: JSON.stringify(getGeneSelectionArg(q))
|
|
124
123
|
});
|
|
125
124
|
const re = JSON.parse(response.body);
|
|
126
125
|
const genes = [];
|
|
@@ -143,13 +142,14 @@ function gdcValidateQuery(ds, genome) {
|
|
|
143
142
|
throw e;
|
|
144
143
|
}
|
|
145
144
|
};
|
|
146
|
-
function getGeneSelectionArg(q
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
gene_ids: tempGetCGCgenes(genome),
|
|
145
|
+
function getGeneSelectionArg(q) {
|
|
146
|
+
const arg = {
|
|
147
|
+
// add any to avoid tsc err
|
|
148
|
+
case_filters: makeFilter(q),
|
|
151
149
|
selection_size: Number(q.maxGenes)
|
|
152
150
|
};
|
|
151
|
+
arg.gene_ids = tempGetCGCgenes(genome);
|
|
152
|
+
return arg;
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
function tempGetCGCgenes(genome) {
|