@sjcrh/proteinpaint-server 2.40.0 → 2.40.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.40.0",
3
+ "version": "2.40.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",
package/routes/gdc.maf.ts CHANGED
@@ -8,8 +8,6 @@ this route lists available gdc MAF files based on user's cohort filter
8
8
  and return them to client to be shown in a table for selection
9
9
  */
10
10
 
11
- const apihost = process.env.PP_GDC_HOST || 'https://api.gdc.cancer.gov' // to switch to serverconfig export
12
-
13
11
  const maxFileNumber = 1000 // determines max number of files to return to client
14
12
  // preliminary testing:
15
13
  // 36s for 1000 (87Mb)
@@ -60,7 +58,7 @@ function init({ genomes }) {
60
58
  const ds = g.datasets.GDC
61
59
  if (!ds) throw 'hg38 GDC missing'
62
60
 
63
- const payload = await listMafFiles(req.query as GdcMafRequest)
61
+ const payload = await listMafFiles(req.query as GdcMafRequest, ds)
64
62
  res.send(payload)
65
63
  } catch (e: any) {
66
64
  res.send({ status: 'error', error: e.message || e })
@@ -80,7 +78,7 @@ ds {
80
78
  }
81
79
  }
82
80
  */
83
- async function listMafFiles(q: GdcMafRequest) {
81
+ async function listMafFiles(q: GdcMafRequest, ds) {
84
82
  const filters = {
85
83
  op: 'and',
86
84
  content: [
@@ -95,7 +93,7 @@ async function listMafFiles(q: GdcMafRequest) {
95
93
  case_filters.content.push(q.filter0)
96
94
  }
97
95
 
98
- const headers = { 'Content-Type': 'application/json', Accept: 'application/json' }
96
+ const { host, headers } = ds.getHostHeaders(q)
99
97
 
100
98
  const data = {
101
99
  filters,
@@ -111,7 +109,7 @@ async function listMafFiles(q: GdcMafRequest) {
111
109
  ].join(',')
112
110
  }
113
111
 
114
- const response = await got.post(path.join(apihost, 'files'), { headers, body: JSON.stringify(data) })
112
+ const response = await got.post(path.join(host.rest, 'files'), { headers, body: JSON.stringify(data) })
115
113
 
116
114
  let re
117
115
  try {
@@ -7,8 +7,6 @@ import Readable from 'stream'
7
7
  import { GdcMafBuildRequest } from '#shared/types/routes/gdc.mafBuild.ts'
8
8
  import { maxTotalSizeCompressed } from './gdc.maf.ts'
9
9
 
10
- const apihost = process.env.PP_GDC_HOST || 'https://api.gdc.cancer.gov'
11
-
12
10
  export const api = {
13
11
  endpoint: 'gdc/mafBuild',
14
12
  methods: {
@@ -27,7 +25,11 @@ export const api = {
27
25
  function init({ genomes }) {
28
26
  return async (req: any, res: any): Promise<void> => {
29
27
  try {
30
- await buildMaf(req.query as GdcMafBuildRequest, res)
28
+ const g = genomes.hg38
29
+ if (!g) throw 'hg38 missing'
30
+ const ds = g.datasets.GDC
31
+ if (!ds) throw 'hg38 GDC missing'
32
+ await buildMaf(req.query as GdcMafBuildRequest, res, ds)
31
33
  } catch (e: any) {
32
34
  if (e.stack) console.log(e.stack)
33
35
  res.send({ status: 'error', error: e.message || e })
@@ -39,10 +41,10 @@ function init({ genomes }) {
39
41
  q{}
40
42
  res{}
41
43
  */
42
- async function buildMaf(q: GdcMafBuildRequest, res: any) {
44
+ async function buildMaf(q: GdcMafBuildRequest, res: any, ds) {
43
45
  const t0 = Date.now()
44
-
45
- const fileLst2 = (await getFileLstUnderSizeLimit(q.fileIdLst)) as string[]
46
+ const { host, headers } = ds.getHostHeaders(q)
47
+ const fileLst2 = (await getFileLstUnderSizeLimit(q.fileIdLst, host, headers)) as string[]
46
48
 
47
49
  if (serverconfig.debugmode)
48
50
  console.log(
@@ -53,7 +55,7 @@ async function buildMaf(q: GdcMafBuildRequest, res: any) {
53
55
  const arg = {
54
56
  fileIdLst: fileLst2,
55
57
  columns: q.columns,
56
- host: path.join(apihost, 'data') // must use the /data/ endpoint from current host
58
+ host: path.join(host.rest, 'data') // must use the /data/ endpoint from current host
57
59
  }
58
60
 
59
61
  const rustStream = run_rust_stream('gdcmaf', JSON.stringify(arg))
@@ -80,7 +82,7 @@ excess files are not processed in order not to crash server
80
82
  must not rely on file size sent by client, as that can be spoofed and never to be trusted
81
83
  it's inexpensive to query api for this
82
84
  */
83
- async function getFileLstUnderSizeLimit(lst: string[]) {
85
+ async function getFileLstUnderSizeLimit(lst: string[], host, headers) {
84
86
  if (lst.length == 0) throw 'fileIdLst[] not array or blank'
85
87
  const data = {
86
88
  filters: {
@@ -90,8 +92,7 @@ async function getFileLstUnderSizeLimit(lst: string[]) {
90
92
  size: 10000,
91
93
  fields: 'file_size'
92
94
  }
93
- const headers = { 'Content-Type': 'application/json', Accept: 'application/json' }
94
- const response = await got.post(path.join(apihost, 'files'), { headers, body: JSON.stringify(data) })
95
+ const response = await got.post(path.join(host.rest, 'files'), { headers, body: JSON.stringify(data) })
95
96
  let re
96
97
  try {
97
98
  re = JSON.parse(response.body)
@@ -2,13 +2,9 @@ import { GdcTopMutatedGeneRequest, GdcTopMutatedGeneResponse, Gene } from '#shar
2
2
  import { mclasscnvgain, mclasscnvloss, dtsnvindel } from '#shared/common.js'
3
3
  import got from 'got'
4
4
  import serverconfig from '#src/serverconfig.js'
5
- import { getheaders } from '#src/mds3.gdc.js'
6
5
 
7
6
  // TODO change to /termdb/topMutatedGenes
8
7
 
9
- const apihost = process.env.PP_GDC_HOST || 'https://api.gdc.cancer.gov'
10
- const apihostGraphql = apihost + (apihost.includes('/v0') ? '' : '/v0') + '/graphql'
11
-
12
8
  export const api = {
13
9
  endpoint: 'gdc/topMutatedGenes',
14
10
  methods: {
@@ -24,7 +20,7 @@ export const api = {
24
20
  }
25
21
  }
26
22
 
27
- function init() {
23
+ function init({ genomes }) {
28
24
  /*
29
25
  genomes parameter is currently not used
30
26
  could be used later to:
@@ -33,8 +29,12 @@ function init() {
33
29
  */
34
30
  return async (req: any, res: any): Promise<void> => {
35
31
  const q: GdcTopMutatedGeneRequest = req.query
32
+ const g = genomes.hg38
33
+ if (!g) throw 'hg38 missing'
34
+ const ds = g.datasets.GDC
35
+ if (!ds) throw 'hg38 GDC missing'
36
36
  try {
37
- const genes = await getGenesGraphql(q)
37
+ const genes = await getGenesGraphql(q, ds)
38
38
  const payload: GdcTopMutatedGeneResponse = { genes }
39
39
  res.send(payload)
40
40
  } catch (e: any) {
@@ -437,9 +437,11 @@ const queryV2: any = {
437
437
  }
438
438
  }
439
439
 
440
- async function getGenesGraphql(q: GdcTopMutatedGeneRequest) {
440
+ async function getGenesGraphql(q: GdcTopMutatedGeneRequest, ds) {
441
441
  let query: string, variables: object
442
+ const { host, headers } = ds.getHostHeaders(q)
442
443
 
444
+ // TODO: change this condition to use host.geneExp != host.rest ???
443
445
  if (serverconfig.features?.geneExpHost) {
444
446
  // quick fix! this is only set on local dev machines, meaning it's using v1 api; delete this after soft launch!!
445
447
  query = queryV1.query
@@ -450,8 +452,8 @@ async function getGenesGraphql(q: GdcTopMutatedGeneRequest) {
450
452
  variables = queryV2.getVariables(q)
451
453
  }
452
454
 
453
- const response = await got.post(apihostGraphql, {
454
- headers: getheaders(q),
455
+ const response = await got.post(host.graphql, {
456
+ headers,
455
457
  body: JSON.stringify({ query, variables })
456
458
  })
457
459
 
@@ -510,7 +512,7 @@ this api only gets ssm-cases and does not account for cnv cases, will not return
510
512
  thus is replaced by getGenesGraphql
511
513
  async function getGenes(q: GdcTopMutatedGeneRequest) {
512
514
  const _f = q.filter0 || { op: 'and', content: [] } // allow blank filter to test geneset edit ui (without filter)
513
- const response = await got.post(path.join(apihost, '/analysis/top_mutated_genes_by_project'), {
515
+ const response = await got.post(path.join(host.rest, '/analysis/top_mutated_genes_by_project'), {
514
516
  headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
515
517
  body: JSON.stringify({
516
518
  size: q.maxGenes || 50,
@@ -2,7 +2,7 @@ import {
2
2
  TermdbTopVariablyExpressedGenesRequest,
3
3
  TermdbTopVariablyExpressedGenesResponse
4
4
  } from '#shared/types/routes/termdb.topVariablyExpressedGenes.ts'
5
- import { gdcGetCasesWithExressionDataFromCohort, apihost, geneExpHost } from '../src/mds3.gdc.js'
5
+ import { gdcGetCasesWithExressionDataFromCohort } from '../src/mds3.gdc.js'
6
6
  import path from 'path'
7
7
  import { run_rust } from '@sjcrh/proteinpaint-rust'
8
8
  import got from 'got'
@@ -142,11 +142,11 @@ function gdcValidateQuery(ds: any, genome: any) {
142
142
  }
143
143
 
144
144
  // change to this when api is available on prod
145
- const url = path.join(geneExpHost, '/gene_expression/gene_selection')
146
-
145
+ const { host, headers } = ds.getHostHeaders(q)
146
+ const url = path.join(host.geneExp, '/gene_expression/gene_selection')
147
147
  try {
148
148
  const response = await got.post(url, {
149
- headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
149
+ headers,
150
150
  body: JSON.stringify(getGeneSelectionArg(q, caseLst))
151
151
  })
152
152