Loading...
Searching...
No Matches
BamTools::BamWriter Class Reference

Provides write access for generating BAM files. More...

`#include <BamWriter.h>`

## Public Types

enum | CompressionMode { Compressed = 0 , Uncompressed }
| This enum describes the compression behaviors for output BAM files. More...

## Public Member Functions

| BamWriter ()
| constructor
| ~BamWriter ()
| destructor
void | Close ()
| Closes the current BAM file.
std::string | GetErrorString () const
| Returns a human-readable description of the last error that occurred.
bool | IsOpen () const
| Returns `true` if BAM file is open for writing.
bool | Open (const std::string &filename, const std::string &samHeaderText, const RefVector &referenceSequences)
| Opens a BAM file for writing.
bool | Open (const std::string &filename, const SamHeader &samHeader, const RefVector &referenceSequences)
| Opens a BAM file for writing.
bool | SaveAlignment (const BamAlignment &alignment)
| Saves an alignment to the BAM file.
void | SetCompressionMode (const BamWriter::CompressionMode &compressionMode)
| Sets the output compression mode.

## Detailed Description

Provides write access for generating BAM files.

## Member Enumeration Documentation

## CompressionMode

enum BamTools::BamWriter::CompressionMode

This enum describes the compression behaviors for output BAM files.

Enumerator
Compressed | Use normal BAM compression.
Uncompressed | Disable BAM compression. Useful in situations where the BAM data is streamed (e.g. piping). It would be wasteful to compress, and then immediately decompress the data.

## Constructor & Destructor Documentation

## BamWriter()

BamWriter::BamWriter | ( |  | ) |

constructor

## ~BamWriter()

BamWriter::~BamWriter | ( |  | ) |

destructor

## Member Function Documentation

## Close()

void BamWriter::Close | ( |  | ) |

Closes the current BAM file.

See also
  Open()

## GetErrorString()

std::string BamWriter::GetErrorString | ( |  | ) | const

Returns a human-readable description of the last error that occurred.

This method allows elimination of STDERR pollution. Developers of client code may choose how the messages are displayed to the user, if at all.

Returns
  error description

## IsOpen()

bool BamWriter::IsOpen | ( |  | ) | const

Returns `true` if BAM file is open for writing.

See also
  Open()

## Open() [1/2]

bool BamWriter::Open | ( | const std::string & | filename,
|  | const SamHeader & | samHeader,
|  | const RefVector & | referenceSequences )

Opens a BAM file for writing.

This is an overloaded function.

Will overwrite the BAM file if it already exists.

Parameters

  [in] | filename | name of output BAM file
  [in] | samHeader | header data, wrapped in SamHeader object
  [in] | referenceSequences | list of reference entries

Returns
  `true` if opened successfully

See also
  Close(), IsOpen(), BamReader::GetHeader(), BamReader::GetReferenceData()

## Open() [2/2]

bool BamWriter::Open | ( | const std::string & | filename,
|  | const std::string & | samHeaderText,
|  | const RefVector & | referenceSequences )

Opens a BAM file for writing.

Will overwrite the BAM file if it already exists.

Parameters

  [in] | filename | name of output BAM file
  [in] | samHeaderText | header data, as SAM-formatted string
  [in] | referenceSequences | list of reference entries

Returns
  `true` if opened successfully

See also
  Close(), IsOpen(), BamReader::GetHeaderText(), BamReader::GetReferenceData()

## SaveAlignment()

bool BamWriter::SaveAlignment | ( | const BamAlignment & | alignment | ) |

Saves an alignment to the BAM file.

Parameters

  [in] | alignment | BamAlignment record to save

See also
  BamReader::GetNextAlignment(), BamReader::GetNextAlignmentCore()

## SetCompressionMode()

void BamWriter::SetCompressionMode | ( | const BamWriter::CompressionMode & | compressionMode | ) |

Sets the output compression mode.

Default mode is BamWriter::Compressed.

Note
  Changing the compression mode is disabled on open files (i.e. the request will be ignored). Be sure to call this function before opening the BAM file.

BamWriter writer;
writer.SetCompressionMode(BamWriter::Uncompressed);
writer.Open( ... );
// ...
BamTools::BamWriter::BamWriter
BamWriter()
constructor
Definition BamWriter.cpp:37
BamTools::BamWriter::SetCompressionMode
void SetCompressionMode(const BamWriter::CompressionMode &compressionMode)
Sets the output compression mode.
Definition BamWriter.cpp:152
BamTools::BamWriter::Uncompressed
@ Uncompressed
Disable BAM compression.
Definition BamWriter.h:36
BamTools::BamWriter::Open
bool Open(const std::string &filename, const std::string &samHeaderText, const RefVector &referenceSequences)
Opens a BAM file for writing.
Definition BamWriter.cpp:95

Parameters

  [in] | compressionMode | desired output compression behavior

See also
  IsOpen(), Open()

The documentation for this class was generated from the following files:

- BamWriter.h
- BamWriter.cpp