Skip to content

Commit

Permalink
InflaterFactory added
Browse files Browse the repository at this point in the history
  • Loading branch information
pnvaidya committed Feb 2, 2017
1 parent 91c4ee2 commit 7be8116
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ compileTestJava {
}

repositories {
maven { url uri('/home/gspowley/.m2/repository/')}
mavenLocal()
mavenCentral()
maven { url "https://artifactory.broadinstitute.org/artifactory/libs-snapshot/" }
Expand All @@ -24,7 +25,6 @@ dependencies {
compile 'org.apache.logging.log4j:log4j-api:2.5'
compile 'org.apache.logging.log4j:log4j-core:2.5'
compile 'com.github.samtools:htsjdk:2.7.0-18-g4d0070b-SNAPSHOT'

testCompile 'org.testng:testng:6.9.9'
}

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/intel/gkl/compression/IntelInflaterFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.intel.gkl.compression;

import htsjdk.samtools.util.zip.InflaterFactory;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.util.zip.Inflater;

/**
* Created by pnvaidya on 2/1/17.
*/
public class IntelInflaterFactory extends InflaterFactory {
private final static Logger logger = LogManager.getLogger(IntelDeflaterFactory.class);
private boolean intelInflaterSupported;

public IntelInflaterFactory(File tmpDir) {
intelInflaterSupported = new IntelInflater().load(tmpDir);
}

public IntelInflaterFactory() {
this(null);
}

public Inflater makeInflater(final boolean nowrap) {
if (intelInflaterSupported) {
return new IntelInflater(nowrap);
}
logger.warn("IntelInflater is not supported, using Java.util.zip.Inflater");
return new Inflater(nowrap);
}

public boolean usingIntelInflater() {
return intelInflaterSupported;
}
}
2 changes: 1 addition & 1 deletion src/main/native/compression/IntelInflater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ JNIEXPORT void JNICALL Java_com_intel_gkl_compression_IntelInflater_resetNative



fprintf(stdout,"%c",nowrap);

isal_inflate_init(lz_stream);

lz_stream->avail_in = 0;
Expand Down
70 changes: 70 additions & 0 deletions src/test/java/com/intel/gkl/compression/InflaterUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.intel.gkl.compression;

import com.intel.gkl.IntelGKLUtils;
import htsjdk.samtools.util.BlockCompressedInputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

/**
* Created by pnvaidya on 2/1/17.
*/
public class InflaterUnitTest {

private final static Logger log = LogManager.getLogger(InflaterUnitTest.class);
private final static String INPUT_FILE = IntelGKLUtils.pathToTestResource("HiSeq.1mb.1RG.2k_lines.bam");

@Test(enabled = true)
public void integrationTest() throws IOException {

final File inputFile = new File(INPUT_FILE);
long inputBytes = inputFile.length();
int compressedBytes = 0;
final byte[] inputbuffer = new byte[(int)inputBytes];
final byte[] outputbuffer = new byte[(int)inputBytes];
final byte[] finalbuffer = new byte[(int)inputBytes];

long totalTime = 0;

for (int i = 1; i < 10; i++) {

final IntelInflaterFactory intelInflaterFactory = new IntelInflaterFactory();
final Inflater inflater = intelInflaterFactory.makeInflater(true);

final IntelDeflaterFactory intelDeflaterFactory = new IntelDeflaterFactory();
final Deflater deflater = intelDeflaterFactory.makeDeflater(i, true);


final BlockCompressedInputStream inputStream = new BlockCompressedInputStream(inputFile);

inputBytes = inputStream.read(inputbuffer, 0, inputbuffer.length);
deflater.reset();
deflater.setInput(inputbuffer, 0, inputbuffer.length);
deflater.finish();
compressedBytes = deflater.deflate(outputbuffer, 0, outputbuffer.length);


try {
inflater.reset();
inflater.setInput(outputbuffer, 0, compressedBytes);
final long start = System.currentTimeMillis();
inflater.inflate(finalbuffer, 0, inputbuffer.length);
totalTime = System.currentTimeMillis() - start;
System.out.printf("Level: %d, time: %d\n", i, totalTime);


} catch (java.util.zip.DataFormatException e) {
e.printStackTrace();
}
Assert.assertEquals(inputbuffer, finalbuffer);
inflater.end();
deflater.end();
}
}
}

0 comments on commit 7be8116

Please sign in to comment.