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