From 7be8116e21a02bf483b306a04627e917b04ed6ca Mon Sep 17 00:00:00 2001 From: pnvaidya Date: Thu, 2 Feb 2017 11:02:38 -0500 Subject: [PATCH] InflaterFactory added --- .idea/misc.xml | 3 + build.gradle | 2 +- .../gkl/compression/IntelInflaterFactory.java | 37 ++++++++++ src/main/native/compression/IntelInflater.cc | 2 +- .../gkl/compression/InflaterUnitTest.java | 70 +++++++++++++++++++ 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/intel/gkl/compression/IntelInflaterFactory.java create mode 100644 src/test/java/com/intel/gkl/compression/InflaterUnitTest.java diff --git a/.idea/misc.xml b/.idea/misc.xml index cd0eadb1..2139cc15 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + + diff --git a/build.gradle b/build.gradle index 172775b2..ae45d019 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ compileTestJava { } repositories { + maven { url uri('/home/gspowley/.m2/repository/')} mavenLocal() mavenCentral() maven { url "https://artifactory.broadinstitute.org/artifactory/libs-snapshot/" } @@ -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' } diff --git a/src/main/java/com/intel/gkl/compression/IntelInflaterFactory.java b/src/main/java/com/intel/gkl/compression/IntelInflaterFactory.java new file mode 100644 index 00000000..9ae473bc --- /dev/null +++ b/src/main/java/com/intel/gkl/compression/IntelInflaterFactory.java @@ -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; + } +} diff --git a/src/main/native/compression/IntelInflater.cc b/src/main/native/compression/IntelInflater.cc index d7a4bfef..bbf005b1 100644 --- a/src/main/native/compression/IntelInflater.cc +++ b/src/main/native/compression/IntelInflater.cc @@ -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; diff --git a/src/test/java/com/intel/gkl/compression/InflaterUnitTest.java b/src/test/java/com/intel/gkl/compression/InflaterUnitTest.java new file mode 100644 index 00000000..ceb62729 --- /dev/null +++ b/src/test/java/com/intel/gkl/compression/InflaterUnitTest.java @@ -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(); + } + } +}