]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/bam/BamReader_p.h
e8db646e28034eaf20095b31a1fda2b3cd30a8a2
[bamtools.git] / src / api / internal / bam / BamReader_p.h
1 // ***************************************************************************
2 // BamReader_p.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 25 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides the basic functionality for reading BAM files
8 // ***************************************************************************
9
10 #ifndef BAMREADER_P_H
11 #define BAMREADER_P_H
12
13 //  -------------
14 //  W A R N I N G
15 //  -------------
16 //
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.
20 //
21 // We mean it.
22
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"
30 #include <string>
31
32 namespace BamTools {
33 namespace Internal {
34
35 class BamReaderPrivate {
36
37     // ctor & dtor
38     public:
39         BamReaderPrivate(BamReader* parent);
40         ~BamReaderPrivate(void);
41
42     // BamReader interface
43     public:
44
45         // file operations
46         bool Close(void);
47         const std::string Filename(void) const;
48         bool IsOpen(void) const;
49         bool Open(const std::string& filename);
50         bool Rewind(void);
51         bool SetRegion(const BamRegion& region);
52
53         // access alignment data
54         bool GetNextAlignment(BamAlignment& alignment);
55         bool GetNextAlignmentCore(BamAlignment& alignment);
56
57         // access auxiliary data
58         std::string GetHeaderText(void) const;
59         SamHeader GetSamHeader(void) const;
60         int GetReferenceCount(void) const;
61         const RefVector& GetReferenceData(void) const;
62         int GetReferenceID(const std::string& refName) const;
63
64         // index operations
65         bool CreateIndex(const BamIndex::IndexType& type);
66         bool HasIndex(void) const;
67         bool LocateIndex(const BamIndex::IndexType& preferredType);
68         bool OpenIndex(const std::string& indexFilename);
69         void SetIndex(BamIndex* index);
70
71         // error handling
72         std::string GetErrorString(void) const;
73         void SetErrorString(const std::string& where, const std::string& what);
74
75     // internal methods, but available as a BamReaderPrivate 'interface'
76     //
77     // these methods should only be used by BamTools::Internal classes
78     // (currently only used by the BamIndex subclasses)
79     public:
80         // retrieves header text from BAM file
81         void LoadHeaderData(void);
82         // retrieves BAM alignment under file pointer
83         // (does no overlap checking or character data parsing)
84         bool LoadNextAlignment(BamAlignment& alignment);
85         // builds reference data structure from BAM file
86         bool LoadReferenceData(void);
87         // seek reader to file position
88         bool Seek(const int64_t& position);
89         // return reader's file position
90         int64_t Tell(void) const;
91
92     // data members
93     public:
94
95         // general BAM file data
96         int64_t     m_alignmentsBeginOffset;
97         std::string m_filename;
98         RefVector   m_references;
99
100         // system data
101         bool m_isBigEndian;
102
103         // parent BamReader
104         BamReader* m_parent;
105
106         // BamReaderPrivate components
107         BamHeader m_header;
108         BamRandomAccessController m_randomAccessController;
109         BgzfStream m_stream;
110
111         // error handling
112         std::string m_errorString;
113 };
114
115 } // namespace Internal
116 } // namespace BamTools
117
118 #endif // BAMREADER_P_H