VariantFactoryImpl implements VariantFactory { @Override public Stream<VariantEvaluation> createVariantEvaluations(Stream<VariantContext> variantContextStream) { logger.info("Annotating variant records, trimming sequences and normalising positions..."); VariantCounter counter = new VariantCounter(); return variantContextStream .peek(counter.countVariantContext()) .flatMap(toVariantEvaluations()) .peek(counter.countAnnotatedVariant()) .onClose(counter::logCount); } VariantFactoryImpl(VariantAnnotator variantAnnotator); @Override Stream<VariantEvaluation> createVariantEvaluations(Stream<VariantContext> variantContextStream);  }
@Test public void testStreamCreateVariantsSingleAlleles() { Path vcfPath = Paths.get("src/test/resources/smallTest.vcf"); long numVariants; try (Stream<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath)) { numVariants = variants .peek(printVariant()) .count(); } assertThat(numVariants, equalTo(3L)); }
@Test public void testCreateVariantContextsMultipleAllelesDiferentSingleSampleGenotypes() { Path vcfPath = Paths.get("src/test/resources/multiAlleleGenotypes.vcf"); List<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath).collect(toList()); variants.forEach(printVariant()); assertThat(variants.size(), equalTo(11)); }
@Test public void testCreateVariantsSingleAlleles() { Path vcfPath = Paths.get("src/test/resources/smallTest.vcf"); List<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath).collect(toList()); variants.forEach(printVariant()); assertThat(variants.size(), equalTo(3)); }
@Test public void testCreateVariantsMultipleAllelesProduceOneVariantPerAllele() { Path vcfPath = Paths.get("src/test/resources/altAllele.vcf"); List<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath).collect(toList()); variants.forEach(printVariant()); assertThat(variants.size(), equalTo(2)); }
@Test public void testCreateVariantsMultipleAllelesSingleSampleGenotypesShouldOnlyReturnRepresentedVariationFromGenotype() { Path vcfPath = Paths.get("src/test/resources/multiAlleleGenotypes.vcf"); List<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath).collect(toList()); variants.forEach(printVariant()); assertThat(variants.size(), equalTo(11)); }
@Test public void testCreateVariantsNoVariantAnnotationsProduceVariantEvaluationsWithNoAnnotations() { Path vcfPath = Paths.get("src/test/resources/noAnnotations.vcf"); List<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath).collect(toList()); assertThat(variants.size(), equalTo(2)); for (VariantEvaluation variant : variants) { System.out.println(variant.getChromosomeName() + " " + variant); assertThat(variant.hasTranscriptAnnotations(), is(false)); } }
@Test public void testStreamVariantEvaluationsMultipleAllelesDifferentSingleSampleGenotypes() { Path vcfPath = Paths.get("src/test/resources/multiAlleleGenotypes.vcf"); List<VariantEvaluation> variants = instance.createVariantEvaluations(vcfPath).collect(toList()); assertThat(variants.size(), equalTo(11)); }
@Test public void testKnownSingleSampleSnp() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample") .parseVariantContext("10\t123256215\t.\tT\tG\t100\tPASS\tGENE=FGFR2;INHERITANCE=AD;MIM=101600\tGT\t1|0"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); System.out.println(variantEvaluation); assertThat(variantEvaluation.getChromosome(), equalTo(10)); assertThat(variantEvaluation.getChromosomeName(), equalTo("10")); assertThat(variantEvaluation.getPosition(), equalTo(123256215)); assertThat(variantEvaluation.getRef(), equalTo("T")); assertThat(variantEvaluation.getAlt(), equalTo("G")); assertThat(variantEvaluation.hasTranscriptAnnotations(), is(true)); System.out.println(variantEvaluation.getTranscriptAnnotations()); assertThat(variantEvaluation.getGeneId(), equalTo("2263")); assertThat(variantEvaluation.getGeneSymbol(), equalTo("FGFR2")); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.MISSENSE_VARIANT)); assertThat(variantEvaluation.getSampleGenotypes(), equalTo(ImmutableMap.of("Sample", SampleGenotype.phased(AlleleCall.ALT, AlleleCall.REF)))); }
@Test public void testUnKnownSingleSampleSnp() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample") .parseVariantContext("UNKNOWN\t12345\t.\tT\tC\t0\tPASS\t.\tGT:DP\t0/1:21"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); System.out.println(variantEvaluation); assertThat(variantEvaluation.getChromosome(), equalTo(0)); assertThat(variantEvaluation.getChromosomeName(), equalTo("UNKNOWN")); assertThat(variantEvaluation.getPosition(), equalTo(12345)); assertThat(variantEvaluation.getRef(), equalTo("T")); assertThat(variantEvaluation.getAlt(), equalTo("C")); assertThat(variantEvaluation.hasTranscriptAnnotations(), is(false)); System.out.println(variantEvaluation.getTranscriptAnnotations()); assertThat(variantEvaluation.getGeneId(), equalTo("")); assertThat(variantEvaluation.getGeneSymbol(), equalTo(".")); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.SEQUENCE_VARIANT)); assertThat(variantEvaluation.getSampleGenotypes(), equalTo(ImmutableMap.of("Sample", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT)))); }
@Test public void testSingleSampleDeletion() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample") .parseVariantContext("1\t123256213\t.\tCA\tC\t100.15\tPASS\tGENE=RBM8A\tGT:DP\t0/1:33"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); System.out.println(variantEvaluation); assertThat(variantEvaluation.getChromosome(), equalTo(1)); assertThat(variantEvaluation.getChromosomeName(), equalTo("1")); assertThat(variantEvaluation.getPosition(), equalTo(123256213)); assertThat(variantEvaluation.getRef(), equalTo("CA")); assertThat(variantEvaluation.getAlt(), equalTo("C")); assertThat(variantEvaluation.hasTranscriptAnnotations(), is(true)); System.out.println(variantEvaluation.getTranscriptAnnotations()); assertThat(variantEvaluation.getGeneId(), equalTo("9939")); assertThat(variantEvaluation.getGeneSymbol(), equalTo("RBM8A")); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.INTERGENIC_VARIANT)); assertThat(variantEvaluation.getSampleGenotypes(), equalTo(ImmutableMap.of("Sample", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT)))); }
@Test public void testSnpWithNoGenotypeReturnsNothing() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples() .parseVariantContext("UNKNOWN\t12345\t.\tT\tC\t0\tPASS\t."); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.isEmpty(), is(true)); }
@Test public void testSingleSampleHomVar() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample") .parseVariantContext("1\t120612040\t.\tT\tTCCGCCG\t258.62\tPASS\t.\tGT\t1/1"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variant = variants.get(0); assertThat(variant.getSampleGenotypes(), equalTo(ImmutableMap.of("Sample", SampleGenotype.of(AlleleCall.ALT, AlleleCall.ALT)))); }
@Test public void testSingleSampleMultiPosition() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample") .parseVariantContext("1\t120612040\t.\tT\tTCCGCCG,TCCTCCGCCG\t258.62\tPASS\t.\tGT\t1/2"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(2)); assertThat(variants.get(0).getSampleGenotypes(), equalTo(ImmutableMap.of("Sample", SampleGenotype.of(AlleleCall.OTHER_ALT, AlleleCall.ALT)))); assertThat(variants.get(1).getSampleGenotypes(), equalTo(ImmutableMap.of("Sample", SampleGenotype.of(AlleleCall.OTHER_ALT, AlleleCall.ALT)))); }
@Test public void testMultiSampleMultiPositionAlleleIsSplitIntoAlternateAlleles() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample1", "Sample2") .parseVariantContext("1\t120612040\t.\tT\tTCCGCCG,TCCTCCGCCG\t258.62\tPASS\t.\tGT\t0/1\t0/2"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(2)); VariantEvaluation firstAllele = variants.get(0); System.out.println(firstAllele); assertThat(firstAllele.getChromosome(), equalTo(1)); assertThat(firstAllele.getChromosomeName(), equalTo("1")); assertThat(firstAllele.getPosition(), equalTo(120612040)); assertThat(firstAllele.getRef(), equalTo("T")); assertThat(firstAllele.getAlt(), equalTo("TCCGCCG")); assertThat(firstAllele.hasTranscriptAnnotations(), is(true)); System.out.println(firstAllele.getTranscriptAnnotations()); assertThat(firstAllele.getGeneId(), equalTo("9939")); assertThat(firstAllele.getGeneSymbol(), equalTo("RBM8A")); assertThat(firstAllele.getVariantEffect(), equalTo(VariantEffect.INTERGENIC_VARIANT)); assertThat(firstAllele.getSampleGenotypes(), equalTo( ImmutableMap.of( "Sample1", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT), "Sample2", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT) )) ); VariantEvaluation secondAllele = variants.get(1); System.out.println(secondAllele); assertThat(secondAllele.getChromosome(), equalTo(1)); assertThat(secondAllele.getChromosomeName(), equalTo("1")); assertThat(secondAllele.getPosition(), equalTo(120612040)); assertThat(secondAllele.getRef(), equalTo("T")); assertThat(secondAllele.getAlt(), equalTo("TCCTCCGCCG")); assertThat(secondAllele.hasTranscriptAnnotations(), is(true)); System.out.println(secondAllele.getTranscriptAnnotations()); assertThat(secondAllele.getGeneId(), equalTo("9939")); assertThat(secondAllele.getGeneSymbol(), equalTo("RBM8A")); assertThat(secondAllele.getVariantEffect(), equalTo(VariantEffect.INTERGENIC_VARIANT)); assertThat(secondAllele.getSampleGenotypes(), equalTo( ImmutableMap.of( "Sample1", SampleGenotype.of(AlleleCall.REF, AlleleCall.OTHER_ALT), "Sample2", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT) )) ); }
@Test public void testMultiSampleMultiPositionOnlyOneAltAlleleIsPresentInSamplesProducesOneVariantEvaluation() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample1", "Sample2") .parseVariantContext("1\t120612040\t.\tT\tTCCGCCG,TCCTCCGCCG\t258.62\tPASS\t.\tGT\t0/1\t0/1"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); System.out.println(variantEvaluation); assertThat(variantEvaluation.getChromosome(), equalTo(1)); assertThat(variantEvaluation.getChromosomeName(), equalTo("1")); assertThat(variantEvaluation.getPosition(), equalTo(120612040)); assertThat(variantEvaluation.getRef(), equalTo("T")); assertThat(variantEvaluation.getAlt(), equalTo("TCCGCCG")); assertThat(variantEvaluation.hasTranscriptAnnotations(), is(true)); System.out.println(variantEvaluation.getTranscriptAnnotations()); assertThat(variantEvaluation.getGeneId(), equalTo("9939")); assertThat(variantEvaluation.getGeneSymbol(), equalTo("RBM8A")); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.INTERGENIC_VARIANT)); assertThat(variantEvaluation.getSampleGenotypes(), equalTo( ImmutableMap.of( "Sample1", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT), "Sample2", SampleGenotype.of(AlleleCall.REF, AlleleCall.ALT) )) ); }
@Test public void testStructuralVariant() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample1") .parseVariantContext("10 123256215 . T <DEL> 6 PASS SVTYPE=DEL;END=123256110;SVLEN=-205;CIPOS=-56,20;CIEND=-10,62 GT:GQ 0/1:12"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); assertThat(variantEvaluation.getVariantEffect(), equalTo(VariantEffect.STRUCTURAL_VARIANT)); }
@Test void testVariantContextIdIsCaptured() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample1") .parseVariantContext("1 112992009 esv3587212 T A 100 PASS . GT 1|0"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); assertThat(variantEvaluation.getId(), equalTo("esv3587212")); }
@Test void testVariantContextIdIsEmptyWhenDotInVcf() { Stream<VariantContext> variantContexts = TestVcfParser.forSamples("Sample1") .parseVariantContext("1 112992009 . T A 100 PASS . GT 1|0"); List<VariantEvaluation> variants = instance.createVariantEvaluations(variantContexts) .peek(printVariant()) .collect(toList()); assertThat(variants.size(), equalTo(1)); VariantEvaluation variantEvaluation = variants.get(0); assertThat(variantEvaluation.getId(), equalTo("")); }