@sjcrh/proteinpaint-server 2.81.3 → 2.81.5-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 +1 -1
- package/routes/termdb.cluster.js +14 -3
- package/src/app.js +30 -8
package/package.json
CHANGED
package/routes/termdb.cluster.js
CHANGED
|
@@ -37,6 +37,12 @@ function init({ genomes }) {
|
|
|
37
37
|
if (q.dataType == TermTypes.GENE_EXPRESSION || q.dataType == TermTypes.METABOLITE_INTENSITY) {
|
|
38
38
|
if (!ds.queries?.[q.dataType])
|
|
39
39
|
throw `no ${q.dataType} data on this dataset`;
|
|
40
|
+
if (!q.terms)
|
|
41
|
+
throw `missing gene list`;
|
|
42
|
+
if (!Array.isArray(q.terms))
|
|
43
|
+
throw `gene list is not an array`;
|
|
44
|
+
if (q.terms.length < 3)
|
|
45
|
+
throw `A minimum of three genes is required for clustering. Please refresh this page to clear this error.`;
|
|
40
46
|
result = await getResult(q, ds);
|
|
41
47
|
} else {
|
|
42
48
|
throw "unknown q.dataType " + q.dataType;
|
|
@@ -66,18 +72,21 @@ async function getResult(q, ds) {
|
|
|
66
72
|
return { term: { gene: g, type: TermTypes.GENE_EXPRESSION }, data: term2sample2value.get(g) };
|
|
67
73
|
}
|
|
68
74
|
const t = Date.now();
|
|
69
|
-
const clustering = await doClustering(term2sample2value, q);
|
|
75
|
+
const clustering = await doClustering(term2sample2value, q, Object.keys(bySampleId).length);
|
|
70
76
|
if (serverconfig.debugmode)
|
|
71
77
|
console.log("clustering done:", Date.now() - t, "ms");
|
|
72
78
|
return { clustering, byTermId, bySampleId };
|
|
73
79
|
}
|
|
74
|
-
async function doClustering(data, q) {
|
|
80
|
+
async function doClustering(data, q, numCases = 1e3) {
|
|
75
81
|
const sampleSet = /* @__PURE__ */ new Set();
|
|
76
82
|
for (const o of data.values()) {
|
|
77
83
|
for (const s in o)
|
|
78
84
|
sampleSet.add(s);
|
|
79
|
-
|
|
85
|
+
if (sampleSet.size >= numCases)
|
|
86
|
+
break;
|
|
80
87
|
}
|
|
88
|
+
if (sampleSet.size == 0)
|
|
89
|
+
throw "termdb.cluster: no samples";
|
|
81
90
|
if (!clusterMethodLst.find((i) => i.value == q.clusterMethod))
|
|
82
91
|
throw "Invalid cluster method";
|
|
83
92
|
if (!distanceMethodLst.find((i) => i.value == q.distanceMethod))
|
|
@@ -101,6 +110,8 @@ async function doClustering(data, q) {
|
|
|
101
110
|
}
|
|
102
111
|
inputData.matrix.push(getZscore(row));
|
|
103
112
|
}
|
|
113
|
+
if (inputData.matrix.length == 0)
|
|
114
|
+
throw "Clustering matrix is empty";
|
|
104
115
|
const Routput = JSON.parse(
|
|
105
116
|
await run_R(path.join(serverconfig.binpath, "utils", "hclust.R"), JSON.stringify(inputData))
|
|
106
117
|
);
|