6
|
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 <BamAlignment.h>
|
|
25 #include <BamIndex.h>
|
|
26 #include <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 // fills out character data for BamAlignment data
|
|
81 bool BuildCharData(BamAlignment& bAlignment);
|
|
82 // checks to see if alignment overlaps current region
|
|
83 RegionState IsOverlap(BamAlignment& bAlignment);
|
|
84 // retrieves header text from BAM file
|
|
85 void LoadHeaderData(void);
|
|
86 // retrieves BAM alignment under file pointer
|
|
87 bool LoadNextAlignment(BamAlignment& bAlignment);
|
|
88 // builds reference data structure from BAM file
|
|
89 void LoadReferenceData(void);
|
|
90 // mark references with 'HasAlignments' status
|
|
91 void MarkReferences(void);
|
|
92
|
|
93 // ---------------------------------
|
|
94 // index file handling
|
|
95
|
|
96 // clear out inernal index data structure
|
|
97 void ClearIndex(void);
|
|
98 // loads index from BAM index file
|
|
99 bool LoadIndex(const bool lookForIndex, const bool preferStandardIndex);
|
|
100
|
|
101 // data members
|
|
102 public:
|
|
103
|
|
104 // general file data
|
|
105 BgzfData mBGZF;
|
|
106 std::string HeaderText;
|
|
107 BamIndex* Index;
|
|
108 RefVector References;
|
|
109 bool HasIndex;
|
|
110 int64_t AlignmentsBeginOffset;
|
|
111 std::string Filename;
|
|
112 std::string IndexFilename;
|
|
113
|
|
114 // Internal::BamHeader* m_header;
|
|
115
|
|
116 // index caching mode
|
|
117 BamIndex::BamIndexCacheMode IndexCacheMode;
|
|
118
|
|
119 // system data
|
|
120 bool IsBigEndian;
|
|
121
|
|
122 // user-specified region values
|
|
123 BamRegion Region;
|
|
124 bool HasAlignmentsInRegion;
|
|
125
|
|
126 // parent BamReader
|
|
127 BamReader* Parent;
|
|
128
|
|
129 // BAM character constants
|
|
130 const char* DNA_LOOKUP;
|
|
131 const char* CIGAR_LOOKUP;
|
|
132 };
|
|
133
|
|
134 } // namespace Internal
|
|
135 } // namespace BamTools
|
|
136
|
|
137 #endif // BAMREADER_P_H
|