]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/BamRandomAccessController_p.h
Major update to BamTools version 1.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 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 24 February 2011(DB)
7 // ---------------------------------------------------------------------------
8 // Manages random access operations in a BAM file
9 // ***************************************************************************
10
11 #ifndef BAMRACONTROLLER_P_H
12 #define BAMRACONTROLLER_P_H
13
14 //  -------------
15 //  W A R N I N G
16 //  -------------
17 //
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.
21 //
22 // We mean it.
23
24 #include <api/BamAux.h>
25 #include <api/BamIndex.h>
26
27 namespace BamTools {
28
29 class BamAlignment;
30
31 namespace Internal {
32
33 class BamReaderPrivate;
34
35 class BamRandomAccessController {
36
37     // enums
38     public: enum RegionState { BeforeRegion = 0
39                              , OverlapsRegion
40                              , AfterRegion
41                              };
42
43     // ctor & dtor
44     public:
45         BamRandomAccessController(void);
46         ~BamRandomAccessController(void);
47
48     // general interface
49     public:
50         void Close(void);
51
52     // index operations
53     public:
54         //
55         void ClearIndex(void);
56         bool CreateIndex(BamReaderPrivate* reader, const BamIndex::IndexType& type);
57         bool HasIndex(void) const;
58         bool IndexHasAlignmentsForReference(const int& refId);
59         bool LocateIndex(const std::string& bamFilename, const BamIndex::IndexType& preferredType);
60         bool OpenIndex(const std::string& indexFilename);
61         void SetIndex(BamIndex* index);
62         void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
63
64     // region operations
65     public:
66         void ClearRegion(void);
67         bool HasRegion(void) const;
68         RegionState AlignmentState(const BamAlignment& alignment) const;
69         bool RegionHasAlignments(void) const;
70         bool SetRegion(BamReaderPrivate* reader,
71                        const BamRegion& region,
72                        const int& referenceCount);
73
74     // 'internal' methods
75     public:
76         // adjusts requested region if necessary (depending on where data actually begins)
77         void AdjustRegion(const int& referenceCount);
78
79     // data members
80     private:
81
82         // index data
83         BamIndex* m_index;  // owns index, not a copy - responsible for deleting
84         BamIndex::IndexCacheMode m_indexCacheMode;
85
86         // region data
87         BamRegion m_region;
88         bool m_hasAlignmentsInRegion;
89 };
90
91 } // namespace Internal
92 } // namespace BamTools
93
94 #endif // BAMRACONTROLLER_P_H