// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 19 November 2010 (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;
-
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);
+ // file operations
+ void 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);
+
+ // 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);
- // 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
+ bool 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);
// 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;
-
- // system data
- bool IsBigEndian;
+ // general BAM file data
+ int64_t m_alignmentsBeginOffset;
+ std::string m_filename;
+ RefVector m_references;
- // user-specified region values
- BamRegion Region;
- bool HasAlignmentsInRegion;
+ // system data
+ bool m_isBigEndian;
- // parent BamReader
- BamReader* Parent;
+ // parent BamReader
+ 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