]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamIndex.h
Cleaned up output/exception/asserts, etc after last merge
[bamtools.git] / src / api / BamIndex.h
1 // ***************************************************************************
2 // BamIndex.h (c) 2009 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 6 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides basic BAM index interface
8 // ***************************************************************************
9
10 #ifndef BAM_INDEX_H
11 #define BAM_INDEX_H
12
13 #include <api/api_global.h>
14 #include <api/BamAux.h>
15 #include <string>
16
17 namespace BamTools {
18
19 namespace Internal {
20     class BamReaderPrivate;
21 } // namespace Internal
22
23 /*! \class BamTools::BamIndex
24     \brief Provides methods for generating & loading BAM index files.
25
26     This class straddles the line between public API and internal
27     implementation detail. Most client code should never have to use this
28     class directly.
29
30     It is exposed to the public API to allow advanced users to implement
31     their own custom indexing schemes.
32
33     More documentation on methods & enums coming soon.
34 */
35
36 class API_EXPORT BamIndex {
37
38     // enums
39     public:
40         // specify index-caching behavior
41         enum IndexCacheMode { FullIndexCaching = 0 // store entire index file contents in memory
42                             , LimitedIndexCaching  // store only index data for current reference
43                             , NoIndexCaching       // do not store any index data between jumps
44                             };
45
46         // list of supported BamIndex types
47         enum IndexType { BAMTOOLS = 0
48                        , STANDARD
49                        };
50   
51     // ctor & dtor
52     public:
53         BamIndex(Internal::BamReaderPrivate* reader) : m_reader(reader) { }
54         virtual ~BamIndex(void) { }
55         
56     // index interface
57     public:
58         // builds index from associated BAM file & writes out to index file
59         virtual bool Create(void) =0;
60
61         // returns a human-readable description of the last error encountered
62         std::string GetErrorString(void) { return m_errorString; }
63
64         // returns whether reference has alignments or no
65         virtual bool HasAlignments(const int& referenceID) const =0;
66
67         // attempts to use index data to jump to @region, returns success/fail
68         // a "successful" jump indicates no error, but not whether this region has data
69         //   * thus, the method sets a flag to indicate whether there are alignments
70         //     available after the jump position
71         virtual bool Jump(const BamTools::BamRegion& region, bool* hasAlignmentsInRegion) =0;
72
73         // loads existing data from file into memory
74         virtual bool Load(const std::string& filename) =0;
75
76         // change the index caching behavior
77         virtual void SetCacheMode(const BamIndex::IndexCacheMode& mode) =0;
78
79     // internal methods
80     protected:
81         void SetErrorString(const std::string& where, const std::string& what) const {
82             m_errorString = where + ": " + what;
83         }
84
85     // data members
86     protected:
87         Internal::BamReaderPrivate* m_reader; // copy, not owned
88         mutable std::string m_errorString;
89 };
90
91 } // namespace BamTools
92
93 #endif // BAM_INDEX_H