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