Beispiel #1
0
 public void createIndex(File fn) throws Exception {
   BlockCompressedInputStream fp = new BlockCompressedInputStream(fn);
   makeIndex(fp);
   fp.close();
   File indexFile = new File(fn + ".tbi");
   BlockCompressedOutputStream fpidx = new BlockCompressedOutputStream(indexFile);
   saveIndex(fpidx);
   fpidx.close();
 }
Beispiel #2
0
  private void saveIndex(BlockCompressedOutputStream fp) throws IOException {
    fp.write("TBI\1".getBytes(LATIN1));
    writeInt(fp, binningIndex.size());

    // Write the ti_conf_t
    writeInt(fp, mPreset);
    writeInt(fp, mSc);
    writeInt(fp, mBc);
    writeInt(fp, mEc);
    writeInt(fp, mMeta);
    writeInt(fp, mSkip);

    // Write sequence dictionary.  Since mChr2tid is a LinkedHashmap, the keyset
    // will be returned in insertion order.
    int l = 0;
    for (String k : mChr2tid.keySet()) {
      l += k.length() + 1;
    }
    writeInt(fp, l);
    for (String k : mChr2tid.keySet()) {
      fp.write(k.getBytes(LATIN1));
      fp.write(0);
    }

    for (int i = 0; i < mChr2tid.size(); i++) {
      Map<Integer, List<TPair64>> binningForChr = binningIndex.get(i);

      // Write the binning index.
      writeInt(fp, binningForChr.size());
      for (int k : binningForChr.keySet()) {
        List<TPair64> p = binningForChr.get(k);
        writeInt(fp, k);
        writeInt(fp, p.size());
        for (TPair64 bin : p) {
          writeLong(fp, bin.u);
          writeLong(fp, bin.v);
        }
      }
      // Write the linear index.
      List<Long> linearForChr = linearIndex.get(i);
      writeInt(fp, linearForChr.size());
      for (int x = 0; x < linearForChr.size(); x++) {
        writeLong(fp, linearForChr.get(x));
      }
    }
  }