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 // ***************************************************************************
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.
24 #include <api/BamAlignment.h>
25 #include <api/BamIndex.h>
35 class BamReaderPrivate {
38 public: enum RegionState { BEFORE_REGION = 0
45 BamReaderPrivate(BamReader* parent);
46 ~BamReaderPrivate(void);
48 // 'public' interface to BamReader
53 bool Open(const std::string& filename,
54 const std::string& indexFilename,
55 const bool lookForIndex,
56 const bool preferStandardIndex);
58 bool SetRegion(const BamRegion& region);
60 // access alignment data
61 bool GetNextAlignment(BamAlignment& bAlignment);
62 bool GetNextAlignmentCore(BamAlignment& bAlignment);
64 // access auxiliary data
65 const std::string GetHeaderText(void) const;
66 int GetReferenceID(const std::string& refName) const;
69 bool CreateIndex(bool useStandardIndex);
70 void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);
75 // ---------------------------------------
76 // reading alignments and auxiliary data
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);
93 // ---------------------------------
94 // index file handling
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);
106 std::string HeaderText;
108 RefVector References;
110 int64_t AlignmentsBeginOffset;
111 std::string Filename;
112 std::string IndexFilename;
114 // Internal::BamHeader* m_header;
116 // index caching mode
117 BamIndex::BamIndexCacheMode IndexCacheMode;
122 // user-specified region values
124 bool HasAlignmentsInRegion;
129 // BAM character constants
130 const char* DNA_LOOKUP;
131 const char* CIGAR_LOOKUP;
134 } // namespace Internal
135 } // namespace BamTools
137 #endif // BAMREADER_P_H