]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamReader.h
Moved BamAlignment data structure out to its own .h/.cpp. BamAux.h was getting over...
[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: 18 September 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 <string>\r
18 #include "BamAlignment.h"\r
19 \r
20 namespace BamTools {\r
21   \r
22 class BamReader {\r
23 \r
24     // constructor / destructor\r
25     public:\r
26         BamReader(void);\r
27         ~BamReader(void);\r
28 \r
29     // public interface\r
30     public:\r
31 \r
32         // ----------------------\r
33         // BAM file operations\r
34         // ----------------------\r
35 \r
36         // close BAM file\r
37         void Close(void);\r
38         // returns whether index data is loaded (i.e. reader is able to Jump() or not)\r
39         bool IsIndexLoaded(void) const;\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 for an existing index file\r
46         // @preferStandardIndex - if true, give priority in index file searching to standard BAM index\r
47         bool Open(const std::string& filename, \r
48                   const std::string& indexFilename = "", \r
49                   const bool lookForIndex = false, \r
50                   const bool preferStandardIndex = false);\r
51         // returns file pointer to beginning of alignments\r
52         bool Rewind(void);\r
53         // sets a region of interest (with left & right bound reference/position)\r
54         // attempts a Jump() to left bound as well\r
55         // returns success/failure of Jump()\r
56         bool SetRegion(const BamRegion& region);\r
57         bool SetRegion(const int& leftRefID, const int& leftBound, const int& rightRefID, const int& rightBound);\r
58 \r
59         // ----------------------\r
60         // access alignment data\r
61         // ----------------------\r
62 \r
63         // retrieves next available alignment (returns success/fail)\r
64         bool GetNextAlignment(BamAlignment& bAlignment);\r
65         \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 (refId/position, alignment flags, CIGAR, mapQuality, etc)\r
69         bool GetNextAlignmentCore(BamAlignment& bAlignment);\r
70 \r
71         // ----------------------\r
72         // access auxiliary data\r
73         // ----------------------\r
74 \r
75         // returns SAM header text\r
76         const std::string GetHeaderText(void) const;\r
77         // returns number of reference sequences\r
78         int GetReferenceCount(void) const;\r
79         // returns vector of reference objects\r
80         const BamTools::RefVector& GetReferenceData(void) const;\r
81         // returns reference id (used for BamReader::Jump()) for the given reference name\r
82         int GetReferenceID(const std::string& refName) const;\r
83         // returns the name of the file associated with this BamReader\r
84         const std::string GetFilename(void) const;\r
85 \r
86         // ----------------------\r
87         // BAM index operations\r
88         // ----------------------\r
89 \r
90         // creates index for BAM file, saves to file\r
91         // default behavior is to create the BAM standard index (".bai")\r
92         // set flag to false to create the BamTools-specific index (".bti")\r
93         bool CreateIndex(bool useStandardIndex = true);\r
94         \r
95     // private implementation\r
96     private:\r
97         struct BamReaderPrivate;\r
98         BamReaderPrivate* d;\r
99 };\r
100 \r
101 } // namespace BamTools\r
102 \r
103 #endif // BAMREADER_H\r