GeneReassigner { public void reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(VariantEvaluation variantEvaluation) { if (isInUnknownGene(variantEvaluation)) { return; } List<String> geneSymbols = new ArrayList<>(); List<VariantEffect> variantEffects = new ArrayList<>(); List<TranscriptAnnotation> newAnnotations = new ArrayList<>(); for (TranscriptAnnotation annotation : variantEvaluation.getTranscriptAnnotations()) { String geneSymbol = annotation.getGeneSymbol(); geneSymbols.add(geneSymbol); variantEffects.add(annotation.getVariantEffect()); newAnnotations.add(annotation); if (isValidFusionProtein(geneSymbol)) { String[] separateGeneSymbols = geneSymbol.split("-"); for (String separateGeneSymbol : separateGeneSymbols) { geneSymbols.add(separateGeneSymbol); variantEffects.add(VariantEffect.CUSTOM); newAnnotations.add(null); } } } Gene currentlyAssignedGene = getCurrentlyAssignedGene(variantEvaluation); double bestScore = prioritiserScore(currentlyAssignedGene); Gene geneWithHighestPhenotypeScore = null; VariantEffect variantEffectForTopHit = null; TranscriptAnnotation bestAnnotation = null; for (int i = 0; i < geneSymbols.size(); i++) { Gene gene = allGenes.get(geneSymbols.get(i)); double geneScore = prioritiserScore(gene); if (geneScore > bestScore) { bestScore = geneScore; geneWithHighestPhenotypeScore = gene; variantEffectForTopHit = variantEffects.get(i); bestAnnotation = newAnnotations.get(i); } } List<TranscriptAnnotation> finalAnnotations = new ArrayList<>(); if (bestAnnotation != null) { finalAnnotations.add(bestAnnotation); } if (prioritiserScore(currentlyAssignedGene) == bestScore) { return; } if (geneWithHighestPhenotypeScore == null) { return; } if (variantEffectForTopHit == null) { return; } if (variantEvaluation.getVariantEffect() != VariantEffect.REGULATORY_REGION_VARIANT) { variantEvaluation.setVariantEffect(variantEffectForTopHit); } assignVariantToGene(variantEvaluation, geneWithHighestPhenotypeScore, finalAnnotations); } GeneReassigner(PriorityType priorityType, Map<String, Gene> allGenes, ChromosomalRegionIndex<TopologicalDomain> tadIndex); void reassignRegulatoryRegionVariantToMostPhenotypicallySimilarGeneInTad(VariantEvaluation variantEvaluation); void reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(VariantEvaluation variantEvaluation);  }
@Test public void testReassignGeneToMostPhenotypicallySimilarGeneInAnnotationsVariantInUnKnownGeneIsNotAltered() { addPriorityResultWithScore(gene1, 1d); addPriorityResultWithScore(gene2, 0d); TopologicalDomain tad = makeTad(1, 1, 20000, gene1, gene2); instance = makeInstance(PriorityType.HIPHIVE_PRIORITY, tad); Gene noKnownGene = new Gene(".", -1); VariantEvaluation variant = regulatoryVariantInTad(tad, noKnownGene); instance.reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(variant); assertThat(variant, isAssignedTo(noKnownGene)); assertThat(variant.getVariantEffect(), equalTo(VariantEffect.REGULATORY_REGION_VARIANT)); }
@Test public void testReassignGeneToMostPhenotypicallySimilarGeneInAnnotationsVariantEffectIsNullIsNotAltered() { addPriorityResultWithScore(gene1, 1d); addPriorityResultWithScore(gene2, 0d); TopologicalDomain tad = makeTad(1, 1, 20000, gene1, gene2); instance = makeInstance(PriorityType.HIPHIVE_PRIORITY, tad); VariantEvaluation variant = regulatoryVariantInTad(tad, gene2); VariantEffect originalVariantEffect = variant.getVariantEffect(); TranscriptAnnotation nullEffectAnnotation = TranscriptAnnotation.builder() .geneSymbol(gene2.getGeneSymbol()) .variantEffect(null) .build(); List<TranscriptAnnotation> originalAnnotations = Collections.singletonList(nullEffectAnnotation); variant.setAnnotations(originalAnnotations); instance.reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(variant); assertThat(variant, isAssignedTo(gene2)); assertThat(variant.getVariantEffect(), equalTo(originalVariantEffect)); assertThat(variant.getTranscriptAnnotations(), equalTo(originalAnnotations)); }
@Test public void testReassignGeneToMostPhenotypicallySimilarGeneInAnnotationsHandlesFusionProteinAnnotationsToTwoKnownGenes() { addPriorityResultWithScore(gene1, 1d); addPriorityResultWithScore(gene2, 0d); TopologicalDomain tad = makeTad(1, 1, 20000, gene1, gene2); instance = makeInstance(PriorityType.HIPHIVE_PRIORITY, tad); VariantEvaluation variant = variantInTadWithEffect(tad, VariantEffect.MISSENSE_VARIANT, gene2); TranscriptAnnotation stopGainInGene2 = TranscriptAnnotation.builder() .geneSymbol(gene2.getGeneSymbol()) .variantEffect(VariantEffect.STOP_GAINED) .build(); TranscriptAnnotation fusionProteinAnnotation = TranscriptAnnotation.builder() .geneSymbol(gene2.getGeneSymbol() + "-" + gene1.getGeneSymbol()) .variantEffect(VariantEffect.MISSENSE_VARIANT) .build(); List<TranscriptAnnotation> annotations = Arrays.asList(stopGainInGene2, fusionProteinAnnotation); variant.setAnnotations(annotations); instance.reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(variant); logger.info("{} {}:{} {} {} {} {}", variant.getGeneSymbol(), variant.getChromosome(), variant.getPosition(), variant.getRef(), variant.getAlt(), variant.getVariantEffect(), variant.getTranscriptAnnotations() .size()); variant.getTranscriptAnnotations().forEach(transcriptAnnotation -> logger.info("{}", transcriptAnnotation)); assertThat(variant, isAssignedTo(gene1)); assertThat(variant.getVariantEffect(), equalTo(VariantEffect.CUSTOM)); assertThat(variant.getTranscriptAnnotations(), equalTo(Collections.emptyList())); }
@Test public void testReassignGeneToMostPhenotypicallySimilarGeneInAnnotationsMissenseAnnotationsAreNotReassigned() { Stream<VariantContext> variantContext = TestVcfParser .forSamples("Adam", "Eve") .parseVariantContext("1 145510730 . T C,A 123.15 PASS GENE=GNRHR2 GT 1/1 0/2"); VariantFactory variantFactory = TestFactory.buildDefaultVariantFactory(); List<VariantEvaluation> variants = variantFactory.createVariantEvaluations(variantContext).collect(toList()); Gene GNRHR2 = TestFactory.newGeneGNRHR2(); allGenes.put(GNRHR2.getGeneSymbol(), GNRHR2); TopologicalDomain unimportantForThisTestTad = makeTad(1, 1, 20000, gene1, gene2); instance = makeInstance(PriorityType.HIPHIVE_PRIORITY, unimportantForThisTestTad); variants.forEach(variantEvaluation -> { logger.info("{} {}:{} {} {} {} {}", variantEvaluation.getGeneSymbol(), variantEvaluation.getChromosome(), variantEvaluation .getPosition(), variantEvaluation.getRef(), variantEvaluation.getAlt(), variantEvaluation.getVariantEffect(), variantEvaluation .getTranscriptAnnotations() .size()); VariantEffect originalVariantEffect = VariantEffect.MISSENSE_VARIANT; List<TranscriptAnnotation> originalAnnotations = new ArrayList<>(variantEvaluation.getTranscriptAnnotations()); assertThat(variantEvaluation, isAssignedTo(GNRHR2)); assertThat(variantEvaluation.getVariantEffect(), equalTo(originalVariantEffect)); assertThat(variantEvaluation.getTranscriptAnnotations(), equalTo(originalAnnotations)); instance.reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(variantEvaluation); assertThat(variantEvaluation, isAssignedTo(GNRHR2)); assertThat(variantEvaluation.getVariantEffect(), equalTo(originalVariantEffect)); assertThat(variantEvaluation.getTranscriptAnnotations(), equalTo(originalAnnotations)); }); }
@Test public void testReassignGeneToMostPhenotypicallySimilarGeneInAnnotationsAnnotationsOverlapTwoGenesShouldOnlyHaveTopPhenotypeGeneMatchAnnotations() { Stream<VariantContext> variantContext = TestVcfParser.forSamples("Adam", "Eve") .parseVariantContext("1 145510730 . T C,A 123.15 PASS GENE=GNRHR2 GT 1/1 0/2"); VariantFactory variantFactory = TestFactory.buildDefaultVariantFactory(); List<VariantEvaluation> variants = variantFactory.createVariantEvaluations(variantContext) .collect(toList()); Gene topPhenotypeMatchGene = TestFactory.newGeneRBM8A(); Gene GNRHR2 = TestFactory.newGeneGNRHR2(); allGenes.put(topPhenotypeMatchGene.getGeneSymbol(), topPhenotypeMatchGene); allGenes.put(GNRHR2.getGeneSymbol(), GNRHR2); addPriorityResultWithScore(topPhenotypeMatchGene, 1d); addPriorityResultWithScore(GNRHR2, 0d); TopologicalDomain topologicalDomain = makeTad(1, 1, 20000, GNRHR2, topPhenotypeMatchGene); instance = makeInstance(PriorityType.HIPHIVE_PRIORITY, topologicalDomain); variants.forEach(variantEvaluation -> { logger.info("Before re-assigning variant to best phenotype match ({})", topPhenotypeMatchGene.getGeneSymbol()); logger.info("{} {}:{} {} {} {} {}", variantEvaluation.getGeneSymbol(), variantEvaluation.getChromosome(), variantEvaluation .getPosition(), variantEvaluation.getRef(), variantEvaluation.getAlt(), variantEvaluation.getVariantEffect(), variantEvaluation .getTranscriptAnnotations() .size()); assertThat(variantEvaluation, isAssignedTo(GNRHR2)); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.MISSENSE_VARIANT)); variantEvaluation.getTranscriptAnnotations() .forEach(transcriptAnnotation -> logger.info("{}", transcriptAnnotation)); List<TranscriptAnnotation> reassignedAnnotations = variantEvaluation.getTranscriptAnnotations().stream() .filter(transcriptAnnotation -> transcriptAnnotation.getGeneSymbol() .equals(topPhenotypeMatchGene.getGeneSymbol())) .collect(toList()); instance.reassignGeneToMostPhenotypicallySimilarGeneInAnnotations(variantEvaluation); logger.info("After re-assigning variant to best phenotype match ({})", topPhenotypeMatchGene.getGeneSymbol()); logger.info("{} {}:{} {} {} {} {}", variantEvaluation.getGeneSymbol(), variantEvaluation.getChromosome(), variantEvaluation .getPosition(), variantEvaluation.getRef(), variantEvaluation.getAlt(), variantEvaluation.getVariantEffect(), variantEvaluation .getTranscriptAnnotations() .size()); assertThat(variantEvaluation, isAssignedTo(topPhenotypeMatchGene)); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.THREE_PRIME_UTR_EXON_VARIANT)); assertThat(variantEvaluation.getTranscriptAnnotations(), equalTo(reassignedAnnotations)); variantEvaluation.getTranscriptAnnotations() .forEach(transcriptAnnotation -> logger.info("{}", transcriptAnnotation)); }); }