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 // 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);
91 // ---------------------------------
92 // index file handling
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);
104 std::string HeaderText;
106 RefVector References;
108 int64_t AlignmentsBeginOffset;
109 std::string Filename;
110 std::string IndexFilename;
112 // Internal::BamHeader* m_header;
114 // index caching mode
115 BamIndex::BamIndexCacheMode IndexCacheMode;
120 // user-specified region values
122 bool HasAlignmentsInRegion;
127 // BAM character constants
128 const char* DNA_LOOKUP;
129 const char* CIGAR_LOOKUP;
132 } // namespace Internal
133 } // namespace BamTools
135 #endif // BAMREADER_P_H