Loading...
Searching...
No Matches
BamReader.h
Go to the documentation of this file.
// ***************************************************************************
// BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
// Last modified: 18 November 2012 (DB)
// ---------------------------------------------------------------------------
// Provides read access to BAM files.
// ***************************************************************************
#ifndef BAMREADER_H
#define BAMREADER_H
#include <string>
#include "api/BamAlignment.h"
#include "api/BamIndex.h"
#include "api/SamHeader.h"
#include "api/api_global.h"
namespace BamTools {
namespace Internal {
class BamReaderPrivate;
} // namespace Internal
class API_EXPORT BamReader
{
// constructor / destructor
public:
BamReader();
~BamReader();
// public interface
public:
// ----------------------
// BAM file operations
// ----------------------
// closes the current BAM file
bool Close();
// returns filename of current BAM file
const std::string GetFilename() const;
// returns true if a BAM file is open for reading
bool IsOpen() const;
// performs random-access jump within BAM file
bool Jump(int refID, int position = 0);
// opens a BAM file
bool Open(const std::string& filename);
// returns internal file pointer to beginning of alignment data
bool Rewind();
// sets the target region of interest
bool SetRegion(const BamRegion& region);
// sets the target region of interest
bool SetRegion(const int& leftRefID, const int& leftPosition, const int& rightRefID,
const int& rightPosition);
int64_t Tell() const;
// ----------------------
// access alignment data
// ----------------------
// retrieves next available alignment
bool GetNextAlignment(BamAlignment& alignment);
// retrieves next available alignmnet (without populating the alignment's string data fields)
bool GetNextAlignmentCore(BamAlignment& alignment);
// ----------------------
// access header data
// ----------------------
// returns a read-only reference to SAM header data
const SamHeader& GetConstSamHeader() const;
// returns an editable copy of SAM header data
SamHeader GetHeader() const;
// returns SAM header data, as SAM-formatted text
std::string GetHeaderText() const;
// ----------------------
// access reference data
// ----------------------
// returns the number of reference sequences
int GetReferenceCount() const;
// returns all reference sequence entries
const RefVector& GetReferenceData() const;
// returns the ID of the reference with this name
int GetReferenceID(const std::string& refName) const;
// ----------------------
// BAM index operations
// ----------------------
// creates an index file for current BAM file, using the requested index type
bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
// returns true if index data is available
bool HasIndex() const;
// looks in BAM file's directory for a matching index file
bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
// opens a BAM index file
bool OpenIndex(const std::string& indexFilename);
// sets a custom BamIndex on this reader
void SetIndex(BamIndex* index);
// ----------------------
// error handling
// ----------------------
// returns a human-readable description of the last error that occurred
std::string GetErrorString() const;
// private implementation
private:
Internal::BamReaderPrivate* d;
};
} // namespace BamTools
#endif // BAMREADER_H
BamAlignment.h
BamIndex.h
SamHeader.h
api_global.h
BamTools::BamAlignment
The main BAM alignment data structure.
Definition BamAlignment.h:34
BamTools::BamIndex
Provides methods for generating & loading BAM index files.
Definition BamIndex.h:35
BamTools::BamIndex::IndexType
IndexType
Definition BamIndex.h:41
BamTools::BamIndex::STANDARD
@ STANDARD
Definition BamIndex.h:43
BamTools::BamReader::CreateIndex
bool CreateIndex(const BamIndex::IndexType &type=BamIndex::STANDARD)
Creates an index file for current BAM file.
Definition BamReader.cpp:61
BamTools::BamReader::GetFilename
const std::string GetFilename() const
Returns name of current BAM file.
Definition BamReader.cpp:106
BamTools::BamReader::SetRegion
bool SetRegion(const BamRegion &region)
Sets a target region of interest.
Definition BamReader.cpp:373
BamTools::BamReader::IsOpen
bool IsOpen() const
Returns true if a BAM file is open for reading.
Definition BamReader.cpp:234
BamTools::BamReader::HasIndex
bool HasIndex() const
Returns true if index data is available.
Definition BamReader.cpp:226
BamTools::BamReader::Close
bool Close()
Closes the current BAM file.
Definition BamReader.cpp:49
BamTools::BamReader::GetReferenceData
const RefVector & GetReferenceData() const
Returns all reference sequence entries.
Definition BamReader.cpp:206
BamTools::BamReader::GetReferenceID
int GetReferenceID(const std::string &refName) const
Returns the ID of the reference with this name.
Definition BamReader.cpp:218
BamTools::BamReader::GetReferenceCount
int GetReferenceCount() const
Returns number of reference sequences.
Definition BamReader.cpp:197
BamTools::BamReader::GetHeaderText
std::string GetHeaderText() const
Returns SAM header data, as SAM-formatted text.
Definition BamReader.cpp:141
BamTools::BamReader::GetErrorString
std::string GetErrorString() const
Returns a human-readable description of the last error that occurred.
Definition BamReader.cpp:91
BamTools::BamReader::LocateIndex
bool LocateIndex(const BamIndex::IndexType &preferredType=BamIndex::STANDARD)
Looks in BAM file's directory for a matching index file.
Definition BamReader.cpp:275
BamTools::BamReader::SetIndex
void SetIndex(BamIndex *index)
Sets a custom BamIndex on this reader.
Definition BamReader.cpp:345
BamTools::BamReader::Tell
int64_t Tell() const
Definition BamReader.cpp:404
BamTools::BamReader::Open
bool Open(const std::string &filename)
Opens a BAM file.
Definition BamReader.cpp:291
BamTools::BamReader::GetNextAlignment
bool GetNextAlignment(BamAlignment &alignment)
Retrieves next available alignment.
Definition BamReader.cpp:170
BamTools::BamReader::Jump
bool Jump(int refID, int position=0)
Performs a random-access jump within BAM file.
Definition BamReader.cpp:251
BamTools::BamReader::OpenIndex
bool OpenIndex(const std::string &indexFilename)
Opens a BAM index file.
Definition BamReader.cpp:304
BamTools::BamReader::GetHeader
SamHeader GetHeader() const
Returns SAM header data.
Definition BamReader.cpp:125
BamTools::BamReader::GetNextAlignmentCore
bool GetNextAlignmentCore(BamAlignment &alignment)
Retrieves next available alignment, without populating the alignment's string data fields.
Definition BamReader.cpp:189
BamTools::BamReader::BamReader
BamReader()
constructor
Definition BamReader.cpp:28
BamTools::BamReader::Rewind
bool Rewind()
Returns the internal file pointer to the first alignment record.
Definition BamReader.cpp:321
BamTools::BamReader::GetConstSamHeader
const SamHeader & GetConstSamHeader() const
Returns const reference to SAM header data.
Definition BamReader.cpp:78
BamTools
Contains all BamTools classes & methods.
Definition Sort.h:24
BamTools::RefVector
std::vector< RefData > RefVector
convenience typedef for vector of RefData entries
Definition BamAux.h:75
BamTools::BamRegion
Represents a sequential genomic region.
Definition BamAux.h:90
BamTools::SamHeader
Represents the SAM-formatted text header that is part of the BAM file header.
Definition SamHeader.h:24