BamTools  2.5.1
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 <string>
14 #include "api/BamAlignment.h"
15 #include "api/BamIndex.h"
16 #include "api/SamHeader.h"
17 #include "api/api_global.h"
18 
19 namespace BamTools {
20 
21 namespace Internal {
22 class BamReaderPrivate;
23 } // namespace Internal
24 
26 {
27 
28  // constructor / destructor
29 public:
30  BamReader();
31  ~BamReader();
32 
33  // public interface
34 public:
35  // ----------------------
36  // BAM file operations
37  // ----------------------
38 
39  // closes the current BAM file
40  bool Close();
41  // returns filename of current BAM file
42  const std::string GetFilename() const;
43  // returns true if a BAM file is open for reading
44  bool IsOpen() 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();
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, const int& leftPosition, const int& rightRefID,
55  const int& rightPosition);
56 
57  // ----------------------
58  // access alignment data
59  // ----------------------
60 
61  // retrieves next available alignment
62  bool GetNextAlignment(BamAlignment& alignment);
63  // retrieves next available alignmnet (without populating the alignment's string data fields)
64  bool GetNextAlignmentCore(BamAlignment& alignment);
65 
66  // ----------------------
67  // access header data
68  // ----------------------
69 
70  // returns a read-only reference to SAM header data
71  const SamHeader& GetConstSamHeader() const;
72  // returns an editable copy of SAM header data
73  SamHeader GetHeader() const;
74  // returns SAM header data, as SAM-formatted text
75  std::string GetHeaderText() const;
76 
77  // ----------------------
78  // access reference data
79  // ----------------------
80 
81  // returns the number of reference sequences
82  int GetReferenceCount() const;
83  // returns all reference sequence entries
84  const RefVector& GetReferenceData() const;
85  // returns the ID of the reference with this name
86  int GetReferenceID(const std::string& refName) const;
87 
88  // ----------------------
89  // BAM index operations
90  // ----------------------
91 
92  // creates an index file for current BAM file, using the requested index type
93  bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
94  // returns true if index data is available
95  bool HasIndex() const;
96  // looks in BAM file's directory for a matching index file
97  bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
98  // opens a BAM index file
99  bool OpenIndex(const std::string& indexFilename);
100  // sets a custom BamIndex on this reader
101  void SetIndex(BamIndex* index);
102 
103  // ----------------------
104  // error handling
105  // ----------------------
106 
107  // returns a human-readable description of the last error that occurred
108  std::string GetErrorString() const;
109 
110  // private implementation
111 private:
112  Internal::BamReaderPrivate* d;
113 };
114 
115 } // namespace BamTools
116 
117 #endif // BAMREADER_H
SamHeader.h
BamTools::BamIndex::STANDARD
@ STANDARD
Definition: BamIndex.h:43
BamAlignment.h
BamTools::BamAlignment
The main BAM alignment data structure.
Definition: BamAlignment.h:33
BamTools::SamHeader
Represents the SAM-formatted text header that is part of the BAM file header.
Definition: SamHeader.h:23
BamIndex.h
BamTools::BamReader
Provides read access to BAM files.
Definition: BamReader.h:25
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::RefVector
std::vector< RefData > RefVector
convenience typedef for vector of RefData entries
Definition: BamAux.h:75
BamTools::BamRegion
Represents a sequential genomic region.
Definition: BamAux.h:89