Class Block
java.lang.Object
htsjdk.samtools.cram.structure.block.Block
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Only external blocks have meaningful Content IDs Other blocks are required to have a Content ID of 0 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static Block
createGZIPFileHeaderBlock
(byte[] rawContent) Create a new file header block with the given uncompressed content.static Block
createRawCompressionHeaderBlock
(byte[] rawContent) Create a new compression header block with the given uncompressed content.static Block
createRawCoreDataBlock
(byte[] rawContent) Create a new core data block with the given uncompressed content.static Block
createRawSliceHeaderBlock
(byte[] rawContent) Create a new slice header block with the given uncompressed content.final byte[]
final int
final BlockCompressionMethod
int
Return the External Content ID for this block.final BlockContentType
Identifies whether this is a header or data block, and which kindfinal byte[]
Return the raw (uncompressed) content from a block.final byte[]
getUncompressedContent
(CompressorCache compressorCache) Uncompress the stored block content (if not RAW) and return the uncompressed content.int
static Block
read
(CRAMVersion cramVersion, InputStream inputStream) Deserialize the Block from theInputStream
.toString()
final void
write
(CRAMVersion cramVersion, OutputStream outputStream) Write the block out to the the specifiedOutputStream
.
-
Field Details
-
NO_CONTENT_ID
public static final int NO_CONTENT_IDOnly 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 uncompressedcontentType
- whether this is a header or data block, and which kindcontentId
- the External Block Content ID, or NO_CONTENT_ID for non-External blockcompressedContent
- the compressed form of the data to be stored in this blockuncompressedLength
- the length of the content stored in this block when uncompressed
-
-
Method Details
-
createGZIPFileHeaderBlock
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
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
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
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 blockcontentId
- the external identifier for the blockcompressedContent
- the content of this block, in compressed modeuncompressedLength
- the length of the content stored in this block when uncompressed
-
getCompressionMethod
-
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 haveBlockCompressionMethod
BlockCompressionMethod.RAW
.- Returns:
- The raw, uncompressed block content.
- Throws:
IllegalArgumentException
- if the block is notBlockCompressionMethod.RAW
.
-
getUncompressedContent
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
Deserialize the Block from theInputStream
. The reading is parameterized by the major CRAM version number.- Parameters:
cramVersion
- CRAM versioninputStream
- input stream to read the block from- Returns:
- a subtype of
Block
object with fields and content from the input stream
-
write
Write the block out to the the specifiedOutputStream
. The method is parameterized with the CRAM major version number.- Parameters:
cramVersion
- CRAM version major numberoutputStream
- output stream to write to
-
toString
-