X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FBamToolsIndex_p.h;h=1e9ec18c62e02021b01c6fec3a6c943e95dcb658;hb=a50400c186a05160e1164bf544571b739ff6fac8;hp=269792ed979152e09131a232d512b83dd35aa523;hpb=c1fc1c5423ca73a1b5bcbe790650821d73e5959c;p=bamtools.git diff --git a/src/api/internal/BamToolsIndex_p.h b/src/api/internal/BamToolsIndex_p.h index 269792e..1e9ec18 100644 --- a/src/api/internal/BamToolsIndex_p.h +++ b/src/api/internal/BamToolsIndex_p.h @@ -2,7 +2,7 @@ // 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") // *************************************************************************** @@ -20,8 +20,8 @@ // // We mean it. -#include -#include +#include "api/BamAux.h" +#include "api/BamIndex.h" #include #include #include @@ -87,7 +87,7 @@ class BamToolsIndex : public BamIndex { // (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 @@ -96,6 +96,7 @@ class BamToolsIndex : public BamIndex { enum Version { BTI_1_0 = 1 , BTI_1_1 , BTI_1_2 + , BTI_2_0 }; // ctor & dtor @@ -116,66 +117,63 @@ class BamToolsIndex : public BamIndex { 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;