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

The GenomicIntervalQuery class provides iterable access to a DataSet‘s BAM records, limiting results to those overlapping a GenomicInterval.


// using C++11 range-based for loop
GenomicIntervalQuery query(GenomicInterval("chr1:1000-2000"), dataset);
for (const BamRecord& record : query) {
    // ... do stuff ...

// OR

// using iterators directly
GenomicIntervalQuery query(GenomicInterval("chr1:1000-2000"), dataset);
auto iter = query.cbegin();
auto end  = query.cend();
for (; iter != end; ++iter) {
    // ... do stuff ...

Currently, all BAM files must have a corresponding ”.bai” index file. Use BamFile::EnsureStandardIndexExists before creating the query if one may not be present.

Inherits from IQuery

Public Functions

GenomicIntervalQuery(const GenomicInterval &interval, const PacBio::BAM::DataSet &dataset)

Constructs a new GenomiIntervalQuery, limiting record results to only those overalpping a GenomicInterval.

  • interval: genomic interval of interest
  • dataset: input data source(s)
  • std::runtime_error: on failure to open/read underlying BAM or BAI files.

bool GetNext(BamRecord &r)

Main iteration point for record access.

Most client code should not need to use this method directly. Use iterators instead.

GenomicIntervalQuery &Interval(const GenomicInterval &interval)

Sets a new genomic interval.

This allows the same dataset/query to be re-used over multiple regions of interest:

DataSet ds("data.xml");
GenomicIntervalQuery query(GenomicInterval(), ds);
for (const GenomicInterval& interval : intervals) {
    for (const BamRecord& record : query) {}
        // do stuff

reference to this query
  • interval: new genomic interval

const GenomicInterval &Interval() const

Current genomic interval active on this query.