FantomEnhancerToBedConverter { public void run() { Path inFile = dataPath.resolve("hg19_permissive_enhancer_usage.csv.gz"); Path outFile = outputPath.resolve("hg19_fantom_permissive_enhancer_usage.bed"); Path tissueIndexFile = outputPath.resolve("fantom_permissive_enhancer_tissue_index.tsv.gz"); logger.info("Parsing Fantom enhancers file: {} Writing out to: {}", inFile, outFile); try (BufferedReader reader = bufferedGZipReader(inFile); BufferedWriter bedFileWriter = Files.newBufferedWriter(outFile, Charset.defaultCharset()); BufferedWriter tissueIndexWriter = bufferedGZipWriter(tissueIndexFile)) { String header = reader.readLine(); String tissueHeader = header.replaceAll(",", "\t"); tissueIndexWriter.write(tissueHeader); tissueIndexWriter.newLine(); String line; int tissueIndex = 0; while ((line = reader.readLine()) != null) { tissueIndex++; line = line.replaceAll("\n", ""); String[] lineParts = line.split(","); tissueIndexWriter.write(generateIndexLine(tissueIndex, lineParts)); tissueIndexWriter.newLine(); String chromosomalRegion = lineParts[0].replaceAll("\"", ""); String[] chrRegionParts = chromosomalRegion.split(":"); String chr = chrRegionParts[0].substring(3); String[] startEnd = chrRegionParts[1].split("-"); String start = startEnd[0]; String end = startEnd[1]; if (tissueIsExpressed(lineParts)) { bedFileWriter.write(generateLine(chr, start, end, tissueIndex)); bedFileWriter.newLine(); } } } catch (IOException ex) { logger.error(null, ex); } logger.info("Done"); } FantomEnhancerToBedConverter(Path dataPath, Path outputPath); void download(); void run();  }
@Test @ExtendWith(TempDirectory.class) public void run(@TempDir Path tempDir) throws Exception { Path inputFile = Paths.get("src/test/resources/genome/liftover"); Path expectedOutputFile = Paths.get("src/test/resources/genome/liftover/hg19_fantom_permissive_enhancer_usage.bed"); FantomEnhancerToBedConverter instance = new FantomEnhancerToBedConverter(inputFile, tempDir); instance.run(); List<String> expected = Files.readAllLines(expectedOutputFile); List<String> actual = Files.readAllLines(tempDir.resolve("hg19_fantom_permissive_enhancer_usage.bed")); assertThat(actual, equalTo(expected)); }