HtmlResultsWriter implements ResultsWriter { @Override public void writeFile(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings) { logger.debug("Writing HTML results"); String outFileName = ResultsWriterUtils.makeOutputFilename(analysis.getVcfPath(), settings.getOutputPrefix(), OUTPUT_FORMAT, modeOfInheritance); Path outFile = Paths.get(outFileName); try (BufferedWriter writer = Files.newBufferedWriter(outFile, StandardCharsets.UTF_8)) { Context context = buildContext(modeOfInheritance, analysis, analysisResults, settings); templateEngine.process("results", context, writer); } catch (IOException ex) { logger.error("Unable to write results to file {}", outFileName, ex); } logger.debug("{} ALL results written to file {}", OUTPUT_FORMAT, outFileName); } HtmlResultsWriter(); @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 testWriteTemplateWithEmptyData() { Analysis analysis = Analysis.builder().build(); AnalysisResults analysisResults = buildAnalysisResults(Collections.emptyList(), Collections.emptyList()); String outputPrefix = testOutDir.resolve("testWriteTemplateWithEmptyData").toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(outputPrefix) .build(); instance.writeFile(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); Path testOutFile = Paths.get(outputPrefix + "_AD.html"); assertTrue(testOutFile.toFile().exists()); assertTrue(testOutFile.toFile().delete()); }
@Test public void testWriteTemplateWithUnAnnotatedVariantData() { Analysis analysis = Analysis.builder().build(); List<VariantEvaluation> variants = Lists.newArrayList(unAnnotatedVariantEvaluation1, unAnnotatedVariantEvaluation2); AnalysisResults analysisResults = buildAnalysisResults(Collections.emptyList(), variants); String testOutFilePrefix = testOutDir.resolve("testWriteTemplateWithUnAnnotatedVariantData").toString(); OutputSettings settings = OutputSettings.builder() .outputPrefix(testOutFilePrefix) .build(); instance.writeFile(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, settings); Path testOutFile = Paths.get(testOutFilePrefix + "_AD.html"); assertTrue(testOutFile.toFile().exists()); assertTrue(testOutFile.toFile().delete()); }
@Test public void testWriteTemplateWithUnAnnotatedVariantDataAndGenes() throws Exception { Analysis analysis = Analysis.builder().build(); List<VariantEvaluation> variants = Lists.newArrayList(unAnnotatedVariantEvaluation1, unAnnotatedVariantEvaluation2); List<Gene> genes = Lists.newArrayList(fgfr2Gene, shhGene); AnalysisResults analysisResults = buildAnalysisResults(genes, variants); String testOutFilePrefix = testOutDir.resolve("testWriteTemplateWithUnAnnotatedVariantDataAndGenes").toString(); OutputSettings settings = OutputSettings.builder().outputPrefix(testOutFilePrefix).build(); instance.writeFile(ModeOfInheritance.ANY, analysis, analysisResults, settings); Path testOutFile = Paths.get(testOutFilePrefix + ".html"); List<String> lines = Files.readAllLines(testOutFile); assertFalse(lines.isEmpty()); assertTrue(testOutFile.toFile().exists()); assertTrue(testOutFile.toFile().delete()); }