1 // ***************************************************************************
2 // BamIndex.h (c) 2009 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides basic BAM index interface
8 // ***************************************************************************
13 #include "api/api_global.h"
14 #include "api/BamAux.h"
20 class BamReaderPrivate;
21 } // namespace Internal
23 /*! \class BamTools::BamIndex
24 \brief Provides methods for generating & loading BAM index files.
26 This class straddles the line between public API and internal
27 implementation detail. Most client code should never have to use this
30 It is exposed to the public API to allow advanced users to implement
31 their own custom indexing schemes.
34 class API_EXPORT BamIndex {
38 // specify index-caching behavior
39 enum IndexCacheMode { FullIndexCaching = 0 // store entire index file contents in memory
40 , LimitedIndexCaching // store only index data for current reference
41 , NoIndexCaching // do not store any index data between jumps
44 // list of supported BamIndex types
45 enum IndexType { BAMTOOLS = 0
51 BamIndex(Internal::BamReaderPrivate* reader) : m_reader(reader) { }
52 virtual ~BamIndex(void) { }
56 // builds index from associated BAM file & writes out to index file
57 virtual bool Create(void) =0;
59 // returns a human-readable description of the last error encountered
60 std::string GetErrorString(void) { return m_errorString; }
62 // returns whether reference has alignments or no
63 virtual bool HasAlignments(const int& referenceID) const =0;
65 // attempts to use index data to jump to @region, returns success/fail
66 // a "successful" jump indicates no error, but not whether this region has data
67 // * thus, the method sets a flag to indicate whether there are alignments
68 // available after the jump position
69 virtual bool Jump(const BamTools::BamRegion& region, bool* hasAlignmentsInRegion) =0;
71 // loads existing data from file into memory
72 virtual bool Load(const std::string& filename) =0;
74 // change the index caching behavior
75 virtual void SetCacheMode(const BamIndex::IndexCacheMode& mode) =0;
81 void SetErrorString(const std::string& where, const std::string& what) const {
82 m_errorString = where + ": " + what;
87 Internal::BamReaderPrivate* m_reader; // copy, not owned
88 mutable std::string m_errorString;
93 } // namespace BamTools