1 // ***************************************************************************
\r
2 // BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg
\r
3 // Marth Lab, Department of Biology, Boston College
\r
4 // ---------------------------------------------------------------------------
\r
5 // Last modified: 10 October 2011 (DB)
\r
6 // ---------------------------------------------------------------------------
\r
7 // Provides read access to BAM files.
\r
8 // ***************************************************************************
\r
13 #include "api/api_global.h"
\r
14 #include "api/BamAlignment.h"
\r
15 #include "api/BamIndex.h"
\r
16 #include "api/SamHeader.h"
\r
19 namespace BamTools {
\r
21 namespace Internal {
\r
22 class BamReaderPrivate;
\r
23 } // namespace Internal
\r
25 class API_EXPORT BamReader {
\r
27 // constructor / destructor
\r
35 // ----------------------
\r
36 // BAM file operations
\r
37 // ----------------------
\r
39 // closes the current BAM file
\r
41 // returns filename of current BAM file
\r
42 const std::string GetFilename(void) const;
\r
43 // returns true if a BAM file is open for reading
\r
44 bool IsOpen(void) const;
\r
45 // performs random-access jump within BAM file
\r
46 bool Jump(int refID, int position = 0);
\r
48 bool Open(const std::string& filename);
\r
49 // returns internal file pointer to beginning of alignment data
\r
51 // sets the target region of interest
\r
52 bool SetRegion(const BamRegion& region);
\r
53 // sets the target region of interest
\r
54 bool SetRegion(const int& leftRefID,
\r
55 const int& leftPosition,
\r
56 const int& rightRefID,
\r
57 const int& rightPosition);
\r
59 // ----------------------
\r
60 // access alignment data
\r
61 // ----------------------
\r
63 // retrieves next available alignment
\r
64 bool GetNextAlignment(BamAlignment& alignment);
\r
65 // retrieves next available alignmnet (without populating the alignment's string data fields)
\r
66 bool GetNextAlignmentCore(BamAlignment& alignment);
\r
68 // ----------------------
\r
69 // access header data
\r
70 // ----------------------
\r
72 // returns SAM header data
\r
73 SamHeader GetHeader(void) const;
\r
74 // returns SAM header data, as SAM-formatted text
\r
75 std::string GetHeaderText(void) const;
\r
77 // ----------------------
\r
78 // access reference data
\r
79 // ----------------------
\r
81 // returns the number of reference sequences
\r
82 int GetReferenceCount(void) const;
\r
83 // returns all reference sequence entries
\r
84 const RefVector& GetReferenceData(void) const;
\r
85 // returns the ID of the reference with this name
\r
86 int GetReferenceID(const std::string& refName) const;
\r
88 // ----------------------
\r
89 // BAM index operations
\r
90 // ----------------------
\r
92 // creates an index file for current BAM file, using the requested index type
\r
93 bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
\r
94 // returns true if index data is available
\r
95 bool HasIndex(void) const;
\r
96 // looks in BAM file's directory for a matching index file
\r
97 bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
\r
98 // opens a BAM index file
\r
99 bool OpenIndex(const std::string& indexFilename);
\r
100 // sets a custom BamIndex on this reader
\r
101 void SetIndex(BamIndex* index);
\r
103 // ----------------------
\r
105 // ----------------------
\r
107 // returns a human-readable description of the last error that occurred
\r
108 std::string GetErrorString(void) const;
\r
110 // private implementation
\r
112 Internal::BamReaderPrivate* d;
\r
115 } // namespace BamTools
\r
117 #endif // BAMREADER_H
\r