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
14 #include <api/api_global.h>
\r
15 #include <api/BamAlignment.h>
\r
16 #include <api/BamIndex.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
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
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
61 // ----------------------
\r
62 // access alignment data
\r
63 // ----------------------
\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
73 // ----------------------
\r
74 // access auxiliary data
\r
75 // ----------------------
\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
88 // ----------------------
\r
89 // BAM index operations
\r
90 // ----------------------
\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
105 // deprecated methods
\r
108 // deprecated (but still available): prefer HasIndex() instead
\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
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
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
123 // private implementation
\r
125 Internal::BamReaderPrivate* d;
\r
128 } // namespace BamTools
\r
130 #endif // BAMREADER_H
\r