Package htsjdk.samtools

# Class BAMFileWriter

java.lang.Object
htsjdk.samtools.SAMFileWriterImpl
htsjdk.samtools.BAMFileWriter

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

public class BAMFileWriter extends SAMFileWriterImpl
Concrete implementation of SAMFileWriter for writing gzipped BAM files.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`BAMFileWriter(File path)`
`protected`
`BAMFileWriter(File path, int compressionLevel)`
`protected`
`BAMFileWriter(OutputStream os, File file)`
`protected`
`BAMFileWriter(OutputStream os, File file, int compressionLevel)`
`protected`
`BAMFileWriter(OutputStream os, File file, int compressionLevel, DeflaterFactory deflaterFactory)`
`protected`
`BAMFileWriter(OutputStream os, String absoluteFilename, int compressionLevel, DeflaterFactory deflaterFactory)`

## 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)`
Writes the record to disk.
`protected static void`
`writeHeader(BinaryCodec outputBinaryCodec, SAMFileHeader samFileHeader)`
Writes a header to a BAM file.
`protected static void`
`writeHeader(BinaryCodec outputBinaryCodec, SAMFileHeader samFileHeader, String headerText)`
Writes a header to a BAM file.
`static void`
`writeHeader(OutputStream outputStream, SAMFileHeader samFileHeader)`
Write a BAM file header to an output stream in block compressed BAM format.
`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, writeHeader`

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

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

## Constructor Details

### BAMFileWriter

protected BAMFileWriter(File path)

### BAMFileWriter

protected BAMFileWriter(File path, int compressionLevel)

### BAMFileWriter

protected BAMFileWriter(OutputStream os, File file)

### BAMFileWriter

protected BAMFileWriter(OutputStream os, File file, int compressionLevel)

### BAMFileWriter

protected BAMFileWriter(OutputStream os, File file, int compressionLevel, DeflaterFactory deflaterFactory)

### BAMFileWriter

protected BAMFileWriter(OutputStream os, String absoluteFilename, int compressionLevel, DeflaterFactory deflaterFactory)

## Method Details

### writeAlignment

protected void writeAlignment(SAMRecord alignment)
Description copied from class: `SAMFileWriterImpl`
Writes the record to disk. Sort order has been taken care of by the time this method is called. The record must hava a non-null SAMFileHeader.

Specified by:
  `writeAlignment` in class `SAMFileWriterImpl`
Parameters:
  `alignment` -

### 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.

### 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:
  absolute path in URI format, or null if this writer does not correspond to a file. To get a Path from this, use: IOUtil.getPath(getFilename())

### writeHeader

protected static void writeHeader(BinaryCodec outputBinaryCodec, SAMFileHeader samFileHeader, String headerText)
Writes a header to a BAM file. samFileHeader and headerText are redundant - one can be used to regenerate the other but in some instances we already have both so this allows us to save some cycles

### writeHeader

protected static void writeHeader(BinaryCodec outputBinaryCodec, SAMFileHeader samFileHeader)
Writes a header to a BAM file.

### writeHeader

public static void writeHeader(OutputStream outputStream, SAMFileHeader samFileHeader)
Write a BAM file header to an output stream in block compressed BAM format.

Parameters:
  `outputStream` - the stream to write the BAM header to
  `samFileHeader` - the header to write