Class TrialCompressor
java.lang.Object
htsjdk.samtools.cram.compression.ExternalCompressor
htsjdk.samtools.cram.compression.TrialCompressor
An
ExternalCompressor that tries multiple candidate compressors and selects the one
that produces the smallest output. Matches htslib's trial compression approach.
Not thread-safe. Instances must not be shared across threads.
- Trial phase (
nTrialsnon-empty blocks): compresses with ALL candidates, picks the smallest for each block, and accumulates sizes to determine the overall winner. - Production phase (next
trialSpanblocks): uses the cached winner only. - Re-trial: after
trialSpanblocks, re-enters the trial phase to adapt to changing data characteristics.
The compression method is initially null and is set after the first non-empty block is
compressed. Calling ExternalCompressor.getMethod() before any non-empty compress(byte[], CRAMCodecModelContext) call will
throw IllegalStateException.
- See Also:
-
Field Summary
Fields inherited from class ExternalCompressor
NO_COMPRESSION_ARG -
Constructor Summary
ConstructorsConstructorDescriptionTrialCompressor(List<ExternalCompressor> candidates) Create a trial compressor with the given candidate compressors. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]compress(byte[] data, CRAMCodecModelContext contextModel) Compress data.byte[]uncompress(byte[] data) Decompress data.Methods inherited from class ExternalCompressor
equals, getCompressorForMethod, getMethod, hashCode, setMethod, toString
-
Constructor Details
-
TrialCompressor
Create a trial compressor with the given candidate compressors.- Parameters:
candidates- the candidate compressors to try (must have at least 2)
-
-
Method Details
-
compress
Compress data. During the trial phase, tries all candidates and accumulates size statistics. AfternTrialsnon-empty blocks, selects the overall winner and uses it exclusively until the next re-trial.- Specified by:
compressin classExternalCompressor- Parameters:
data- the data to compresscontextModel- optional codec context model- Returns:
- the compressed data from the best compressor for this block
-
uncompress
public byte[] uncompress(byte[] data) Decompress data. Delegates to the winner if one has been selected, otherwise to the first candidate. In practice, decompression is handled by the method-specific decompressor selected based on the block's compression method ID, not through this trial compressor.- Specified by:
uncompressin classExternalCompressor- Parameters:
data- the compressed data- Returns:
- the decompressed data
-