From 558f52f296d52b9468afa010af05814da79111eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20G=C3=B3mez-S=C3=A1nchez?= Date: Tue, 4 Apr 2017 14:13:23 +0200 Subject: [PATCH 1/5] Throw instead of silently failing for Index.writeBasedOnFeaturePath --- src/main/java/htsjdk/tribble/index/AbstractIndex.java | 3 +-- src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/htsjdk/tribble/index/AbstractIndex.java b/src/main/java/htsjdk/tribble/index/AbstractIndex.java index b1cc1364c..ac90e5d2b 100644 --- a/src/main/java/htsjdk/tribble/index/AbstractIndex.java +++ b/src/main/java/htsjdk/tribble/index/AbstractIndex.java @@ -386,8 +386,7 @@ public void write(final Path idxPath) throws IOException { @Override public void writeBasedOnFeaturePath(final Path featurePath) throws IOException { if (!Files.isRegularFile(featurePath)) { - logger.warn("Index not written into ", featurePath); - return; + throw new IOException("Cannot write based on a non-regular file: " + featurePath.toUri()); } write(Tribble.indexPath(featurePath)); } diff --git a/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java b/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java index 43b1a2b40..1a3767666 100644 --- a/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java +++ b/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java @@ -230,8 +230,7 @@ public void write(final Path tabixPath) throws IOException { @Override public void writeBasedOnFeaturePath(final Path featurePath) throws IOException { if (!Files.isRegularFile(featurePath)) { - LOGGER.warn("Index not written into ", featurePath); - return; + throw new IOException("Cannot write based on a non-regular file: " + featurePath.toUri()); } write(Tribble.tabixIndexPath(featurePath)); } From 647b21d65dd08484eeb231707f74bfd5d4d99df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20G=C3=B3mez-S=C3=A1nchez?= Date: Tue, 4 Apr 2017 14:13:44 +0200 Subject: [PATCH 2/5] Remove unused logger --- src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java b/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java index 1a3767666..435144592 100644 --- a/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java +++ b/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java @@ -66,8 +66,6 @@ MAGIC_NUMBER = bb.order(ByteOrder.LITTLE_ENDIAN).getInt(); } - private static final Log LOGGER = Log.getInstance(TabixIndex.class); - private final TabixFormat formatSpec; private final List sequenceNames; private final BinningIndexContent[] indices; From b7e1495516a13778af5583822beec812abc99413 Mon Sep 17 00:00:00 2001 From: magicDGS Date: Sun, 23 Apr 2017 17:34:24 +0200 Subject: [PATCH 3/5] Update javadoc --- src/main/java/htsjdk/tribble/index/Index.java | 3 ++- src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/htsjdk/tribble/index/Index.java b/src/main/java/htsjdk/tribble/index/Index.java index c5a63ff6e..51982c6d2 100644 --- a/src/main/java/htsjdk/tribble/index/Index.java +++ b/src/main/java/htsjdk/tribble/index/Index.java @@ -92,11 +92,11 @@ public default void write(final File idxFile) throws IOException { /** * Write an appropriately named and located Index file based on the name and location of the featureFile. - * If featureFile is not a normal file, the index will silently not be written. * * Default implementation delegates to {@link #writeBasedOnFeaturePath(Path)} * * @param featureFile + * @throws IOException if featureFile is not a normal file. */ public default void writeBasedOnFeatureFile(File featureFile) throws IOException { writeBasedOnFeaturePath(featureFile.toPath()); @@ -107,6 +107,7 @@ public default void writeBasedOnFeatureFile(File featureFile) throws IOException * If featureFile is not a normal file, the index will silently not be written. * * @param featurePath + * @throws IOException if featureFile is not a normal file. */ public void writeBasedOnFeaturePath(Path featurePath) throws IOException; diff --git a/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java b/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java index 435144592..d7cc31cef 100644 --- a/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java +++ b/src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java @@ -224,6 +224,7 @@ public void write(final Path tabixPath) throws IOException { * Writes to a path with appropriate name and directory based on feature path. * * @param featurePath Path being indexed. + * @throws IOException if featureFile is not a normal file. */ @Override public void writeBasedOnFeaturePath(final Path featurePath) throws IOException { From 06074a516e6f26c00a32c9b66e7e9a3ec4b9625a Mon Sep 17 00:00:00 2001 From: magicDGS Date: Sun, 23 Apr 2017 17:35:04 +0200 Subject: [PATCH 4/5] Add test to exercise the new behaviour --- src/test/java/htsjdk/tribble/index/IndexTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/htsjdk/tribble/index/IndexTest.java b/src/test/java/htsjdk/tribble/index/IndexTest.java index 06fb311a5..b9e47bd4a 100644 --- a/src/test/java/htsjdk/tribble/index/IndexTest.java +++ b/src/test/java/htsjdk/tribble/index/IndexTest.java @@ -121,4 +121,13 @@ public void testWritePathIndex(final File inputFile, final IndexFactory.IndexTyp } } } + + @Test(dataProvider = "writeIndexData") + public void testWriteBasedOnNonRegularFeatureFile(final File inputFile, final IndexFactory.IndexType type, final FeatureCodec codec) throws Exception { + final File tmpFolder = IOUtil.createTempDir("NonRegultarFeatureFile", null); + // create the index + final Index index = IndexFactory.createIndex(inputFile, codec, type); + // try to write based on the tmpFolder + Assert.assertThrows(IOException.class, () -> index.writeBasedOnFeatureFile(tmpFolder)); + } } From 9ca384636be9f354f057d194b776f568a5656728 Mon Sep 17 00:00:00 2001 From: magicDGS Date: Sun, 23 Apr 2017 17:51:14 +0200 Subject: [PATCH 5/5] Fix import --- src/test/java/htsjdk/tribble/index/IndexTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/htsjdk/tribble/index/IndexTest.java b/src/test/java/htsjdk/tribble/index/IndexTest.java index b9e47bd4a..d1ff18eb7 100644 --- a/src/test/java/htsjdk/tribble/index/IndexTest.java +++ b/src/test/java/htsjdk/tribble/index/IndexTest.java @@ -3,6 +3,7 @@ import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; import htsjdk.HtsjdkTest; +import htsjdk.samtools.util.IOUtil; import htsjdk.tribble.FeatureCodec; import htsjdk.tribble.TestUtils; import htsjdk.tribble.Tribble;