VcfResultsWriter implements ResultsWriter { @Override public String writeString(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings) { VCFHeader vcfHeader = VcfFiles.readVcfHeader(analysis.getVcfPath()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (VariantContextWriter writer = VariantContextWriterConstructionHelper.openVariantContextWriter(vcfHeader, baos, getAdditionalHeaderLines())) { writeData(modeOfInheritance, analysisResults, settings.outputContributingVariantsOnly(), writer); } logger.info("{} results written to string buffer", OUTPUT_FORMAT); return new String(baos.toByteArray(), StandardCharsets.UTF_8); } VcfResultsWriter(); @Override void writeFile(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings); @Override String writeString(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings);  }
@Test public void testWriteHeaderFile() { AnalysisResults analysisResults = AnalysisResults.builder() .build(); assertThat(instance.writeString(ModeOfInheritance.ANY, analysis, analysisResults, settings), equalTo(EXPECTED_HEADER)); }
@Test public void testWriteAnnotatedVariantsNoFiltersApplied() { AnalysisResults analysisResults = buildAnalysisResults(fgfr2Gene, shhGene); fgfr2Gene.addVariant(fgfr2ContributingVariant); String vcf = instance.writeString(ModeOfInheritance.ANY, analysis, analysisResults, settings); final String expected = EXPECTED_HEADER + "chr10\t123256215\t.\tT\tG\t2.20\t.\tExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=2263;ExGeneSymbol=FGFR2;ExVarEff=missense_variant;ExVarHgvs=10:g.123256215T>G;ExVarScore=1.0;RD=30\tGT:RD\t0/1:30\n" + "chr10\t123256214\t.\tA\tG\t2.20\t.\tExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=2263;ExGeneSymbol=FGFR2;ExVarEff=missense_variant;ExVarHgvs=10:g.123256214A>G;ExVarScore=0.89;RD=30\tGT:RD\t0/1:30\n" + "chr7\t155604800\t.\tC\tCTT\t1\t.\tExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=6469;ExGeneSymbol=SHH;ExVarEff=frameshift_variant;ExVarHgvs=7:g.155604800C>CTT;ExVarScore=1.0;RD=30\tGT:RD\t0/1:30\n"; assertThat(vcf, equalTo(expected)); }
@Test public void testAnnotatedVariantGeneSymbolWhitespaceIsReplacedWithUnderscore() { GeneIdentifier incorrectGeneSymbol = GeneIdentifier.builder() .geneId("6469") .geneSymbol("SHH alpha spaces") .hgncId("HGNC:10848") .hgncSymbol("SHH") .entrezId("6469") .ensemblId("ENSG00000164690") .ucscId("uc003wmk.2") .build(); Gene gene = new Gene(incorrectGeneSymbol); gene.addVariant(shhIndelVariant); gene.addPriorityResult(new OmimPriorityResult(gene.getEntrezGeneID(), gene.getGeneSymbol(), 1f, Collections.emptyList(), Collections.emptyMap())); gene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); AnalysisResults analysisResults = buildAnalysisResults(gene); String vcf = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); final String expected = EXPECTED_HEADER + "chr7\t155604800\t.\tC\tCTT\t1\t.\tExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=6469;ExGeneSymbol=SHH_alpha_spaces;ExVarEff=frameshift_variant;ExVarHgvs=7:g.155604800C>CTT;ExVarScore=1.0;RD=30\tGT:RD\t0/1:30\n"; assertThat(vcf, equalTo(expected)); }
@Test public void testWritePassVariants() { fgfr2PassMissenseVariant.addFilterResult(PASS_TARGET_RESULT); fgfr2PassMissenseVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2ContributingVariant.addFilterResult(PASS_TARGET_RESULT); fgfr2ContributingVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2ContributingVariant.setContributesToGeneScoreUnderMode(ModeOfInheritance.AUTOSOMAL_DOMINANT); GeneScore geneScore = GeneScore.builder() .modeOfInheritance(ModeOfInheritance.AUTOSOMAL_DOMINANT) .geneIdentifier(fgfr2Gene.getGeneIdentifier()) .contributingVariants(ImmutableList.of(fgfr2ContributingVariant)) .build(); fgfr2Gene.addVariant(fgfr2ContributingVariant); fgfr2Gene.addGeneScore(geneScore); fgfr2Gene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); AnalysisResults analysisResults = buildAnalysisResults(fgfr2Gene); String vcf = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); String expected = EXPECTED_HEADER + CHR10_FGFR2_CONTRIBUTING_VARIANT + CHR10_FGFR2_PASS_VARIANT; assertThat(vcf, equalTo(expected)); }
@Test public void testWriteFailTargetVariant() { EnumSet<ModeOfInheritance> autosomalDominantCompatible = EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT); fgfr2PassMissenseVariant.addFilterResult(FAIL_TARGET_RESULT); fgfr2PassMissenseVariant.setCompatibleInheritanceModes(autosomalDominantCompatible); fgfr2Gene.setCompatibleInheritanceModes(autosomalDominantCompatible); AnalysisResults analysisResults = buildAnalysisResults(fgfr2Gene); String vcfAD = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); assertThat(vcfAD, equalTo(failedFgfr2VariantWithFilterField("var-effect"))); String vcfAR = instance.writeString(ModeOfInheritance.AUTOSOMAL_RECESSIVE, analysis, analysisResults, settings); assertThat(vcfAR, equalTo(failedFgfr2VariantWithFilterField("inheritance;var-effect"))); }
@Test public void testWriteContributingVariantsOnlyContainsOnlyContributingVariantLine() { shhIndelVariant.addFilterResult(FAIL_TARGET_RESULT); shhIndelVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2PassMissenseVariant.addFilterResult(PASS_TARGET_RESULT); fgfr2PassMissenseVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2ContributingVariant.addFilterResult(PASS_TARGET_RESULT); fgfr2ContributingVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2ContributingVariant.setContributesToGeneScoreUnderMode(ModeOfInheritance.AUTOSOMAL_DOMINANT); GeneScore geneScore = GeneScore.builder() .modeOfInheritance(ModeOfInheritance.AUTOSOMAL_DOMINANT) .geneIdentifier(fgfr2Gene.getGeneIdentifier()) .contributingVariants(ImmutableList.of(fgfr2ContributingVariant)) .build(); fgfr2Gene.addGeneScore(geneScore); fgfr2Gene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); AnalysisResults analysisResults = buildAnalysisResults(fgfr2Gene, shhGene); OutputSettings outputContributingVariantsOnly = OutputSettings.builder() .outputFormats(EnumSet.of(OutputFormat.VCF)) .outputContributingVariantsOnly(true) .build(); String output = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, outputContributingVariantsOnly); String expected = EXPECTED_HEADER + CHR10_FGFR2_CONTRIBUTING_VARIANT; assertThat(output, equalTo(expected)); }
@Test public void testWritePassVariantsWithNoPassingVariants() { fgfr2PassMissenseVariant.addFilterResult(FAIL_TARGET_RESULT); fgfr2PassMissenseVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); shhIndelVariant.addFilterResult(FAIL_TARGET_RESULT); shhIndelVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2Gene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); shhGene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); AnalysisResults analysisResults = buildAnalysisResults(fgfr2Gene, shhGene); OutputSettings outputPassVariantsOnlySettings = OutputSettings.builder() .outputFormats(EnumSet.of(OutputFormat.VCF)) .outputContributingVariantsOnly(true) .build(); String output = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, outputPassVariantsOnlySettings); assertThat(output, equalTo(EXPECTED_HEADER)); }
@Test public void testAlternativeAllelesAreWrittenOnSuccessiveLines() { TestVariantFactory varFactory = new TestVariantFactory(); VariantEvaluation alt1 = varFactory.buildVariant(1, 120612040, "T", "TCCGCCG", Genotype.HETEROZYGOUS, 30, 0, 258.62); VariantEvaluation alt2 = varFactory.buildVariant(1, 120612040, "T", "TCCTCCGCCG", Genotype.HOMOZYGOUS_ALT, 30, 0, 258.62); Gene gene = new Gene("TEST", 12345); gene.addVariant(alt1); gene.addVariant(alt2); gene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); AnalysisResults analysisResults = buildAnalysisResults(gene); String output = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); System.out.println(output); String expected = EXPECTED_HEADER + "chr1\t120612040\t.\tT\tTCCGCCG\t258.62\t.\tExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=12345;ExGeneSymbol=TEST;ExVarEff=intergenic_variant;ExVarHgvs=1:g.120612040T>TCCGCCG;ExVarScore=0.0;RD=30\tGT:RD\t0/1:30\n" + "chr1\t120612040\t.\tT\tTCCTCCGCCG\t258.62\t.\tExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=12345;ExGeneSymbol=TEST;ExVarEff=intergenic_variant;ExVarHgvs=1:g.120612040T>TCCTCCGCCG;ExVarScore=0.0;RD=30\tGT:RD\t1/1:30\n"; assertThat(output, equalTo(expected)); }
@Test public void testHomozygousAltAlleleOutputVcfContainsConcatenatedVariantScoresOnOneLine() { Path vcfPath = Paths.get("src/test/resources/multiAlleleGenotypes.vcf"); VariantFactory variantFactory = TestFactory.buildDefaultVariantFactory(); List<VariantEvaluation> variants = variantFactory.createVariantEvaluations(vcfPath).collect(toList()); variants.forEach(System.out::println); VariantEvaluation altAlleleOne = variants.get(3); altAlleleOne.setVariantEffect(VariantEffect.FRAMESHIFT_VARIANT); altAlleleOne.setContributesToGeneScoreUnderMode(ModeOfInheritance.AUTOSOMAL_DOMINANT); VariantEvaluation altAlleleTwo = variants.get(4); Gene gene = new Gene(GeneIdentifier.builder() .geneSymbol(altAlleleOne.getGeneSymbol()) .geneId(altAlleleOne.getGeneId()) .build()); gene.addVariant(altAlleleOne); gene.addVariant(altAlleleTwo); gene.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); AnalysisResults analysisResults = buildAnalysisResults(gene); String output = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); System.out.println(output); String expected = EXPECTED_HEADER + "10\t123256215\t.\tT\tG,A\t100\t.\tExContribAltAllele=0;ExGeneSCombi=0.0;ExGeneSPheno=0.0;ExGeneSVar=0.0;ExGeneSymbId=2263;ExGeneSymbol=FGFR2;ExVarEff=frameshift_variant,missense_variant;ExVarHgvs=10:g.123256215T>G,10:g.123256215T>A;ExVarScore=1.0,0.6;GENE=FGFR2;INHERITANCE=AD;MIM=101600\tGT\t1/2\n"; assertThat(output, equalTo(expected)); }