]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/BamRandomAccessController_p.h
Cleaned up intra-API includes & moved version numbers to 2.0.0
[bamtools.git] / src / api / internal / BamRandomAccessController_p.h
1 // ***************************************************************************
2 // BamRandomAccessController_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 October 2011(DB)
6 // ---------------------------------------------------------------------------
7 // Manages random access operations in a BAM file
8 // ***************************************************************************
9
10 #ifndef BAMRACONTROLLER_P_H
11 #define BAMRACONTROLLER_P_H
12
13 //  -------------
14 //  W A R N I N G
15 //  -------------
16 //
17 // This file is not part of the BamTools API.  It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
20 //
21 // We mean it.
22
23 #include "api/BamAux.h"
24 #include "api/BamIndex.h"
25
26 namespace BamTools {
27
28 class BamAlignment;
29
30 namespace Internal {
31
32 class BamReaderPrivate;
33
34 class BamRandomAccessController {
35
36     // enums
37     public: enum RegionState { BeforeRegion = 0
38                              , OverlapsRegion
39                              , AfterRegion
40                              };
41
42     // ctor & dtor
43     public:
44         BamRandomAccessController(void);
45         ~BamRandomAccessController(void);
46
47     // BamRandomAccessController interface
48     public:
49
50         // index methods
51         void ClearIndex(void);
52         bool CreateIndex(BamReaderPrivate* reader, const BamIndex::IndexType& type);
53         bool HasIndex(void) const;
54         bool IndexHasAlignmentsForReference(const int& refId);
55         bool LocateIndex(BamReaderPrivate* reader, const BamIndex::IndexType& preferredType);
56         bool OpenIndex(const std::string& indexFilename, BamReaderPrivate* reader);
57         void SetIndex(BamIndex* index);
58         void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
59
60         // region methods
61         void ClearRegion(void);
62         bool HasRegion(void) const;
63         RegionState AlignmentState(const BamAlignment& alignment) const;
64         bool RegionHasAlignments(void) const;
65         bool SetRegion(const BamRegion& region, const int& referenceCount);
66
67         // general methods
68         void Close(void);
69         std::string GetErrorString(void) const;
70
71     // internal methods
72     private:
73         // adjusts requested region if necessary (depending on where data actually begins)
74         void AdjustRegion(const int& referenceCount);
75         // error-string handling
76         void SetErrorString(const std::string& where, const std::string& what);
77
78     // data members
79     private:
80
81         // index data
82         BamIndex* m_index;  // owns the index, not a copy - responsible for deleting
83         BamIndex::IndexCacheMode m_indexCacheMode;
84
85         // region data
86         BamRegion m_region;
87         bool m_hasAlignmentsInRegion;
88
89         // general data
90         std::string m_errorString;
91 };
92
93 } // namespace Internal
94 } // namespace BamTools
95
96 #endif // BAMRACONTROLLER_P_H