@sjcrh/proteinpaint-server 2.43.0 → 2.43.2

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.2",
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
  }
@@ -79,29 +73,43 @@ export async function validate_query_singleCell(ds: any, genome: any) {
79
73
  if (q.data.src == 'gdcapi') {
80
74
  gdc_validate_query_singleCell_data(ds, genome)
81
75
  } else if (q.data.src == 'native') {
82
- validateDataNative(q.data as SingleCellDataNative, ds)
76
+ getDataNative(q.data as SingleCellDataNative, ds)
83
77
  } else {
84
78
  throw 'unknown singleCell.data.src'
85
79
  }
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 isSamples = ds.cohort.termdb.q.getAllValues4term(S.isSampleTerm)
87
+ if (isSamples.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 isSamples.keys()) {
90
+ if (isSamples.get(sampleid) == '1')
91
+ samples.push({
92
+ sample: ds.cohort.termdb.q.id2sampleName(sampleid), // string name for display
93
+ sampleid // temporarily kept to assign term value to each sample
94
+ })
96
95
  }
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
96
+ if (S.sampleColumns) {
97
+ // has optional terms to show as table columns and annotate samples
98
+ for (const term of S.sampleColumns) {
99
+ const s2v = ds.cohort.termdb.q.getAllValues4term(term.termid) // map. k: sampleid, v: term value
100
+ for (const s of samples) {
101
+ if (s2v.has(s.sampleid)) s[term.termid] = s2v.get(s.sampleid)
102
+ }
103
+ }
104
+ }
105
+ for (const s of samples) delete s.sampleid
106
+
99
107
  S.get = () => {
100
- return { samples, fields: ['sample'], columnNames: ['Sample'] }
108
+ return { samples: samples as Sample[] }
101
109
  }
102
110
  }
103
111
 
104
- function validateDataNative(D: SingleCellDataNative, ds: any) {
112
+ function getDataNative(D: SingleCellDataNative, ds: any) {
105
113
  const nameSet = new Set() // guard against duplicating plot names
106
114
  for (const plot of D.plots) {
107
115
  if (nameSet.has(plot.name)) throw 'duplicate plot.name'
@@ -110,19 +118,11 @@ function validateDataNative(D: SingleCellDataNative, ds: any) {
110
118
 
111
119
  // scoped and cached for runtime
112
120
  const _terms = [] as any
113
- const _tid2cellvalue = {} as any
114
121
 
115
122
  for (const tid of D.termIds) {
116
123
  const t = ds.cohort.termdb.q.termjsonByOneid(tid)
117
124
  if (!t) throw 'invalid term id from queries.singleCell.data.termIds[]'
118
125
  _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
126
  }
127
127
  D.get = async q => {
128
128
  // if sample is int, may convert to string