TadHg38BedToPgConverter { public void run() { try (BufferedReader bufferedReader = Files.newBufferedReader(inFile); BufferedWriter bufferedWriter = Files.newBufferedWriter(outFile)) { String line = bufferedReader.readLine(); TadLine tadLine = parseLine(line); while ((line = bufferedReader.readLine()) != null) { TadLine currentTadLine = parseLine(line); if (tadLine.geneId.equals(currentTadLine.geneId)) { tadLine.addStart(currentTadLine.start); tadLine.addEnd(currentTadLine.end); } else { bufferedWriter.write(tadLine.writePg()); bufferedWriter.newLine(); tadLine = currentTadLine; } } bufferedWriter.write(tadLine.writePg()); } catch (IOException e) { logger.error("Unable to process file", e); } } TadHg38BedToPgConverter(Path inFile, Path outFile); void run();  }
@Test @ExtendWith(TempDirectory.class) public void testMerge(@TempDir Path tempDir) throws Exception { Path inputFile = Paths.get("src/test/resources/genome/liftover/test_split_tad.bed"); Path expectedOutputFile = Paths.get("src/test/resources/genome/liftover/test_expected_tad.bed"); Path outputFile = tempDir.resolve("test_expected_tad.bed"); TadHg38BedToPgConverter instance = new TadHg38BedToPgConverter(inputFile, outputFile); instance.run(); List<String> expected = Files.readAllLines(expectedOutputFile); List<String> actual = Files.readAllLines(outputFile); assertThat(actual, equalTo(expected)); }