diff --git a/src/shared/lib/MutationUtils.spec.ts b/src/shared/lib/MutationUtils.spec.ts index c5f481794ce..4a4d199d737 100644 --- a/src/shared/lib/MutationUtils.spec.ts +++ b/src/shared/lib/MutationUtils.spec.ts @@ -440,88 +440,171 @@ describe('MutationUtils', () => { ]; it('match chorosome X and Y to 23 and 24', () => { - assert.equal("23,47836189,47836189,C,T", genomicLocationString(genomicLocation[0])); - assert.equal("24,24089764,24089764,T,G", genomicLocationString(genomicLocation[1])); - assert.equal("23,153694368,153694368,C,T", genomicLocationString(genomicLocation[2])); - assert.equal("24,152057792,152057792,C,G", genomicLocationString(genomicLocation[3])); + assert.equal("23,47836189,47836189,C,G", genomicLocationString(genomicLocation[0]), "should ocnver X to 23"); + assert.equal("24,24089764,24089764,T,G", genomicLocationString(genomicLocation[1]), "should ocnver Y to 24"); + assert.equal("23,153694368,153694368,C,T", genomicLocationString(genomicLocation[2]), "should ocnver x to 23"); + assert.equal("24,152057792,152057792,C,G", genomicLocationString(genomicLocation[3]), "should ocnver y to 24"); }); }); describe('generate Hgvsg by mutation', () => { - const mutations:Partial[] = [ - { - // snp - chr: "17", - startPosition: 7577121, - endPosition: 7577121, - referenceAllele: "G", - variantAllele: "A" - }, - { - // ins - chr: "17", - startPosition: 7579590, - endPosition: 7579591, - referenceAllele: "-", - variantAllele: "CT" - }, - { - // del - chr: "17", - startPosition: 7574030, - endPosition: 7574030, - referenceAllele: "G", - variantAllele: "-" - }, - { - // delins - chr: "17", - startPosition: 7578205, - endPosition: 7578207, - referenceAllele: "CTA", - variantAllele: "TTT" - }, - { - // chromosome is X - chr: "X", - startPosition: 47836189, - endPosition: 47836189, - referenceAllele: "C", - variantAllele: "G" - }, - { - // invalid allele - chr: "17", - startPosition: 7574030, - endPosition: 7574030, - referenceAllele: "NA", - variantAllele: "G" - }, - { - // invalid position - chr: "17", - startPosition: -1, - endPosition: -1, - referenceAllele: "G", - variantAllele: "C" - } - ] - it('has valid genomic location', () => { - assert.equal(true, isValidGenomicLocation(mutations[0])); - assert.equal(false, isValidGenomicLocation(mutations[5])); - assert.equal(false, isValidGenomicLocation(mutations[6])); + const validateMutations: Partial[] = [ + { + // valid + chr: "X", + startPosition: 47836189, + endPosition: 47836189, + referenceAllele: "C", + variantAllele: "G" + }, + { + // invalid allele, referenceAllele = "NA" + chr: "17", + startPosition: 7574030, + endPosition: 7574030, + referenceAllele: "NA", + variantAllele: "G" + }, + { + // invalid allele, both referenceAllele and variantAllele are "-" + chr: "17", + startPosition: 7577498, + endPosition: 7577498, + referenceAllele: "-", + variantAllele: "-" + }, + { + // invalid allele, referenceAllele is empty + chr: "17", + startPosition: 7577498, + endPosition: 7577498, + referenceAllele: "", + variantAllele: "-" + }, + { + // invalid position, startPosition is -1 + chr: "17", + startPosition: -1, + endPosition: 7664673, + referenceAllele: "G", + variantAllele: "C" + }, + { + // invalid, missing chr + chr: "", + startPosition: 7577594, + endPosition: 7577595, + referenceAllele: "AC", + variantAllele: "-" + } + ]; + + assert.equal(true, isValidGenomicLocation(validateMutations[0]), + "should be valid genomic location"); + assert.equal(false, isValidGenomicLocation(validateMutations[1]), + "should be invalid allele, referenceAllele = NA"); + assert.equal(false, isValidGenomicLocation(validateMutations[2]), + "should be invalid allele, both referenceAllele and variantAllele are -"); + assert.equal(false, isValidGenomicLocation(validateMutations[3]), + "should be invalid allele, referenceAllele is empty"); + assert.equal(false, isValidGenomicLocation(validateMutations[4]), + "should be invalid position, startPosition is -1"); + assert.equal(false, isValidGenomicLocation(validateMutations[5]), + "should be invalid, missing chr"); + + }); + + it('generate substitution hgvsg', () => { + const substitutionMutation: Partial[] = [ + { + // substitution + chr: "17", + startPosition: 7577121, + endPosition: 7577121, + referenceAllele: "G", + variantAllele: "A" + } + ]; + + assert.equal("17:g.7577121G>A", generateHgvsgByMutation(substitutionMutation[0]), "the hgvsg should be 17:g.7577121G>A"); + }); + + it('generate insertion hgvsg', () => { + const insertionMutations: Partial[] = [ + { + // ins, length of variantAllele > 1 + chr: "17", + startPosition: 7579590, + endPosition: 7579591, + referenceAllele: "-", + variantAllele: "CT" + }, + { + // ins, length of variantAllele = 1 + chr: "17", + startPosition: 3637855, + endPosition: 3637856, + referenceAllele: "-", + variantAllele: "C" + }]; + + assert.equal("17:g.7579590_7579591insCT", generateHgvsgByMutation(insertionMutations[0]), + "should be insertion 17:g.7579590_7579591insCT: (chr):g.(start)_(end)ins(var)"); + assert.equal("17:g.3637855_3637856insC", generateHgvsgByMutation(insertionMutations[1]), + "should be insertion 17:g.3637855_3637856insC: (chr):g.(start)_(end)ins(var)"); + + }); + + it('generate deletion hgvsg', () => { + const deletionMutations: Partial[] = [ + { + // del, length of referenceAllele = 1 + chr: "17", + startPosition: 7574030, + endPosition: 7574030, + referenceAllele: "G", + variantAllele: "-" + }, + { + // del, length of referenceAllele > 1 + chr: "17", + startPosition: 7577594, + endPosition: 7577595, + referenceAllele: "AC", + variantAllele: "-" + }]; + + assert.equal("17:g.7574030del", generateHgvsgByMutation(deletionMutations[0]), + "should be deletion 17:g.7574030del: (chr):g.(start)del"); + assert.equal("17:g.7577594_7577595del", generateHgvsgByMutation(deletionMutations[1]), + "should be deletion 17:g.7577594_7577595del: (chr):g.(start)_(end)del"); }); - it('generate hgvsg', () => { - assert.equal("17:g.7577121G>A", generateHgvsgByMutation(mutations[0])); - assert.equal("17:g.7579590_7579591insCT", generateHgvsgByMutation(mutations[1])); - assert.equal("17:g.7574030_7574030del", generateHgvsgByMutation(mutations[2])); - assert.equal("17:g.7578205_7578205delinsTTT", generateHgvsgByMutation(mutations[3])); - assert.equal("23:g.47836189C>G", generateHgvsgByMutation(mutations[4])); - assert.equal(null, generateHgvsgByMutation(mutations[5])); - assert.equal(null, generateHgvsgByMutation(mutations[6])); + it('generate delins hgvsg', () => { + const delinsMutations: Partial[] = [ + { + // delins, length of variantAllele = 1 + chr: "17", + startPosition: 7573443, + endPosition: 7573443, + referenceAllele: "C", + variantAllele: "TGG" + }, + { + // delins, length of variantAllele > 1 + chr: "17", + startPosition: 7578205, + endPosition: 7578207, + referenceAllele: "CTA", + variantAllele: "TTT" + }]; + + assert.equal("17:g.7573443delinsTGG", generateHgvsgByMutation(delinsMutations[0]), + "should be delins 17:g.7573443delinsTGG: (chr):g.(start)delins(var)"); + assert.equal("17:g.7578205_7578207delinsTTT", generateHgvsgByMutation(delinsMutations[1]), + "should be delins 17:g.7578205_7578207delinsTTT: (chr):g.(start)_(end)delins(var)"); }); }); }); diff --git a/src/shared/lib/MutationUtils.ts b/src/shared/lib/MutationUtils.ts index ed33964a236..af56eae7a5e 100644 --- a/src/shared/lib/MutationUtils.ts +++ b/src/shared/lib/MutationUtils.ts @@ -233,8 +233,8 @@ export function extractGenomicLocation(mutation: Mutation) export function genomicLocationString(genomicLocation: GenomicLocation) { // mapping chromosome X with 23 - let chromosome = genomicLocation.chromosome.toUpperCase(); - switch(genomicLocation.chromosome) { + let chromosome = genomicLocation.chromosome; + switch(genomicLocation.chromosome.toUpperCase()) { case "X": chromosome = "23"; break; @@ -271,17 +271,24 @@ export function generateHgvsgByMutation(mutation: Partial): string | n } // del (in new format that no ref after del, may differ with genome nexus hgvsg response) else if (mutation.variantAllele === "-") { + if (mutation.startPosition === mutation.endPosition) { + return `${mutation.chr}:g.${mutation.startPosition}del`; + } return `${mutation.chr}:g.${mutation.startPosition}_${mutation.endPosition}del`; } // substitution - else if (mutation.referenceAllele!.length === 1 && mutation.variantAllele!.length === 1) { + else if (mutation.referenceAllele!.length === 1 && mutation.variantAllele!.length === 1) { return `${mutation.chr}:g.${mutation.startPosition}${mutation.referenceAllele}>${mutation.variantAllele}`; } // delins (in new format that no ref after del, may differ with genome nexus hgvsg response) - // for cases (mutation.referenceAllele.length > 1 && mutation.variantAllele.length > 1) - else { + else if (mutation.referenceAllele!.length === 1 && mutation.variantAllele!.length > 1) { return `${mutation.chr}:g.${mutation.startPosition}delins${mutation.variantAllele}`; } + // delins (in new format that no ref after del, may differ with genome nexus hgvsg response) + // for cases mutation.referenceAllele.length > 1 && mutation.variantAllele.length >= 1 + else { + return `${mutation.chr}:g.${mutation.startPosition}_${mutation.endPosition}delins${mutation.variantAllele}`; + } } return null; @@ -293,10 +300,12 @@ export function isValidGenomicLocation(mutation: Partial): boolean { && mutation.endPosition && mutation.endPosition !== -1 && mutation.referenceAllele && mutation.referenceAllele !== "NA" && mutation.variantAllele && mutation.variantAllele !== "NA") { - - return true; - } - else { - return false; + if (mutation.referenceAllele === "-" && mutation.variantAllele === "-") { + return false; + } + return true; } + + return false; + } \ No newline at end of file