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
10 // ---------------------------------------------------------------------------
\r
11 // Provides the basic functionality for reading BAM files
\r
12 // ***************************************************************************
\r
18 #include "BamAlignment.h"
\r
20 namespace BamTools {
\r
24 // constructor / destructor
\r
32 // ----------------------
\r
33 // BAM file operations
\r
34 // ----------------------
\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
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
59 // ----------------------
\r
60 // access alignment data
\r
61 // ----------------------
\r
63 // retrieves next available alignment (returns success/fail)
\r
64 bool GetNextAlignment(BamAlignment& bAlignment);
\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
71 // ----------------------
\r
72 // access auxiliary data
\r
73 // ----------------------
\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
86 // ----------------------
\r
87 // BAM index operations
\r
88 // ----------------------
\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
95 // private implementation
\r
97 struct BamReaderPrivate;
\r
98 BamReaderPrivate* d;
\r
101 } // namespace BamTools
\r
103 #endif // BAMREADER_H
\r