// enums
public:
- // specify index-caching behavior
- enum IndexCacheMode { FullIndexCaching = 0 // store entire index file contents in memory
- , LimitedIndexCaching // store only index data for current reference
- , NoIndexCaching // do not store any index data between jumps
- };
// list of supported BamIndex types
enum IndexType { BAMTOOLS = 0
// loads existing data from file into memory
virtual bool Load(const std::string& filename) =0;
- // change the index caching behavior
- virtual void SetCacheMode(const BamIndex::IndexCacheMode& mode) =0;
-
//! \cond
// internal methods
return d->Rewind();
}
-/*! \fn void BamMultiReader::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode)
- \brief Changes the caching behavior of the index data.
-
- Default mode is BamIndex::LimitedIndexCaching.
-
- \param[in] mode desired cache mode for index, see BamIndex::IndexCacheMode for
- description of the available cache modes
- \sa HasIndex(), BamReader::SetIndexCacheMode()
-*/
-void BamMultiReader::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode) {
- d->SetIndexCacheMode(mode);
-}
-
/*! \fn bool BamMultiReader::SetRegion(const BamRegion& region)
\brief Sets a target region of interest
bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
// opens index files for current BAM files.
bool OpenIndexes(const std::vector<std::string>& indexFilenames);
- // changes the caching behavior of the index data
- void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
// ----------------------
// error handling
d->SetIndex(index);
}
-/*! \fn void BamReader::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode)
- \brief Changes the caching behavior of the index data.
-
- Default mode is BamIndex::LimitedIndexCaching.
-
- \param[in] mode desired cache mode for index, see BamIndex::IndexCacheMode for
- description of the available cache modes
- \sa HasIndex()
-*/
-void BamReader::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode) {
- d->SetIndexCacheMode(mode);
-}
-
/*! \fn bool BamReader::SetRegion(const BamRegion& region)
\brief Sets a target region of interest
bool OpenIndex(const std::string& indexFilename);\r
// sets a custom BamIndex on this reader\r
void SetIndex(BamIndex* index);\r
- // changes the caching behavior of the index data\r
- void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);\r
\r
// ----------------------\r
// error handling\r
m_errorString = where + SEPARATOR + what;
}
-// sets the index caching mode on the readers
-void BamMultiReaderPrivate::SetIndexCacheMode(const BamIndex::IndexCacheMode mode) {
-
- // iterate over readers
- vector<MergeItem>::iterator readerIter = m_readers.begin();
- vector<MergeItem>::iterator readerEnd = m_readers.end();
- for ( ; readerIter != readerEnd; ++readerIter ) {
- MergeItem& item = (*readerIter);
- BamReader* reader = item.Reader;
- if ( reader == 0 ) continue;
-
- // set reader's index cache mode
- reader->SetIndexCacheMode(mode);
- }
-}
-
bool BamMultiReaderPrivate::SetRegion(const BamRegion& region) {
// NB: While it may make sense to track readers in which we can
bool HasIndexes(void) const;
bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
bool OpenIndexes(const std::vector<std::string>& indexFilenames);
- void SetIndexCacheMode(const BamIndex::IndexCacheMode mode);
// error handling
std::string GetErrorString(void) const;
BamRandomAccessController::BamRandomAccessController(void)
: m_index(0)
- , m_indexCacheMode(BamIndex::LimitedIndexCaching)
, m_hasAlignmentsInRegion(true)
{ }
return false;
}
- // save new index
+ // save new index & return success
SetIndex(newIndex);
-
- // set new index's cache mode & return success
- newIndex->SetCacheMode(m_indexCacheMode);
return true;
}
return false;
}
- // set cache mode
- index->SetCacheMode(m_indexCacheMode);
-
// attempt to load data from index file
if ( !index->Load(indexFilename) ) {
const string indexError = index->GetErrorString();
m_index = index;
}
-void BamRandomAccessController::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode) {
- m_indexCacheMode = mode;
- if ( m_index )
- m_index->SetCacheMode(mode);
-}
-
bool BamRandomAccessController::SetRegion(const BamRegion& region, const int& referenceCount) {
// store region
bool LocateIndex(BamReaderPrivate* reader, const BamIndex::IndexType& preferredType);
bool OpenIndex(const std::string& indexFilename, BamReaderPrivate* reader);
void SetIndex(BamIndex* index);
- void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
// region methods
void ClearRegion(void);
// index data
BamIndex* m_index; // owns the index, not a copy - responsible for deleting
- BamIndex::IndexCacheMode m_indexCacheMode;
// region data
BamRegion m_region;
m_randomAccessController.SetIndex(index);
}
-// change the index caching behavior
-void BamReaderPrivate::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode) {
- m_randomAccessController.SetIndexCacheMode(mode);
-}
-
// sets current region & attempts to jump to it
// returns success/failure
bool BamReaderPrivate::SetRegion(const BamRegion& region) {
bool LocateIndex(const BamIndex::IndexType& preferredType);
bool OpenIndex(const std::string& indexFilename);
void SetIndex(BamIndex* index);
- void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
// error handling
std::string GetErrorString(void) const;
// ctor
BamStandardIndex::BamStandardIndex(Internal::BamReaderPrivate* reader)
: BamIndex(reader)
- , m_cacheMode(BamIndex::LimitedIndexCaching)
, m_bufferLength(0)
{
m_isBigEndian = BamTools::SystemIsBigEndian();
throw BamException("BamStandardIndex::Seek", "could not seek in BAI file");
}
-// change the index caching behavior
-void BamStandardIndex::SetCacheMode(const BamIndex::IndexCacheMode& mode) {
- m_cacheMode = mode;
- // do nothing else here ? cache mode will be ignored from now on, most likely
-}
-
void BamStandardIndex::SkipBins(const int& numBins) {
uint32_t binId;
int32_t numAlignmentChunks;
bool Jump(const BamTools::BamRegion& region, bool* hasAlignmentsInRegion);
// loads existing data from file into memory
bool Load(const std::string& filename);
- // change the index caching behavior
- void SetCacheMode(const BamIndex::IndexCacheMode& mode);
public:
// returns format's file extension
static const std::string Extension(void);
// data members
private:
bool m_isBigEndian;
- BamIndex::IndexCacheMode m_cacheMode;
BaiFileSummary m_indexFileSummary;
// our input buffer
// ctor
BamToolsIndex::BamToolsIndex(Internal::BamReaderPrivate* reader)
: BamIndex(reader)
- , m_cacheMode(BamIndex::LimitedIndexCaching)
, m_blockSize(BamToolsIndex::DEFAULT_BLOCK_LENGTH)
, m_inputVersion(0)
, m_outputVersion(BTI_2_0) // latest version - used for writing new index files
throw BamException("BamToolsIndex::Seek", "could not seek in BAI file");
}
-// change the index caching behavior
-void BamToolsIndex::SetCacheMode(const BamIndex::IndexCacheMode& mode) {
- m_cacheMode = mode;
- // do nothing else here ? cache mode will be ignored from now on, most likely
-}
-
void BamToolsIndex::SkipBlocks(const int& numBlocks) {
Seek( numBlocks*BamToolsIndex::SIZEOF_BLOCK, SEEK_CUR );
}
bool Jump(const BamTools::BamRegion& region, bool* hasAlignmentsInRegion);
// loads existing data from file into memory
bool Load(const std::string& filename);
- // change the index caching behavior
- void SetCacheMode(const BamIndex::IndexCacheMode& mode);
public:
// returns format's file extension
static const std::string Extension(void);
// data members
private:
bool m_isBigEndian;
- BamIndex::IndexCacheMode m_cacheMode;
BtiFileSummary m_indexFileSummary;
uint32_t m_blockSize;
int32_t m_inputVersion; // Version is serialized as int