# Class FQZCompEncode

java.lang.Object
htsjdk.samtools.cram.compression.fqzcomp.FQZCompEncode

public class FQZCompEncode extends Object
Encoder for the CRAM 3.1 FQZComp quality score compression codec. Uses an adaptive arithmetic (range) coder with a 16-bit context model built from quality history, position within read, and optionally delta and selector information.

The encoder analyzes quality data to select context model parameters, matching the adaptive parameter training in htslib's `fqz_pick_parameters` (`fqzcomp_qual.c`). Features:

- Quality map for sparse symbol sets (e.g., NovaSeq 4-bin quality)
- Delta table with approximate-sqrt mapping for running quality difference context
- Symbol-count-based tuning (NovaSeq, HiSeqX, small datasets)
- Duplicate detection for consecutive identical quality strings
- Quality reversal for reverse-complemented reads (GFLAG_DO_REV)
- Fixed-length read optimization

See Also:
  - `FQZCompDecode`
  - CRAM 3.1 specification

## Constructor Summary

Constructors
Constructor
Description
`FQZCompEncode()`

## Method Summary

Modifier and Type
Method
Description
`ByteBuffer`
`compress(ByteBuffer inBuffer, int[] recordLengths)`
Compress concatenated quality scores using the FQZComp codec.
`ByteBuffer`
`compress(ByteBuffer inBuffer, int[] recordLengths, int[] bamFlags)`
Compress concatenated quality scores using the FQZComp codec with per-record BAM flags.
`static void`
`storeArray(ByteBuffer outBuffer, int[] array, int size)`
Serialize an array using the two-level run-length encoding used by FQZComp for tables.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### FQZCompEncode

public FQZCompEncode()

## Method Details

### compress

public ByteBuffer compress(ByteBuffer inBuffer, int[] recordLengths)
Compress concatenated quality scores using the FQZComp codec.

Parameters:
  `inBuffer` - concatenated quality scores for all records (position to limit is compressed)
  `recordLengths` - per-record quality score lengths; sum must equal inBuffer.remaining()
Returns:
  a rewound ByteBuffer containing the compressed data

### compress

public ByteBuffer compress(ByteBuffer inBuffer, int[] recordLengths, int[] bamFlags)
Compress concatenated quality scores using the FQZComp codec with per-record BAM flags.

Parameters:
  `inBuffer` - concatenated quality scores for all records (position to limit is compressed)
  `recordLengths` - per-record quality score lengths; sum must equal inBuffer.remaining()
  `bamFlags` - per-record BAM flags (for reverse-complement and dedup detection), or null
Returns:
  a rewound ByteBuffer containing the compressed data

### storeArray

public static void storeArray(ByteBuffer outBuffer, int[] array, int size)
Serialize an array using the two-level run-length encoding used by FQZComp for tables. This is the inverse of `FQZUtils.readArray(ByteBuffer, int[], int)`.

Parameters:
  `outBuffer` - output buffer to write to
  `array` - the array to serialize
  `size` - number of elements to serialize