Class Container

java.lang.Object
htsjdk.samtools.cram.structure.Container

public class Container extends Object
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 Details

    • Container

      public Container(CompressionHeader compressionHeader, List<Slice> containerSlices, long containerByteOffset, long globalRecordCounter)
      Create a Container with a ReferenceContext derived from its Slices. 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 CRAM CompressionHeader to use for the Container
      containerSlices - the Slices for the Container
      containerByteOffset - the Container's byte offset from the start of the stream
      globalRecordCounter - the global record count for the first record in this container
      Throws:
      CRAMException - for invalid Container states
    • Container

      public 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.
      Parameters:
      containerHeader - the container header for the container
      containerByteOffset - the byte offset of this container in the containing stream
    • Container

      public Container(CRAMVersion cramVersion, InputStream inputStream, long containerByteOffset)
      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 stream
      inputStream - input stream to read
      containerByteOffset - byte offset within the stream of this container
  • Method Details

    • write

      public int write(CRAMVersion cramVersion, OutputStream outputStream)
      Writes a complete Container with it's header to a OutputStream.
      Parameters:
      cramVersion - the CRAM version to assume
      outputStream - 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 read
      inputStream - stream from which to read the header container
      id - 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 write
      os - 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 bases
      compressorCache - compressor cache to use for decompressing streams
      samFileHeader - the SAMFileHeader for this CRAM stream (for resolving read groups)
      Returns:
      the SAMRecords from this container
    • getContainerHeader

      public ContainerHeader getContainerHeader()
    • getCompressionHeader

      public CompressionHeader getCompressionHeader()
    • getAlignmentContext

      public AlignmentContext getAlignmentContext()
    • getContainerByteOffset

      public long getContainerByteOffset()
    • getSlices

      public List<Slice> getSlices()
    • isEOF

      public boolean isEOF()
    • getCRAIEntries

      public List<CRAIEntry> getCRAIEntries(CompressorCache compressorCache)
      Retrieve the list of CRAI Index entries corresponding to this Container
      Returns:
      the list of CRAI Index entries
    • getBAIEntries

      public List<BAIEntry> getBAIEntries(CompressorCache compressorCache)
      Retrieve the list of BAIEntry Index entries corresponding to this Container
      Returns:
      the list of BAIEntry Index entries
    • toString

      public String toString()
      Overrides:
      toString in class Object