]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/BamReader_p.h
Moved BuildCharData() from BamReader to BamAlignment
[bamtools.git] / src / api / internal / BamReader_p.h
1 // ***************************************************************************
2 // BamReader_p.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 19 November 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides the basic functionality for reading BAM files
9 // ***************************************************************************
10
11 #ifndef BAMREADER_P_H
12 #define BAMREADER_P_H
13
14 //  -------------
15 //  W A R N I N G
16 //  -------------
17 //
18 // This file is not part of the BamTools API.  It exists purely as an
19 // implementation detail. This header file may change from version to version
20 // without notice, or even be removed.
21 //
22 // We mean it.
23
24 #include <api/BamAlignment.h>
25 #include <api/BamIndex.h>
26 #include <api/BGZF.h>
27 #include <string>
28
29 namespace BamTools {
30
31 class BamReader;
32
33 namespace Internal {
34
35 class BamReaderPrivate {
36
37     // enums
38     public: enum RegionState { BEFORE_REGION = 0
39                              , WITHIN_REGION
40                              , AFTER_REGION
41                              };
42
43     // ctor & dtor
44     public:
45         BamReaderPrivate(BamReader* parent);
46         ~BamReaderPrivate(void);
47
48     // 'public' interface to BamReader
49     public:
50
51         // file operations
52         void Close(void);
53         bool Open(const std::string& filename,
54                   const std::string& indexFilename,
55                   const bool lookForIndex,
56                   const bool preferStandardIndex);
57         bool Rewind(void);
58         bool SetRegion(const BamRegion& region);
59
60         // access alignment data
61         bool GetNextAlignment(BamAlignment& bAlignment);
62         bool GetNextAlignmentCore(BamAlignment& bAlignment);
63
64         // access auxiliary data
65         const std::string GetHeaderText(void) const;
66         int GetReferenceID(const std::string& refName) const;
67
68         // index operations
69         bool CreateIndex(bool useStandardIndex);
70         void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);
71
72     // 'internal' methods
73     public:
74
75         // ---------------------------------------
76         // reading alignments and auxiliary data
77
78         // adjusts requested region if necessary (depending on where data actually begins)
79         void AdjustRegion(BamRegion& region);
80         // checks to see if alignment overlaps current region
81         RegionState IsOverlap(BamAlignment& bAlignment);
82         // retrieves header text from BAM file
83         void LoadHeaderData(void);
84         // retrieves BAM alignment under file pointer
85         bool LoadNextAlignment(BamAlignment& bAlignment);
86         // builds reference data structure from BAM file
87         void LoadReferenceData(void);
88         // mark references with 'HasAlignments' status
89         void MarkReferences(void);
90
91         // ---------------------------------
92         // index file handling
93
94         // clear out inernal index data structure
95         void ClearIndex(void);
96         // loads index from BAM index file
97         bool LoadIndex(const bool lookForIndex, const bool preferStandardIndex);
98
99     // data members
100     public:
101
102         // general file data
103         BgzfData  mBGZF;
104         std::string HeaderText;
105         BamIndex* Index;
106         RefVector References;
107         bool      HasIndex;
108         int64_t   AlignmentsBeginOffset;
109         std::string    Filename;
110         std::string    IndexFilename;
111
112         //      Internal::BamHeader* m_header;
113
114         // index caching mode
115         BamIndex::BamIndexCacheMode IndexCacheMode;
116
117         // system data
118         bool IsBigEndian;
119
120         // user-specified region values
121         BamRegion Region;
122         bool HasAlignmentsInRegion;
123
124         // parent BamReader
125         BamReader* Parent;
126
127         // BAM character constants
128         const char* DNA_LOOKUP;
129         const char* CIGAR_LOOKUP;
130 };
131
132 } // namespace Internal
133 } // namespace BamTools
134
135 #endif // BAMREADER_P_H