Skip to content

Commit 4fc74bb

Browse files
committed
feat(graphql-api): v4 variants include LoF curation results
1 parent aa04b3f commit 4fc74bb

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
type GnomadVersion = 'ExAC' | 'v2'
1+
type GnomadVersion = 'ExAC' | 'v2' | 'v4'
22

33
const GNOMAD_LOF_CURATION_RESULTS_INDICES = {
44
ExAC: 'gnomad_v2_lof_curation_results',
55
v2: 'gnomad_v2_lof_curation_results',
6+
v4: 'gnomad_v4_lof_curation_results',
67
}
78

89
// ================================================================================================

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { UserVisibleError } from '../../errors'
77
import { fetchLocalAncestryPopulationsByVariant } from '../local-ancestry-queries'
88
import { fetchAllSearchResults } from '../helpers/elasticsearch-helpers'
99
import { mergeOverlappingRegions } from '../helpers/region-helpers'
10+
import {
11+
fetchLofCurationResultsByVariant,
12+
fetchLofCurationResultsByGene,
13+
fetchLofCurationResultsByRegion,
14+
} from '../lof-curation-result-queries'
1015

1116
import { getFlagsForContext } from './shared/flags'
1217
import { getConsequenceForContext } from './shared/transcriptConsequence'
@@ -113,6 +118,12 @@ const fetchVariantById = async (esClient: any, variantId: any, subset: Subset) =
113118

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

121+
const lofCurationResults = await fetchLofCurationResultsByVariant(
122+
esClient,
123+
'v4',
124+
variant.variant_id
125+
)
126+
116127
let genome_ancestry_groups = subsetGenomeFreq.ancestry_groups || []
117128
// Include HGDP and 1KG populations with gnomAD subsets
118129
if (variant.genome.freq.hgdp.ac_raw > 0) {
@@ -232,6 +243,7 @@ const fetchVariantById = async (esClient: any, variantId: any, subset: Subset) =
232243
: null,
233244
flags: variantFlags,
234245
// TODO: Include RefSeq transcripts once the browser supports them.
246+
lof_curations: lofCurationResults,
235247
transcript_consequences: (variant.transcript_consequences || []).filter((csq: any) =>
236248
csq.gene_id.startsWith('ENSG')
237249
),
@@ -466,6 +478,20 @@ const fetchVariantsByGene = async (esClient: any, gene: any, subset: Subset) =>
466478
)
467479
.map(shapeVariantSummary(subset, { type: 'gene', geneId: gene.gene_id }))
468480

481+
const lofCurationResults = await fetchLofCurationResultsByGene(esClient, 'v4', gene)
482+
const lofCurationResultsByVariant = {}
483+
lofCurationResults.forEach((result: any) => {
484+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
485+
lofCurationResultsByVariant[result.variant_id] = result.lof_curations.find(
486+
(c: any) => c.gene_id === gene.gene_id
487+
)
488+
})
489+
490+
shapedHits.forEach((variant: any) => {
491+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
492+
variant.lof_curation = lofCurationResultsByVariant[variant.variant_id] // eslint-disable-line no-param-reassign
493+
})
494+
469495
return shapedHits
470496
} catch (error) {
471497
throw new Error(`'Error fetching variants by gene:', ${error}`)
@@ -506,14 +532,41 @@ const fetchVariantsByRegion = async (esClient: any, region: any, subset: Subset)
506532
},
507533
})
508534

509-
return hits
535+
const variants = hits
510536
.map((hit: any) => hit._source.value)
511537
.filter(
512538
(variant: any) =>
513539
(variant.genome.freq.all && variant.genome.freq.all.ac_raw > 0) ||
514540
variant.exome.freq[subset].ac_raw > 0
515541
)
516542
.map(shapeVariantSummary(subset, { type: 'region' }))
543+
544+
const lofCurationResults = await fetchLofCurationResultsByRegion(esClient, 'v2', region)
545+
546+
const lofCurationResultsByVariant = {}
547+
lofCurationResults.forEach((result: any) => {
548+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
549+
lofCurationResultsByVariant[result.variant_id] = result.lof_curations.reduce(
550+
// @ts-expect-error TS(7006) FIXME: Parameter 'acc' implicitly has an 'any' type.
551+
(acc, c) => ({
552+
...acc,
553+
[c.gene_id]: c,
554+
}),
555+
{}
556+
)
557+
})
558+
559+
variants.forEach((variant: any) => {
560+
if (variant.transcript_consequence) {
561+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
562+
// eslint-disable-next-line no-param-reassign
563+
variant.lof_curation = (lofCurationResultsByVariant[variant.variant_id] || {})[
564+
variant.transcript_consequence.gene_id
565+
]
566+
}
567+
})
568+
569+
return variants
517570
}
518571

519572
// ================================================================================================

0 commit comments

Comments
 (0)