BamTools  2.5.1
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 <string>
14 #include "api/BamAux.h"
15 #include "api/api_global.h"
16 
17 namespace BamTools {
18 
19 namespace Internal {
20 class BamReaderPrivate;
21 } // namespace Internal
22 
35 {
36 
37  // enums
38 public:
39  // list of supported BamIndex types
40  enum IndexType
41  {
42  BAMTOOLS = 0,
43  STANDARD
44  };
45 
46  // ctor & dtor
47 public:
48  BamIndex(Internal::BamReaderPrivate* reader)
49  : m_reader(reader)
50  {}
51  virtual ~BamIndex() {}
52 
53  // index interface
54 public:
55  // builds index from associated BAM file & writes out to index file
56  virtual bool Create() = 0;
57 
58  // returns a human-readable description of the last error encountered
59  std::string GetErrorString()
60  {
61  return m_errorString;
62  }
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  // returns the 'type' enum for derived index format
77  virtual BamIndex::IndexType Type() const = 0;
78 
80 
81  // internal methods
82 protected:
83  void SetErrorString(const std::string& where, const std::string& what) const
84  {
85  m_errorString = where + ": " + what;
86  }
87 
88  // data members
89 protected:
90  Internal::BamReaderPrivate* m_reader; // copy, not owned
91  mutable std::string m_errorString;
92 
94 };
95 
96 } // namespace BamTools
97 
98 #endif // BAM_INDEX_H
BamAux.h
BamTools::BamIndex::GetErrorString
std::string GetErrorString()
Definition: BamIndex.h:59
BamTools
Contains all BamTools classes & methods.
Definition: Sort.h:24
API_EXPORT
#define API_EXPORT
Definition: api_global.h:18
BamTools::BamIndex::IndexType
IndexType
Definition: BamIndex.h:40
BamTools::BamIndex
Provides methods for generating & loading BAM index files.
Definition: BamIndex.h:34
api_global.h
BamTools::BamIndex::~BamIndex
virtual ~BamIndex()
Definition: BamIndex.h:51
BamTools::BamRegion
Represents a sequential genomic region.
Definition: BamAux.h:89
BamTools::BamIndex::BamIndex
BamIndex(Internal::BamReaderPrivate *reader)
Definition: BamIndex.h:48