Examples of HuffmanParamsCalculator


Examples of net.sf.cram.stats.CompressionHeaderFactory.HuffmanParamsCalculator

  @Test
  public void test() throws IOException {
    int size = 100000 ;
   
    long time5 = System.nanoTime() ;
    CompressionHeaderFactory.HuffmanParamsCalculator cal = new HuffmanParamsCalculator();
    for (int i = 0; i < size; i++) {
      cal.add(ReadTag.nameType3BytesToInt("OQ", 'Z'));
      cal.add(ReadTag.nameType3BytesToInt("X0", 'C'));
      cal.add(ReadTag.nameType3BytesToInt("X0", 'c'));
      cal.add(ReadTag.nameType3BytesToInt("X0", 's'));
      cal.add(ReadTag.nameType3BytesToInt("X1", 'C'));
      cal.add(ReadTag.nameType3BytesToInt("X1", 'c'));
      cal.add(ReadTag.nameType3BytesToInt("X1", 's'));
      cal.add(ReadTag.nameType3BytesToInt("XA", 'Z'));
      cal.add(ReadTag.nameType3BytesToInt("XC", 'c'));
      cal.add(ReadTag.nameType3BytesToInt("XT", 'A'));
      cal.add(ReadTag.nameType3BytesToInt("OP", 'i'));
      cal.add(ReadTag.nameType3BytesToInt("OC", 'Z'));
      cal.add(ReadTag.nameType3BytesToInt("BQ", 'Z'));
      cal.add(ReadTag.nameType3BytesToInt("AM", 'c'));
    }

    cal.calculate();

    CanonicalHuffmanIntegerCodec c = new CanonicalHuffmanIntegerCodec(
        cal.values(), cal.bitLens());
    long time6 = System.nanoTime() ;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DefaultBitOutputStream bos = new DefaultBitOutputStream(baos);
   
    long time1=System.nanoTime() ;
    for (int i = 0; i < size; i++) {
      for (int b : cal.values()) {
        c.write(bos, b);
      }
    }

    bos.close();
    long time2=System.nanoTime() ;

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DefaultBitInputStream bis = new DefaultBitInputStream(bais);

    long time3=System.nanoTime() ;
    for (int i = 0; i < size; i++) {
      for (int b : cal.values()) {
        int v = c.read(bis);
        if (v != b)
          fail("Mismatch: " + v + " vs " + b);
      }
    }
    long time4=System.nanoTime() ;
   
    System.out.printf("Size: %d bytes, bits per value: %.2f, create time %dms, write time %d ms, read time %d ms.", baos.size(), 8f*baos.size()/size/cal.values().length, (time6-time5)/1000000, (time2-time1)/1000000, (time4-time3)/1000000);
  }
View Full Code Here

Examples of net.sf.cram.stats.CompressionHeaderFactory.HuffmanParamsCalculator

    SAMFileReader r = new SAMFileReader(
        new File(
            "c:/temp/HG00096.mapped.illumina.mosaik.GBR.exome.20110411.chr20.bam"));
    SAMRecordIterator iterator = r.iterator();

    CompressionHeaderFactory.HuffmanParamsCalculator c = new HuffmanParamsCalculator();

    String[] names = new String [100000] ;
    for (int i = 0; i < names.length && iterator.hasNext(); i++) {
      names[i] = iterator.next().getReadName() ;
      c.add(names[i].length());
    }
    iterator.close();
    r.close();
    c.calculate();

    int[] values = c.values();
    int[] lens = c.bitLens();
    System.out.println(Arrays.toString(values));
    System.out.println(Arrays.toString(lens));

    EncodingParams params = HuffmanIntegerEncoding.toParam(values, lens);
    HuffmanIntegerEncoding e = new HuffmanIntegerEncoding();
View Full Code Here

Examples of net.sf.cram.stats.CompressionHeaderFactory.HuffmanParamsCalculator

  public static void main(String[] args) throws IOException {
    int size = 1000000;

    long time5 = System.nanoTime();
    CompressionHeaderFactory.HuffmanParamsCalculator cal = new HuffmanParamsCalculator();
    for (byte i = 33; i < 33 + 15; i++)
      cal.add(i);
    cal.calculate();

    // CanonicalHuffmanByteCodec helper = new CanonicalHuffmanByteCodec(
    // cal.valuesAsBytes(), cal.bitLens());
    HelperByte helper = new HelperByte(cal.valuesAsBytes(), cal.bitLens());
    long time6 = System.nanoTime();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DefaultBitOutputStream bos = new DefaultBitOutputStream(baos);

    long time1 = System.nanoTime();
    for (int i = 0; i < size; i++) {
      for (byte b : cal.valuesAsBytes()) {
        helper.write(bos, b);
      }
    }

    bos.close();
    long time2 = System.nanoTime();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DefaultBitInputStream bis = new DefaultBitInputStream(bais);

    long time3 = System.nanoTime();
    int counter = 0;
    for (int i = 0; i < size; i++) {
      for (int b : cal.values()) {
        int v = helper.read(bis);
        if (v != b)
          fail("Mismatch: " + v + " vs " + b + " at " + counter);

        counter++;
      }
    }
    long time4 = System.nanoTime();

    System.out
        .printf("Size: %d bytes, bits per value: %.2f, create time %dms, write time %d ms, read time %d ms.",
            baos.size(), 8f * baos.size() / size
                / cal.values().length,
            (time6 - time5) / 1000000, (time2 - time1) / 1000000,
            (time4 - time3) / 1000000);
  }
View Full Code Here

Examples of net.sf.cram.stats.CompressionHeaderFactory.HuffmanParamsCalculator

  public static void main(String[] args) throws IOException {
    int size = 1000000;

    long time5 = System.nanoTime();
    CompressionHeaderFactory.HuffmanParamsCalculator cal = new HuffmanParamsCalculator();
    cal.add(ReadTag.nameType3BytesToInt("OQ", 'Z'), size);
    cal.add(ReadTag.nameType3BytesToInt("X0", 'C'), size);
    cal.add(ReadTag.nameType3BytesToInt("X0", 'c'), size);
    cal.add(ReadTag.nameType3BytesToInt("X0", 's'), size);
    cal.add(ReadTag.nameType3BytesToInt("X1", 'C'), size);
    cal.add(ReadTag.nameType3BytesToInt("X1", 'c'), size);
    cal.add(ReadTag.nameType3BytesToInt("X1", 's'), size);
    cal.add(ReadTag.nameType3BytesToInt("XA", 'Z'), size);
    cal.add(ReadTag.nameType3BytesToInt("XC", 'c'), size);
    cal.add(ReadTag.nameType3BytesToInt("XT", 'A'), size);
    cal.add(ReadTag.nameType3BytesToInt("OP", 'i'), size);
    cal.add(ReadTag.nameType3BytesToInt("OC", 'Z'), size);
    cal.add(ReadTag.nameType3BytesToInt("BQ", 'Z'), size);
    cal.add(ReadTag.nameType3BytesToInt("AM", 'c'), size);

    cal.calculate();

    // CanonicalHuffmanIntegerCodec helper = new
    // CanonicalHuffmanIntegerCodec(
    // cal.values(), cal.bitLens());
    Helper helper = new Helper(cal.values(), cal.bitLens());
    long time6 = System.nanoTime();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DefaultBitOutputStream bos = new DefaultBitOutputStream(baos);

    long time1 = System.nanoTime();
    for (int i = 0; i < size; i++) {
      for (int b : cal.values()) {
        helper.write(bos, b);
      }
    }

    bos.close();
    long time2 = System.nanoTime();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DefaultBitInputStream bis = new DefaultBitInputStream(bais);

    long time3 = System.nanoTime();
    int counter = 0;
    for (int i = 0; i < size; i++) {
      for (int b : cal.values()) {
        int v = helper.read(bis);
        if (v != b)
          fail("Mismatch: " + v + " vs " + b + " at " + counter);

        counter++;
      }
    }
    long time4 = System.nanoTime();

    System.out
        .printf("Size: %d bytes, bits per value: %.2f, create time %dms, write time %d ms, read time %d ms.",
            baos.size(), 8f * baos.size() / size
                / cal.values().length,
            (time6 - time5) / 1000000, (time2 - time1) / 1000000,
            (time4 - time3) / 1000000);

    // String message = "12341111111111111122222223334";
    //
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.