Examples of BlockCompressedInputStream


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

Examples of htsjdk.samtools.util.BlockCompressedInputStream

        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

Examples of htsjdk.samtools.util.BlockCompressedInputStream

        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

Examples of htsjdk.samtools.util.BlockCompressedInputStream

        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

Examples of htsjdk.samtools.util.BlockCompressedInputStream

                // 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

Examples of htsjdk.samtools.util.BlockCompressedInputStream

    }

    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

Examples of htsjdk.samtools.util.BlockCompressedInputStream

        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

Examples of net.sf.samtools.util.BlockCompressedInputStream

   *
   * @param fn File name of the data file
   */
  public TabixReader(final String fn) throws IOException {
    mFn = fn;
    mFp = new BlockCompressedInputStream(new File(fn));
    readIndex();
  }
View Full Code Here

Examples of net.sf.samtools.util.BlockCompressedInputStream

   *
   * @param fp File pointer
   */
  public void readIndex(final File fp) throws IOException {
    if (fp == null) return;
    BlockCompressedInputStream is = new BlockCompressedInputStream(fp);
    byte[] buf = new byte[4];

    is.read(buf, 0, 4); // read "TBI\1"
    mSeq = new String[readInt(is)]; // # sequences
    mChr2tid = new HashMap<String, Integer>();
    mPreset = readInt(is);
    mSc = readInt(is);
    mBc = readInt(is);
    mEc = readInt(is);
    mMeta = readInt(is);
    mSkip = readInt(is);
    // read sequence dictionary
    int i, j, k, l = readInt(is);
    buf = new byte[l];
    is.read(buf);
    for (i = j = k = 0; i < buf.length; ++i) {
      if (buf[i] == 0) {
        byte[] b = new byte[i - j];
        System.arraycopy(buf, j, b, 0, b.length);
        String s = new String(b);
        mChr2tid.put(s, k);
        mSeq[k++] = s;
        j = i + 1;
      }
    }
    // read the index
    mIndex = new TIndex[mSeq.length];
    for (i = 0; i < mSeq.length; ++i) {
      // the binning index
      int n_bin = readInt(is);
      mIndex[i] = new TIndex();
      mIndex[i].b = new HashMap<Integer, TPair64[]>();
      for (j = 0; j < n_bin; ++j) {
        int bin = readInt(is);
        TPair64[] chunks = new TPair64[readInt(is)];
        for (k = 0; k < chunks.length; ++k) {
          long u = readLong(is);
          long v = readLong(is);
          chunks[k] = new TPair64(u, v); // in C, this is inefficient
        }
        mIndex[i].b.put(bin, chunks);
      }
      // the linear index
      mIndex[i].l = new long[readInt(is)];
      for (k = 0; k < mIndex[i].l.length; ++k)
        mIndex[i].l[k] = readLong(is);
    }
    // close
    is.close();
  }
View Full Code Here

Examples of net.sf.samtools.util.BlockCompressedInputStream

                    bufferedStream.close();
                    mReader = new BAMFileReader(file, indexFile, eagerDecode, validationStringency, this.samRecordFactory);
                }
            } else if (BlockCompressedInputStream.isValidFile(bufferedStream)) {
                mIsBinary = false;
                mReader = new SAMTextReader(new BlockCompressedInputStream(bufferedStream), validationStringency, this.samRecordFactory);
            } else if (isGzippedSAMFile(bufferedStream)) {
                mIsBinary = false;
                mReader = new SAMTextReader(new GZIPInputStream(bufferedStream), validationStringency, this.samRecordFactory);
            } else if (isSAMFile(bufferedStream)) {
                if (indexFile != null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.