diff --git a/src/main/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractor.java b/src/main/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractor.java index 305575a70f..d5bc5a13dc 100644 --- a/src/main/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractor.java +++ b/src/main/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractor.java @@ -29,9 +29,10 @@ import htsjdk.samtools.cram.structure.Container; import htsjdk.samtools.cram.structure.CramHeader; import htsjdk.samtools.reference.ReferenceSequenceFileFactory; +import htsjdk.samtools.seekablestream.SeekablePathStream; +import htsjdk.samtools.seekablestream.SeekableStream; import htsjdk.samtools.util.*; import htsjdk.tribble.util.ParsingUtils; -import htsjdk.variant.vcf.VCFFileReader; import java.io.File; import java.io.IOException; @@ -102,8 +103,10 @@ SAMSequenceDictionary extractDictionary(final Path sam) { @Override SAMSequenceDictionary extractDictionary(final Path vcf) { - try (VCFFileReader vcfPathReader = new VCFFileReader(vcf, false)){ - return vcfPathReader.getFileHeader().getSequenceDictionary(); + try (SeekableStream vcfSeekableStream = new SeekablePathStream(vcf)){ + return VCFHeaderReader.readHeaderFrom(vcfSeekableStream).getSequenceDictionary(); + } catch (IOException e) { + throw new RuntimeIOException(e); } } }, diff --git a/src/main/java/htsjdk/variant/utils/VCFHeaderReader.java b/src/main/java/htsjdk/variant/utils/VCFHeaderReader.java index 9d4be262d2..8749bc5f89 100644 --- a/src/main/java/htsjdk/variant/utils/VCFHeaderReader.java +++ b/src/main/java/htsjdk/variant/utils/VCFHeaderReader.java @@ -1,6 +1,5 @@ package htsjdk.variant.utils; -import htsjdk.samtools.SamStreams; import htsjdk.samtools.cram.io.InputStreamUtils; import htsjdk.samtools.seekablestream.SeekableStream; import htsjdk.samtools.util.IOUtil; @@ -30,6 +29,7 @@ private VCFHeaderReader(){} * Read a VCF header from a stream that may be a VCF file (possibly gzip or block compressed) or a BCF file. * After successfully reading a header the stream is positioned immediately after the header, otherwise, if an * exception is thrown, the state of the stream is undefined. + * For BCF files, the version validation is ignored * * @param in the stream to read the header from * @return the VCF header read from the stream @@ -43,7 +43,12 @@ public static VCFHeader readHeaderFrom(final SeekableStream in) throws IOExcepti if (magicBytes[0] == '#') { // VCF return readHeaderFrom(in, new VCFCodec()); } else if (Arrays.equals(magicBytes, BCFVersion.MAGIC_HEADER_START)) { - return readHeaderFrom(in, new BCF2Codec()); + return readHeaderFrom(in, new BCF2Codec() { + @Override + protected void validateVersionCompatibility(final BCFVersion supportedVersion, final BCFVersion actualVersion) { + // ignore validation, might be used to get samples in recent BCF + } + }); } throw new TribbleException.InvalidHeader("No VCF header found in " + in.getSource()); } diff --git a/src/test/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractorTest.java b/src/test/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractorTest.java index 7446d03d88..6b62857180 100644 --- a/src/test/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractorTest.java +++ b/src/test/java/htsjdk/variant/utils/SAMSequenceDictionaryExtractorTest.java @@ -46,6 +46,7 @@ public Object[][] dictionaries() { new Object[]{"test1_comp.interval_list", "test1.dict"}, new Object[]{"test1.vcf", "test1.dict"}, new Object[]{"test1.dict", "test1.dict"}, + new Object[]{"test1.bcf2_2.bcf", "test1.dict"}, new Object[]{"empty.interval_list", "test1.dict"}, new Object[]{"Homo_sapiens_assembly18.trimmed.fasta", "Homo_sapiens_assembly18.trimmed.dict"}, new Object[]{"test2_comp.interval_list", "Homo_sapiens_assembly18.trimmed.dict"}, diff --git a/src/test/java/htsjdk/variant/utils/VCFHeaderReaderTest.java b/src/test/java/htsjdk/variant/utils/VCFHeaderReaderTest.java index cc2c5b7545..59f6d72039 100644 --- a/src/test/java/htsjdk/variant/utils/VCFHeaderReaderTest.java +++ b/src/test/java/htsjdk/variant/utils/VCFHeaderReaderTest.java @@ -22,6 +22,7 @@ Object[][] pathsData() { {TEST_DATA_DIR + "VcfThatLacksAnIndex.vcf"}, {TEST_DATA_DIR + "VcfThatLacksAnIndex.vcf.bgz"}, {TEST_DATA_DIR + "VcfThatLacksAnIndex.vcf.gz"}, + {TEST_DATA_DIR + "BCFVersion22Uncompressed.bcf"} }; } diff --git a/src/test/resources/htsjdk/variant/utils/SamSequenceDictionaryExtractor/test1.BCF2_2.bcf b/src/test/resources/htsjdk/variant/utils/SamSequenceDictionaryExtractor/test1.BCF2_2.bcf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/resources/htsjdk/variant/utils/SamSequenceDictionaryExtractor/test1.bcf2_2.bcf b/src/test/resources/htsjdk/variant/utils/SamSequenceDictionaryExtractor/test1.bcf2_2.bcf new file mode 100644 index 0000000000..da5f5f4552 Binary files /dev/null and b/src/test/resources/htsjdk/variant/utils/SamSequenceDictionaryExtractor/test1.bcf2_2.bcf differ