@sjcrh/proteinpaint-server 2.151.0 → 2.152.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.151.0",
3
+ "version": "2.152.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",
@@ -64,8 +64,8 @@
64
64
  "@sjcrh/proteinpaint-python": "2.151.0",
65
65
  "@sjcrh/proteinpaint-r": "2.149.0",
66
66
  "@sjcrh/proteinpaint-rust": "2.150.0",
67
- "@sjcrh/proteinpaint-shared": "2.150.0",
68
- "@sjcrh/proteinpaint-types": "2.150.0",
67
+ "@sjcrh/proteinpaint-shared": "2.152.0",
68
+ "@sjcrh/proteinpaint-types": "2.152.0",
69
69
  "@types/express": "^5.0.0",
70
70
  "@types/express-session": "^1.18.1",
71
71
  "better-sqlite3": "^9.4.1",
@@ -31,6 +31,8 @@ function init({ genomes }) {
31
31
  }
32
32
  const g = genomes[q.genome];
33
33
  const ds = g.datasets[q.dslabel];
34
+ if (q.singleCellPlot)
35
+ return getSingleCellScatter(req, res, ds);
34
36
  try {
35
37
  let refSamples = [], cohortSamples;
36
38
  const terms = [];
@@ -116,6 +118,55 @@ function init({ genomes }) {
116
118
  }
117
119
  };
118
120
  }
121
+ async function getSingleCellScatter(req, res, ds) {
122
+ const q = req.query;
123
+ const { name, sample } = q.singleCellPlot;
124
+ const tw = q.colorTW;
125
+ try {
126
+ const data = await ds.queries.singleCell.data.get({ plots: [name], sample });
127
+ const plot = data.plots[0];
128
+ const cells = [...plot.expCells, ...plot.noExpCells];
129
+ const samples = cells.map((cell) => {
130
+ const hidden = {
131
+ category: tw?.q?.hiddenValues ? cell.category in tw.q.hiddenValues : false
132
+ };
133
+ return {
134
+ sample: cell.cellId,
135
+ sampleId: cell.cellId,
136
+ x: cell.x,
137
+ y: cell.y,
138
+ z: 0,
139
+ category: cell.category,
140
+ shape: "Ref",
141
+ hidden
142
+ };
143
+ });
144
+ const [xMin, xMax, yMin, yMax] = samples.reduce(
145
+ (s, d) => [d.x < s[0] ? d.x : s[0], d.x > s[1] ? d.x : s[1], d.y < s[2] ? d.y : s[2], d.y > s[3] ? d.y : s[3]],
146
+ [samples[0].x, samples[0].x, samples[0].y, samples[0].y]
147
+ );
148
+ const categories = new Set(samples.map((s) => s.category));
149
+ const colorMap = {};
150
+ const k2c = getColors(categories.size);
151
+ for (const category of categories) {
152
+ const color = k2c(category);
153
+ colorMap[category] = {
154
+ sampleCount: samples.filter((s) => s.category == category).length,
155
+ color,
156
+ key: category
157
+ };
158
+ }
159
+ const shapeLegend = [["Ref", { sampleCount: samples.length, shape: 0, key: "Ref" }]];
160
+ const colorLegend = Object.entries(colorMap);
161
+ res.send({
162
+ result: { Default: { samples, colorLegend, shapeLegend } },
163
+ range: { xMin, xMax, yMin, yMax }
164
+ });
165
+ } catch (e) {
166
+ console.log(e);
167
+ res.send({ error: e.message || e });
168
+ }
169
+ }
119
170
  async function getSamples(ds, plot) {
120
171
  if (!plot.filterableSamples) await loadFile(plot, ds);
121
172
  return [readSamples(plot.referenceSamples), readSamples(plot.filterableSamples)];