@sjcrh/proteinpaint-server 2.31.0 → 2.32.2-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.
|
|
3
|
+
"version": "2.32.2-0",
|
|
4
4
|
"description": "a genomics visualization tool for exploring a cohort's genotype and phenotype data",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": "start.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"pretest:integration": "tsc --esModuleInterop genome/*.ts dataset/*.ts",
|
|
26
26
|
"test:integration": "echo 'TODO: server integration tests'",
|
|
27
27
|
"prepack": "tsc --esModuleInterop genome/*.ts dataset/*.ts && webpack --env NODE_ENV=production",
|
|
28
|
+
"test:tsc": "tsc --esModuleInterop --noEmit --allowImportingTsExtensions ./shared/types/test/*.type.spec.ts",
|
|
28
29
|
"response": "nodemon modules/test/test.server.js --watch src",
|
|
29
30
|
"getconf": "../build/getConfigProp.js",
|
|
30
31
|
"doc": "../augen/build.sh routes shared/types/routes shared/checkers ../public/docs/server"
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"webpack-notifier": "^1.15.0"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"@sjcrh/augen": "2.
|
|
59
|
+
"@sjcrh/augen": "2.32.2-0",
|
|
59
60
|
"@sjcrh/proteinpaint-rust": "2.31.0",
|
|
60
61
|
"better-sqlite3": "^7.5.3",
|
|
61
62
|
"body-parser": "^1.15.2",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TermdbSinglecellDataRequest,
|
|
3
|
+
TermdbSinglecellDataResponse
|
|
4
|
+
} from '#shared/types/routes/termdb.singlecellData.ts'
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
given a sample, return it's singlecell data from dataset
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const api: any = {
|
|
11
|
+
endpoint: 'termdb/singlecellData',
|
|
12
|
+
methods: {
|
|
13
|
+
get: {
|
|
14
|
+
init,
|
|
15
|
+
request: {
|
|
16
|
+
typeId: 'TermdbSinglecellDataRequest'
|
|
17
|
+
},
|
|
18
|
+
response: {
|
|
19
|
+
typeId: 'TermdbSinglecellDataResponse'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
post: {
|
|
23
|
+
alternativeFor: 'get',
|
|
24
|
+
init
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function init({ genomes }) {
|
|
30
|
+
return async (req: any, res: any): Promise<void> => {
|
|
31
|
+
const q = req.query as TermdbSinglecellDataRequest
|
|
32
|
+
try {
|
|
33
|
+
const g = genomes[q.genome]
|
|
34
|
+
if (!g) throw 'invalid genome name'
|
|
35
|
+
const ds = g.datasets[q.dslabel]
|
|
36
|
+
if (!ds) throw 'invalid dataset name'
|
|
37
|
+
if (!ds.queries?.singleCell) throw 'no singlecell data on this dataset'
|
|
38
|
+
const result = (await ds.queries.singleCell.data.get(q)) as TermdbSinglecellDataResponse
|
|
39
|
+
res.send(result)
|
|
40
|
+
} catch (e: any) {
|
|
41
|
+
if (e instanceof Error && e.stack) console.log(e)
|
|
42
|
+
res.send({ error: e.message || e })
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { read_file } from '#src/utils.js'
|
|
4
|
+
import serverconfig from '#src/serverconfig.js'
|
|
1
5
|
import {
|
|
6
|
+
SingleCellQuery,
|
|
7
|
+
SingleCellSamplesNative,
|
|
8
|
+
SingleCellSamplesGdc,
|
|
9
|
+
SingleCellDataNative,
|
|
10
|
+
SingleCellDataGdc
|
|
11
|
+
} from '#shared/types/dataset.ts'
|
|
12
|
+
import {
|
|
13
|
+
Sample,
|
|
2
14
|
TermdbSinglecellsamplesRequest,
|
|
3
15
|
TermdbSinglecellsamplesResponse
|
|
4
16
|
} from '#shared/types/routes/termdb.singlecellSamples.ts'
|
|
17
|
+
import {
|
|
18
|
+
Cell,
|
|
19
|
+
Plot,
|
|
20
|
+
HasdataResponse,
|
|
21
|
+
NodataResponse,
|
|
22
|
+
ErrorResponse
|
|
23
|
+
} from '#shared/types/routes/termdb.singlecellData.ts'
|
|
24
|
+
import { gdc_validate_query_singleCell_samples, gdc_validate_query_singleCell_data } from '#src/mds3.gdc.js'
|
|
5
25
|
|
|
6
26
|
/* route returns list of samples with sc data
|
|
7
27
|
this is due to the fact that sometimes not all samples in a dataset has sc data
|
|
@@ -35,11 +55,113 @@ function init({ genomes }) {
|
|
|
35
55
|
const ds = g.datasets[q.dslabel]
|
|
36
56
|
if (!ds) throw 'invalid dataset name'
|
|
37
57
|
if (!ds.queries?.singleCell) throw 'no singlecell data on this dataset'
|
|
38
|
-
const
|
|
39
|
-
res.send(
|
|
58
|
+
const samples = (await ds.queries.singleCell.samples.get(q)) as TermdbSinglecellsamplesResponse
|
|
59
|
+
res.send({ samples })
|
|
40
60
|
} catch (e: any) {
|
|
41
61
|
if (e instanceof Error && e.stack) console.log(e)
|
|
42
62
|
res.send({ error: e.message || e })
|
|
43
63
|
}
|
|
44
64
|
}
|
|
45
65
|
}
|
|
66
|
+
|
|
67
|
+
/////////////////// ds query validator
|
|
68
|
+
export async function validate_query_singleCell(ds: any, genome: any) {
|
|
69
|
+
const q = ds.queries.singleCell as SingleCellQuery
|
|
70
|
+
if (!q) return
|
|
71
|
+
|
|
72
|
+
if (q.samples.src == 'gdcapi') {
|
|
73
|
+
gdc_validate_query_singleCell_samples(ds, genome)
|
|
74
|
+
} else {
|
|
75
|
+
validateSamplesNative(q.samples as SingleCellSamplesNative, ds)
|
|
76
|
+
}
|
|
77
|
+
// q.samples.get() added
|
|
78
|
+
|
|
79
|
+
if (q.data.src == 'gdcapi') {
|
|
80
|
+
gdc_validate_query_singleCell_data(ds, genome)
|
|
81
|
+
} else {
|
|
82
|
+
validateDataNative(q.data as SingleCellDataNative, ds)
|
|
83
|
+
}
|
|
84
|
+
// q.data.get() added
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function validateSamplesNative(S: SingleCellSamplesNative, ds: any) {
|
|
88
|
+
// for now use this quick fix method to pull sample ids annotated by this term
|
|
89
|
+
// to support situation where not all samples from a dataset has sc data
|
|
90
|
+
const samples = [] as Sample[] // list of sample ids with sc data
|
|
91
|
+
const s = ds.cohort.termdb.q.getAllValues4term(S.isSampleTerm)
|
|
92
|
+
for (const id of s.keys()) {
|
|
93
|
+
samples.push({ sample: ds.cohort.termdb.q.id2sampleName(id) })
|
|
94
|
+
}
|
|
95
|
+
if (samples.length == 0) throw 'no sample with sc data'
|
|
96
|
+
// getter returns array of {name:<samplename>, files:[]} where files is gdc specific. each sample is an obj and allows to add ds-specific stuff
|
|
97
|
+
S.get = () => samples
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function validateDataNative(D: SingleCellDataNative, ds: any) {
|
|
101
|
+
const nameSet = new Set() // guard against duplicating plot names
|
|
102
|
+
for (const plot of D.plots) {
|
|
103
|
+
if (nameSet.has(plot.name)) throw 'duplicate plot.name'
|
|
104
|
+
nameSet.add(plot.name)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// scoped and cached for runtime
|
|
108
|
+
const _terms = [] as any
|
|
109
|
+
const _tid2cellvalue = {} as any
|
|
110
|
+
|
|
111
|
+
for (const tid of D.termIds) {
|
|
112
|
+
const t = ds.cohort.termdb.q.termjsonByOneid(tid)
|
|
113
|
+
if (!t) throw 'invalid term id from queries.singleCell.data.termIds[]'
|
|
114
|
+
_terms.push(t)
|
|
115
|
+
_tid2cellvalue[tid] = ds.cohort.termdb.q.getAllValues4term(tid)
|
|
116
|
+
}
|
|
117
|
+
D.get = async sample => {
|
|
118
|
+
// if sample is int, may convert to string
|
|
119
|
+
try {
|
|
120
|
+
const tid2cellvalue = {}
|
|
121
|
+
for (const tid of D.termIds) tid2cellvalue[tid] = {} // k: cell id, v: cell value for this term
|
|
122
|
+
|
|
123
|
+
const plots = [] as Plot[] // given a sample name, collect every plot data for this sample and return
|
|
124
|
+
for (const plot of D.plots) {
|
|
125
|
+
const tsvfile = path.join(serverconfig.tpmasterdir, plot.folder, sample, plot.fileSuffix)
|
|
126
|
+
try {
|
|
127
|
+
await fs.promises.stat(tsvfile)
|
|
128
|
+
} catch (e: any) {
|
|
129
|
+
if (e.code == 'ENOENT') {
|
|
130
|
+
// no file found for this sample; allowed because sampleView tests if that sample has sc data or not
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
if (e.code == 'EACCES') throw 'cannot read file, permission denied'
|
|
134
|
+
throw 'failed to load sc data file'
|
|
135
|
+
}
|
|
136
|
+
const lines = (await read_file(tsvfile)).trim().split('\n')
|
|
137
|
+
// 1st line is header
|
|
138
|
+
const cells = [] as Cell[]
|
|
139
|
+
for (let i = 1; i < lines.length; i++) {
|
|
140
|
+
// each line is a cell
|
|
141
|
+
const l = lines[i].split('\t')
|
|
142
|
+
const cellId = l[0],
|
|
143
|
+
x = Number(l[4]), // FIXME standardize, or define idx in plot
|
|
144
|
+
y = Number(l[5])
|
|
145
|
+
if (!cellId) throw 'cell id missing'
|
|
146
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) throw 'x/y not number'
|
|
147
|
+
cells.push({ cellId, x, y })
|
|
148
|
+
|
|
149
|
+
for (const tid of D.termIds) {
|
|
150
|
+
if (_tid2cellvalue[tid].has(cellId)) {
|
|
151
|
+
tid2cellvalue[tid][cellId] = _tid2cellvalue[tid].get(cellId)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
plots.push({ name: plot.name, cells })
|
|
156
|
+
}
|
|
157
|
+
if (plots.length == 0) {
|
|
158
|
+
// no data available for this sample
|
|
159
|
+
return { nodata: true }
|
|
160
|
+
}
|
|
161
|
+
return { plots, terms: _terms, tid2cellvalue }
|
|
162
|
+
} catch (e: any) {
|
|
163
|
+
if (e.stack) console.log(e.stack)
|
|
164
|
+
return { error: e.message || e }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|