1 // ***************************************************************************
2 // BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 15 March 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 {
29 enum SortOrder { SortedByPosition = 0
34 // constructor / destructor
37 ~BamMultiReader(void);
42 // ----------------------
43 // BAM file operations
44 // ----------------------
46 // closes all open BAM files
48 // close only the requested BAM file
49 void CloseFile(const std::string& filename);
50 // returns list of filenames for all open BAM files
51 const std::vector<std::string> Filenames(void) const;
52 // returns true if multireader has any open BAM files
53 bool HasOpenReaders(void) const;
54 // performs random-access jump within current BAM files
55 bool Jump(int refID, int position = 0);
57 bool Open(const std::vector<std::string>& filenames);
58 // opens a single BAM file, adding to any other current BAM files
59 bool OpenFile(const std::string& filename);
60 // returns file pointers to beginning of alignments
62 // sets the target region of interest
63 bool SetRegion(const BamRegion& region);
64 // sets the target region of interest
65 bool SetRegion(const int& leftRefID,
66 const int& leftPosition,
67 const int& rightRefID,
68 const int& rightPosition);
70 // ----------------------
71 // access alignment data
72 // ----------------------
74 // retrieves next available alignment
75 bool GetNextAlignment(BamAlignment& alignment);
76 // retrieves next available alignmnet (without populating the alignment's string data fields)
77 bool GetNextAlignmentCore(BamAlignment& alignment);
79 // sets the expected sorting order for reading across multiple BAM files
80 void SetSortOrder(const SortOrder& order);
82 // ----------------------
83 // access auxiliary data
84 // ----------------------
86 // returns unified SAM header for all files
87 SamHeader GetHeader(void) const;
88 // returns unified SAM header text for all files
89 std::string GetHeaderText(void) const;
90 // returns number of reference sequences
91 int GetReferenceCount(void) const;
92 // returns all reference sequence entries.
93 const BamTools::RefVector GetReferenceData(void) const;
94 // returns the ID of the reference with this name.
95 int GetReferenceID(const std::string& refName) const;
97 // ----------------------
98 // BAM index operations
99 // ----------------------
101 // creates index files for current BAM files
102 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
103 // returns true if all BAM files have index data available
104 bool HasIndexes(void) const;
105 // looks for index files that match current BAM files
106 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
107 // opens index files for current BAM files.
108 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
109 // changes the caching behavior of the index data
110 void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
112 // deprecated methods
114 // returns \c true if all BAM files have index data available.
115 bool IsIndexLoaded(void) const;
116 // convenience method for printing filenames to stdout
117 void PrintFilenames(void) const;
119 // private implementation
121 Internal::BamMultiReaderPrivate* d;
124 } // namespace BamTools
126 #endif // BAMMULTIREADER_H