From 761d416e9180d35aeb5655ca257a6f2d562ff64a Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Tue, 6 Feb 2024 09:55:01 +0100 Subject: [PATCH] feat: fix parsing of non-uppercase SvType (bihealth/reev#434) (#95) --- src/lib/genomicVars.spec.ts | 4 ++-- src/lib/genomicVars.ts | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib/genomicVars.spec.ts b/src/lib/genomicVars.spec.ts index b2460f4..0c8a5e3 100644 --- a/src/lib/genomicVars.spec.ts +++ b/src/lib/genomicVars.spec.ts @@ -458,8 +458,8 @@ describe.concurrent('parseSeparatedStrucvar()', () => { }) }) - it('parse DEL:GRCh37:1:100:200', () => { - expect(parseSeparatedStrucvar('DEL:1:100:200')).toEqual({ + it('parse Del:GRCh37:1:100:200', () => { + expect(parseSeparatedStrucvar('Del:1:100:200')).toEqual({ chrom: '1', copyNumber: undefined, genomeBuild: 'grch37', diff --git a/src/lib/genomicVars.ts b/src/lib/genomicVars.ts index 7bdc6a6..7e1d9cd 100644 --- a/src/lib/genomicVars.ts +++ b/src/lib/genomicVars.ts @@ -67,7 +67,7 @@ export type SvType = 'DEL' | 'DUP' /** Interface for regex groups when parsing with `REGEX_CNV_COLON` or `REGEX_CNV_HYPHEN`. */ export interface RegexCnvGroups { - svType: SvType + svType: string genomeBuild?: string chrom?: string sequence?: string @@ -420,7 +420,7 @@ export function parseSeparatedStrucvar( // Obtain the genome build and chromosome from the parsed groups. Also, // perform validation. const { - svType, + svType: svType$Regex, genomeBuild: genomeBuildValue, sequence, chrom: chromValue, @@ -460,6 +460,16 @@ export function parseSeparatedStrucvar( } } + // Normalize the SV type. + let svType: SvType + if (svType$Regex.toUpperCase() === 'DEL') { + svType = 'DEL' + } else if (svType$Regex.toUpperCase() === 'DUP') { + svType = 'DUP' + } else { + throw new ParseError(`Unknown SV type: ${svType$Regex}`) + } + return { svType, genomeBuild,