@sjcrh/proteinpaint-server 2.40.8 → 2.41.1-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
package/routes/termdb.cluster.ts
CHANGED
|
@@ -104,9 +104,7 @@ async function doClustering(data: any, q: TermdbClusterRequest) {
|
|
|
104
104
|
const Rinputfile = path.join(serverconfig.cachedir, Math.random().toString() + '.json')
|
|
105
105
|
await utils.write_file(Rinputfile, JSON.stringify(inputData))
|
|
106
106
|
const Routput = JSON.parse(await lines2R(path.join(serverconfig.binpath, 'utils/hclust.R'), [], [Rinputfile]))
|
|
107
|
-
fs.unlink(Rinputfile
|
|
108
|
-
return
|
|
109
|
-
})
|
|
107
|
+
await fs.promises.unlink(Rinputfile)
|
|
110
108
|
|
|
111
109
|
const row_names_index: number[] = Routput.RowOrder.map(row => inputData.row_names.indexOf(row.name)) // sorted rows. value is array index in input data
|
|
112
110
|
const col_names_index: number[] = Routput.ColOrder.map(col => inputData.col_names.indexOf(col.name)) // sorted columns, value is array index from input array
|
|
@@ -164,7 +162,7 @@ export async function validate_query_geneExpression(ds: any, genome: any) {
|
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
async function validateNative(q: GeneExpressionQueryNative, ds: any, genome: any) {
|
|
167
|
-
q.file = path.join(serverconfig.tpmasterdir, q.file)
|
|
165
|
+
if (!q.file.startsWith(serverconfig.tpmasterdir)) q.file = path.join(serverconfig.tpmasterdir, q.file)
|
|
168
166
|
if (!q.samples) q.samples = []
|
|
169
167
|
await utils.validate_tabixfile(q.file)
|
|
170
168
|
q.nochr = await utils.tabix_is_nochr(q.file, null, genome)
|
|
@@ -184,16 +182,6 @@ async function validateNative(q: GeneExpressionQueryNative, ds: any, genome: any
|
|
|
184
182
|
console.log(q.samples.length, 'samples from geneExpression of', ds.label)
|
|
185
183
|
}
|
|
186
184
|
|
|
187
|
-
/*
|
|
188
|
-
query exp data one gene at a time
|
|
189
|
-
param{}
|
|
190
|
-
.genes[{}]
|
|
191
|
-
.gene=str
|
|
192
|
-
.chr=str
|
|
193
|
-
.start=int
|
|
194
|
-
.stop=int
|
|
195
|
-
.filterObj{}
|
|
196
|
-
*/
|
|
197
185
|
q.get = async (param: TermdbClusterRequest) => {
|
|
198
186
|
const limitSamples = await mayLimitSamples(param, q.samples, ds)
|
|
199
187
|
if (limitSamples?.size == 0) {
|
|
@@ -216,6 +204,7 @@ async function validateNative(q: GeneExpressionQueryNative, ds: any, genome: any
|
|
|
216
204
|
}
|
|
217
205
|
}
|
|
218
206
|
|
|
207
|
+
// only valid genes with data are added. invalid genes or genes missing from data file is not added. backend returned genes is allowed to be fewer than supplied by client
|
|
219
208
|
const gene2sample2value = new Map() // k: gene symbol, v: { sampleId : value }
|
|
220
209
|
|
|
221
210
|
for (const g of param.genes) {
|
|
@@ -232,7 +221,7 @@ async function validateNative(q: GeneExpressionQueryNative, ds: any, genome: any
|
|
|
232
221
|
g.chr = j.chr
|
|
233
222
|
}
|
|
234
223
|
|
|
235
|
-
|
|
224
|
+
const s2v = {}
|
|
236
225
|
await utils.get_lines_bigfile({
|
|
237
226
|
args: [q.file, (q.nochr ? g.chr?.replace('chr', '') : g.chr) + ':' + g.start + '-' + g.stop], // must do g.chr?.replace to avoid tsc error
|
|
238
227
|
callback: line => {
|
|
@@ -242,14 +231,15 @@ async function validateNative(q: GeneExpressionQueryNative, ds: any, genome: any
|
|
|
242
231
|
for (let i = 4; i < l.length; i++) {
|
|
243
232
|
const sampleId = samples[i - 4]
|
|
244
233
|
if (limitSamples && !limitSamples.has(sampleId)) continue // doing filtering and sample of current column is not used
|
|
245
|
-
|
|
234
|
+
if (!l[i]) continue // blank string
|
|
246
235
|
const v = Number(l[i])
|
|
247
236
|
if (Number.isNaN(v)) throw 'exp value not number'
|
|
248
|
-
|
|
237
|
+
s2v[sampleId] = v
|
|
249
238
|
}
|
|
250
239
|
}
|
|
251
240
|
} as any)
|
|
252
241
|
// Above!! add "as any" to suppress a npx tsc alert
|
|
242
|
+
if (Object.keys(s2v).length) gene2sample2value.set(g.gene, s2v) // only add gene if has data
|
|
253
243
|
}
|
|
254
244
|
// pass blank byTermId to match with expected output structure
|
|
255
245
|
const byTermId = {}
|
|
@@ -150,17 +150,18 @@ function validateDataNative(D: SingleCellDataNative, ds: any) {
|
|
|
150
150
|
// each line is a cell
|
|
151
151
|
const l = lines[i].split('\t')
|
|
152
152
|
const cellId = l[0],
|
|
153
|
-
x = Number(l[
|
|
154
|
-
y = Number(l[
|
|
153
|
+
x = Number(l[plot.coordsColumns.x]), // FIXME standardize, or define idx in plot
|
|
154
|
+
y = Number(l[plot.coordsColumns.y])
|
|
155
|
+
const category = l[plot.colorColumn?.index] || ''
|
|
155
156
|
if (!cellId) throw 'cell id missing'
|
|
156
157
|
if (!Number.isFinite(x) || !Number.isFinite(y)) throw 'x/y not number'
|
|
157
|
-
cells.push({ cellId, x, y })
|
|
158
|
+
cells.push({ cellId, x, y, category })
|
|
158
159
|
|
|
159
160
|
for (const tid of D.termIds) {
|
|
160
161
|
tid2cellvalue[tid][cellId] = l[1]
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
plots.push({ name: plot.name, cells })
|
|
164
|
+
plots.push({ name: plot.name, cells, colorBy: plot.colorColumn?.name })
|
|
164
165
|
}
|
|
165
166
|
if (plots.length == 0) {
|
|
166
167
|
// no data available for this sample
|