Package net.sf.samtools.util

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


   *
   * @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

                    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

        stream.mark(buffSize);
        final byte[] buffer = new byte[buffSize];
        readBytes(stream, buffer, 0, buffSize);
        stream.reset();
        final byte[] magicBuf = new byte[4];
        final int magicLength = readBytes(new BlockCompressedInputStream(new ByteArrayInputStream(buffer)), magicBuf, 0, 4);
        return magicLength == BAMFileConstants.BAM_MAGIC.length && Arrays.equals(BAMFileConstants.BAM_MAGIC, magicBuf);
    }
View Full Code Here

     *
     * @param args Command line arguments
     */
    public static void main(String[] args) throws IOException {
        String filename = args[0];
        BlockCompressedInputStream stream =
                new BlockCompressedInputStream(new File(filename));
        DataInputStream in = new DataInputStream(stream);
        WarcRecord warcRecord = null;
        Vector<long[]> markers = new Vector<long[]>();
        while ((warcRecord = readNextWarcRecord(in)) != null) {
            //System.out.println(warcRecord.toString());
            markers.add(new long[]{warcRecord.getStartMarker(), warcRecord.getStopMarker()});
        }
        stream.close();

        // check if we can read the substreams from the markers
        for (Iterator<long[]> iterator = markers.iterator(); iterator.hasNext(); ) {
            long[] ls = iterator.next();
            stream =
                    new BlockCompressedInputStream(new File(filename));
            SegmentedInputStream sis = new SegmentedInputStream(stream, ls[0], ls[1]);
            in = new DataInputStream(sis);
            while ((warcRecord = readNextWarcRecord(in)) != null) {
                System.out.println(warcRecord.toString());
                WarcHTMLResponseRecord w = new WarcHTMLResponseRecord(warcRecord);
                if (w.isHTMLResponse()) {
                    //System.out.println(w.getHTMLContent());

                    // See how the parsed content looks like
                    BulletParser parser = new BulletParser(TRECParsingFactory.INSTANCE);
                    ComposedCallbackBuilder composedBuilder = new ComposedCallbackBuilder();
                    StructuredTextExtractor textExtractor = new StructuredTextExtractor();
                    composedBuilder.add(textExtractor);
                    parser.setCallback(composedBuilder.compose());
                    parser.parse(w.getHTMLContent().toCharArray());
                    System.out.println(textExtractor.getText());
                }
            }
            in.close();
            stream.close();
        }

    }
View Full Code Here

            throws IOException {
        if (compression == null) compression = Compression.NONE;

        switch (compression) {
            case BLOCK_GZIP:
                return new BlockCompressedInputStream(new File(fileName));
            case GZIP:
                return new GZIPInputStream(new FileInputStream(fileName));
            case XZ:
                return new SeekableXZInputStream(new SeekableFileInputStream(fileName));
            case NONE:
View Full Code Here

   *
   * @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

   *
   * @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

TOP

Related Classes of net.sf.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.