@sjcrh/proteinpaint-server 2.42.2 → 2.43.1

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.42.2",
3
+ "version": "2.43.1",
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",
@@ -71,6 +71,7 @@
71
71
  "image-size": "^0.5.5",
72
72
  "jsonwebtoken": "^9.0.0",
73
73
  "jstat": "^1.9.3",
74
+ "ky": "^1.2.1",
74
75
  "lazy": "^1.0.11",
75
76
  "micromatch": "^4.0.5",
76
77
  "minimatch": "^3.1.2",
@@ -2,13 +2,7 @@ import fs from 'fs'
2
2
  import path from 'path'
3
3
  import { read_file } from '#src/utils.js'
4
4
  import serverconfig from '#src/serverconfig.js'
5
- import {
6
- SingleCellQuery,
7
- SingleCellSamplesNative,
8
- SingleCellSamplesGdc,
9
- SingleCellDataNative,
10
- SingleCellDataGdc
11
- } from '#shared/types/dataset.ts'
5
+ import { SingleCellQuery, SingleCellSamplesNative, SingleCellDataNative } from '#shared/types/dataset.ts'
12
6
  import {
13
7
  Sample,
14
8
  TermdbSinglecellsamplesRequest,
@@ -51,7 +45,6 @@ function init({ genomes }) {
51
45
  if (!ds) throw 'invalid dataset name'
52
46
  if (!ds.queries?.singleCell) throw 'no singlecell data on this dataset'
53
47
  result = (await ds.queries.singleCell.samples.get(q)) as TermdbSinglecellsamplesResponse
54
- result.sameLegend = ds.queries.singleCell.samples.sameLegend
55
48
  } catch (e: any) {
56
49
  if (e.stack) console.log(e.stack)
57
50
  result = {
@@ -71,7 +64,7 @@ export async function validate_query_singleCell(ds: any, genome: any) {
71
64
  if (q.samples.src == 'gdcapi') {
72
65
  gdc_validate_query_singleCell_samples(ds, genome)
73
66
  } else if (q.samples.src == 'native') {
74
- validateSamplesNative(q.samples as SingleCellSamplesNative, ds)
67
+ getSamplesNative(q.samples as SingleCellSamplesNative, ds)
75
68
  } else {
76
69
  throw 'unknown singleCell.samples.src'
77
70
  }
@@ -87,18 +80,31 @@ export async function validate_query_singleCell(ds: any, genome: any) {
87
80
  // q.data.get() added
88
81
  }
89
82
 
90
- function validateSamplesNative(S: SingleCellSamplesNative, ds: any) {
83
+ async function getSamplesNative(S: SingleCellSamplesNative, ds: any) {
91
84
  // for now use this quick fix method to pull sample ids annotated by this term
92
85
  // to support situation where not all samples from a dataset has sc data
93
- const samples = [] as Sample[] // list of sample ids with sc data
94
- const s = ds.cohort.termdb.q.getAllValues4term(S.isSampleTerm)
95
- for (const id of s.keys()) {
96
- samples.push({ sample: ds.cohort.termdb.q.id2sampleName(id) })
86
+ const samplesNotCells = ds.cohort.termdb.q.getAllValues4term(S.isSampleTerm)
87
+ if (samplesNotCells.size == 0) throw 'no samples found that are identified by isSampleTerm'
88
+ const samples = [] as any // array of samples with sc data to be sent to client and list in table; cannot use Sample type for the use of "sampleid" temp property
89
+ for (const sampleid of samplesNotCells.keys()) {
90
+ samples.push({
91
+ sample: ds.cohort.termdb.q.id2sampleName(sampleid), // string name for display
92
+ sampleid // temporarily kept to assign term value to each sample
93
+ })
97
94
  }
98
- if (samples.length == 0) throw 'no sample with sc data'
99
- // getter returns array of {sample:<samplename>, files:[]} where files is gdc specific. each sample is an obj and allows to add ds-specific stuff
95
+ if (S.sampleColumns) {
96
+ // has optional terms to show as table columns and annotate samples
97
+ for (const term of S.sampleColumns) {
98
+ const s2v = ds.cohort.termdb.q.getAllValues4term(term.termid) // map. k: sampleid, v: term value
99
+ for (const s of samples) {
100
+ if (s2v.has(s.sampleid)) s[term.termid] = s2v.get(s.sampleid)
101
+ }
102
+ }
103
+ }
104
+ for (const s of samples) delete s.sampleid
105
+
100
106
  S.get = () => {
101
- return { samples, fields: ['sample'], columnNames: ['Sample'] }
107
+ return { samples: samples as Sample[] }
102
108
  }
103
109
  }
104
110
 
@@ -111,19 +117,11 @@ function validateDataNative(D: SingleCellDataNative, ds: any) {
111
117
 
112
118
  // scoped and cached for runtime
113
119
  const _terms = [] as any
114
- const _tid2cellvalue = {} as any
115
120
 
116
121
  for (const tid of D.termIds) {
117
122
  const t = ds.cohort.termdb.q.termjsonByOneid(tid)
118
123
  if (!t) throw 'invalid term id from queries.singleCell.data.termIds[]'
119
124
  _terms.push(t)
120
- // _tid2cellvalue[tid] = {}
121
- // const clusterMap = ds.cohort.termdb.q.getAllValues4term(tid)
122
- // for(const [id, cluster] of clusterMap)
123
- // {
124
- // const name = ds.cohort.termdb.q.id2sampleName(id)
125
- // _tid2cellvalue[tid][name] = cluster
126
- // }
127
125
  }
128
126
  D.get = async q => {
129
127
  // if sample is int, may convert to string