Package htsjdk.samtools.util

Examples of htsjdk.samtools.util.BlockCompressedInputStream


        try {
            // If the file ends with ".gz" assume it is a tabix indexed file
            if (locator.getURLPath().toLowerCase().endsWith(".gz")) {
                // NOTE:  MUST USE THE PICARD VERSION OF ParsingUtils.  The IGV version will return a gzip stream.
                reader = new BufferedReader(new InputStreamReader(new BlockCompressedInputStream(
                        htsjdk.tribble.util.ParsingUtils.openInputStream(path))));
            } else {
                reader = ParsingUtils.openBufferedReader(path);
            }
            // Look for fileformat directive.  This should be the first line, but just in case check the first 20
View Full Code Here


        WalkerTestSpec spec = new WalkerTestSpec("-T UnifiedGenotyper -R " + b37KGReference + " -I "
                + privateTestDir + "PCRFree.2x250.Illumina.20_10_11.bam"
                + " -o %s -L 20:10,000,000-10,100,000 -nt 4",
                1, Arrays.asList("vcf.gz"), Arrays.asList(""));
        final File vcf = executeTest("testCompressedVCFOutputWithNT", spec).first.get(0);
        final AsciiLineReader reader = new AsciiLineReader(new BlockCompressedInputStream(vcf));
        int nLines = 0;
        while ( reader.readLine() != null )
            nLines++;
        Assert.assertTrue(nLines > 0);
    }
View Full Code Here

        this.blockPositions.add(0L);

        try {
            if(validate) {
                System.out.printf("BlockInputStream %s: BGZF block validation mode activated%n",this);
                validatingInputStream = new BlockCompressedInputStream(reader.samFile);
                // A bug in ValidatingInputStream means that calling getFilePointer() immediately after initialization will result in an NPE.
                // Poke the stream to start reading data.
                validatingInputStream.available();
            }
            else
View Full Code Here

        final byte[] buffer = new byte[BAM_MAGIC.length];
        try {
            InputStream fstream = new BufferedInputStream(new FileInputStream(file));
            if ( !BlockCompressedInputStream.isValidFile(fstream) )
                return false;
            final BlockCompressedInputStream BCIS = new BlockCompressedInputStream(fstream);
            BCIS.read(buffer, 0, BAM_MAGIC.length);
            BCIS.close();
            return Arrays.equals(buffer, BAM_MAGIC);
        } catch ( IOException e ) {
            return false;
        } catch ( htsjdk.samtools.FileTruncatedException e ) {
            return false;
View Full Code Here

                // a) It's good to check that the end of the file is valid and b) we need to know if there's a terminator block and not copy it
                final BlockCompressedInputStream.FileTermination term = BlockCompressedInputStream.checkTermination(f);
                if (term == BlockCompressedInputStream.FileTermination.DEFECTIVE) throw new PicardException(f.getAbsolutePath() + " does not have a valid GZIP block at the end of the file.");

                if (!isFirstFile) {
                    final BlockCompressedInputStream blockIn = new BlockCompressedInputStream(in, false);
                    boolean lastByteNewline = true;

                    while (in.available() > 0) {
                        // Read a block - blockIn.available() is guaranteed to return the bytes remaining in the block that has been
                        // read, and since we haven't consumed any yet, that is the block size.
                        final int blockLength = blockIn.available();
                        final byte[] blockContents = new byte[blockLength];
                        final int read = blockIn.read(blockContents);
                        if (blockLength == 0 || read != blockLength) throw new IllegalStateException("Could not read available bytes from BlockCompressedInputStream.");

                        // Scan forward within the block to see if we can find the end of the header within this block
                        int firstNonHeaderByteIndex = -1;
                        for (int i=0; i<read; ++i) {
View Full Code Here

    }

    public static long getNumberOfClusters(final File file) {
        InputStream stream = null;
        try {
            if (isBlockGzipped(file)) stream = new BlockCompressedInputStream(IOUtil.maybeBufferedSeekableStream(file));
            else if (isGzipped(file)) stream = new GZIPInputStream(IOUtil.maybeBufferInputStream(new FileInputStream(file)));
            else stream = IOUtil.maybeBufferInputStream(new FileInputStream(file));

            return getNumberOfClusters(file.getAbsolutePath(), stream);
View Full Code Here

        try {
            // Open up a buffered stream to read from the file and optionally wrap it in a gzip stream
            // if necessary
            if (isBgzf) {
                // Only BlockCompressedInputStreams can seek, and only if they are fed a SeekableStream.
                return new BlockCompressedInputStream(IOUtil.maybeBufferedSeekableStream(file));
            } else if (isGzip) {
                if (seekable) {
                    throw new IllegalArgumentException(
                            String.format("Cannot create a seekable reader for gzip bcl: %s.", filePath)
                    );
View Full Code Here

TOP

Related Classes of htsjdk.samtools.util.BlockCompressedInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.