Skip to content

Commit

Permalink
Use CompressionUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-puligundla committed Feb 7, 2024
1 parent a7a9b06 commit 94ea9e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package htsjdk.samtools.cram.compression.fqzcomp;

import htsjdk.samtools.cram.CRAMException;
import htsjdk.samtools.cram.compression.CompressionUtils;
import htsjdk.samtools.cram.compression.range.ByteModel;
import htsjdk.samtools.cram.compression.range.RangeCoder;
import htsjdk.samtools.cram.compression.rans.Utils;

import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand All @@ -13,7 +13,7 @@ public class FQZCompDecode {
private static final int NUMBER_OF_SYMBOLS = 256;

public static ByteBuffer uncompress( final ByteBuffer inBuffer) {
final int bufferLength = Utils.readUint7(inBuffer);
final int bufferLength = CompressionUtils.readUint7(inBuffer);
final int version = inBuffer.get() & 0xFF;
if (version != 5) {
throw new CRAMException("Invalid FQZComp format version number: " + version);
Expand Down Expand Up @@ -52,7 +52,7 @@ public static ByteBuffer uncompress( final ByteBuffer inBuffer) {
FQZParam params = null;
int last = 0;
final int[] rev = null;
final ByteBuffer outBuffer = ByteBuffer.allocate(bufferLength);
final ByteBuffer outBuffer = CompressionUtils.allocateByteBuffer(bufferLength);
while (i<bufferLength){
if (fqzState.getBases()==0) {
decodeFQZNewRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class RangeCoder {
private boolean carry;
private int cache;

protected RangeCoder() {
public RangeCoder() {
// Spec: RangeEncodeStart
this.low = 0;
this.range = Constants.MAX_RANGE; // 4 bytes of all 1's
Expand All @@ -21,7 +21,7 @@ protected RangeCoder() {
this.cache = 0;
}

protected void rangeDecodeStart(final ByteBuffer inBuffer){
public void rangeDecodeStart(final ByteBuffer inBuffer){
for (int i = 0; i < 5; i++){
code = (code << 8) + (inBuffer.get() & 0xFF);
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/htsjdk/samtools/cram/FQZCompInteropTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package htsjdk.samtools.cram;

import htsjdk.HtsjdkTest;
import htsjdk.samtools.cram.compression.CompressionUtils;
import htsjdk.samtools.cram.compression.fqzcomp.FQZCompDecode;
import org.apache.commons.compress.utils.IOUtils;
import org.testng.Assert;
Expand Down Expand Up @@ -62,8 +63,8 @@ public void testDecodeOnly(
// preprocess the uncompressed data (to match what the htscodecs-library test harness does)
// by filtering out the embedded newlines, and then round trip through FQZComp codec
// and compare the results
final ByteBuffer uncompressedInteropBytes = ByteBuffer.wrap(CRAMInteropTestUtils.filterEmbeddedNewlines(IOUtils.toByteArray(uncompressedInteropStream)));
final ByteBuffer preCompressedInteropBytes = ByteBuffer.wrap(IOUtils.toByteArray(preCompressedInteropStream));
final ByteBuffer uncompressedInteropBytes = CompressionUtils.wrap(CRAMInteropTestUtils.filterEmbeddedNewlines(IOUtils.toByteArray(uncompressedInteropStream)));
final ByteBuffer preCompressedInteropBytes = CompressionUtils.wrap(IOUtils.toByteArray(preCompressedInteropStream));

// Use htsjdk to uncompress the precompressed file from htscodecs repo
final ByteBuffer uncompressedHtsjdkBytes = fqzcompDecode.uncompress(preCompressedInteropBytes);
Expand Down

0 comments on commit 94ea9e9

Please sign in to comment.