BamReader

#include <pbbam/BamReader.h>
class PacBio::BAM::BamReader

The BamReader class provides basic read-access to a BAM file.

The base-class implementation provides a sequential read-through of BAM records. Derived classes may implement other access schemes (e.g. genomic region, PBI-enabled record filtering).

Subclassed by PacBio::BAM::BaiIndexedBamReader, PacBio::BAM::PbiIndexedBamReader

Constructors & Related Methods

BamReader(const std::string &fn)

Opens BAM file for reading.

Parameters
  • fn: BAM filename
Exceptions
  • std::runtime_error: if failed to open

BamReader(const BamFile &bamFile)

Opens BAM file for reading.

Parameters
Exceptions
  • std::runtime_error: if failed to open

BamReader(BamFile &&bamFile)

Opens BAM file for reading.

Parameters
Exceptions
  • std::runtime_error: if failed to open

virtual ~BamReader()

BAM File Attributes

const BamFile &File() const

Return
the underlying BamFile

std::string Filename() const

Return
BAM filename

const BamHeader &Header() const

Return
BamHeader object from BAM header contents

BAM File I/O

bool GetNext(BamRecord &record)

Fetches the “next” BAM record.

Default implementation will read records until EOF. Derived readers may use additional criteria to decide which record is “next” and when reading is done.

Return
true if record was read successfully. Returns false if EOF (or end of iterator in derived readers). False is not an error, it indicates “end of data”.
Parameters
  • record: next BamRecord object. Should not be used if method returns false.
Exceptions
  • std::runtime_error: if failed to read from file (e.g. possible truncated or corrupted file).

void VirtualSeek(int64_t virtualOffset)

Seeks to virtual offset in BAM.

Note
This is NOT a normal file offset, but the virtual offset used in BAM indexing.
Exceptions
  • std::runtime_error: if failed to seek

int64_t VirtualTell() const

Return
current (virtual) file position.
Note
This is NOT a normal file offset, but the virtual offset used in BAM indexing.

BGZF *Bgzf() const

Helper method for access to underlying BGZF stream pointer.

Useful for derived readers’ contact points with htslib methods.

Return
BGZF stream pointer

virtual int ReadRawData(BGZF *bgzf, bam1_t *b)

Performs the actual raw read of the next record from the BAM file.

Default implementation will read records, sequentially, until EOF. Derived readers may use additional criteria to decide which record is “next” and when reading is done.

Return value should be equivalent to htslib’s bam_read1(): >= 0 : normal -1 : EOF (not an error) < -1 : error

Return
integer status code, see description
Parameters
  • bgzf: BGZF stream pointer
  • b: BAM record pointer