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: 3 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
20 // BamTools includes
\r
23 namespace BamTools {
\r
27 // constructor / destructor
\r
35 // ----------------------
\r
36 // BAM file operations
\r
37 // ----------------------
\r
41 // returns whether index data is loaded (i.e. reader is able to Jump() or not)
\r
42 bool IsIndexLoaded(void) const;
\r
43 // returns whether reader is open for reading or not
\r
44 bool IsOpen(void) const;
\r
45 // performs random-access jump to reference, position
\r
46 bool Jump(int refID, int position = 0);
\r
47 // opens BAM file (and optional BAM index file, if provided)
\r
48 // @lookForIndex - if no indexFilename provided, look for an existing index file
\r
49 // @preferStandardIndex - if true, give priority in index file searching to standard BAM index
\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 // attempts a Jump() to left bound as well
\r
58 // returns success/failure of Jump()
\r
59 bool SetRegion(const BamRegion& region);
\r
60 bool SetRegion(const int& leftRefID, const int& leftBound, const int& rightRefID, const int& rightBound);
\r
62 // ----------------------
\r
63 // access alignment data
\r
64 // ----------------------
\r
66 // retrieves next available alignment (returns success/fail)
\r
67 bool GetNextAlignment(BamAlignment& bAlignment);
\r
69 // retrieves next available alignment core data (returns success/fail)
\r
70 // ** DOES NOT parse any character data (read name, bases, qualities, tag data)
\r
71 // these can be accessed, if necessary, from the supportData
\r
72 // useful for operations requiring ONLY positional or other alignment-related information
\r
73 bool GetNextAlignmentCore(BamAlignment& bAlignment);
\r
75 // ----------------------
\r
76 // access auxiliary data
\r
77 // ----------------------
\r
79 // returns SAM header text
\r
80 const std::string GetHeaderText(void) const;
\r
81 // returns number of reference sequences
\r
82 int GetReferenceCount(void) const;
\r
83 // returns vector of reference objects
\r
84 const BamTools::RefVector& GetReferenceData(void) const;
\r
85 // returns reference id (used for BamReader::Jump()) for the given reference name
\r
86 int GetReferenceID(const std::string& refName) const;
\r
87 // returns the name of the file associated with this BamReader
\r
88 const std::string GetFilename(void) const;
\r
90 // ----------------------
\r
91 // BAM index operations
\r
92 // ----------------------
\r
94 // creates index for BAM file, saves to file
\r
95 // default behavior is to create the BAM standard index (".bai")
\r
96 // set flag to false to create the BamTools-specific index (".bti")
\r
97 bool CreateIndex(bool useStandardIndex = true);
\r
99 // private implementation
\r
101 struct BamReaderPrivate;
\r
102 BamReaderPrivate* d;
\r
105 } // namespace BamTools
\r
107 #endif // BAMREADER_H
\r