1 // ***************************************************************************
2 // BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Convenience class for reading multiple BAM files.
8 // ***************************************************************************
10 #ifndef BAMMULTIREADER_H
11 #define BAMMULTIREADER_H
13 #include "api/api_global.h"
14 #include "api/BamReader.h"
23 class BamMultiReaderPrivate;
24 } // namespace Internal
26 class API_EXPORT BamMultiReader {
28 // constructor / destructor
31 ~BamMultiReader(void);
36 // ----------------------
37 // BAM file operations
38 // ----------------------
40 // closes all open BAM files
42 // close only the requested BAM file
43 bool CloseFile(const std::string& filename);
44 // returns list of filenames for all open BAM files
45 const std::vector<std::string> Filenames(void) const;
46 // returns true if multireader has any open BAM files
47 bool HasOpenReaders(void) const;
48 // performs random-access jump within current BAM files
49 bool Jump(int refID, int position = 0);
51 bool Open(const std::vector<std::string>& filenames);
52 // opens a single BAM file, adding to any other current BAM files
53 bool OpenFile(const std::string& filename);
54 // returns file pointers to beginning of alignments
56 // sets the target region of interest
57 bool SetRegion(const BamRegion& region);
58 // sets the target region of interest
59 bool SetRegion(const int& leftRefID,
60 const int& leftPosition,
61 const int& rightRefID,
62 const int& rightPosition);
64 // ----------------------
65 // access alignment data
66 // ----------------------
68 // retrieves next available alignment
69 bool GetNextAlignment(BamAlignment& alignment);
70 // retrieves next available alignment (without populating the alignment's string data fields)
71 bool GetNextAlignmentCore(BamAlignment& alignment);
73 // ----------------------
74 // access auxiliary data
75 // ----------------------
77 // returns unified SAM header for all files
78 SamHeader GetHeader(void) const;
79 // returns unified SAM header text for all files
80 std::string GetHeaderText(void) const;
81 // returns number of reference sequences
82 int GetReferenceCount(void) const;
83 // returns all reference sequence entries.
84 const BamTools::RefVector GetReferenceData(void) const;
85 // returns the ID of the reference with this name.
86 int GetReferenceID(const std::string& refName) const;
88 // ----------------------
89 // BAM index operations
90 // ----------------------
92 // creates index files for current BAM files
93 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
94 // returns true if all BAM files have index data available
95 bool HasIndexes(void) const;
96 // looks for index files that match current BAM files
97 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
98 // opens index files for current BAM files.
99 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
101 // ----------------------
103 // ----------------------
105 // returns a human-readable description of the last error that occurred
106 std::string GetErrorString(void) const;
108 // private implementation
110 Internal::BamMultiReaderPrivate* d;
113 } // namespace BamTools
115 #endif // BAMMULTIREADER_H