Skip to content

Commit 2588ef7

Browse files
Use RNU4ATAC transcript patches in API
1 parent bce7252 commit 2588ef7

File tree

3 files changed

+54
-33
lines changed

3 files changed

+54
-33
lines changed

graphql-api/src/queries/gene-queries.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import elasticsearch from '@elastic/elasticsearch'
22
import { withCache } from '../cache'
33

4-
import { fetchAllSearchResultsFromMultipleIndices } from './helpers/elasticsearch-helpers'
4+
import {
5+
fetchAllSearchResultsFromMultipleIndices,
6+
getFromMultipleIndices,
7+
} from './helpers/elasticsearch-helpers'
58

69
import { ReferenceGenome } from '@gnomad/dataset-metadata/metadata'
710
import { LimitedElasticClient, GetResponse, SearchResponse, SearchHit } from '../elasticsearch'
@@ -38,17 +41,7 @@ const _fetchGeneById = async (
3841
throw err
3942
}) as Promise<GetResponse | null>
4043
)
41-
return Promise.all(requests).then(
42-
(responses) => {
43-
const responsesWithValue = responses.filter((response) => response !== null)
44-
return responsesWithValue.length > 0
45-
? responsesWithValue[responsesWithValue.length - 1]!.body._source.value
46-
: null
47-
},
48-
(err) => {
49-
throw err
50-
}
51-
)
44+
return getFromMultipleIndices(requests)
5245
}
5346

5447
export const fetchGeneById = withCache(

graphql-api/src/queries/helpers/elasticsearch-helpers.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import elasticsearch from '@elastic/elasticsearch'
2-
import { LimitedElasticClient, SearchResponse, SearchHit } from '../../elasticsearch'
2+
import { LimitedElasticClient, SearchResponse, SearchHit, GetResponse } from '../../elasticsearch'
33

44
/**
55
* Search and then scroll to retrieve all pages of search results.
@@ -69,3 +69,16 @@ export const fetchIndexMetadata = async (esClient: any, index: any) => {
6969
// eslint-disable-next-line no-underscore-dangle
7070
return Object.values(response.body)[0].mappings._meta
7171
}
72+
73+
export const getFromMultipleIndices = (requests: Promise<GetResponse | null>[]) =>
74+
Promise.all(requests).then(
75+
(responses) => {
76+
const responsesWithValue = responses.filter((response) => response !== null)
77+
return responsesWithValue.length > 0
78+
? responsesWithValue[responsesWithValue.length - 1]!.body._source.value
79+
: null
80+
},
81+
(err) => {
82+
throw err
83+
}
84+
)
Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
const TRANSCRIPT_INDICES = {
2-
GRCh37: 'transcripts_grch37',
3-
GRCh38: 'transcripts_grch38',
1+
import { ReferenceGenome } from '@gnomad/dataset-metadata/metadata'
2+
import { GetResponse, LimitedElasticClient } from '../elasticsearch'
3+
import { getFromMultipleIndices } from './helpers/elasticsearch-helpers'
4+
5+
type TranscriptIndex =
6+
| 'transcripts_grch37'
7+
| 'transcripts_grch38'
8+
| 'transcripts_grch38_patched-2025-10-17--18-18'
9+
10+
const TRANSCRIPT_INDICES: Record<ReferenceGenome, TranscriptIndex[]> = {
11+
GRCh37: ['transcripts_grch37'],
12+
GRCh38: ['transcripts_grch38', 'transcripts_grch38_patched-2025-10-17--18-18'],
413
}
514

6-
export const fetchTranscriptById = async (es: any, transcriptId: any, referenceGenome: any) => {
7-
try {
8-
const response = await es.get({
9-
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
10-
index: TRANSCRIPT_INDICES[referenceGenome],
11-
type: '_doc',
12-
id: transcriptId,
13-
})
15+
export const fetchTranscriptById = async (
16+
esClient: LimitedElasticClient,
17+
transcriptId: string,
18+
referenceGenome: ReferenceGenome
19+
) => {
20+
const indices = TRANSCRIPT_INDICES[referenceGenome]
21+
const requests = indices.map(
22+
(index) =>
23+
esClient
24+
.get({
25+
index,
26+
type: '_doc',
27+
id: transcriptId,
28+
})
29+
.catch((err) => {
30+
// meta will not be present if the request times out in the queue before reaching ES
31+
if (err.meta && err.meta.body.found === false) {
32+
return null
33+
}
34+
throw err
35+
}) as Promise<GetResponse | null>
36+
)
1437

15-
return response.body._source.value
16-
} catch (err) {
17-
// meta will not be present if the request times out in the queue before reaching ES
18-
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
19-
if (err.meta && err.meta.body.found === false) {
20-
return null
21-
}
22-
throw err
23-
}
38+
return getFromMultipleIndices(requests)
2439
}

0 commit comments

Comments
 (0)