// BamToolsIndex.h (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 5 April 2011 (DB)
+// Last modified: 10 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides index operations for the BamTools index format (".bti")
// ***************************************************************************
//
// We mean it.
-#include <api/BamAux.h>
-#include <api/BamIndex.h>
+#include "api/BamAux.h"
+#include "api/BamIndex.h"
#include <map>
#include <string>
#include <vector>
// (might be useful later to handle any 'legacy' versions if the format changes)
// listed for example like: BTI_1_0 = 1, BTI_1_1 = 2, BTI_1_2 = 3, BTI_2_0 = 4, and so on
//
- // so a change introduced in (hypothetical) BTI_1_2 would be handled from then on by:
+ // so a change introduced in BTI_1_2 may be handled from then on by:
//
// if ( indexVersion >= BTI_1_2 )
// do something new
enum Version { BTI_1_0 = 1
, BTI_1_1
, BTI_1_2
+ , BTI_2_0
};
// ctor & dtor
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);
+ BamIndex::IndexType Type(void) const { return BamIndex::BAMTOOLS; }
public:
// returns format's file extension
static const std::string Extension(void);
- // internal file ops
+ // internal methods
private:
- bool CheckMagicNumber(void);
- bool CheckVersion(void);
+
+ // index file ops
+ void CheckMagicNumber(void);
+ void CheckVersion(void);
void CloseFile(void);
bool IsFileOpen(void) const;
- bool OpenFile(const std::string& filename, const char* mode);
- bool Seek(const int64_t& position, const int& origin);
+ void OpenFile(const std::string& filename, const char* mode);
+ void Seek(const int64_t& position, const int& origin);
int64_t Tell(void) const;
- // internal BTI index building methods
- private:
+ // index-creation methods
void ClearReferenceEntry(BtiReferenceEntry& refEntry);
-
- // internal random-access methods
- private:
- bool GetOffset(const BamRegion& region, int64_t& offset, bool* hasAlignmentsInRegion);
-
- // internal BTI summary data methods
- private:
+ void WriteBlock(const BtiBlock& block);
+ void WriteBlocks(const BtiBlockVector& blocks);
+ void WriteHeader(void);
+ void WriteReferenceEntry(const BtiReferenceEntry& refEntry);
+
+ // random-access methods
+ void GetOffset(const BamRegion& region, int64_t& offset, bool* hasAlignmentsInRegion);
+ void ReadBlock(BtiBlock& block);
+ void ReadBlocks(const BtiReferenceSummary& refSummary, BtiBlockVector& blocks);
+ void ReadReferenceEntry(BtiReferenceEntry& refEntry);
+
+ // BTI summary data methods
void InitializeFileSummary(const int& numReferences);
- bool LoadFileSummary(void);
- bool LoadHeader(void);
- bool LoadNumBlocks(int& numBlocks);
- bool LoadNumReferences(int& numReferences);
- bool LoadReferenceSummary(BtiReferenceSummary& refSummary);
- bool SkipBlocks(const int& numBlocks);
-
- // internal BTI full index input methods
- private:
- bool ReadBlock(BtiBlock& block);
- bool ReadBlocks(const BtiReferenceSummary& refSummary, BtiBlockVector& blocks);
- bool ReadReferenceEntry(BtiReferenceEntry& refEntry);
-
- // internal BTI full index output methods
- private:
- bool WriteBlock(const BtiBlock& block);
- bool WriteBlocks(const BtiBlockVector& blocks);
- bool WriteHeader(void);
- bool WriteReferenceEntry(const BtiReferenceEntry& refEntry);
+ void LoadFileSummary(void);
+ void LoadHeader(void);
+ void LoadNumBlocks(int& numBlocks);
+ void LoadNumReferences(int& numReferences);
+ void LoadReferenceSummary(BtiReferenceSummary& refSummary);
+ void SkipBlocks(const int& numBlocks);
// data members
private:
- FILE* m_indexStream;
bool m_isBigEndian;
- BamIndex::IndexCacheMode m_cacheMode;
BtiFileSummary m_indexFileSummary;
- int m_blockSize;
+ uint32_t m_blockSize;
int32_t m_inputVersion; // Version is serialized as int
Version m_outputVersion;
+ struct RaiiWrapper {
+ FILE* IndexStream;
+ RaiiWrapper(void);
+ ~RaiiWrapper(void);
+ };
+ RaiiWrapper Resources;
+
// static constants
private:
- static const int DEFAULT_BLOCK_LENGTH;
+ static const uint32_t DEFAULT_BLOCK_LENGTH;
static const std::string BTI_EXTENSION;
static const char* const BTI_MAGIC;
static const int SIZEOF_BLOCK;