]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/BamRandomAccessController_p.h
86af28c26cbd36efda32f1fde8ec58580927086d
[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: 24 February 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     // general interface
48     public:
49         void Close(void);
50
51     // index operations
52     public:
53         //
54         void ClearIndex(void);
55         bool CreateIndex(BamReaderPrivate* reader, const BamIndex::IndexType& type);
56         bool HasIndex(void) const;
57         bool IndexHasAlignmentsForReference(const int& refId);
58         bool LocateIndex(BamReaderPrivate* reader, const BamIndex::IndexType& preferredType);
59         bool OpenIndex(const std::string& indexFilename, BamReaderPrivate* reader);
60         void SetIndex(BamIndex* index);
61         void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
62
63     // region operations
64     public:
65         void ClearRegion(void);
66         bool HasRegion(void) const;
67         RegionState AlignmentState(const BamAlignment& alignment) const;
68         bool RegionHasAlignments(void) const;
69         bool SetRegion(BamReaderPrivate* reader,
70                        const BamRegion& region,
71                        const int& referenceCount);
72
73     // 'internal' methods
74     public:
75         // adjusts requested region if necessary (depending on where data actually begins)
76         void AdjustRegion(const int& referenceCount);
77
78     // data members
79     private:
80
81         // index data
82         BamIndex* m_index;  // owns 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
90 } // namespace Internal
91 } // namespace BamTools
92
93 #endif // BAMRACONTROLLER_P_H