Search in sources :

Example 6 with BlockCompressedInputStream

use of htsjdk.samtools.util.BlockCompressedInputStream in project jvarkit by lindenb.

the class FindCorruptedFiles method testVcf.

private void testVcf(File f) {
    LOG.fine("Test VCF for " + f);
    Exception error1 = null;
    BlockCompressedInputStream in1 = null;
    try {
        in1 = new BlockCompressedInputStream(f);
        testVcf(f, in1);
    } catch (Exception err) {
        error1 = err;
    } finally {
        if (in1 != null)
            try {
                in1.close();
                in1 = null;
            } catch (IOException e) {
            }
    }
    if (error1 == null) {
        try {
            BlockCompressedInputStream.FileTermination type = BlockCompressedInputStream.checkTermination(f);
            if (type != BlockCompressedInputStream.FileTermination.HAS_TERMINATOR_BLOCK) {
                LOG.warning("bgz:" + type + " for " + f);
                stdout().println(f);
                return;
            }
        } catch (Exception err) {
            stdout().println(f);
            return;
        }
        // TEST BGZF termination
        return;
    }
    GZIPInputStream in2 = null;
    try {
        in2 = new GZIPInputStream(new FileInputStream(f));
        testVcf(f, in2);
        LOG.warning("gzip but not bgzip :" + f);
        return;
    } catch (Exception err) {
        err.printStackTrace();
    } finally {
        if (in2 != null)
            try {
                in2.close();
            } catch (IOException e) {
            }
    }
    LOG.fine("Not a BGZIP file / Error in VCF: " + f);
    stdout().println(f);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) IOException(java.io.IOException) BlockCompressedInputStream(htsjdk.samtools.util.BlockCompressedInputStream) TribbleException(htsjdk.tribble.TribbleException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

BlockCompressedInputStream (htsjdk.samtools.util.BlockCompressedInputStream)6 IOException (java.io.IOException)5 GZIPInputStream (java.util.zip.GZIPInputStream)3 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)2 LineIterator (htsjdk.tribble.readers.LineIterator)2 VariantContext (htsjdk.variant.variantcontext.VariantContext)2 VCFHeader (htsjdk.variant.vcf.VCFHeader)2 FileInputStream (java.io.FileInputStream)2 PushbackInputStream (java.io.PushbackInputStream)2 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)1 BlockCompressedOutputStream (htsjdk.samtools.util.BlockCompressedOutputStream)1 TribbleException (htsjdk.tribble.TribbleException)1 AsciiLineReader (htsjdk.tribble.readers.AsciiLineReader)1 LineIteratorImpl (htsjdk.tribble.readers.LineIteratorImpl)1 SynchronousLineReader (htsjdk.tribble.readers.SynchronousLineReader)1 TabixReader (htsjdk.tribble.readers.TabixReader)1 Allele (htsjdk.variant.variantcontext.Allele)1 Genotype (htsjdk.variant.variantcontext.Genotype)1 AbstractVCFCodec (htsjdk.variant.vcf.AbstractVCFCodec)1 VCFCodec (htsjdk.variant.vcf.VCFCodec)1