X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FBamReader_p.h;h=2f670d59d94d829aead92868f0ed8c7a13e2cec3;hb=9f1ce8c47aeadb6dc1320b52ee671c3341b97935;hp=ed3940a504ba50e2678b2d5e5b9214b42b0c66a4;hpb=94193d06ce788ba7df8b7bd856a983d1e98daac6;p=bamtools.git diff --git a/src/api/internal/BamReader_p.h b/src/api/internal/BamReader_p.h index ed3940a..2f670d5 100644 --- a/src/api/internal/BamReader_p.h +++ b/src/api/internal/BamReader_p.h @@ -1,9 +1,8 @@ // *************************************************************************** // BamReader_p.h (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 19 November 2010 (DB) +// Last modified: 10 October 2011 (DB) // --------------------------------------------------------------------------- // Provides the basic functionality for reading BAM files // *************************************************************************** @@ -21,112 +20,97 @@ // // We mean it. -#include -#include -#include +#include "api/BamAlignment.h" +#include "api/BamIndex.h" +#include "api/BamReader.h" +#include "api/SamHeader.h" +#include "api/internal/BamHeader_p.h" +#include "api/internal/BamRandomAccessController_p.h" +#include "api/internal/BgzfStream_p.h" #include namespace BamTools { - -class BamReader; - namespace Internal { class BamReaderPrivate { - // enums - public: enum RegionState { BEFORE_REGION = 0 - , WITHIN_REGION - , AFTER_REGION - }; - // ctor & dtor public: BamReaderPrivate(BamReader* parent); ~BamReaderPrivate(void); - // 'public' interface to BamReader + // BamReader interface public: // file operations - void Close(void); - bool Open(const std::string& filename, - const std::string& indexFilename, - const bool lookForIndex, - const bool preferStandardIndex); + bool Close(void); + const std::string Filename(void) const; + bool IsOpen(void) const; + bool Open(const std::string& filename); bool Rewind(void); bool SetRegion(const BamRegion& region); // access alignment data - bool GetNextAlignment(BamAlignment& bAlignment); - bool GetNextAlignmentCore(BamAlignment& bAlignment); + bool GetNextAlignment(BamAlignment& alignment); + bool GetNextAlignmentCore(BamAlignment& alignment); // access auxiliary data - const std::string GetHeaderText(void) const; + std::string GetHeaderText(void) const; + SamHeader GetSamHeader(void) const; + int GetReferenceCount(void) const; + const RefVector& GetReferenceData(void) const; int GetReferenceID(const std::string& refName) const; // index operations - bool CreateIndex(bool useStandardIndex); - void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode); - - // 'internal' methods + bool CreateIndex(const BamIndex::IndexType& type); + bool HasIndex(void) const; + 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; + void SetErrorString(const std::string& where, const std::string& what); + + // internal methods, but available as a BamReaderPrivate 'interface' + // + // these methods should only be used by BamTools::Internal classes + // (currently only used by the BamIndex subclasses) public: - - // --------------------------------------- - // reading alignments and auxiliary data - - // adjusts requested region if necessary (depending on where data actually begins) - void AdjustRegion(BamRegion& region); - // checks to see if alignment overlaps current region - RegionState IsOverlap(BamAlignment& bAlignment); // retrieves header text from BAM file void LoadHeaderData(void); // retrieves BAM alignment under file pointer - bool LoadNextAlignment(BamAlignment& bAlignment); + // (does no overlap checking or character data parsing) + bool LoadNextAlignment(BamAlignment& alignment); // builds reference data structure from BAM file - void LoadReferenceData(void); - // mark references with 'HasAlignments' status - void MarkReferences(void); - - // --------------------------------- - // index file handling - - // clear out inernal index data structure - void ClearIndex(void); - // loads index from BAM index file - bool LoadIndex(const bool lookForIndex, const bool preferStandardIndex); + bool LoadReferenceData(void); + // seek reader to file position + bool Seek(const int64_t& position); + // return reader's file position + int64_t Tell(void) const; // data members public: - // general file data - BgzfData mBGZF; - std::string HeaderText; - BamIndex* Index; - RefVector References; - bool HasIndex; - int64_t AlignmentsBeginOffset; - std::string Filename; - std::string IndexFilename; - - // Internal::BamHeader* m_header; - - // index caching mode - BamIndex::BamIndexCacheMode IndexCacheMode; + // general BAM file data + int64_t m_alignmentsBeginOffset; + std::string m_filename; + RefVector m_references; // system data - bool IsBigEndian; - - // user-specified region values - BamRegion Region; - bool HasAlignmentsInRegion; + bool m_isBigEndian; // parent BamReader - BamReader* Parent; + BamReader* m_parent; + + // BamReaderPrivate components + BamHeader m_header; + BamRandomAccessController m_randomAccessController; + BgzfStream m_stream; - // BAM character constants - const char* DNA_LOOKUP; - const char* CIGAR_LOOKUP; + // error handling + std::string m_errorString; }; } // namespace Internal