use of htsjdk.variant.bcf2.BCF2Codec in project gatk by broadinstitute.
the class GenomicsDBImportIntegrationTest method testPreserveContigOrderingInHeader.
@Test
public void testPreserveContigOrderingInHeader() throws IOException {
final String workspace = createTempDir("testPreserveContigOrderingInHeader-").getAbsolutePath() + "/workspace";
writeToGenomicsDB(Arrays.asList(GENOMICSDB_TEST_DIR + "testHeaderContigLineSorting1.g.vcf", GENOMICSDB_TEST_DIR + "testHeaderContigLineSorting2.g.vcf"), new SimpleInterval("chr20", 17959479, 17959479), workspace, 0, false, 0);
try (final GenomicsDBFeatureReader<VariantContext, PositionalBufferedStream> genomicsDBFeatureReader = new GenomicsDBFeatureReader<>(new File(workspace, GenomicsDBConstants.DEFAULT_VIDMAP_FILE_NAME).getAbsolutePath(), new File(workspace, GenomicsDBConstants.DEFAULT_CALLSETMAP_FILE_NAME).getAbsolutePath(), workspace, GenomicsDBConstants.DEFAULT_ARRAY_NAME, b38_reference_20_21, null, new BCF2Codec());
final AbstractFeatureReader<VariantContext, LineIterator> inputGVCFReader = AbstractFeatureReader.getFeatureReader(GENOMICSDB_TEST_DIR + "testHeaderContigLineSorting1.g.vcf", new VCFCodec(), true)) {
final SAMSequenceDictionary dictionaryFromGenomicsDB = ((VCFHeader) genomicsDBFeatureReader.getHeader()).getSequenceDictionary();
final SAMSequenceDictionary dictionaryFromInputGVCF = ((VCFHeader) inputGVCFReader.getHeader()).getSequenceDictionary();
Assert.assertEquals(dictionaryFromGenomicsDB, dictionaryFromInputGVCF, "Sequence dictionary from GenomicsDB does not match original sequence dictionary from input GVCF");
}
}
use of htsjdk.variant.bcf2.BCF2Codec in project gatk by broadinstitute.
the class GenomicsDBImportIntegrationTest method checkGenomicsDBAgainstExpected.
private static void checkGenomicsDBAgainstExpected(final String workspace, final SimpleInterval interval, final String expectedCombinedVCF) throws IOException {
final GenomicsDBFeatureReader<VariantContext, PositionalBufferedStream> genomicsDBFeatureReader = new GenomicsDBFeatureReader<>(new File(workspace, GenomicsDBConstants.DEFAULT_VIDMAP_FILE_NAME).getAbsolutePath(), new File(workspace, GenomicsDBConstants.DEFAULT_CALLSETMAP_FILE_NAME).getAbsolutePath(), workspace, GenomicsDBConstants.DEFAULT_ARRAY_NAME, b38_reference_20_21, null, new BCF2Codec());
final AbstractFeatureReader<VariantContext, LineIterator> combinedVCFReader = AbstractFeatureReader.getFeatureReader(expectedCombinedVCF, new VCFCodec(), true);
try (CloseableTribbleIterator<VariantContext> actualVcs = genomicsDBFeatureReader.query(interval.getContig(), interval.getStart(), interval.getEnd());
CloseableTribbleIterator<VariantContext> expectedVcs = combinedVCFReader.query(interval.getContig(), interval.getStart(), interval.getEnd())) {
BaseTest.assertCondition(actualVcs, expectedVcs, (a, e) -> {
// TODO: Temporary hacks to make this test pass. Must be removed later
if (// allele order
e.getStart() != 17967343 && e.getStart() != 17966384 && // split block
e.getEnd() != 17981447) {
VariantContextTestUtils.assertVariantContextsAreEqual(a, e, Collections.emptyList());
}
});
}
}
use of htsjdk.variant.bcf2.BCF2Codec in project gatk by broadinstitute.
the class FeatureDataSource method getGenomicsDBFeatureReader.
private static FeatureReader<VariantContext> getGenomicsDBFeatureReader(final String path, final File reference) {
if (!isGenomicsDBPath(path)) {
throw new IllegalArgumentException("Trying to create a GenomicsDBReader from a non-GenomicsDB input");
}
final String noheader = path.replace(GENOMIC_DB_URI_SCHEME, "");
final File workspace = new File(noheader);
final File callsetJson = new File(noheader, GenomicsDBConstants.DEFAULT_CALLSETMAP_FILE_NAME);
final File vidmapJson = new File(noheader, GenomicsDBConstants.DEFAULT_VIDMAP_FILE_NAME);
if (!workspace.exists() || !workspace.canRead() || !workspace.isDirectory()) {
throw new UserException("GenomicsDB workspace " + workspace.getAbsolutePath() + " does not exist, " + " is not readable, or is not a directory");
}
try {
IOUtils.canReadFile(callsetJson);
IOUtils.canReadFile(vidmapJson);
} catch (UserException.CouldNotReadInputFile e) {
throw new UserException("Couldn't connect to GenomicsDB because the vidmap and/or callset JSON files (" + GenomicsDBConstants.DEFAULT_VIDMAP_FILE_NAME + " and " + GenomicsDBConstants.DEFAULT_CALLSETMAP_FILE_NAME + ") could not be read from GenomicsDB workspace " + workspace.getAbsolutePath(), e);
}
try {
return new GenomicsDBFeatureReader<>(vidmapJson.getAbsolutePath(), callsetJson.getAbsolutePath(), workspace.getAbsolutePath(), GenomicsDBConstants.DEFAULT_ARRAY_NAME, reference.getAbsolutePath(), null, new BCF2Codec());
} catch (final IOException e) {
throw new UserException("Couldn't create GenomicsDBFeatureReader", e);
}
}
Aggregations