]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/BamReader_p.h
Major update to BamTools version 1.0
[bamtools.git] / src / api / internal / BamReader_p.h
index 3d49a6370bc11393cd91f967334127d2983a7bbb..7dda67f14569a5412a0eff3df9c0867fa9515902 100644 (file)
@@ -3,7 +3,7 @@
 // Marth Lab, Department of Biology, Boston College
 // All rights reserved.
 // ---------------------------------------------------------------------------
-// Last modified: 11 January 2011 (DB)
+// Last modified: 24 February 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides the basic functionality for reading BAM files
 // ***************************************************************************
 
 #include <api/BamAlignment.h>
 #include <api/BamIndex.h>
-#include <api/BGZF.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 <string>
 
 namespace BamTools {
-
-class BamReader;
-class SamHeader;
-
 namespace Internal {
 
-class BamHeader;
-
 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);
+        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;
-        const SamHeader GetSamHeader(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);
+        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);
+
+    // BamReaderPrivate interface
+    public:
+        BgzfStream* Stream(void);
 
     // 'internal' methods
     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);
+        bool 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);
 
     // data members
     public:
 
-        // general file data
-        BgzfData  mBGZF;
-        BamIndex* Index;
-        RefVector References;
-        bool      HasIndex;
-        int64_t   AlignmentsBeginOffset;
-        std::string    Filename;
-        std::string    IndexFilename;
-
-
-        // 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;
-        BamHeader* m_header;
+        BamReader* m_parent;
 
-        // BAM character constants
-        const char* DNA_LOOKUP;
-        const char* CIGAR_LOOKUP;
+        // BamReaderPrivate components
+        BamHeader m_header;
+        BamRandomAccessController m_randomAccessController;
+        BgzfStream m_stream;
 };
 
 } // namespace Internal