]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamMultiReader.h
Minor cleanup
[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: 15 March 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     public:
29         enum SortOrder { SortedByPosition = 0
30                        , SortedByReadName
31                        , Unsorted
32                        };
33
34     // constructor / destructor
35     public:
36         BamMultiReader(void);
37         ~BamMultiReader(void);
38
39     // public interface
40     public:
41
42         // ----------------------
43         // BAM file operations
44         // ----------------------
45
46         // closes all open BAM files
47         void Close(void);
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);
56         // opens BAM files
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
61         bool Rewind(void);
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);
69
70         // ----------------------
71         // access alignment data
72         // ----------------------
73
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);
78
79         // sets the expected sorting order for reading across multiple BAM files
80         void SetSortOrder(const SortOrder& order);
81
82         // ----------------------
83         // access auxiliary data
84         // ----------------------
85
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;
96
97         // ----------------------
98         // BAM index operations
99         // ----------------------
100
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);
111
112     // deprecated methods
113     public:
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;
118
119     // private implementation
120     private:
121         Internal::BamMultiReaderPrivate* d;
122 };
123
124 } // namespace BamTools
125
126 #endif // BAMMULTIREADER_H