@sjcrh/proteinpaint-server 2.107.0 → 2.108.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.107.0",
3
+ "version": "2.108.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",
@@ -60,8 +60,8 @@
60
60
  "dependencies": {
61
61
  "@sjcrh/augen": "2.87.0",
62
62
  "@sjcrh/proteinpaint-rust": "2.99.0",
63
- "@sjcrh/proteinpaint-shared": "2.106.0",
64
- "@sjcrh/proteinpaint-types": "2.107.0",
63
+ "@sjcrh/proteinpaint-shared": "2.108.0",
64
+ "@sjcrh/proteinpaint-types": "2.108.0",
65
65
  "@types/express": "^5.0.0",
66
66
  "@types/express-session": "^1.18.1",
67
67
  "better-sqlite3": "^9.4.1",
@@ -3,7 +3,10 @@ import { getData } from "../src/termdb.matrix.js";
3
3
  import run_R from "../src/run_R.js";
4
4
  import serverconfig from "../src/serverconfig.js";
5
5
  import { mayLog } from "#src/helpers.ts";
6
+ import { stdDev } from "#shared/violin.bins.js";
6
7
  import path from "path";
8
+ const minArrayLength = 3;
9
+ const minSD = 0.05;
7
10
  const api = {
8
11
  endpoint: "termdb/correlationVolcano",
9
12
  methods: {
@@ -65,16 +68,31 @@ async function compute(q, ds, genome) {
65
68
  vtid2array.get(tw.$id).v2.push(variableValue);
66
69
  }
67
70
  }
71
+ const [acceptedVariables, skippedVariables] = Array.from(vtid2array.values()).reduce(
72
+ ([accepted, skipped], t) => {
73
+ const grterThanOne = t.v1.length > minArrayLength && t.v2.length > minArrayLength;
74
+ const significantSD = stdDev(t.v1) > minSD && stdDev(t.v2) > minSD;
75
+ const v = grterThanOne && significantSD ? accepted : skipped;
76
+ if (v === accepted)
77
+ accepted.push(t);
78
+ if (v === skipped)
79
+ skipped.push({ tw$id: t.id });
80
+ return [accepted, skipped];
81
+ },
82
+ [[], []]
83
+ );
84
+ const result = { skippedVariables, variableItems: [] };
85
+ if (!acceptedVariables.length)
86
+ return result;
68
87
  const input = {
69
88
  method: q.correlationMethod || "pearson",
70
- terms: [...vtid2array.values()]
89
+ terms: acceptedVariables
71
90
  };
72
91
  const time1 = Date.now();
73
92
  const output = {
74
93
  terms: JSON.parse(await run_R(path.join(serverconfig.binpath, "utils", "corr.R"), JSON.stringify(input)))
75
94
  };
76
95
  mayLog("Time taken to run correlation analysis:", Date.now() - time1);
77
- const result = { variableItems: [] };
78
96
  for (const t of output.terms) {
79
97
  const t2 = {
80
98
  tw$id: t.id,
@@ -58,12 +58,14 @@ async function run_DE(param, ds, term_results) {
58
58
  throw "samplelst.groups[0].values.length<1";
59
59
  if (param.samplelst.groups[1].values?.length < 1)
60
60
  throw "samplelst.groups[1].values.length<1";
61
- param.storage_type = ds.queries.rnaseqGeneCount.storage_type;
62
61
  const q = ds.queries.rnaseqGeneCount;
63
62
  if (!q)
64
63
  return;
65
64
  if (!q.file)
66
65
  throw "unknown data type for rnaseqGeneCount";
66
+ if (!q.storage_type)
67
+ throw "storage_type is not defined";
68
+ param.storage_type = q.storage_type;
67
69
  const group1names = [];
68
70
  const conf1_group1 = [];
69
71
  for (const s of param.samplelst.groups[0].values) {
@@ -73,9 +75,17 @@ async function run_DE(param, ds, term_results) {
73
75
  if (!n)
74
76
  continue;
75
77
  if (q.allSampleSet.has(n)) {
76
- group1names.push(n);
77
78
  if (param.tw) {
78
- conf1_group1.push(term_results.samples[s.sampleId][param.tw.$id]["value"]);
79
+ if (term_results.samples[s.sampleId]) {
80
+ if (param.tw.q.mode == "continuous") {
81
+ conf1_group1.push(term_results.samples[s.sampleId][param.tw.$id]["value"]);
82
+ } else {
83
+ conf1_group1.push(term_results.samples[s.sampleId][param.tw.$id]["key"]);
84
+ }
85
+ group1names.push(n);
86
+ }
87
+ } else {
88
+ group1names.push(n);
79
89
  }
80
90
  } else {
81
91
  }
@@ -89,9 +99,17 @@ async function run_DE(param, ds, term_results) {
89
99
  if (!n)
90
100
  continue;
91
101
  if (q.allSampleSet.has(n)) {
92
- group2names.push(n);
93
102
  if (param.tw) {
94
- conf1_group2.push(term_results.samples[s.sampleId][param.tw.$id]["value"]);
103
+ if (term_results.samples[s.sampleId]) {
104
+ if (param.tw.q.mode == "continuous") {
105
+ conf1_group2.push(term_results.samples[s.sampleId][param.tw.$id]["value"]);
106
+ } else {
107
+ conf1_group2.push(term_results.samples[s.sampleId][param.tw.$id]["key"]);
108
+ }
109
+ group2names.push(n);
110
+ }
111
+ } else {
112
+ group2names.push(n);
95
113
  }
96
114
  } else {
97
115
  }
@@ -115,7 +133,10 @@ async function run_DE(param, ds, term_results) {
115
133
  };
116
134
  if (param.tw) {
117
135
  expression_input.conf1 = [...conf1_group2, ...conf1_group1];
118
- expression_input.conf1_type = param.tw.term.type;
136
+ expression_input.conf1_mode = param.tw.q.mode;
137
+ if (new Set(expression_input.conf1).size === 1) {
138
+ throw "Confounding variable has only one value";
139
+ }
119
140
  }
120
141
  const sample_size_limit = 8;
121
142
  let result;
@@ -9,6 +9,7 @@ import { clusterMethodLst, distanceMethodLst } from "#shared/clustering.js";
9
9
  import { getResult as getResultGene } from "#src/gene.js";
10
10
  import { TermTypes, NUMERIC_DICTIONARY_TERM } from "#shared/terms.js";
11
11
  import { getData } from "#src/termdb.matrix.js";
12
+ import { termType2label } from "#shared/terms.js";
12
13
  const api = {
13
14
  endpoint: "termdb/cluster",
14
15
  methods: {
@@ -106,14 +107,24 @@ async function getNumericDictTermAnnotation(q, ds, genome) {
106
107
  }
107
108
  async function doClustering(data, q, numCases = 1e3) {
108
109
  const sampleSet = /* @__PURE__ */ new Set();
110
+ let firstTerm = true;
109
111
  for (const o of data.values()) {
110
- for (const s in o)
111
- sampleSet.add(s);
112
- if (sampleSet.size >= numCases)
113
- break;
112
+ const currentSampleIds = new Set(Object.keys(o));
113
+ if (firstTerm) {
114
+ currentSampleIds.forEach((id) => sampleSet.add(id));
115
+ firstTerm = false;
116
+ } else {
117
+ for (const id of sampleSet) {
118
+ if (!currentSampleIds.has(id)) {
119
+ sampleSet.delete(id);
120
+ }
121
+ }
122
+ }
114
123
  }
115
124
  if (sampleSet.size == 0)
116
- throw "termdb.cluster: no samples";
125
+ throw `termdb.cluster: There are no overlapping tested samples shared across the selected ${termType2label(
126
+ q.dataType
127
+ )}`;
117
128
  if (!clusterMethodLst.find((i) => i.value == q.clusterMethod))
118
129
  throw "Invalid cluster method";
119
130
  if (!distanceMethodLst.find((i) => i.value == q.distanceMethod))
@@ -122,7 +133,7 @@ async function doClustering(data, q, numCases = 1e3) {
122
133
  matrix: [],
123
134
  row_names: [],
124
135
  // genes
125
- col_names: [...sampleSet],
136
+ col_names: [...sampleSet].slice(0, numCases),
126
137
  // samples
127
138
  cluster_method: q.clusterMethod,
128
139
  distance_method: q.distanceMethod,
@@ -133,7 +144,7 @@ async function doClustering(data, q, numCases = 1e3) {
133
144
  inputData.row_names.push(gene);
134
145
  const row = [];
135
146
  for (const s of inputData.col_names) {
136
- row.push(o[s] || 0);
147
+ row.push(o[s]);
137
148
  }
138
149
  inputData.matrix.push(q.zScoreTransformation ? getZscore(row) : row);
139
150
  }