@sjcrh/proteinpaint-server 2.77.1 → 2.79.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.77.1",
3
+ "version": "2.79.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",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@sjcrh/augen": "2.46.0",
65
- "@sjcrh/proteinpaint-rust": "2.75.0",
65
+ "@sjcrh/proteinpaint-rust": "2.78.0",
66
66
  "better-sqlite3": "^9.4.1",
67
67
  "body-parser": "^1.15.2",
68
68
  "canvas": "~2.11.2",
@@ -58,7 +58,8 @@ function make(q, res, ds, genome) {
58
58
  lollipop: tdb.lollipop,
59
59
  urlTemplates: tdb.urlTemplates,
60
60
  title: "title" in ds.cohort ? ds.cohort.title : { text: ds.label },
61
- hideGroupsTab: ds.cohort.hideGroupsTab
61
+ hideGroupsTab: ds.cohort.hideGroupsTab,
62
+ tracks: tdb.tracks
62
63
  };
63
64
  if (tdb.chartConfigByType)
64
65
  c.chartConfigByType = tdb.chartConfigByType;
@@ -86,6 +87,8 @@ function make(q, res, ds, genome) {
86
87
  c.excludedTermtypeByTarget = tdb.excludedTermtypeByTarget;
87
88
  if (tdb.about)
88
89
  c.about = tdb.about;
90
+ if (tdb.survival)
91
+ c.survival = tdb.survival;
89
92
  if (ds.assayAvailability)
90
93
  c.assayAvailability = ds.assayAvailability;
91
94
  if (ds.customTwQByType)
@@ -2,9 +2,11 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { read_file } from "#src/utils.js";
4
4
  import run_R from "#src/run_R.js";
5
+ import { run_rust } from "@sjcrh/proteinpaint-rust";
5
6
  import serverconfig from "#src/serverconfig.js";
6
7
  import { validate_query_singleCell_DEgenes } from "./termdb.singlecellDEgenes.ts";
7
8
  import { gdc_validate_query_singleCell_samples, gdc_validate_query_singleCell_data } from "#src/mds3.gdc.js";
9
+ import ky from "ky";
8
10
  const api = {
9
11
  endpoint: "termdb/singlecellSamples",
10
12
  methods: {
@@ -66,6 +68,7 @@ async function validate_query_singleCell(ds, genome) {
66
68
  if (q.geneExpression.src == "native") {
67
69
  validateGeneExpressionNative(q.geneExpression);
68
70
  } else if (q.geneExpression.src == "gdcapi") {
71
+ gdc_validateGeneExpression(q.geneExpression, ds, genome);
69
72
  } else {
70
73
  throw "unknown singleCell.geneExpression.src";
71
74
  }
@@ -108,7 +111,11 @@ function validateDataNative(D, ds) {
108
111
  for (const plot of D.plots) {
109
112
  if (!q.plots.includes(plot.name))
110
113
  continue;
111
- const tsvfile = path.join(serverconfig.tpmasterdir, plot.folder, q.sample + plot.fileSuffix);
114
+ const tsvfile = path.join(
115
+ serverconfig.tpmasterdir,
116
+ plot.folder,
117
+ (q.sample.eID || q.sample.sID) + plot.fileSuffix
118
+ );
112
119
  if (!file2Lines[tsvfile]) {
113
120
  try {
114
121
  await fs.promises.stat(tsvfile);
@@ -154,23 +161,81 @@ function validateDataNative(D, ds) {
154
161
  };
155
162
  }
156
163
  function validateGeneExpressionNative(G) {
164
+ G.sample2gene2expressionBins = {};
165
+ if (G.storage_type == "RDS" || !G.storage_type) {
166
+ G.get = async (q) => {
167
+ const rdsfile = path.join(serverconfig.tpmasterdir, G.folder, (q.sample.eID || q.sample.sID) + ".rds");
168
+ try {
169
+ await fs.promises.stat(rdsfile);
170
+ } catch (e) {
171
+ return {};
172
+ }
173
+ let out;
174
+ try {
175
+ out = JSON.parse(
176
+ await run_R(path.join(serverconfig.binpath, "utils", "getGeneFromMatrix.R"), null, [rdsfile, q.gene])
177
+ );
178
+ } catch (e) {
179
+ return {};
180
+ }
181
+ console.log("out:", out);
182
+ return out;
183
+ };
184
+ } else if (G.storage_type == "HDF5") {
185
+ G.get = async (q) => {
186
+ const rdsfile = path.join(serverconfig.tpmasterdir, G.folder, (q.sample.eID || q.sample.sID) + ".h5");
187
+ try {
188
+ await fs.promises.stat(rdsfile);
189
+ } catch (e) {
190
+ return {};
191
+ }
192
+ const read_hdf5_input_type = { gene: q.gene, hdf5_file: rdsfile };
193
+ let out;
194
+ try {
195
+ const time1 = (/* @__PURE__ */ new Date()).valueOf();
196
+ const rust_output = await run_rust("readHDF5", JSON.stringify(read_hdf5_input_type));
197
+ const time2 = (/* @__PURE__ */ new Date()).valueOf();
198
+ console.log("Time taken to query HDF5 file:", time2 - time1, "ms");
199
+ for (const line of rust_output.split("\n")) {
200
+ if (line.startsWith("output_string:")) {
201
+ out = JSON.parse(line.replace("output_string:", ""));
202
+ } else {
203
+ console.log(line);
204
+ }
205
+ }
206
+ } catch (e) {
207
+ return {};
208
+ }
209
+ return out;
210
+ };
211
+ }
212
+ }
213
+ function gdc_validateGeneExpression(G, ds, genome) {
157
214
  G.sample2gene2expressionBins = {};
158
215
  G.get = async (q) => {
159
- const rdsfile = path.join(serverconfig.tpmasterdir, G.folder, q.sample + ".rds");
160
216
  try {
161
- await fs.promises.stat(rdsfile);
162
- } catch (e) {
163
- return {};
164
- }
165
- let out;
166
- try {
167
- out = JSON.parse(
168
- await run_R(path.join(serverconfig.binpath, "utils", "getGeneFromMatrix.R"), null, [rdsfile, q.gene])
169
- );
217
+ const uuid = ds.__gdc.map2caseid.get(q.sample.sID);
218
+ const fileid = q.sample.eID;
219
+ const aliasLst = genome.genedb.getAliasByName.all(q.gene);
220
+ const gencodeId = aliasLst.find((a) => a?.alias.toUpperCase().startsWith("ENSG"))?.alias;
221
+ const body = {
222
+ case_id: uuid,
223
+ gene_ids: [gencodeId],
224
+ file_id: fileid
225
+ };
226
+ const { host } = ds.getHostHeaders(q);
227
+ const out = await ky.post(path.join(host.rest, "scrna_seq/gene_expression"), { timeout: false, json: body }).json();
228
+ const result = out.data[0].cells;
229
+ const data = {};
230
+ for (const r of result) {
231
+ data[r.cell_id] = r.value;
232
+ }
233
+ return data;
170
234
  } catch (e) {
171
- return {};
235
+ if (e.stack)
236
+ console.log(e.stack);
237
+ return { error: e.message || e };
172
238
  }
173
- return out;
174
239
  };
175
240
  }
176
241
  export {