Skip to content

Commit aa04b3f

Browse files
committed
refactor(graphql-api): parametrize lof curation dataset in query
1 parent 79a2e02 commit aa04b3f

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

graphql-api/src/queries/lof-curation-result-queries.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
const GNOMAD_V2_LOF_CURATION_RESULTS_INDEX = 'gnomad_v2_lof_curation_results'
1+
type GnomadVersion = 'ExAC' | 'v2'
2+
3+
const GNOMAD_LOF_CURATION_RESULTS_INDICES = {
4+
ExAC: 'gnomad_v2_lof_curation_results',
5+
v2: 'gnomad_v2_lof_curation_results',
6+
}
27

38
// ================================================================================================
49
// Variant query
510
// ================================================================================================
611

7-
export const fetchLofCurationResultsByVariant = async (esClient: any, variantId: any) => {
12+
export const fetchLofCurationResultsByVariant = async (
13+
esClient: any,
14+
gnomadVersion: GnomadVersion,
15+
variantId: any
16+
) => {
817
const response = await esClient.search({
9-
index: GNOMAD_V2_LOF_CURATION_RESULTS_INDEX,
18+
index: GNOMAD_LOF_CURATION_RESULTS_INDICES[gnomadVersion],
1019
type: '_doc',
1120
body: {
1221
query: {
@@ -29,9 +38,13 @@ export const fetchLofCurationResultsByVariant = async (esClient: any, variantId:
2938
// Gene query
3039
// ================================================================================================
3140

32-
export const fetchLofCurationResultsByGene = async (esClient: any, gene: any) => {
41+
export const fetchLofCurationResultsByGene = async (
42+
esClient: any,
43+
gnomadVersion: GnomadVersion,
44+
gene: any
45+
) => {
3346
const response = await esClient.search({
34-
index: GNOMAD_V2_LOF_CURATION_RESULTS_INDEX,
47+
index: GNOMAD_LOF_CURATION_RESULTS_INDICES[gnomadVersion],
3548
type: '_doc',
3649
size: 1000,
3750
body: {
@@ -54,9 +67,13 @@ export const fetchLofCurationResultsByGene = async (esClient: any, gene: any) =>
5467
// Region query
5568
// ================================================================================================
5669

57-
export const fetchLofCurationResultsByRegion = async (esClient: any, region: any) => {
70+
export const fetchLofCurationResultsByRegion = async (
71+
esClient: any,
72+
gnomadVersion: GnomadVersion,
73+
region: any
74+
) => {
5875
const response = await esClient.search({
59-
index: GNOMAD_V2_LOF_CURATION_RESULTS_INDEX,
76+
index: GNOMAD_LOF_CURATION_RESULTS_INDICES[gnomadVersion],
6077
type: '_doc',
6178
size: 1000,
6279
body: {

graphql-api/src/queries/variant-datasets/exac-variant-queries.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export const fetchVariantById = async (esClient: any, variantIdOrRsid: any) => {
7878

7979
const { variantFlags, exomeFlags } = getFlagsForContext({ type: 'region' }, variant)
8080

81-
const lofCurationResults = await fetchLofCurationResultsByVariant(esClient, variant.variant_id)
81+
const lofCurationResults = await fetchLofCurationResultsByVariant(
82+
esClient,
83+
'ExAC',
84+
variant.variant_id
85+
)
8286

8387
return {
8488
...variant,
@@ -184,7 +188,7 @@ export const fetchVariantsByGene = async (esClient: any, gene: any) => {
184188
.map((hit: any) => hit._source.value)
185189
.map(shapeVariantSummary({ type: 'gene', geneId: gene.gene_id }))
186190

187-
const lofCurationResults = await fetchLofCurationResultsByGene(esClient, gene)
191+
const lofCurationResults = await fetchLofCurationResultsByGene(esClient, 'ExAC', gene)
188192
const lofCurationResultsByVariant = {}
189193
lofCurationResults.forEach((result: any) => {
190194
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
@@ -246,7 +250,7 @@ export const fetchVariantsByRegion = async (esClient: any, region: any) => {
246250
.map((hit: any) => hit._source.value)
247251
.map(shapeVariantSummary({ type: 'region' }))
248252

249-
const lofCurationResults = await fetchLofCurationResultsByRegion(esClient, region)
253+
const lofCurationResults = await fetchLofCurationResultsByRegion(esClient, 'ExAC', region)
250254

251255
const lofCurationResultsByVariant = {}
252256
lofCurationResults.forEach((result: any) => {

graphql-api/src/queries/variant-datasets/gnomad-v2-variant-queries.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ const fetchVariantById = async (esClient: any, variantIdOrRsid: any, subset: any
119119

120120
const { variantFlags, exomeFlags, genomeFlags } = getFlagsForContext({ type: 'region' }, variant)
121121

122-
const lofCurationResults = await fetchLofCurationResultsByVariant(esClient, variant.variant_id)
122+
const lofCurationResults = await fetchLofCurationResultsByVariant(
123+
esClient,
124+
'v2',
125+
variant.variant_id
126+
)
123127

124128
return {
125129
...variant,
@@ -272,7 +276,7 @@ const fetchVariantsByGene = async (esClient: any, gene: any, subset: any) => {
272276
)
273277
.map(shapeVariantSummary(exomeSubset, genomeSubset, { type: 'gene', geneId: gene.gene_id }))
274278

275-
const lofCurationResults = await fetchLofCurationResultsByGene(esClient, gene)
279+
const lofCurationResults = await fetchLofCurationResultsByGene(esClient, 'v2', gene)
276280
const lofCurationResultsByVariant = {}
277281
lofCurationResults.forEach((result: any) => {
278282
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
@@ -344,7 +348,7 @@ const fetchVariantsByRegion = async (esClient: any, region: any, subset: any) =>
344348
)
345349
.map(shapeVariantSummary(exomeSubset, genomeSubset, { type: 'region' }))
346350

347-
const lofCurationResults = await fetchLofCurationResultsByRegion(esClient, region)
351+
const lofCurationResults = await fetchLofCurationResultsByRegion(esClient, 'v2', region)
348352

349353
const lofCurationResultsByVariant = {}
350354
lofCurationResults.forEach((result: any) => {

0 commit comments

Comments
 (0)