1 // ***************************************************************************
2 // BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 1 October 2011 (DB)
7 // ---------------------------------------------------------------------------
8 // Convenience class for reading multiple BAM files.
9 // ***************************************************************************
11 #ifndef BAMMULTIREADER_H
12 #define BAMMULTIREADER_H
14 #include <api/api_global.h>
15 #include <api/BamReader.h>
24 class BamMultiReaderPrivate;
25 } // namespace Internal
27 class API_EXPORT BamMultiReader {
29 // constructor / destructor
32 ~BamMultiReader(void);
37 // ----------------------
38 // BAM file operations
39 // ----------------------
41 // closes all open BAM files
43 // close only the requested BAM file
44 void CloseFile(const std::string& filename);
45 // returns list of filenames for all open BAM files
46 const std::vector<std::string> Filenames(void) const;
47 // returns true if multireader has any open BAM files
48 bool HasOpenReaders(void) const;
49 // performs random-access jump within current BAM files
50 bool Jump(int refID, int position = 0);
52 bool Open(const std::vector<std::string>& filenames);
53 // opens a single BAM file, adding to any other current BAM files
54 bool OpenFile(const std::string& filename);
55 // returns file pointers to beginning of alignments
57 // sets the target region of interest
58 bool SetRegion(const BamRegion& region);
59 // sets the target region of interest
60 bool SetRegion(const int& leftRefID,
61 const int& leftPosition,
62 const int& rightRefID,
63 const int& rightPosition);
65 // ----------------------
66 // access alignment data
67 // ----------------------
69 // retrieves next available alignment
70 bool GetNextAlignment(BamAlignment& alignment);
71 // retrieves next available alignment (without populating the alignment's string data fields)
72 bool GetNextAlignmentCore(BamAlignment& alignment);
74 // ----------------------
75 // access auxiliary data
76 // ----------------------
78 // returns unified SAM header for all files
79 SamHeader GetHeader(void) const;
80 // returns unified SAM header text for all files
81 std::string GetHeaderText(void) const;
82 // returns number of reference sequences
83 int GetReferenceCount(void) const;
84 // returns all reference sequence entries.
85 const BamTools::RefVector GetReferenceData(void) const;
86 // returns the ID of the reference with this name.
87 int GetReferenceID(const std::string& refName) const;
89 // ----------------------
90 // BAM index operations
91 // ----------------------
93 // creates index files for current BAM files
94 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
95 // returns true if all BAM files have index data available
96 bool HasIndexes(void) const;
97 // looks for index files that match current BAM files
98 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
99 // opens index files for current BAM files.
100 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
101 // changes the caching behavior of the index data
102 void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
104 // private implementation
106 Internal::BamMultiReaderPrivate* d;
109 } // namespace BamTools
111 #endif // BAMMULTIREADER_H