Skip to content

Commit

Permalink
feat: Retrieval of affected genes in SV from mehari (#56) (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon authored Oct 4, 2023
1 parent 2ce7de2 commit d16af74
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 228 deletions.
35 changes: 32 additions & 3 deletions frontend/src/api/__tests__/mehari.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import createFetchMock from 'vitest-fetch-mock'

import { MehariClient } from '@/api/mehari'
import * as BRCA1TxInfo from '@/assets/__tests__/BRCA1TxInfo.json'
import * as SVInfo from '@/assets/__tests__/ExampleSVTxInfo.json'

const fetchMocker = createFetchMock(vi)

Expand All @@ -16,15 +17,22 @@ describe.concurrent('Mehari Client', () => {
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1TxInfo))

const client = new MehariClient()
const result = await client.retrieveTxCsq('grch37', 'chr17', 43044295, 'A', 'G', 'HGNC:1100')
const result = await client.retrieveSeqvarsCsq(
'grch37',
'chr17',
43044295,
'A',
'G',
'HGNC:1100'
)
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1TxInfo))
})

it('fetches TxCsq info correctly without HGNC id', async () => {
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1TxInfo))

const client = new MehariClient()
const result = await client.retrieveTxCsq('grch37', 'chr17', 43044295, 'A', 'G')
const result = await client.retrieveSeqvarsCsq('grch37', 'chr17', 43044295, 'A', 'G')
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1TxInfo))
})

Expand All @@ -37,7 +45,28 @@ describe.concurrent('Mehari Client', () => {
})

const client = new MehariClient()
const result = await client.retrieveTxCsq('grch37', 'chr17', 43044295, 'A', 'T')
const result = await client.retrieveSeqvarsCsq('grch37', 'chr17', 43044295, 'A', 'T')
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})

it('fetches Structur Variant info correctly', async () => {
fetchMocker.mockResponseOnce(JSON.stringify(SVInfo))

const client = new MehariClient()
const result = await client.retrieveStrucvarsCsq('grch37', 'chr17', 43044295, 43044297, 'DEL')
expect(JSON.stringify(result)).toEqual(JSON.stringify(SVInfo))
})

it('fails to fetch variant info with wrong variant', async () => {
fetchMocker.mockResponse((req) => {
if (req.url.includes('alternative=G')) {
return Promise.resolve(JSON.stringify(SVInfo))
}
return Promise.resolve(JSON.stringify({ status: 400 }))
})

const client = new MehariClient()
const result = await client.retrieveStrucvarsCsq('grch37', 'chr17', 43044295, 43044297, 'INS')
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
})
18 changes: 17 additions & 1 deletion frontend/src/api/mehari.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MehariClient {
this.csrfToken = csrfToken ?? null
}

async retrieveTxCsq(
async retrieveSeqvarsCsq(
genomeRelease: string,
chromosome: string,
pos: number,
Expand All @@ -30,4 +30,20 @@ export class MehariClient {
})
return await response.json()
}

async retrieveStrucvarsCsq(
genomeRelease: string,
chromosome: string,
start: number,
stop: number,
sv_type: string
): Promise<any> {
const url =
`${this.apiBaseUrl}strucvars/csq?genome_release=${genomeRelease}&` +
`chromosome=${chromosome}&start=${start}&stop=${stop}&sv_type=${sv_type}`
const response = await fetch(url, {
method: 'GET'
})
return await response.json()
}
}
3 changes: 3 additions & 0 deletions frontend/src/assets/__tests__/ExampleSV.json
Git LFS file not shown
3 changes: 3 additions & 0 deletions frontend/src/assets/__tests__/ExampleSVTxInfo.json
Git LFS file not shown
Loading

0 comments on commit d16af74

Please sign in to comment.