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