]> git.donarmstrong.com Git - bamtools.git/blob - BamReader.h
Gracefully handle empty files with the BamMultiReader
[bamtools.git] / 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: 16 June 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 // C++ includes\r
18 #include <string>\r
19 \r
20 // BamTools includes\r
21 #include "BamAux.h"\r
22 \r
23 namespace BamTools {\r
24   \r
25 class 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         // performs random-access jump to reference, position\r
42         bool Jump(int refID, int position = 0);\r
43         // opens BAM file (and optional BAM index file, if provided)\r
44         void Open(const std::string& filename, const std::string& indexFilename = "");\r
45         // returns file pointer to beginning of alignments\r
46         bool Rewind(void);\r
47         // sets a region of interest (with left & right bound reference/position)\r
48         // attempts a Jump() to left bound as well\r
49         // returns success/failure of Jump()\r
50         bool SetRegion(const BamRegion& region);\r
51         bool SetRegion(const int& leftRefID, const int& leftBound, const int& rightRefID, const int& rightBound);\r
52 \r
53         // ----------------------\r
54         // access alignment data\r
55         // ----------------------\r
56 \r
57         // retrieves next available alignment (returns success/fail)\r
58         bool GetNextAlignment(BamAlignment& bAlignment);\r
59         \r
60         // retrieves next available alignment core data (returns success/fail)\r
61         // ** DOES NOT parse any character data (bases, qualities, tag data)\r
62         //    these can be accessed, if necessary, from the supportData \r
63         // useful for operations requiring ONLY positional or other alignment-related information\r
64         bool GetNextAlignmentCore(BamAlignment& bAlignment);\r
65 \r
66         // ----------------------\r
67         // access auxiliary data\r
68         // ----------------------\r
69 \r
70         // returns SAM header text\r
71         const std::string GetHeaderText(void) const;\r
72         // returns number of reference sequences\r
73         int GetReferenceCount(void) const;\r
74         // returns vector of reference objects\r
75         const BamTools::RefVector GetReferenceData(void) const;\r
76         // returns reference id (used for BamReader::Jump()) for the given reference name\r
77         int GetReferenceID(const std::string& refName) const;\r
78         // returns the name of the file associated with this BamReader\r
79         const std::string GetFilename(void) const;\r
80 \r
81         // ----------------------\r
82         // BAM index operations\r
83         // ----------------------\r
84 \r
85         // creates index for BAM file, saves to file (default = bamFilename + ".bai")\r
86         bool CreateIndex(void);\r
87 \r
88     // private implementation\r
89     private:\r
90         struct BamReaderPrivate;\r
91         BamReaderPrivate* d;\r
92 };\r
93 \r
94 } // namespace BamTools\r
95 \r
96 #endif // BAMREADER_H\r