BamTools  2.4.0
BamIndex.h
Go to the documentation of this file.
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 // ***************************************************************************
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 
35 
36  // enums
37  public:
38 
39  // list of supported BamIndex types
40  enum IndexType { BAMTOOLS = 0
41  , STANDARD
42  };
43 
44  // ctor & dtor
45  public:
46  BamIndex(Internal::BamReaderPrivate* reader) : m_reader(reader) { }
47  virtual ~BamIndex(void) { }
48 
49  // index interface
50  public:
51  // builds index from associated BAM file & writes out to index file
52  virtual bool Create(void) =0;
53 
54  // returns a human-readable description of the last error encountered
55  std::string GetErrorString(void) { return m_errorString; }
56 
57  // returns whether reference has alignments or no
58  virtual bool HasAlignments(const int& referenceID) const =0;
59 
60  // attempts to use index data to jump to @region, returns success/fail
61  // a "successful" jump indicates no error, but not whether this region has data
62  // * thus, the method sets a flag to indicate whether there are alignments
63  // available after the jump position
64  virtual bool Jump(const BamTools::BamRegion& region, bool* hasAlignmentsInRegion) =0;
65 
66  // loads existing data from file into memory
67  virtual bool Load(const std::string& filename) =0;
68 
69  // returns the 'type' enum for derived index format
70  virtual BamIndex::IndexType Type(void) const =0;
71 
73 
74  // internal methods
75  protected:
76  void SetErrorString(const std::string& where, const std::string& what) const {
77  m_errorString = where + ": " + what;
78  }
79 
80  // data members
81  protected:
82  Internal::BamReaderPrivate* m_reader; // copy, not owned
83  mutable std::string m_errorString;
84 
86 };
87 
88 } // namespace BamTools
89 
90 #endif // BAM_INDEX_H
std::string GetErrorString(void)
Definition: BamIndex.h:55
virtual ~BamIndex(void)
Definition: BamIndex.h:47
Represents a sequential genomic region.
Definition: BamAux.h:88
IndexType
Definition: BamIndex.h:40
#define API_EXPORT
Definition: api_global.h:18
BamIndex(Internal::BamReaderPrivate *reader)
Definition: BamIndex.h:46
Provides methods for generating & loading BAM index files.
Definition: BamIndex.h:34
Contains all BamTools classes & methods.
Definition: Sort.h:24