-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve test coverage + fix warnings
- Loading branch information
1 parent
e56f572
commit 28dc7ef
Showing
7 changed files
with
71 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/org/molgenis/vcf/decisiontree/filter/WriterThreadInterruptedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.molgenis.vcf.decisiontree.filter; | ||
|
||
import java.io.Serial; | ||
import static java.lang.String.format; | ||
|
||
public class WriterThreadInterruptedException extends RuntimeException { | ||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
public WriterThreadInterruptedException(String message) { | ||
super(format("VCF writer was interrupted with message: %s", message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/org/molgenis/vcf/decisiontree/runner/ModifiedVcfWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.molgenis.vcf.decisiontree.runner; | ||
|
||
import org.molgenis.vcf.decisiontree.WriterSettings; | ||
|
||
import java.io.*; | ||
import java.nio.file.Path; | ||
|
||
public class ModifiedVcfWriter { | ||
public static final String CNV_TR = "<CNV:TR>"; | ||
public static final String PATTERN = "<CNV:TR\\d+>"; | ||
|
||
private ModifiedVcfWriter() { | ||
} | ||
|
||
public static Thread getWriterThread(PipedOutputStream pipedOut, WriterSettings settings) throws IOException { | ||
Path outputVcfPath = settings.getOutputVcfPath(); | ||
PipedInputStream pipedIn = new PipedInputStream(pipedOut); | ||
|
||
// Create a thread to write the modified output to a file | ||
Thread writerThread = new Thread(() -> { | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(pipedIn)); | ||
BufferedWriter finalWriter = new BufferedWriter(new FileWriter(outputVcfPath.toFile()))) { | ||
|
||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
String modifiedContent = line.replaceAll(PATTERN, CNV_TR); | ||
|
||
finalWriter.write(modifiedContent); | ||
finalWriter.newLine(); | ||
} | ||
|
||
} catch (IOException ioException) { | ||
throw new UncheckedIOException(ioException); | ||
} | ||
}); | ||
|
||
writerThread.start(); | ||
return writerThread; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/org/molgenis/vcf/decisiontree/runner/RecordWriterFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/test/java/org/molgenis/vcf/decisiontree/filter/WriterThreadInterruptedExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.molgenis.vcf.decisiontree.filter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class WriterThreadInterruptedExceptionTest { | ||
|
||
@Test | ||
void getMessage() { | ||
assertEquals( | ||
"VCF writer was interrupted with message: I don't want to interrupt, but ...", | ||
new WriterThreadInterruptedException( | ||
"I don't want to interrupt, but ...").getMessage()); | ||
} | ||
} |