@sjcrh/proteinpaint-server 2.62.0 → 2.63.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.62.0",
3
+ "version": "2.63.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",
@@ -85,6 +85,7 @@ function make(q, res, ds, genome) {
85
85
  addScatterplots(c, ds);
86
86
  addMatrixplots(c, ds);
87
87
  addGenomicQueries(c, ds, genome);
88
+ addImageQueries(c, ds);
88
89
  res.send({ termdbConfig: c });
89
90
  }
90
91
  function addRestrictAncestries(c, tdb) {
@@ -94,6 +95,13 @@ function addRestrictAncestries(c, tdb) {
94
95
  return { name: i.name, tvs: i.tvs, PCcount: i.PCcount };
95
96
  });
96
97
  }
98
+ function addImageQueries(c, ds) {
99
+ const q = ds.queries;
100
+ const q2 = c.queries;
101
+ if (q.images) {
102
+ q2.images = {};
103
+ }
104
+ }
97
105
  function addScatterplots(c, ds) {
98
106
  if (!ds.cohort.scatterplots)
99
107
  return;
@@ -0,0 +1,67 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import serverconfig from "#src/serverconfig.js";
4
+ const api = {
5
+ endpoint: "termdb/getSampleImages",
6
+ methods: {
7
+ all: {
8
+ init,
9
+ request: {
10
+ typeId: "TermdbGetSampleImagesRequest"
11
+ },
12
+ response: {
13
+ typeId: "TermdbGetSampleImagesResponse"
14
+ }
15
+ }
16
+ }
17
+ };
18
+ function init({ genomes }) {
19
+ return async (req, res) => {
20
+ try {
21
+ const q = req.query;
22
+ const sampleId = q.sampleId;
23
+ const genome = genomes[q.genome];
24
+ if (!genome)
25
+ throw "invalid genome";
26
+ const ds = genome.datasets?.[q.dslabel];
27
+ if (!ds)
28
+ throw "invalid dslabel";
29
+ const images = await ds.queries.images.getSampleImages({ sampleId });
30
+ res.send({ images });
31
+ } catch (e) {
32
+ res.send({ status: "error", error: e.message || e });
33
+ }
34
+ };
35
+ }
36
+ function validate_query_getSampleImages(ds, genome) {
37
+ const q = ds.queries.images;
38
+ if (!q)
39
+ return;
40
+ nativeValidateQuery(ds);
41
+ }
42
+ function nativeValidateQuery(ds) {
43
+ ds.queries.images.getSampleImages = async (q) => {
44
+ const folder = ds.queries.images.folder;
45
+ const images = await getSampleImages(ds, folder, q.sampleId);
46
+ return images;
47
+ };
48
+ }
49
+ async function getSampleImages(ds, folder, sampleId) {
50
+ const sql = `SELECT * FROM images WHERE sample = ${sampleId}`;
51
+ const rows = ds.cohort.db.connection.prepare(sql).all();
52
+ const images = [];
53
+ for (const row of rows) {
54
+ const file = path.join(serverconfig.tpmasterdir, folder, row.fileName);
55
+ if (!fs.existsSync(file))
56
+ throw new Error(`File ${row.fileName} does not exist`);
57
+ const data = await fs.promises.readFile(file);
58
+ images.push({
59
+ src: "data:image/jpeg;base64," + Buffer.from(data).toString("base64")
60
+ });
61
+ }
62
+ return images;
63
+ }
64
+ export {
65
+ api,
66
+ validate_query_getSampleImages
67
+ };