1 // ***************************************************************************
2 // BamReader_p.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 18 November 2012 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides the basic functionality for reading BAM files
8 // ***************************************************************************
17 // This file is not part of the BamTools API. It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
23 #include "api/BamAlignment.h"
24 #include "api/BamIndex.h"
25 #include "api/BamReader.h"
26 #include "api/SamHeader.h"
27 #include "api/internal/bam/BamHeader_p.h"
28 #include "api/internal/bam/BamRandomAccessController_p.h"
29 #include "api/internal/io/BgzfStream_p.h"
35 class BamReaderPrivate {
39 BamReaderPrivate(BamReader* parent);
40 ~BamReaderPrivate(void);
42 // BamReader interface
47 const std::string Filename(void) const;
48 bool IsOpen(void) const;
49 bool Open(const std::string& filename);
51 bool SetRegion(const BamRegion& region);
53 // access alignment data
54 bool GetNextAlignment(BamAlignment& alignment);
55 bool GetNextAlignmentCore(BamAlignment& alignment);
57 // access auxiliary data
58 std::string GetHeaderText(void) const;
59 const SamHeader& GetConstSamHeader(void) const;
60 SamHeader GetSamHeader(void) const;
61 int GetReferenceCount(void) const;
62 const RefVector& GetReferenceData(void) const;
63 int GetReferenceID(const std::string& refName) const;
66 bool CreateIndex(const BamIndex::IndexType& type);
67 bool HasIndex(void) const;
68 bool LocateIndex(const BamIndex::IndexType& preferredType);
69 bool OpenIndex(const std::string& indexFilename);
70 void SetIndex(BamIndex* index);
73 std::string GetErrorString(void) const;
74 void SetErrorString(const std::string& where, const std::string& what);
76 // internal methods, but available as a BamReaderPrivate 'interface'
78 // these methods should only be used by BamTools::Internal classes
79 // (currently only used by the BamIndex subclasses)
81 // retrieves header text from BAM file
82 void LoadHeaderData(void);
83 // retrieves BAM alignment under file pointer
84 // (does no overlap checking or character data parsing)
85 bool LoadNextAlignment(BamAlignment& alignment);
86 // builds reference data structure from BAM file
87 bool LoadReferenceData(void);
88 // seek reader to file position
89 bool Seek(const int64_t& position);
90 // return reader's file position
91 int64_t Tell(void) const;
96 // general BAM file data
97 int64_t m_alignmentsBeginOffset;
98 std::string m_filename;
99 RefVector m_references;
107 // BamReaderPrivate components
109 BamRandomAccessController m_randomAccessController;
113 std::string m_errorString;
116 } // namespace Internal
117 } // namespace BamTools
119 #endif // BAMREADER_P_H