]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamMultiReader.h
1b1c27021bc457962d17160b019619932d4ecee6
[bamtools.git] / src / api / BamMultiReader.h
1 // ***************************************************************************
2 // BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 7 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Convenience class for reading multiple BAM files.
8 // ***************************************************************************
9
10 #ifndef BAMMULTIREADER_H
11 #define BAMMULTIREADER_H
12
13 #include <api/api_global.h>
14 #include <api/BamReader.h>
15 #include <map>
16 #include <sstream>
17 #include <string>
18 #include <utility>
19
20 namespace BamTools {
21
22 namespace Internal {
23     class BamMultiReaderPrivate;
24 } // namespace Internal
25
26 class API_EXPORT BamMultiReader {
27
28     // constructor / destructor
29     public:
30         BamMultiReader(void);
31         ~BamMultiReader(void);
32
33     // public interface
34     public:
35
36         // ----------------------
37         // BAM file operations
38         // ----------------------
39
40         // closes all open BAM files
41         bool Close(void);
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);
50         // opens BAM files
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
55         bool Rewind(void);
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);
63
64         // ----------------------
65         // access alignment data
66         // ----------------------
67
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);
72
73         // ----------------------
74         // access auxiliary data
75         // ----------------------
76
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;
87
88         // ----------------------
89         // BAM index operations
90         // ----------------------
91
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);
100         // changes the caching behavior of the index data
101         void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
102
103         // ----------------------
104         // error handling
105         // ----------------------
106
107         // returns a human-readable description of the last error that occurred
108         std::string GetErrorString(void) const;
109
110     // private implementation
111     private:
112         Internal::BamMultiReaderPrivate* d;
113 };
114
115 } // namespace BamTools
116
117 #endif // BAMMULTIREADER_H