AnalysisResultsWriter { public static void writeToFile(Analysis analysis, AnalysisResults analysisResults, OutputSettings outputSettings) { ResultsWriterFactory resultsWriterFactory = new ResultsWriterFactory(); logger.info("Writing results..."); Set<OutputFormat> outputFormatsForAnyMoi = EnumSet.noneOf(OutputFormat.class); for (OutputFormat outputFormat : outputSettings.getOutputFormats()) { if (outputFormat == OutputFormat.HTML || outputFormat == OutputFormat.JSON) { writeResultsToFileForMoiWithFormat(ModeOfInheritance.ANY, outputFormat, analysis, analysisResults, outputSettings, resultsWriterFactory); } else { outputFormatsForAnyMoi.add(outputFormat); } } InheritanceModeOptions inheritanceModeOptions = analysis.getInheritanceModeOptions(); if (inheritanceModeOptions.isEmpty()) { writeForInheritanceMode(ModeOfInheritance.ANY, outputFormatsForAnyMoi, analysis, analysisResults, outputSettings, resultsWriterFactory); } else { for (ModeOfInheritance modeOfInheritance : inheritanceModeOptions.getDefinedModes()) { logger.debug("Writing {} results:", modeOfInheritance); analysisResults.getGenes().sort(Gene.comparingScoreForInheritanceMode(modeOfInheritance)); writeForInheritanceMode(modeOfInheritance, outputFormatsForAnyMoi, analysis, analysisResults, outputSettings, resultsWriterFactory); } } } private  AnalysisResultsWriter(); static void writeToFile(Analysis analysis, AnalysisResults analysisResults, OutputSettings outputSettings);  }
@Test public void testWriteToFileOutputsAllModesOfinheritanceForEachFormat() throws Exception { String outputPrefix = tempFile.toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .outputFormats(EnumSet.of(OutputFormat.TSV_GENE, OutputFormat.TSV_VARIANT, OutputFormat.HTML, OutputFormat.VCF)) .build(); Analysis analysis = Analysis.builder() .vcfPath(Paths.get("src/test/resources/smallTest.vcf")) .inheritanceModeOptions(InheritanceModeOptions.defaults()) .build(); AnalysisResultsWriter.writeToFile(analysis, newAnalysisResults(), settings); Path htmlOutputPath = Paths.get(String.format("%s.%s", outputPrefix, OutputFormat.HTML.getFileExtension())); assertThat(htmlOutputPath.toFile().exists(), is(true)); assertThat(htmlOutputPath.toFile().delete(), is(true)); for (OutputFormat outputFormat : Arrays.asList(OutputFormat.TSV_GENE, OutputFormat.TSV_VARIANT, OutputFormat.VCF)) { for (String moi : Arrays.asList("AD", "AR", "XR", "XD", "MT")) { Path outputPath = Paths.get(String.format("%s_%s.%s", outputPrefix, moi, outputFormat.getFileExtension())); assertThat(outputPath.toFile().exists(), is(true)); assertThat(outputPath.toFile().delete(), is(true)); } } }
@Test public void testWriteToFileOutputsAllModesOfinheritanceForEachFormatWhenInheritanceModeIsUndefined() throws Exception { String outputPrefix = tempFile.toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .outputFormats(EnumSet.of(OutputFormat.TSV_GENE, OutputFormat.TSV_VARIANT, OutputFormat.HTML, OutputFormat.VCF)) .build(); Analysis analysis = Analysis.builder() .vcfPath(Paths.get("src/test/resources/smallTest.vcf")) .inheritanceModeOptions(InheritanceModeOptions.empty()) .build(); AnalysisResultsWriter.writeToFile(analysis, newAnalysisResults(), settings); for (OutputFormat outputFormat : Arrays.asList(OutputFormat.HTML, OutputFormat.TSV_GENE, OutputFormat.TSV_VARIANT, OutputFormat.VCF)) { Path outputPath = Paths.get(String.format("%s.%s", outputPrefix, outputFormat.getFileExtension())); assertThat(outputPath.toFile().exists(), is(true)); assertThat(outputPath.toFile().delete(), is(true)); } }
@Test public void testWriteToFileOutputsSingleHtmlFileIfPresentInSettings() throws Exception { String outputPrefix = tempFile.toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .outputFormats(EnumSet.of(OutputFormat.HTML)) .build(); Analysis analysis = Analysis.builder().build(); AnalysisResultsWriter.writeToFile(analysis, newAnalysisResults(), settings); Path outputPath = Paths.get(String.format("%s.%s", outputPrefix, OutputFormat.HTML.getFileExtension())); assertThat(outputPath.toFile().exists(), is(true)); assertThat(outputPath.toFile().delete(), is(true)); }
@Test public void testWriteToFileOutputsSingleJsonFileIfPresentInSettings() throws Exception { String outputPrefix = tempFile.toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .outputFormats(EnumSet.of(OutputFormat.JSON)) .build(); Analysis analysis = Analysis.builder().build(); AnalysisResultsWriter.writeToFile(analysis, newAnalysisResults(), settings); Path outputPath = Paths.get(String.format("%s.%s", outputPrefix, OutputFormat.JSON.getFileExtension())); assertThat(outputPath.toFile().exists(), is(true)); assertThat(outputPath.toFile().delete(), is(true)); }
@Test public void testWriteToFileOutputsSingleJsonOrHtmlFileIfPresentInSettings() throws Exception { String outputPrefix = tempFile.toString(); Set<OutputFormat> singleFileFormats = EnumSet.of(OutputFormat.JSON, OutputFormat.HTML); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .outputFormats(singleFileFormats) .build(); Analysis analysis = Analysis.builder().build(); AnalysisResultsWriter.writeToFile(analysis, newAnalysisResults(), settings); for (OutputFormat outputFormat : singleFileFormats) { Path outputPath = Paths.get(String.format("%s.%s", outputPrefix, outputFormat.getFileExtension())); assertThat(outputPath.toFile().exists(), is(true)); assertThat(outputPath.toFile().delete(), is(true)); } }
@Test public void testWriteToFileDoesNotOutputsSingleHtmlFileIfAbsentFromSettings() throws Exception { String outputPrefix = tempFile.toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .outputFormats(EnumSet.noneOf(OutputFormat.class)) .build(); Analysis analysis = Analysis.builder().build(); AnalysisResultsWriter.writeToFile(analysis, newAnalysisResults(), settings); Path outputPath = Paths.get(String.format("%s.%s", outputPrefix, OutputFormat.HTML.getFileExtension())); assertThat(outputPath.toFile().exists(), is(false)); }