]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamMultiReader.h
MultiReader (&MultiMerger) now using Algorithms::Sort objects
[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 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 1 October 2011 (DB)
7 // ---------------------------------------------------------------------------
8 // Convenience class for reading multiple BAM files.
9 // ***************************************************************************
10
11 #ifndef BAMMULTIREADER_H
12 #define BAMMULTIREADER_H
13
14 #include <api/api_global.h>
15 #include <api/BamReader.h>
16 #include <map>
17 #include <sstream>
18 #include <string>
19 #include <utility>
20
21 namespace BamTools {
22
23 namespace Internal {
24     class BamMultiReaderPrivate;
25 } // namespace Internal
26
27 class API_EXPORT BamMultiReader {
28
29     // constructor / destructor
30     public:
31         BamMultiReader(void);
32         ~BamMultiReader(void);
33
34     // public interface
35     public:
36
37         // ----------------------
38         // BAM file operations
39         // ----------------------
40
41         // closes all open BAM files
42         void Close(void);
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);
51         // opens BAM files
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
56         bool Rewind(void);
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);
64
65         // ----------------------
66         // access alignment data
67         // ----------------------
68
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);
73
74         // ----------------------
75         // access auxiliary data
76         // ----------------------
77
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;
88
89         // ----------------------
90         // BAM index operations
91         // ----------------------
92
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);
103
104     // private implementation
105     private:
106         Internal::BamMultiReaderPrivate* d;
107 };
108
109 } // namespace BamTools
110
111 #endif // BAMMULTIREADER_H