Class CompressionHeaderFactory

java.lang.Object
htsjdk.samtools.cram.build.CompressionHeaderFactory

public final class CompressionHeaderFactory extends Object
Factory for creating CRAM compression headers for containers when writing to a CRAM stream. The fixed data series are generally the same for every container in the stream (this is not required by the spec, but reflects the current htsjdk implementation), however, the tag data series and encodings can vary across containers based on which tags are present in the actual records for that container, and the best compressor to use based on the actual data. This class delegates to a CRAMEncodingStrategy object to determine which encodings to use for the fixed CRAM data series, and dynamically chooses the best encoding for tag data series.
  • Field Details

  • Constructor Details

    • CompressionHeaderFactory

      public CompressionHeaderFactory(CRAMEncodingStrategy encodingStrategy)
      Create a CompressionHeaderFactory using the provided CRAMEncodingStrategy.
      Parameters:
      encodingStrategy - CRAMEncodingStrategy to use, may not be null
  • Method Details

    • createCompressionHeader

      public CompressionHeader createCompressionHeader(List<CRAMCompressionRecord> containerCRAMCompressionRecords, boolean coordinateSorted)
      Creates a compression header for the provided list of CRAMCompressionRecord objects. Resets any internal state (i.e. the tag encoding map state) as preparation for starting the next compression header.
      Parameters:
      containerCRAMCompressionRecords - all CRAMRecords that will be stored in the container
      coordinateSorted - if true the records are assumed to be sorted by alignment position
      Returns:
      CompressionHeader for the container for containerCRAMRecords
    • getEncodingStrategy

      public CRAMEncodingStrategy getEncodingStrategy()
    • getBestExternalCompressor

      public ExternalCompressor getBestExternalCompressor(byte[] data)
      Get the best external compressor to use for the given byte array.
      Parameters:
      data - byte array to compress
      Returns:
      best compressor to use for the data
    • getByteSizeRangeOfTagValues

      public static htsjdk.samtools.cram.build.CompressionHeaderFactory.ByteSizeRange getByteSizeRangeOfTagValues(List<CRAMCompressionRecord> records, int tagID)