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: 4 March 2011 (DB)
\r
7 // ---------------------------------------------------------------------------
\r
8 // Provides read access to BAM files.
\r
9 // ***************************************************************************
\r
14 #include <api/api_global.h>
\r
15 #include <api/BamAlignment.h>
\r
16 #include <api/BamIndex.h>
\r
17 #include <api/SamHeader.h>
\r
20 namespace BamTools {
\r
22 namespace Internal {
\r
23 class BamReaderPrivate;
\r
24 } // namespace Internal
\r
26 class API_EXPORT BamReader {
\r
28 // constructor / destructor
\r
36 // ----------------------
\r
37 // BAM file operations
\r
38 // ----------------------
\r
40 // closes the current BAM file
\r
42 // returns filename of current BAM file
\r
43 const std::string GetFilename(void) const;
\r
44 // returns true if a BAM file is open for reading
\r
45 bool IsOpen(void) const;
\r
46 // performs random-access jump within BAM file
\r
47 bool Jump(int refID, int position = 0);
\r
49 bool Open(const std::string& filename);
\r
50 // returns internal file pointer to beginning of alignment data
\r
52 // sets the target region of interest
\r
53 bool SetRegion(const BamRegion& region);
\r
54 // sets the target region of interest
\r
55 bool SetRegion(const int& leftRefID,
\r
56 const int& leftPosition,
\r
57 const int& rightRefID,
\r
58 const int& rightPosition);
\r
60 // ----------------------
\r
61 // access alignment data
\r
62 // ----------------------
\r
64 // retrieves next available alignment
\r
65 bool GetNextAlignment(BamAlignment& alignment);
\r
66 // retrieves next available alignmnet (without populating the alignment's string data fields)
\r
67 bool GetNextAlignmentCore(BamAlignment& alignment);
\r
69 // ----------------------
\r
70 // access header data
\r
71 // ----------------------
\r
73 // returns SAM header data
\r
74 SamHeader GetHeader(void) const;
\r
75 // returns SAM header data, as SAM-formatted text
\r
76 std::string GetHeaderText(void) const;
\r
78 // ----------------------
\r
79 // access reference data
\r
80 // ----------------------
\r
82 // returns the number of reference sequences
\r
83 int GetReferenceCount(void) const;
\r
84 // returns all reference sequence entries
\r
85 const RefVector& GetReferenceData(void) const;
\r
86 // returns the ID of the reference with this name
\r
87 int GetReferenceID(const std::string& refName) const;
\r
89 // ----------------------
\r
90 // BAM index operations
\r
91 // ----------------------
\r
93 // creates an index file for current BAM file, using the requested index type
\r
94 bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
\r
95 // returns true if index data is available
\r
96 bool HasIndex(void) const;
\r
97 // looks in BAM file's directory for a matching index file
\r
98 bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
\r
99 // opens a BAM index file
\r
100 bool OpenIndex(const std::string& indexFilename);
\r
101 // sets a custom BamIndex on this reader
\r
102 void SetIndex(BamIndex* index);
\r
103 // changes the caching behavior of the index data
\r
104 void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
\r
106 // deprecated methods
\r
108 // returns true if index data is available
\r
109 bool IsIndexLoaded(void) const;
\r
111 // private implementation
\r
113 Internal::BamReaderPrivate* d;
\r
116 } // namespace BamTools
\r
118 #endif // BAMREADER_H
\r