From 63de0ebe3c56afd2dd056f2762ec3b4976dbdde8 Mon Sep 17 00:00:00 2001 From: Dennis Hendriksen Date: Wed, 21 Apr 2021 07:32:34 +0200 Subject: [PATCH 1/2] Retrieve embedded reference sequence data --- package-lock.json | 4 ++-- package.json | 2 +- src/ApiClient.ts | 18 +++++++++++++++++- src/__tests__/ApiClient.test.ts | 27 ++++++++++++++++++++++++++- src/__tests__/interval0.fasta | 2 ++ src/__tests__/interval1.fasta | 2 ++ 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/__tests__/interval0.fasta create mode 100644 src/__tests__/interval1.fasta diff --git a/package-lock.json b/package-lock.json index 7902331..cfaa6e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@molgenis/vip-report-api", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@molgenis/vip-report-api", - "version": "2.0.0", + "version": "2.1.0", "license": "LGPL-3.0", "dependencies": { "ascii85": "^1.0.2", diff --git a/package.json b/package.json index c4872b0..6faf700 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@molgenis/vip-report-api", - "version": "2.0.0", + "version": "2.1.0", "description": "Report API for Variant Call Format (VCF) Report Templates", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/ApiClient.ts b/src/ApiClient.ts index 8f6bc38..e8da8bf 100644 --- a/src/ApiClient.ts +++ b/src/ApiClient.ts @@ -33,10 +33,11 @@ interface Data { interface BinaryData extends BinaryDataNode { vcfGz: Buffer; + fastaGz: BinaryDataNode; } interface BinaryDataNode { - [key: string]: Uint8Array | BinaryDataNode; + [key: string]: Buffer | BinaryDataNode; } export class ApiClient implements Api { @@ -66,6 +67,21 @@ export class ApiClient implements Api { return Promise.resolve(this.reportData.binary.vcfGz); } + getFastaGz(contig: string, pos: number): Promise { + let buffer: Buffer | null = null; + for (const [key, value] of Object.entries(this.reportData.binary.fastaGz)) { + const pair = key.split(':'); + if (pair[0] === contig) { + const interval = pair[1].split('-'); + if (pos >= parseInt(interval[0], 10) && pos <= parseInt(interval[1], 10)) { + buffer = value as Buffer; + break; + } + } + } + return Promise.resolve(buffer); + } + private get(resource: string, params: Params = {}): Promise> { return new Promise((resolve, reject) => { if (!this.reportData.data[resource]) { diff --git a/src/__tests__/ApiClient.test.ts b/src/__tests__/ApiClient.test.ts index ce0d23d..6b31965 100644 --- a/src/__tests__/ApiClient.test.ts +++ b/src/__tests__/ApiClient.test.ts @@ -50,7 +50,15 @@ beforeEach(() => { } }, base85: { - vcfGz: new Base85().encode(Buffer.from(gzipSync(fs.readFileSync(__dirname + '/trio.vcf')))) + vcfGz: new Base85().encode(Buffer.from(gzipSync(fs.readFileSync(__dirname + '/trio.vcf')))), + fastaGz: { + '1:17350500-17350600': new Base85().encode( + Buffer.from(gzipSync(fs.readFileSync(__dirname + '/interval0.fasta'))) + ), + '2:47637200-47637300': new Base85().encode( + Buffer.from(gzipSync(fs.readFileSync(__dirname + '/interval1.fasta'))) + ) + } } }; api = new ApiClient(reportData); @@ -636,3 +644,20 @@ test('getVcfGz', async () => { // null check, because size check differs between local machine and Travis expect(vcfGz).not.toBe(null); }); + +test('getFastaGz', async () => { + const fastaGz = await api.getFastaGz('1', 17350550); + // null check, because size check differs between local machine and Travis + expect(fastaGz).not.toBe(null); +}); + +test('getFastaGz - unknown interval', async () => { + const fastaGz = await api.getFastaGz('1', 17350450); + // null check, because size check differs between local machine and Travis + expect(fastaGz).toBe(null); +}); + +test('getFastaGz - existing interval in other contig', async () => { + const fastaGz = await api.getFastaGz('1', 47637250); + expect(fastaGz).toBe(null); +}); diff --git a/src/__tests__/interval0.fasta b/src/__tests__/interval0.fasta new file mode 100644 index 0000000..2ebf724 --- /dev/null +++ b/src/__tests__/interval0.fasta @@ -0,0 +1,2 @@ +>1:17350500-17350600 +CTCCGTTCCACCAGTAGCTGGGGCAGCTGGTGCTACAGCAGGCACAGAGAATGCACTCGTAGAGCCCGTCCTGTATGGGGAGAAAAGAGAGGCAGGAGCTT \ No newline at end of file diff --git a/src/__tests__/interval1.fasta b/src/__tests__/interval1.fasta new file mode 100644 index 0000000..646cc65 --- /dev/null +++ b/src/__tests__/interval1.fasta @@ -0,0 +1,2 @@ +>2:47637200-47637300 +TTGTTAAATTTTTAAAATTTTATTTTTACTTAGGCTTCTCCTGGCAATCTCTCTCAGTTTGAAGACATTCTCTTTGGTAACAATGATATGTCAGCTTCCAT \ No newline at end of file From 2ff6512d4d30c704912aeb56a8eba9906d28c406 Mon Sep 17 00:00:00 2001 From: Dennis Hendriksen Date: Wed, 21 Apr 2021 07:54:11 +0200 Subject: [PATCH 2/2] Update EncodedData interface: add fastaGz --- src/ApiData.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ApiData.ts b/src/ApiData.ts index ada761f..cb6afa8 100644 --- a/src/ApiData.ts +++ b/src/ApiData.ts @@ -33,6 +33,7 @@ export interface Items { export interface EncodedData extends EncodedDataContainer { vcfGz: string; + fastaGz: EncodedDataContainer; } export interface Resource {