]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamReader.h
Added API_EXPORT macro to classes in BamTools API
[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: 19 November 2010 (DB)\r
7 // ---------------------------------------------------------------------------\r
8 // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad\r
9 // Institute.\r
10 // ---------------------------------------------------------------------------\r
11 // Provides the basic functionality for reading BAM files\r
12 // ***************************************************************************\r
13 \r
14 #ifndef BAMREADER_H\r
15 #define BAMREADER_H\r
16 \r
17 #include <api/api_global.h>\r
18 #include <api/BamAlignment.h>\r
19 #include <api/BamIndex.h>\r
20 #include <string>\r
21 \r
22 namespace BamTools {\r
23   \r
24 class API_EXPORT BamReader {\r
25 \r
26     // constructor / destructor\r
27     public:\r
28         BamReader(void);\r
29         ~BamReader(void);\r
30 \r
31     // public interface\r
32     public:\r
33 \r
34         // ----------------------\r
35         // BAM file operations\r
36         // ----------------------\r
37 \r
38         // close BAM file\r
39         void Close(void);\r
40         // returns whether reader is open for reading or not\r
41         bool IsOpen(void) const;\r
42         // performs random-access jump using (reference, position) as a left-bound\r
43         bool Jump(int refID, int position = 0);\r
44         // opens BAM file (and optional BAM index file, if provided)\r
45         // @lookForIndex - if no indexFilename provided, look in BAM file's directory for an existing index file\r
46         //   default behavior is to skip index file search if no index filename given\r
47         // @preferStandardIndex - if true, give priority in index file searching to standard BAM index (*.bai)\r
48         //   default behavior is to prefer the BamToolsIndex (*.bti) if both are available\r
49         bool Open(const std::string& filename, \r
50                   const std::string& indexFilename = "", \r
51                   const bool lookForIndex = false, \r
52                   const bool preferStandardIndex = false);\r
53         // returns file pointer to beginning of alignments\r
54         bool Rewind(void);\r
55         // sets a region of interest (with left & right bound reference/position)\r
56         // returns success/failure of seeking to left bound of region\r
57         bool SetRegion(const BamRegion& region);\r
58         bool SetRegion(const int& leftRefID, const int& leftBound, const int& rightRefID, const int& rightBound);\r
59 \r
60         // ----------------------\r
61         // access alignment data\r
62         // ----------------------\r
63 \r
64         // retrieves next available alignment (returns success/fail)\r
65         bool GetNextAlignment(BamAlignment& bAlignment);\r
66         // retrieves next available alignment core data (returns success/fail)\r
67         // ** DOES NOT parse any character data (read name, bases, qualities, tag data) **\r
68         // useful for operations requiring ONLY aligner-related information \r
69         // (refId/position, alignment flags, CIGAR, mapQuality, etc)\r
70         bool GetNextAlignmentCore(BamAlignment& bAlignment);\r
71 \r
72         // ----------------------\r
73         // access auxiliary data\r
74         // ----------------------\r
75 \r
76         // returns SAM header text\r
77         const std::string GetHeaderText(void) const;\r
78         // returns number of reference sequences\r
79         int GetReferenceCount(void) const;\r
80         // returns vector of reference objects\r
81         const BamTools::RefVector& GetReferenceData(void) const;\r
82         // returns reference id (used for BamReader::Jump()) for the given reference name\r
83         int GetReferenceID(const std::string& refName) const;\r
84         // returns the name of the file associated with this BamReader\r
85         const std::string GetFilename(void) const;\r
86 \r
87         // ----------------------\r
88         // BAM index operations\r
89         // ----------------------\r
90 \r
91         // creates index for BAM file, saves to file\r
92         // default behavior is to create the BAM standard index (".bai")\r
93         // set flag to false to create the BamTools-specific index (".bti")\r
94         bool CreateIndex(bool useStandardIndex = true);\r
95         // returns whether index data is available for reading \r
96         // (e.g. if true, BamReader should be able to seek to a region)\r
97         bool HasIndex(void) const;\r
98         // change the index caching behavior\r
99         // default BamReader/Index mode is LimitedIndexCaching\r
100         // @mode - can be either FullIndexCaching, LimitedIndexCaching, \r
101         //   or NoIndexCaching. See BamIndex.h for more details\r
102         void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);\r
103         \r
104     // deprecated methods\r
105     public:\r
106         \r
107         // deprecated (but still available): prefer HasIndex() instead\r
108         //\r
109         // Deprecated purely for API semantic clarity - HasIndex() should be clearer \r
110         // than IsIndexLoaded() in light of the new caching modes that may clear the \r
111         // index data from memory, but leave the index file open for later random access \r
112         // seeks.\r
113         //\r
114         // For example, what would (IsIndexLoaded() == true) mean when cacheMode has been \r
115         // explicitly set to NoIndexCaching? This is confusing at best, misleading about \r
116         // current memory behavior at worst.\r
117         //\r
118         // returns whether index data is available \r
119         // (e.g. if true, BamReader should be able to seek to a region)\r
120         bool IsIndexLoaded(void) const;\r
121         \r
122     // private implementation\r
123     private:\r
124         struct BamReaderPrivate;\r
125         BamReaderPrivate* d;\r
126 };\r
127 \r
128 } // namespace BamTools\r
129 \r
130 #endif // BAMREADER_H\r