]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/BamReader_p.h
Cleaned up intra-API includes & moved version numbers to 2.0.0
[bamtools.git] / src / api / internal / BamReader_p.h
index 8c3172f67eebcc8267f8d638f1be665091638b7d..2f670d59d94d829aead92868f0ed8c7a13e2cec3 100644 (file)
@@ -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
 // ***************************************************************************
 //
 // We mean it.
 
-#include <api/BamAlignment.h>
-#include <api/BamIndex.h>
-#include <api/BGZF.h>
+#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 <string>
 
 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);
+        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 Rewind(void);
-       bool SetRegion(const BamRegion& region);
-
-       // access alignment data
-       bool GetNextAlignment(BamAlignment& bAlignment);
-       bool GetNextAlignmentCore(BamAlignment& bAlignment);
-
-       // access auxiliary data
-       const std::string GetHeaderText(void) const;
-       int GetReferenceID(const std::string& refName) const;
-
-       // index operations
-       bool CreateIndex(bool useStandardIndex);
-       void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);
-
-    // 'internal' methods
+        // file operations
+        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& alignment);
+        bool GetNextAlignmentCore(BamAlignment& alignment);
+
+        // access auxiliary data
+        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(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);
-       // fills out character data for BamAlignment data
-       bool BuildCharData(BamAlignment& bAlignment);
-       // 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);
-       // 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);
+        // retrieves header text from BAM file
+        void LoadHeaderData(void);
+        // retrieves BAM alignment under file pointer
+        // (does no overlap checking or character data parsing)
+        bool LoadNextAlignment(BamAlignment& alignment);
+        // builds reference data structure from BAM file
+        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;
+        // system data
+        bool m_isBigEndian;
 
-       // user-specified region values
-       BamRegion Region;
-       bool HasAlignmentsInRegion;
+        // parent BamReader
+        BamReader* m_parent;
 
-       // parent BamReader
-       BamReader* 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