BamTools  2.4.0
BamReader.h
Go to the documentation of this file.
1 // ***************************************************************************
2 // BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 18 November 2012 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides read access to BAM files.
8 // ***************************************************************************
9 
10 #ifndef BAMREADER_H
11 #define BAMREADER_H
12 
13 #include "api/api_global.h"
14 #include "api/BamAlignment.h"
15 #include "api/BamIndex.h"
16 #include "api/SamHeader.h"
17 #include <string>
18 
19 namespace BamTools {
20 
21 namespace Internal {
22  class BamReaderPrivate;
23 } // namespace Internal
24 
26 
27  // constructor / destructor
28  public:
29  BamReader(void);
30  ~BamReader(void);
31 
32  // public interface
33  public:
34 
35  // ----------------------
36  // BAM file operations
37  // ----------------------
38 
39  // closes the current BAM file
40  bool Close(void);
41  // returns filename of current BAM file
42  const std::string GetFilename(void) const;
43  // returns true if a BAM file is open for reading
44  bool IsOpen(void) const;
45  // performs random-access jump within BAM file
46  bool Jump(int refID, int position = 0);
47  // opens a BAM file
48  bool Open(const std::string& filename);
49  // returns internal file pointer to beginning of alignment data
50  bool Rewind(void);
51  // sets the target region of interest
52  bool SetRegion(const BamRegion& region);
53  // sets the target region of interest
54  bool SetRegion(const int& leftRefID,
55  const int& leftPosition,
56  const int& rightRefID,
57  const int& rightPosition);
58 
59  // ----------------------
60  // access alignment data
61  // ----------------------
62 
63  // retrieves next available alignment
64  bool GetNextAlignment(BamAlignment& alignment);
65  // retrieves next available alignmnet (without populating the alignment's string data fields)
66  bool GetNextAlignmentCore(BamAlignment& alignment);
67 
68  // ----------------------
69  // access header data
70  // ----------------------
71 
72  // returns a read-only reference to SAM header data
73  const SamHeader& GetConstSamHeader(void) const;
74  // returns an editable copy of SAM header data
75  SamHeader GetHeader(void) const;
76  // returns SAM header data, as SAM-formatted text
77  std::string GetHeaderText(void) const;
78 
79  // ----------------------
80  // access reference data
81  // ----------------------
82 
83  // returns the number of reference sequences
84  int GetReferenceCount(void) const;
85  // returns all reference sequence entries
86  const RefVector& GetReferenceData(void) const;
87  // returns the ID of the reference with this name
88  int GetReferenceID(const std::string& refName) const;
89 
90  // ----------------------
91  // BAM index operations
92  // ----------------------
93 
94  // creates an index file for current BAM file, using the requested index type
95  bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
96  // returns true if index data is available
97  bool HasIndex(void) const;
98  // looks in BAM file's directory for a matching index file
99  bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
100  // opens a BAM index file
101  bool OpenIndex(const std::string& indexFilename);
102  // sets a custom BamIndex on this reader
103  void SetIndex(BamIndex* index);
104 
105  // ----------------------
106  // error handling
107  // ----------------------
108 
109  // returns a human-readable description of the last error that occurred
110  std::string GetErrorString(void) const;
111 
112  // private implementation
113  private:
114  Internal::BamReaderPrivate* d;
115 };
116 
117 } // namespace BamTools
118 
119 #endif // BAMREADER_H
The main BAM alignment data structure.
Definition: BamAlignment.h:32
Definition: BamIndex.h:41
Represents a sequential genomic region.
Definition: BamAux.h:88
IndexType
Definition: BamIndex.h:40
Provides read access to BAM files.
Definition: BamReader.h:25
#define API_EXPORT
Definition: api_global.h:18
Represents the SAM-formatted text header that is part of the BAM file header.
Definition: SamHeader.h:24
Provides methods for generating & loading BAM index files.
Definition: BamIndex.h:34
Contains all BamTools classes & methods.
Definition: Sort.h:24
std::vector< RefData > RefVector
convenience typedef for vector of RefData entries
Definition: BamAux.h:74