TsvVariantResultsWriter implements ResultsWriter { @Override public String writeString(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings) { StringBuilder output = new StringBuilder(); try (CSVPrinter printer = new CSVPrinter(output, format)) { writeData(modeOfInheritance, analysis, analysisResults, settings.outputContributingVariantsOnly(), printer); } catch (IOException ex) { logger.error("Unable to write results to string {}", output, ex); } return output.toString(); } TsvVariantResultsWriter(); @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 testWriteStringUnderAnyInheritanceModeContainsAllVariants() { OutputSettings settings = settingsBuilder.build(); String outString = instance.writeString(ModeOfInheritance.ANY, analysis, analysisResults, settings); String expected = HEADER + PASS_VARIANT_LINE + FAIL_VARIANT_LINE; assertThat(outString, equalTo(expected)); }
@Test public void testWriteContributingVariantsOnlyStringContainsOnlyContributingVariants() { OutputSettings settings = settingsBuilder.outputContributingVariantsOnly(true).build(); Gene fgfr2 = TestFactory.newGeneFGFR2(); fgfr2.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); VariantEvaluation passVariant = makePassVariant(); passVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2.addVariant(passVariant); VariantEvaluation contributingVariant = makeContributingVariant(); contributingVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); contributingVariant.setContributesToGeneScoreUnderMode(ModeOfInheritance.AUTOSOMAL_DOMINANT); GeneScore geneScore = GeneScore.builder() .modeOfInheritance(ModeOfInheritance.AUTOSOMAL_DOMINANT) .geneIdentifier(fgfr2.getGeneIdentifier()) .contributingVariants(ImmutableList.of(contributingVariant)) .build(); fgfr2.addVariant(contributingVariant); fgfr2.addGeneScore(geneScore); AnalysisResults results = AnalysisResults.builder() .genes(Collections.singletonList(fgfr2)) .build(); String outString = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, results, settings); String expected = HEADER + CONTRIBUTING_VARIANT_LINE; assertThat(outString, equalTo(expected)); }
@Test public void testWriteContributingVariantsOnlyStringIsEmptyForIncompatibleMode() { OutputSettings settings = settingsBuilder.outputContributingVariantsOnly(true).build(); Gene fgfr2 = TestFactory.newGeneFGFR2(); fgfr2.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); VariantEvaluation passVariant = makePassVariant(); passVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); fgfr2.addVariant(passVariant); VariantEvaluation contributingVariant = makeContributingVariant(); contributingVariant.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); contributingVariant.setContributesToGeneScoreUnderMode(ModeOfInheritance.AUTOSOMAL_DOMINANT); GeneScore geneScore = GeneScore.builder() .modeOfInheritance(ModeOfInheritance.AUTOSOMAL_DOMINANT) .geneIdentifier(fgfr2.getGeneIdentifier()) .contributingVariants(ImmutableList.of(contributingVariant)) .build(); fgfr2.addVariant(contributingVariant); fgfr2.addGeneScore(geneScore); AnalysisResults results = AnalysisResults.builder() .genes(Collections.singletonList(fgfr2)) .build(); String outString = instance.writeString(ModeOfInheritance.AUTOSOMAL_RECESSIVE, analysis, results, settings); String expected = HEADER; assertThat(outString, equalTo(expected)); }
@Test public void testContributingVariantIsIndicated() { OutputSettings settings = settingsBuilder.build(); Gene fgfr2 = TestFactory.newGeneFGFR2(); fgfr2.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); VariantEvaluation contributing = makeContributingVariant(); contributing.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)); contributing.setContributesToGeneScoreUnderMode(ModeOfInheritance.AUTOSOMAL_DOMINANT); fgfr2.addVariant(contributing); AnalysisResults results = AnalysisResults.builder() .genes(Collections.singletonList(fgfr2)) .build(); String outString = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, results, settings); String expected = HEADER + CONTRIBUTING_VARIANT_LINE; assertThat(outString, equalTo(expected)); }