From 01d984fce46aad6167cd42ab8ba66b565d076de1 Mon Sep 17 00:00:00 2001 From: Can Kockan Date: Tue, 14 Nov 2023 15:54:31 -0500 Subject: [PATCH 1/3] Reject piped input (/dev/stdin) for BedToIntervalList --- src/main/java/picard/util/BedToIntervalList.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/picard/util/BedToIntervalList.java b/src/main/java/picard/util/BedToIntervalList.java index d8378ccb65..878a401065 100644 --- a/src/main/java/picard/util/BedToIntervalList.java +++ b/src/main/java/picard/util/BedToIntervalList.java @@ -24,6 +24,7 @@ import picard.cmdline.CommandLineProgram; import picard.cmdline.StandardOptionDefinitions; import picard.cmdline.programgroups.IntervalsManipulationProgramGroup; +import picard.nio.PicardHtsPath; import java.io.File; import java.io.IOException; @@ -120,6 +121,11 @@ protected int doWork() { IOUtil.assertFileIsReadable(INPUT); IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY); IOUtil.assertFileIsWritable(OUTPUT); + + if(PicardHtsPath.isOther(new PicardHtsPath(INPUT))) { + throw new IllegalArgumentException("BedToIntervalList cannot read from /dev/stdin."); + } + try { // create a new header that we will assign the dictionary provided by the SAMSequenceDictionaryExtractor to. final SAMFileHeader header = new SAMFileHeader(); From b492efb97a1d2a2367d613ed623ea3f4516ff3d4 Mon Sep 17 00:00:00 2001 From: Can Kockan Date: Thu, 15 Feb 2024 15:41:08 -0500 Subject: [PATCH 2/3] Directly compare INPUT to /dev/stdin instead of PicardHtsPath.isOther() --- src/main/java/picard/util/BedToIntervalList.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/picard/util/BedToIntervalList.java b/src/main/java/picard/util/BedToIntervalList.java index 878a401065..f3b7ff2e43 100644 --- a/src/main/java/picard/util/BedToIntervalList.java +++ b/src/main/java/picard/util/BedToIntervalList.java @@ -24,7 +24,6 @@ import picard.cmdline.CommandLineProgram; import picard.cmdline.StandardOptionDefinitions; import picard.cmdline.programgroups.IntervalsManipulationProgramGroup; -import picard.nio.PicardHtsPath; import java.io.File; import java.io.IOException; @@ -119,13 +118,13 @@ public class BedToIntervalList extends CommandLineProgram { @Override protected int doWork() { IOUtil.assertFileIsReadable(INPUT); - IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY); - IOUtil.assertFileIsWritable(OUTPUT); - - if(PicardHtsPath.isOther(new PicardHtsPath(INPUT))) { + if(INPUT.getPath().equals("/dev/stdin")) { throw new IllegalArgumentException("BedToIntervalList cannot read from /dev/stdin."); } + 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(); From ccdbb9037aa83161ee71e3d8391add74f360f2e5 Mon Sep 17 00:00:00 2001 From: Chris Norman Date: Tue, 12 Mar 2024 10:30:52 -0400 Subject: [PATCH 3/3] Update error message and add a test. --- src/main/java/picard/util/BedToIntervalList.java | 2 +- src/test/java/picard/util/BedToIntervalListTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/picard/util/BedToIntervalList.java b/src/main/java/picard/util/BedToIntervalList.java index f3b7ff2e43..375e55df88 100644 --- a/src/main/java/picard/util/BedToIntervalList.java +++ b/src/main/java/picard/util/BedToIntervalList.java @@ -119,7 +119,7 @@ public class BedToIntervalList extends CommandLineProgram { protected int doWork() { IOUtil.assertFileIsReadable(INPUT); if(INPUT.getPath().equals("/dev/stdin")) { - throw new IllegalArgumentException("BedToIntervalList cannot read from /dev/stdin."); + throw new IllegalArgumentException("BedToIntervalList does not support reading from standard input - a file must be provided."); } IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY); diff --git a/src/test/java/picard/util/BedToIntervalListTest.java b/src/test/java/picard/util/BedToIntervalListTest.java index 3727f3973f..67b1c635f5 100644 --- a/src/test/java/picard/util/BedToIntervalListTest.java +++ b/src/test/java/picard/util/BedToIntervalListTest.java @@ -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[][]{