@sjcrh/proteinpaint-server 2.43.0 → 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.43.0",
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,
@@ -70,7 +64,7 @@ export async function validate_query_singleCell(ds: any, genome: any) {
70
64
  if (q.samples.src == 'gdcapi') {
71
65
  gdc_validate_query_singleCell_samples(ds, genome)
72
66
  } else if (q.samples.src == 'native') {
73
- validateSamplesNative(q.samples as SingleCellSamplesNative, ds)
67
+ getSamplesNative(q.samples as SingleCellSamplesNative, ds)
74
68
  } else {
75
69
  throw 'unknown singleCell.samples.src'
76
70
  }
@@ -86,18 +80,31 @@ export async function validate_query_singleCell(ds: any, genome: any) {
86
80
  // q.data.get() added
87
81
  }
88
82
 
89
- function validateSamplesNative(S: SingleCellSamplesNative, ds: any) {
83
+ async function getSamplesNative(S: SingleCellSamplesNative, ds: any) {
90
84
  // for now use this quick fix method to pull sample ids annotated by this term
91
85
  // to support situation where not all samples from a dataset has sc data
92
- const samples = [] as Sample[] // list of sample ids with sc data
93
- const s = ds.cohort.termdb.q.getAllValues4term(S.isSampleTerm)
94
- for (const id of s.keys()) {
95
- 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
+ })
96
94
  }
97
- if (samples.length == 0) throw 'no sample with sc data'
98
- // 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
+
99
106
  S.get = () => {
100
- return { samples, fields: ['sample'], columnNames: ['Sample'] }
107
+ return { samples: samples as Sample[] }
101
108
  }
102
109
  }
103
110
 
@@ -110,19 +117,11 @@ function validateDataNative(D: SingleCellDataNative, ds: any) {
110
117
 
111
118
  // scoped and cached for runtime
112
119
  const _terms = [] as any
113
- const _tid2cellvalue = {} as any
114
120
 
115
121
  for (const tid of D.termIds) {
116
122
  const t = ds.cohort.termdb.q.termjsonByOneid(tid)
117
123
  if (!t) throw 'invalid term id from queries.singleCell.data.termIds[]'
118
124
  _terms.push(t)
119
- // _tid2cellvalue[tid] = {}
120
- // const clusterMap = ds.cohort.termdb.q.getAllValues4term(tid)
121
- // for(const [id, cluster] of clusterMap)
122
- // {
123
- // const name = ds.cohort.termdb.q.id2sampleName(id)
124
- // _tid2cellvalue[tid][name] = cluster
125
- // }
126
125
  }
127
126
  D.get = async q => {
128
127
  // if sample is int, may convert to string