Package htsjdk.samtools.cram.structure
Class Container
java.lang.Object
htsjdk.samtools.cram.structure.Container
Notes: Container will construct a container out of as many CRAMCompressionRecords as it is handed, respecting only
the maximum number of slices. The policy around how to break up lists of records into containers is enforced
by ContainerFactory.
-
Constructor Summary
ConstructorsConstructorDescriptionContainer
(CRAMVersion cramVersion, InputStream inputStream, long containerByteOffset) Read a Container from a CRAM stream.Container
(CompressionHeader compressionHeader, List<Slice> containerSlices, long containerByteOffset, long globalRecordCounter) Create a Container with aReferenceContext
derived from itsSlice
s.Container
(ContainerHeader containerHeader, long containerByteOffset) Create a container for use by CramContainerHeaderIterator, which is only used to find the offsets within a CRAM stream where containers start. -
Method Summary
Modifier and TypeMethodDescriptiongetBAIEntries
(CompressorCache compressorCache) Retrieve the list of BAIEntry Index entries corresponding to this Containerlong
getCRAIEntries
(CompressorCache compressorCache) Retrieve the list of CRAI Index entries corresponding to this ContainergetSAMRecords
(ValidationStringency validationStringency, CRAMReferenceRegion cramReferenceRegion, CompressorCache compressorCache, SAMFileHeader samFileHeader) Get SAMRecords from all Slices in this container.boolean
isEOF()
static SAMFileHeader
readSAMFileHeaderContainer
(CRAMVersion cramVersion, InputStream inputStream, String id) Reads the special container that contains the SAMFileHeader from a CRAM stream, and returns just the SAMFileHeader (we don't want to hand out the container since its not a real container in that it has no compression header block, slices, etc).toString()
int
write
(CRAMVersion cramVersion, OutputStream outputStream) Writes a completeContainer
with it's header to aOutputStream
.static long
writeSAMFileHeaderContainer
(CRAMVersion cramVersion, SAMFileHeader samFileHeader, OutputStream os) Write a SAMFileHeader container to a CRAM stream.
-
Constructor Details
-
Container
public Container(CompressionHeader compressionHeader, List<Slice> containerSlices, long containerByteOffset, long globalRecordCounter) Create a Container with aReferenceContext
derived from itsSlice
s. A Single Reference Container contains only Single Reference Slices mapped to the same reference. - set the Container's ReferenceContext to be the same as those slices - set the Container's Alignment Start and Span to cover all slices A Multiple Reference Container contains only Multiple Reference Slices. - set the Container's ReferenceContext to MULTIPLE_REFERENCE_CONTEXT - unset the Container's Alignment Start and Span An Unmapped Container contains only Unmapped Slices. - set the Container's ReferenceContext to UNMAPPED_UNPLACED_CONTEXT - unset the Container's Alignment Start and Span Any other combination is invalid.- Parameters:
compressionHeader
- the CRAMCompressionHeader
to use for the ContainercontainerSlices
- theSlice
s for the ContainercontainerByteOffset
- the Container's byte offset from the start of the streamglobalRecordCounter
- the global record count for the first record in this container- Throws:
CRAMException
- for invalid Container states
-
Container
Create a container for use by CramContainerHeaderIterator, which is only used to find the offsets within a CRAM stream where containers start.- Parameters:
containerHeader
- the container header for the containercontainerByteOffset
- the byte offset of this container in the containing stream
-
Container
Read a Container from a CRAM stream. This reads the container header and all slice blocks, but does not resolve the blocks into CRAMRecords, since we don't want to do that until its necessary (and it might not be if, for example, we're indexing the container).- Parameters:
cramVersion
- CRAM version of the input streaminputStream
- input stream to readcontainerByteOffset
- byte offset within the stream of this container
-
-
Method Details
-
write
Writes a completeContainer
with it's header to aOutputStream
.- Parameters:
cramVersion
- the CRAM version to assumeoutputStream
- the stream to write to- Returns:
- the number of bytes written out
-
readSAMFileHeaderContainer
public static SAMFileHeader readSAMFileHeaderContainer(CRAMVersion cramVersion, InputStream inputStream, String id) Reads the special container that contains the SAMFileHeader from a CRAM stream, and returns just the SAMFileHeader (we don't want to hand out the container since its not a real container in that it has no compression header block, slices, etc).- Parameters:
cramVersion
- CRAM version being readinputStream
- stream from which to read the header containerid
- id from the cram header, for error reporting- Returns:
- the
SAMFileHeader
for this CRAM stream
-
writeSAMFileHeaderContainer
public static long writeSAMFileHeaderContainer(CRAMVersion cramVersion, SAMFileHeader samFileHeader, OutputStream os) Write a SAMFileHeader container to a CRAM stream.- Parameters:
cramVersion
- CRAM version being written.samFileHeader
- SAMFileHeader to writeos
- stream to which the header container should be written- Returns:
- the number of bytes written to the stream
-
getSAMRecords
public List<SAMRecord> getSAMRecords(ValidationStringency validationStringency, CRAMReferenceRegion cramReferenceRegion, CompressorCache compressorCache, SAMFileHeader samFileHeader) Get SAMRecords from all Slices in this container. This is a 3 step process: 1) deserialize the slice blocks and create a list of CRAMRecords 2) Normalize the CRAMRecords 3) Convert the normalized CRAMRecords into SAMRecords- Parameters:
validationStringency
- validation stringency to use (when reading tags)cramReferenceRegion
- reference region to use to restore basescompressorCache
- compressor cache to use for decompressing streamssamFileHeader
- the SAMFileHeader for this CRAM stream (for resolving read groups)- Returns:
- the
SAMRecord
s from this container
-
getContainerHeader
-
getCompressionHeader
-
getAlignmentContext
-
getContainerByteOffset
public long getContainerByteOffset() -
getSlices
-
isEOF
public boolean isEOF() -
getCRAIEntries
Retrieve the list of CRAI Index entries corresponding to this Container- Returns:
- the list of CRAI Index entries
-
getBAIEntries
Retrieve the list of BAIEntry Index entries corresponding to this Container- Returns:
- the list of BAIEntry Index entries
-
toString
-