Search in sources :

Example 1 with PositionalBufferedStream

use of htsjdk.tribble.readers.PositionalBufferedStream 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");
    }
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) VariantContext(htsjdk.variant.variantcontext.VariantContext) LineIterator(htsjdk.tribble.readers.LineIterator) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) GenomicsDBFeatureReader(com.intel.genomicsdb.GenomicsDBFeatureReader) PositionalBufferedStream(htsjdk.tribble.readers.PositionalBufferedStream) BCF2Codec(htsjdk.variant.bcf2.BCF2Codec) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 2 with PositionalBufferedStream

use of htsjdk.tribble.readers.PositionalBufferedStream in project gatk by broadinstitute.

the class GenotypeGVCFsIntegrationTest method getVariantContexts.

/**
     * Returns a list of VariantContext records from a VCF file
     *
     * @param vcfFile VCF file
     * @return list of VariantContext records
     * @throws IOException if the file does not exist or can not be opened
     */
private static List<VariantContext> getVariantContexts(final File vcfFile) throws IOException {
    final VCFCodec codec = new VCFCodec();
    final FileInputStream s = new FileInputStream(vcfFile);
    final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s));
    codec.readHeader(lineIteratorVCF);
    final List<VariantContext> VCs = new ArrayList<>();
    while (lineIteratorVCF.hasNext()) {
        final String line = lineIteratorVCF.next();
        Assert.assertFalse(line == null);
        VCs.add(codec.decode(line));
    }
    return VCs;
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) PositionalBufferedStream(htsjdk.tribble.readers.PositionalBufferedStream) ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext) LineIterator(htsjdk.tribble.readers.LineIterator) FileInputStream(java.io.FileInputStream)

Example 3 with PositionalBufferedStream

use of htsjdk.tribble.readers.PositionalBufferedStream 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());
            }
        });
    }
}
Also used : PositionalBufferedStream(htsjdk.tribble.readers.PositionalBufferedStream) VCFCodec(htsjdk.variant.vcf.VCFCodec) BCF2Codec(htsjdk.variant.bcf2.BCF2Codec) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) LineIterator(htsjdk.tribble.readers.LineIterator) GenomicsDBFeatureReader(com.intel.genomicsdb.GenomicsDBFeatureReader)

Example 4 with PositionalBufferedStream

use of htsjdk.tribble.readers.PositionalBufferedStream in project gatk-protected by broadinstitute.

the class GenotypeGVCFsIntegrationTest method getVariantContexts.

/**
     * Returns a list of VariantContext records from a VCF file
     *
     * @param vcfFile VCF file
     * @return list of VariantContext records
     * @throws IOException if the file does not exist or can not be opened
     */
private static List<VariantContext> getVariantContexts(final File vcfFile) throws IOException {
    final VCFCodec codec = new VCFCodec();
    final FileInputStream s = new FileInputStream(vcfFile);
    final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s));
    codec.readHeader(lineIteratorVCF);
    final List<VariantContext> VCs = new ArrayList<>();
    while (lineIteratorVCF.hasNext()) {
        final String line = lineIteratorVCF.next();
        Assert.assertFalse(line == null);
        VCs.add(codec.decode(line));
    }
    return VCs;
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) PositionalBufferedStream(htsjdk.tribble.readers.PositionalBufferedStream) ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext) LineIterator(htsjdk.tribble.readers.LineIterator) FileInputStream(java.io.FileInputStream)

Aggregations

LineIterator (htsjdk.tribble.readers.LineIterator)4 PositionalBufferedStream (htsjdk.tribble.readers.PositionalBufferedStream)4 VariantContext (htsjdk.variant.variantcontext.VariantContext)4 VCFCodec (htsjdk.variant.vcf.VCFCodec)4 GenomicsDBFeatureReader (com.intel.genomicsdb.GenomicsDBFeatureReader)2 BCF2Codec (htsjdk.variant.bcf2.BCF2Codec)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)1 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1 Test (org.testng.annotations.Test)1