Skip to content

Commit

Permalink
Treat .vcf.bgz as a valid vcf extension in FileExtension (#1727)
Browse files Browse the repository at this point in the history
* Fix so that .vcf.bgz is treated as a valid compressed vcf extension.
  • Loading branch information
lindenb authored Oct 29, 2024
1 parent fd56496 commit 4ea3285
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class VCFCodec implements VariantsCodec {
{
add(FileExtensions.VCF);
add(FileExtensions.COMPRESSED_VCF);
add(".vcf.bgz");
add(FileExtensions.COMPRESSED_VCF_BGZ);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static <T extends IOPath> Optional<Tuple<String, String>> getInferredCon
final String ext = extension.get();
if (ext.equals(FileExtensions.VCF)) {
return Optional.of(new Tuple<>(BundleResourceType.CT_VARIANT_CONTEXTS, BundleResourceType.FMT_VARIANTS_VCF));
} else if (ext.equals(FileExtensions.COMPRESSED_VCF)) {
} else if (ext.equals(FileExtensions.COMPRESSED_VCF) || ext.equals(FileExtensions.COMPRESSED_VCF_BGZ)) {
return Optional.of(new Tuple<>(BundleResourceType.CT_VARIANT_CONTEXTS, BundleResourceType.FMT_VARIANTS_VCF));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/htsjdk/samtools/util/FileExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public final class FileExtensions {
public static final String VCF = ".vcf";
public static final String VCF_INDEX = TRIBBLE_INDEX;
public static final String BCF = ".bcf";
public static final String COMPRESSED_VCF_BGZ = ".vcf.bgz"; // suffix used by gnomad see https://gnomad.broadinstitute.org/data#v4
public static final String COMPRESSED_VCF = ".vcf.gz";
public static final String COMPRESSED_VCF_INDEX = ".tbi";
public static final List<String> VCF_LIST = Collections.unmodifiableList(Arrays.asList(VCF, COMPRESSED_VCF, BCF));
public static final List<String> VCF_LIST = Collections.unmodifiableList(Arrays.asList(VCF, COMPRESSED_VCF, COMPRESSED_VCF_BGZ, BCF));

public static final String INTERVAL_LIST = ".interval_list";
public static final String COMPRESSED_INTERVAL_LIST = ".interval_list.gz";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void createTemporaryDirectory() {
public void testBasicWriteAndRead(final String extension) throws IOException {
final File fakeVCFFile = File.createTempFile("testBasicWriteAndRead.", extension, tempDir);
fakeVCFFile.deleteOnExit();
if (FileExtensions.COMPRESSED_VCF.equals(extension)) {
if (FileExtensions.COMPRESSED_VCF.equals(extension) || FileExtensions.COMPRESSED_VCF_BGZ.equals(extension)) {
new File(fakeVCFFile.getAbsolutePath() + FileExtensions.VCF_INDEX);
} else {
Tribble.indexFile(fakeVCFFile).deleteOnExit();
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testBasicWriteAndRead(final String extension) throws IOException {
public void testWriteAndReadVCFHeaderless(final String extension) throws IOException {
final File fakeVCFFile = File.createTempFile("testWriteAndReadVCFHeaderless.", extension, tempDir);
fakeVCFFile.deleteOnExit();
if (FileExtensions.COMPRESSED_VCF.equals(extension)) {
if (FileExtensions.COMPRESSED_VCF.equals(extension) || FileExtensions.COMPRESSED_VCF_BGZ.equals(extension)) {
new File(fakeVCFFile.getAbsolutePath() + ".tbi");
} else {
Tribble.indexFile(fakeVCFFile).deleteOnExit();
Expand All @@ -159,7 +159,7 @@ public void testWriteAndReadVCFHeaderless(final String extension) throws IOExcep
try (BlockCompressedInputStream bcis = new BlockCompressedInputStream(fakeVCFFile);
FileInputStream fis = new FileInputStream(fakeVCFFile)) {
AsciiLineReaderIterator iterator =
new AsciiLineReaderIterator(new AsciiLineReader(".vcf.gz".equals(extension) ? bcis : fis));
new AsciiLineReaderIterator(new AsciiLineReader(FileExtensions.COMPRESSED_VCF.equals(extension) || FileExtensions.COMPRESSED_VCF_BGZ.equals(extension) ? bcis : fis));
int counter = 0;
while (iterator.hasNext()) {
VariantContext context = codec.decode(iterator.next());
Expand Down Expand Up @@ -300,7 +300,7 @@ public void TestWritingLargeVCF(final String extension) throws FileNotFoundExcep

final File vcf = new File(tempDir, "test" + extension);
final String indexExtension;
if (extension.equals(FileExtensions.COMPRESSED_VCF)) {
if (extension.equals(FileExtensions.COMPRESSED_VCF) || extension.equals(FileExtensions.COMPRESSED_VCF_BGZ)) {
indexExtension = FileExtensions.TABIX_INDEX;
} else {
indexExtension = FileExtensions.TRIBBLE_INDEX;
Expand Down Expand Up @@ -333,7 +333,8 @@ public void TestWritingLargeVCF(final String extension) throws FileNotFoundExcep
// TODO: BCF doesn't work because header is not properly constructed.
// {".bcf"},
{FileExtensions.VCF},
{FileExtensions.COMPRESSED_VCF}
{FileExtensions.COMPRESSED_VCF},
{FileExtensions.COMPRESSED_VCF_BGZ}
};
}

Expand Down

0 comments on commit 4ea3285

Please sign in to comment.