Package htsjdk.samtools

# Class CRAMFileWriter

java.lang.Object
htsjdk.samtools.SAMFileWriterImpl
htsjdk.samtools.CRAMFileWriter

All Implemented Interfaces:
  `SAMFileWriter`, `Closeable`, `AutoCloseable`

public class CRAMFileWriter extends SAMFileWriterImpl

## Constructor Summary

Constructors
Constructor
Description
`CRAMFileWriter(CRAMEncodingStrategy encodingStrategy, OutputStream outputStream, OutputStream indexOS, boolean presorted, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)`
Create a CRAMFileWriter and optional index on output streams.
`CRAMFileWriter(OutputStream outputStream, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)`
Create a CRAMFileWriter on an output stream.
`CRAMFileWriter(OutputStream outputStream, OutputStream indexOS, boolean presorted, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)`
Create a CRAMFileWriter and optional index on output streams.
`CRAMFileWriter(OutputStream outputStream, OutputStream indexOS, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)`
Create a CRAMFileWriter and optional index on output streams.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`finish()`
Do any required flushing here.
`protected String`
`getFilename()`
For producing error messages.
`protected void`
`writeAlignment(SAMRecord alignment)`
Write an alignment record.
`protected void`
`writeHeader(SAMFileHeader header)`
Write the header to disk.
`protected void`
`writeHeader(String textHeader)`
Write the header to disk.

### Methods inherited from class htsjdk.samtools.SAMFileWriterImpl

`addAlignment, close, getDefaultMaxRecordsInRam, getFileHeader, getMaxRecordsInRam, getSortOrder, getTempDirectory, setDefaultMaxRecordsInRam, setHeader, setMaxRecordsInRam, setProgressLogger, setSortOrder, setSortOrderChecking, setTempDirectory`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CRAMFileWriter

public CRAMFileWriter(OutputStream outputStream, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)
Create a CRAMFileWriter on an output stream. Requires input records to be presorted to match the sort order defined by the input `samFileHeader`.

Parameters:
  `outputStream` - where to write the output. Can not be null.
  `referenceSource` - reference source. Can not be null.
  `samFileHeader` - `SAMFileHeader` to be used. Can not be null. Sort order is determined by the sortOrder property of this arg.
  `fileName` - used for display in error messages
Throws:
  `IllegalArgumentException` - if the `outputStream`, `referenceSource` or `samFileHeader` are null

### CRAMFileWriter

public CRAMFileWriter(OutputStream outputStream, OutputStream indexOS, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)
Create a CRAMFileWriter and optional index on output streams. Requires input records to be presorted to match the sort order defined by the input `samFileHeader`.

Parameters:
  `outputStream` - where to write the output. Can not be null.
  `indexOS` - where to write the output index. Can be null if no index is required.
  `referenceSource` - reference source
  `samFileHeader` - `SAMFileHeader` to be used. Can not be null. Sort order is determined by the sortOrder property of this arg.
  `fileName` - used for display in error messages
Throws:
  `IllegalArgumentException` - if the `outputStream`, `referenceSource` or `samFileHeader` are null

### CRAMFileWriter

public CRAMFileWriter(OutputStream outputStream, OutputStream indexOS, boolean presorted, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)
Create a CRAMFileWriter and optional index on output streams.

Parameters:
  `outputStream` - where to write the output. Can not be null.
  `indexOS` - where to write the output index. Can be null if no index is required.
  `presorted` - if true records written to this writer must already be sorted in the order specified by the header
  `referenceSource` - reference source
  `samFileHeader` - `SAMFileHeader` to be used. Can not be null. Sort order is determined by the sortOrder property of this arg.
  `fileName` - used for display in error message display
Throws:
  `IllegalArgumentException` - if the `outputStream`, `referenceSource` or `samFileHeader` are null

### CRAMFileWriter

public CRAMFileWriter(CRAMEncodingStrategy encodingStrategy, OutputStream outputStream, OutputStream indexOS, boolean presorted, CRAMReferenceSource referenceSource, SAMFileHeader samFileHeader, String fileName)
Create a CRAMFileWriter and optional index on output streams.

Parameters:
  `encodingStrategy` - encoding strategy to use when writing
  `outputStream` - where to write the output. Can not be null.
  `indexOS` - where to write the output index. Can be null if no index is required.
  `presorted` - if true records written to this writer must already be sorted in the order specified by the header
  `referenceSource` - reference source
  `samFileHeader` - `SAMFileHeader` to be used. Can not be null. Sort order is determined by the sortOrder property of this arg.
  `fileName` - used for display in error message display
Throws:
  `IllegalArgumentException` - if the `outputStream`, `referenceSource` or `samFileHeader` are null

## Method Details

### writeAlignment

protected void writeAlignment(SAMRecord alignment)
Write an alignment record.

Specified by:
  `writeAlignment` in class `SAMFileWriterImpl`
Parameters:
  `alignment` - must not be null and must have a valid SAMFileHeader.

### writeHeader

protected void writeHeader(String textHeader)
Description copied from class: `SAMFileWriterImpl`
Write the header to disk. Header object is available via getHeader().

Specified by:
  `writeHeader` in class `SAMFileWriterImpl`
Parameters:
  `textHeader` - for convenience if the implementation needs it.

### writeHeader

protected void writeHeader(SAMFileHeader header)
Description copied from class: `SAMFileWriterImpl`
Write the header to disk. Header object is available via getHeader().

IMPORTANT: this method will be abstract once `SAMFileWriterImpl.writeHeader(String)` is removed.

Note: default implementation uses `SAMTextHeaderCodec.encode(java.io.Writer, htsjdk.samtools.SAMFileHeader)` and calls `SAMFileWriterImpl.writeHeader(String)`.

Overrides:
  `writeHeader` in class `SAMFileWriterImpl`
Parameters:
  `header` - object to write.

### finish

protected void finish()
Description copied from class: `SAMFileWriterImpl`
Do any required flushing here.

Specified by:
  `finish` in class `SAMFileWriterImpl`

### getFilename

protected String getFilename()
Description copied from class: `SAMFileWriterImpl`
For producing error messages.

Specified by:
  `getFilename` in class `SAMFileWriterImpl`
Returns:
  Output filename, or null if there isn't one.