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: 15 March 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 {
30 enum SortOrder { SortedByPosition = 0
35 // constructor / destructor
38 ~BamMultiReader(void);
43 // ----------------------
44 // BAM file operations
45 // ----------------------
47 // closes all open BAM files
49 // close only the requested BAM file
50 void CloseFile(const std::string& filename);
51 // returns list of filenames for all open BAM files
52 const std::vector<std::string> Filenames(void) const;
53 // returns true if multireader has any open BAM files
54 bool HasOpenReaders(void) const;
55 // performs random-access jump within current BAM files
56 bool Jump(int refID, int position = 0);
58 bool Open(const std::vector<std::string>& filenames);
59 // opens a single BAM file, adding to any other current BAM files
60 bool OpenFile(const std::string& filename);
61 // returns file pointers to beginning of alignments
63 // sets the target region of interest
64 bool SetRegion(const BamRegion& region);
65 // sets the target region of interest
66 bool SetRegion(const int& leftRefID,
67 const int& leftPosition,
68 const int& rightRefID,
69 const int& rightPosition);
71 // ----------------------
72 // access alignment data
73 // ----------------------
75 // retrieves next available alignment
76 bool GetNextAlignment(BamAlignment& alignment);
77 // retrieves next available alignmnet (without populating the alignment's string data fields)
78 bool GetNextAlignmentCore(BamAlignment& alignment);
80 // sets the expected sorting order for reading across multiple BAM files
81 void SetSortOrder(const SortOrder& order);
83 // ----------------------
84 // access auxiliary data
85 // ----------------------
87 // returns unified SAM header for all files
88 SamHeader GetHeader(void) const;
89 // returns unified SAM header text for all files
90 std::string GetHeaderText(void) const;
91 // returns number of reference sequences
92 int GetReferenceCount(void) const;
93 // returns all reference sequence entries.
94 const BamTools::RefVector GetReferenceData(void) const;
95 // returns the ID of the reference with this name.
96 int GetReferenceID(const std::string& refName) const;
98 // ----------------------
99 // BAM index operations
100 // ----------------------
102 // creates index files for current BAM files
103 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
104 // returns true if all BAM files have index data available
105 bool HasIndexes(void) const;
106 // looks for index files that match current BAM files
107 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
108 // opens index files for current BAM files.
109 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
110 // changes the caching behavior of the index data
111 void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
113 // deprecated methods
115 // returns \c true if all BAM files have index data available.
116 bool IsIndexLoaded(void) const;
117 // convenience method for printing filenames to stdout
118 void PrintFilenames(void) const;
120 // private implementation
122 Internal::BamMultiReaderPrivate* d;
125 } // namespace BamTools
127 #endif // BAMMULTIREADER_H