Class CRAMContainerStreamWriter


  • public class CRAMContainerStreamWriter
    extends Object
    Class for writing SAMRecords into a series of CRAM containers on an output stream.
    • Field Detail

      • recordsPerSlice

        protected final int recordsPerSlice
      • containerSize

        protected final int containerSize
    • Constructor Detail

      • CRAMContainerStreamWriter

        public CRAMContainerStreamWriter​(OutputStream outputStream,
                                         OutputStream indexStream,
                                         CRAMReferenceSource source,
                                         SAMFileHeader samFileHeader,
                                         String cramId)
        Create a CRAMContainerStreamWriter for writing SAM records into a series of CRAM containers on output stream, with an optional index.
        Parameters:
        outputStream - where to write the CRAM stream.
        indexStream - where to write the output index. Can be null if no index is required.
        source - reference source
        samFileHeader - SAMFileHeader to be used. Sort order is determined by the sortOrder property of this arg.
        cramId - used for display in error message display
    • Method Detail

      • writeAlignment

        public void writeAlignment​(SAMRecord alignment)
        Write an alignment record.
        Parameters:
        alignment - must not be null
      • writeHeader

        public void writeHeader​(SAMFileHeader header)
        Write a CRAM file header and SAM header to the stream.
        Parameters:
        header - SAMFileHeader to write
      • finish

        public void finish​(boolean writeEOFContainer)
        Finish writing to the stream. Flushes the record cache and optionally emits an EOF container.
        Parameters:
        writeEOFContainer - true if an EOF container should be written. Only use false if writing a CRAM file fragment which will later be aggregated into a complete CRAM file.
      • isPreserveReadNames

        public boolean isPreserveReadNames()
      • setPreserveReadNames

        public void setPreserveReadNames​(boolean preserveReadNames)
      • isCaptureAllTags

        public boolean isCaptureAllTags()
      • setCaptureAllTags

        public void setCaptureAllTags​(boolean captureAllTags)
      • getCaptureTags

        public Set<String> getCaptureTags()
      • setCaptureTags

        public void setCaptureTags​(Set<String> captureTags)
      • getIgnoreTags

        public Set<String> getIgnoreTags()
      • setIgnoreTags

        public void setIgnoreTags​(Set<String> ignoreTags)
      • shouldFlushContainer

        protected boolean shouldFlushContainer​(SAMRecord nextRecord)
        Decide if the current container should be completed and flushed. The decision is based on a) number of records and b) if the reference sequence id has changed.
        Parameters:
        nextRecord - the record to be added into the current or next container
        Returns:
        true if the current container should be flushed and the following records should go into a new container; false otherwise.