Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore version validation for BCF in VCFHeaderReader because we only need the header #1707

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
},
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/htsjdk/variant/utils/VCFHeaderReader.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
};
}

Expand Down
Binary file not shown.
Loading