Skip to content

Commit

Permalink
Add Range encode and decode for EXT flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-puligundla committed Jan 12, 2023
1 parent 119c76e commit c06f952
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public ByteBuffer uncompressStream(final ByteBuffer inBuffer, int outSize) {
return ByteBuffer.wrap(data);
} else if (rangeParams.isExternalCompression()){
byte[] extCompressedBytes = new byte[inBuffer.remaining()];
inBuffer.get( extCompressedBytes,inBuffer.position(), inBuffer.remaining());
int extCompressedBytesIdx = 0;
int start = inBuffer.position();
int end = inBuffer.limit();
for (int i = start; i < end; i++) {
extCompressedBytes[extCompressedBytesIdx] = inBuffer.get();
extCompressedBytesIdx++;
}
uncompressEXT(extCompressedBytes, outBuffer);
} else if (rangeParams.isRLE()){
switch (rangeParams.getOrder()) {
Expand All @@ -90,8 +96,7 @@ public ByteBuffer uncompressStream(final ByteBuffer inBuffer, int outSize) {
if (rangeParams.isPack() && packMappingTable.length > 0) {
outBuffer = decodePack(outBuffer, packMappingTable, numSymbols, packDataLength);
}

outBuffer.position(0);
outBuffer.rewind();
return outBuffer;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package htsjdk.samtools.cram.compression.range;

import htsjdk.samtools.cram.CRAMException;
import htsjdk.samtools.cram.compression.BZIP2ExternalCompressor;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
Expand All @@ -15,7 +16,7 @@ public ByteBuffer compress(final ByteBuffer inBuffer, final RangeParams rangePar
return EMPTY_BUFFER;
}

final ByteBuffer outBuffer = allocateOutputBuffer(inBuffer.remaining());
ByteBuffer outBuffer = allocateOutputBuffer(inBuffer.remaining());
outBuffer.order(ByteOrder.BIG_ENDIAN);
final int formatFlags = rangeParams.getFormatFlags();
outBuffer.put((byte) (formatFlags));
Expand Down Expand Up @@ -67,8 +68,14 @@ public ByteBuffer compress(final ByteBuffer inBuffer, final RangeParams rangePar
outBuffer.rewind(); // set position to 0
return outBuffer;
} else if (rangeParams.isExternalCompression()){

// TODO
byte[] rawBytes = new byte[inputBuffer.remaining()];
inputBuffer.get( rawBytes,inBuffer.position(), inputBuffer.remaining());
final BZIP2ExternalCompressor compressor = new BZIP2ExternalCompressor();
final byte [] extCompressedBytes = compressor.compress(rawBytes);
outBuffer.put(extCompressedBytes);
outBuffer.limit(outBuffer.position());
outBuffer.rewind(); // set position to 0
return outBuffer;
} else if (rangeParams.isRLE()){
switch (rangeParams.getOrder()) {
case ZERO:
Expand All @@ -85,17 +92,7 @@ public ByteBuffer compress(final ByteBuffer inBuffer, final RangeParams rangePar
}

}

// // step 1: Encode meta-data
// var pack_meta
// if (flags & ARITH_PACK)
// [pack_meta, src, e_len] = this.encodePack(src)
//
// // step 2: Write any meta data
// if (flags & ARITH_PACK)
// this.stream.WriteStream(pack_meta)

return inBuffer;
return outBuffer;
}

private ByteBuffer compressOrder0 (
Expand Down Expand Up @@ -268,7 +265,6 @@ private ByteBuffer compressRLEOrder1 (
return outBuffer;
}


protected ByteBuffer allocateOutputBuffer(final int inSize) {

// same as the allocateOutputBuffer in RANS4x8Encode and RANSNx16Encode
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/htsjdk/samtools/cram/CRAMInteropTestUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package htsjdk.samtools.cram;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public Object[][] getRangeCodecs() {
RangeParams.PACK_FLAG_MASK,
RangeParams.PACK_FLAG_MASK | RangeParams. ORDER_FLAG_MASK,
RangeParams.PACK_FLAG_MASK | RangeParams.RLE_FLAG_MASK,
RangeParams.PACK_FLAG_MASK | RangeParams.RLE_FLAG_MASK | RangeParams.ORDER_FLAG_MASK);
RangeParams.PACK_FLAG_MASK | RangeParams.RLE_FLAG_MASK | RangeParams.ORDER_FLAG_MASK,
RangeParams.EXT_FLAG_MASK,
RangeParams.EXT_FLAG_MASK | RangeParams.PACK_FLAG_MASK);
final List<Object[]> testCases = new ArrayList<>();
for (Integer rangeParamsFormatFlag : rangeParamsFormatFlagList) {
Object[] objects = new Object[]{
Expand Down

0 comments on commit c06f952

Please sign in to comment.