Permalink
Browse files
Fix BEDCodec.canDecode() to handle block-compressed extensions (#704)
fix BEDCodec.canDecode to handle block-compressed extensions
- Loading branch information...
|
|
@@ -23,6 +23,7 @@ |
|
|
*/
|
|
|
package htsjdk.tribble.bed;
|
|
|
|
|
|
+import htsjdk.tribble.AbstractFeatureReader;
|
|
|
import htsjdk.tribble.AsciiFeatureCodec;
|
|
|
import htsjdk.tribble.annotation.Strand;
|
|
|
import htsjdk.tribble.index.tabix.TabixFormat;
|
|
|
@@ -40,6 +41,9 @@ |
|
|
*/
|
|
|
public class BEDCodec extends AsciiFeatureCodec<BEDFeature> {
|
|
|
|
|
|
+ /** Default extension for BED files. */
|
|
|
+ public static final String BED_EXTENSION = ".bed";
|
|
|
+
|
|
|
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\t|( +)");
|
|
|
private final int startOffsetValue;
|
|
|
|
|
|
@@ -197,7 +201,13 @@ private void createExons(int start, String[] tokens, FullBEDFeature gene, |
|
|
|
|
|
@Override
|
|
|
public boolean canDecode(final String path) {
|
|
|
- return path.toLowerCase().endsWith(".bed");
|
|
|
+ final String toDecode;
|
|
|
+ if (AbstractFeatureReader.hasBlockCompressedExtension(path)) {
|
|
|
+ toDecode = path.substring(0, path.lastIndexOf("."));
|
|
|
+ } else {
|
|
|
+ toDecode = path;
|
|
|
+ }
|
|
|
+ return toDecode.toLowerCase().endsWith(BED_EXTENSION);
|
|
|
}
|
|
|
|
|
|
public int getStartOffset() {
|
|
|
|
|
|
@@ -226,4 +226,15 @@ private void createIndex(File testFile, File idxFile) throws IOException { |
|
|
public void testGetTabixFormat() {
|
|
|
Assert.assertEquals(new BEDCodec().getTabixFormat(), TabixFormat.BED);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCanDecode() {
|
|
|
+ final BEDCodec codec = new BEDCodec();
|
|
|
+ final String pattern = "filename.%s%s";
|
|
|
+ for(final String bcExt: AbstractFeatureReader.BLOCK_COMPRESSED_EXTENSIONS) {
|
|
|
+ Assert.assertTrue(codec.canDecode(String.format(pattern, "bed", bcExt)));
|
|
|
+ Assert.assertFalse(codec.canDecode(String.format(pattern, "vcf", bcExt)));
|
|
|
+ Assert.assertFalse(codec.canDecode(String.format(pattern, "bed.gzip", bcExt)));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
0 comments on commit
fb1ba06