Skip to content

Commit

Permalink
Reject piped input (/dev/stdin) for BedToIntervalList (#1918)
Browse files Browse the repository at this point in the history
* Reject piped input (/dev/stdin) for BedToIntervalList

* Directly compare INPUT to /dev/stdin instead of PicardHtsPath.isOther()

* Update error message and add a test.

---------

Co-authored-by: Chris Norman <cnorman@broadinstitute.org>
  • Loading branch information
kockan and cmnbroad committed Mar 12, 2024
1 parent 6fe8547 commit 5b0b4c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/picard/util/BedToIntervalList.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ public class BedToIntervalList extends CommandLineProgram {
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
if(INPUT.getPath().equals("/dev/stdin")) {
throw new IllegalArgumentException("BedToIntervalList does not support reading from standard input - a file must be provided.");
}

IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY);
IOUtil.assertFileIsWritable(OUTPUT);

try {
// create a new header that we will assign the dictionary provided by the SAMSequenceDictionaryExtractor to.
final SAMFileHeader header = new SAMFileHeader();
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/picard/util/BedToIntervalListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public void testLengthZeroIntervalsSkipped(final String inputBed) throws IOExcep
doTest(inputBed, "header.sam", false);
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void testRejectStdin() throws IOException {
final BedToIntervalList program = new BedToIntervalList();
final File outputFile = File.createTempFile("bed_to_interval_list_test.", ".interval_list");
outputFile.deleteOnExit();
program.OUTPUT = outputFile;
program.SEQUENCE_DICTIONARY = new File(TEST_DATA_DIR, "header.sam");
program.UNIQUE = true;
program.INPUT = new File("/dev/stdin");
program.doWork();
}

@DataProvider
public Object[][] testBedToIntervalListDataProvider() {
return new Object[][]{
Expand Down

0 comments on commit 5b0b4c0

Please sign in to comment.