java.lang.Object
htsjdk.samtools.cram.structure.block.Block

public class Block extends Object
Class representing CRAM block concept and some methods to operate with block content. CRAM block is used to hold some (usually homogeneous) binary data. An external compression can be applied to the content of a block. The class provides some instantiation static methods, for example to read a block from an input stream. Blocks can be written out to an output stream, this may be considered as a way to serialize/deserialize blocks.
  • Field Details

    • NO_CONTENT_ID

      public static final int NO_CONTENT_ID
      Only external blocks have meaningful Content IDs Other blocks are required to have a Content ID of 0
      See Also:
  • Constructor Details

    • Block

      protected Block(BlockCompressionMethod compressionMethod, BlockContentType contentType, int contentId, byte[] compressedContent, int uncompressedLength)
      Protected constructor of a generic Block, to be called by static factory methods and subclasses.
      Parameters:
      compressionMethod - the block compression method. Can be RAW, if uncompressed
      contentType - whether this is a header or data block, and which kind
      contentId - the External Block Content ID, or NO_CONTENT_ID for non-External block
      compressedContent - the compressed form of the data to be stored in this block
      uncompressedLength - the length of the content stored in this block when uncompressed
  • Method Details

    • createGZIPFileHeaderBlock

      public static Block createGZIPFileHeaderBlock(byte[] rawContent)
      Create a new file header block with the given uncompressed content. The block will have GZIP compression and FILE_HEADER content type.
      Parameters:
      rawContent - the uncompressed content of the block
      Returns:
      a new Block object
    • createRawCompressionHeaderBlock

      public static Block createRawCompressionHeaderBlock(byte[] rawContent)
      Create a new compression header block with the given uncompressed content. The block will have RAW (no) compression and COMPRESSION_HEADER content type.
      Parameters:
      rawContent - the uncompressed content of the block
      Returns:
      a new Block object
    • createRawSliceHeaderBlock

      public static Block createRawSliceHeaderBlock(byte[] rawContent)
      Create a new slice header block with the given uncompressed content. The block will have RAW (no) compression and MAPPED_SLICE content type.
      Parameters:
      rawContent - the uncompressed content of the block
      Returns:
      a new Block object
    • createRawCoreDataBlock

      public static Block createRawCoreDataBlock(byte[] rawContent)
      Create a new core data block with the given uncompressed content. The block will have RAW (no) compression and CORE content type.
      Parameters:
      rawContent - the uncompressed content of the block
      Returns:
      a new Block object
    • createExternalBlock

      public static Block createExternalBlock(BlockCompressionMethod compressionMethod, int contentId, byte[] compressedContent, int uncompressedLength)
      Create a new external data block with the given compression method, uncompressed content, and content ID. The block will have EXTERNAL content type.
      Parameters:
      compressionMethod - the compression method used in this block
      contentId - the external identifier for the block
      compressedContent - the content of this block, in compressed mode
      uncompressedLength - the length of the content stored in this block when uncompressed
    • getCompressionMethod

      public final BlockCompressionMethod getCompressionMethod()
    • getContentType

      public final BlockContentType getContentType()
      Identifies whether this is a header or data block, and which kind
      Returns:
      the CRAM content type of the block
    • getContentId

      public int getContentId()
      Return the External Content ID for this block. Only ExternalBlocks have a meaningful Content ID.
      Returns:
      the External Content ID, or NO_CONTENT_ID
    • getRawContent

      public final byte[] getRawContent()
      Return the raw (uncompressed) content from a block. The block must have BlockCompressionMethod BlockCompressionMethod.RAW.
      Returns:
      The raw, uncompressed block content.
      Throws:
      IllegalArgumentException - if the block is not BlockCompressionMethod.RAW.
    • getUncompressedContent

      public final byte[] getUncompressedContent(CompressorCache compressorCache)
      Uncompress the stored block content (if not RAW) and return the uncompressed content.
      Parameters:
      compressorCache -
      Returns:
      The uncompressed block content.
      Throws:
      CRAMException - The uncompressed length did not match what was expected.
    • getUncompressedContentSize

      public int getUncompressedContentSize()
      Returns:
      The size of the uncompressed content in bytes.
    • getCompressedContent

      public final byte[] getCompressedContent()
      Returns:
      The compressed block content.
    • getCompressedContentSize

      public final int getCompressedContentSize()
      Returns:
      The size of the compressed content in bytes.
    • read

      public static Block read(CRAMVersion cramVersion, InputStream inputStream)
      Deserialize the Block from the InputStream. The reading is parameterized by the major CRAM version number.
      Parameters:
      cramVersion - CRAM version
      inputStream - input stream to read the block from
      Returns:
      a subtype of Block object with fields and content from the input stream
    • write

      public final void write(CRAMVersion cramVersion, OutputStream outputStream)
      Write the block out to the the specified OutputStream. The method is parameterized with the CRAM major version number.
      Parameters:
      cramVersion - CRAM version major number
      outputStream - output stream to write to
    • toString

      public String toString()
      Overrides:
      toString in class Object