CanonicalAnnotation { @VisibleForTesting @NotNull <T extends TranscriptAnnotation> Optional<T> pickCanonicalFavourDriverGene(@NotNull List<T> annotations) { List<T> canonicalAnnotations = annotations.stream() .filter(annotation -> canonicalTranscriptGeneMap.containsKey(trimEnsembleVersion(annotation.transcript()))) .collect(Collectors.toList()); if (!canonicalAnnotations.isEmpty()) { Optional<T> canonicalOnDriverGene = canonicalAnnotations.stream().filter(annotation -> driverCatalogGenes.contains(annotation.gene())).findFirst(); if (canonicalOnDriverGene.isPresent()) { return canonicalOnDriverGene; } return Optional.of(canonicalAnnotations.get(0)); } return Optional.empty(); } CanonicalAnnotation(@NotNull final List<DriverGene> driverGenes, @NotNull final List<CanonicalTranscript> transcripts); @NotNull Optional<SnpEffAnnotation> canonicalSnpEffAnnotation(@NotNull final List<SnpEffAnnotation> allAnnotations);  }
@Test public void favourDriverCatalogGenes() { TranscriptAnnotation nonCanonicalDriverGene = createSnpEffAnnotation("ATP1A1", "ENST00000295598", VariantConsequence.MISSENSE_VARIANT); TranscriptAnnotation noDriverGene = createSnpEffAnnotation("AL136376.1", "ENST00000598661", VariantConsequence.MISSENSE_VARIANT); TranscriptAnnotation canonicalDriverGene = createSnpEffAnnotation("ATP1A1", "ENST00000537345", VariantConsequence.MISSENSE_VARIANT); CanonicalAnnotation victim = new CanonicalAnnotation(genePanel.driverGenes(), transcripts); assertEquals(Optional.empty(), victim.pickCanonicalFavourDriverGene(Lists.newArrayList(nonCanonicalDriverGene))); Optional<TranscriptAnnotation> annotationSecond = victim.pickCanonicalFavourDriverGene(Lists.newArrayList(nonCanonicalDriverGene, noDriverGene)); assertTrue(annotationSecond.isPresent()); assertEquals(noDriverGene, annotationSecond.get()); Optional<TranscriptAnnotation> annotationThird = victim.pickCanonicalFavourDriverGene(Lists.newArrayList(nonCanonicalDriverGene, noDriverGene, canonicalDriverGene)); assertTrue(annotationThird.isPresent()); assertEquals(canonicalDriverGene, annotationThird.get()); }