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: 11 January 2011 (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>
27 #include <api/SamHeader.h>
39 class BamReaderPrivate {
42 public: enum RegionState { BEFORE_REGION = 0
49 BamReaderPrivate(BamReader* parent);
50 ~BamReaderPrivate(void);
52 // 'public' interface to BamReader
57 bool Open(const std::string& filename,
58 const std::string& indexFilename,
59 const bool lookForIndex,
60 const bool preferStandardIndex);
62 bool SetRegion(const BamRegion& region);
64 // access alignment data
65 bool GetNextAlignment(BamAlignment& bAlignment);
66 bool GetNextAlignmentCore(BamAlignment& bAlignment);
68 // access auxiliary data
69 const std::string GetHeaderText(void) const;
70 SamHeader GetSamHeader(void) const;
71 int GetReferenceID(const std::string& refName) const;
74 bool CreateIndex(bool useStandardIndex);
75 void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);
80 // ---------------------------------------
81 // reading alignments and auxiliary data
83 // adjusts requested region if necessary (depending on where data actually begins)
84 void AdjustRegion(BamRegion& region);
85 // checks to see if alignment overlaps current region
86 RegionState IsOverlap(BamAlignment& bAlignment);
87 // retrieves header text from BAM file
88 void LoadHeaderData(void);
89 // retrieves BAM alignment under file pointer
90 bool LoadNextAlignment(BamAlignment& bAlignment);
91 // builds reference data structure from BAM file
92 void LoadReferenceData(void);
93 // mark references with 'HasAlignments' status
94 void MarkReferences(void);
96 // ---------------------------------
97 // index file handling
99 // clear out inernal index data structure
100 void ClearIndex(void);
101 // loads index from BAM index file
102 bool LoadIndex(const bool lookForIndex, const bool preferStandardIndex);
110 RefVector References;
112 int64_t AlignmentsBeginOffset;
113 std::string Filename;
114 std::string IndexFilename;
117 // index caching mode
118 BamIndex::BamIndexCacheMode IndexCacheMode;
123 // user-specified region values
125 bool HasAlignmentsInRegion;
131 // BAM character constants
132 const char* DNA_LOOKUP;
133 const char* CIGAR_LOOKUP;
136 } // namespace Internal
137 } // namespace BamTools
139 #endif // BAMREADER_P_H