]> git.donarmstrong.com Git - bamtools.git/blob - BamMultiReader.h
BamMultiReader data structure rewrite
[bamtools.git] / BamMultiReader.h
1 // ***************************************************************************\r
2 // BamMultiReader.h (c) 2010 Erik Garrison\r
3 // Marth Lab, Department of Biology, Boston College\r
4 // All rights reserved.\r
5 // ---------------------------------------------------------------------------\r
6 // Last modified: 22 February 2010 (EG)\r
7 // ---------------------------------------------------------------------------\r
8 // Functionality for simultaneously reading multiple BAM files\r
9 // ***************************************************************************\r
10 \r
11 #ifndef BAMMULTIREADER_H\r
12 #define BAMMULTIREADER_H\r
13 \r
14 // C++ includes\r
15 #include <string>\r
16 #include <map>\r
17 #include <utility> // for pair\r
18 \r
19 using namespace std;\r
20 \r
21 // BamTools includes\r
22 #include "BamAux.h"\r
23 #include "BamReader.h"\r
24 \r
25 namespace BamTools {\r
26 \r
27 // index mapping reference/position pairings to bamreaders and their alignments\r
28 typedef multimap<pair<int, int>, pair<BamReader*, BamAlignment*> > AlignmentIndex;\r
29 \r
30 class BamMultiReader {\r
31 \r
32     // constructor / destructor\r
33     public:\r
34         BamMultiReader(void);\r
35         ~BamMultiReader(void);\r
36 \r
37     // public interface\r
38     public:\r
39 \r
40         // positioning\r
41         int CurrentRefID;\r
42         int CurrentLeft;\r
43 \r
44         // ----------------------\r
45         // BAM file operations\r
46         // ----------------------\r
47 \r
48         // close BAM files\r
49         void Close(void);\r
50         // performs random-access jump to reference, position\r
51         bool Jump(int refID, int position = 0);\r
52         // opens BAM files (and optional BAM index files, if provided)\r
53         //void Open(const vector<std::string&> filenames, const vector<std::string&> indexFilenames);\r
54         void Open(const vector<string> filenames, bool openIndexes = true);\r
55         // returns file pointers to beginning of alignments\r
56         bool Rewind(void);\r
57 \r
58         // ----------------------\r
59         // access alignment data\r
60         // ----------------------\r
61         // updates the reference id marker to match the lower limit of our readers\r
62         void UpdateReferenceID(void);\r
63 \r
64         // retrieves next available alignment (returns success/fail) from all files\r
65         bool GetNextAlignment(BamAlignment&);\r
66         // ... should this be private?\r
67         bool HasOpenReaders(void);\r
68 \r
69         // ----------------------\r
70         // access auxiliary data\r
71         // ----------------------\r
72 \r
73         // returns unified SAM header text for all files\r
74         const string GetHeaderText(void) const;\r
75         // returns number of reference sequences\r
76         const int GetReferenceCount(void) const;\r
77         // returns vector of reference objects\r
78         const BamTools::RefVector GetReferenceData(void) const;\r
79         // returns reference id (used for BamMultiReader::Jump()) for the given reference name\r
80         const int GetReferenceID(const std::string& refName) const;\r
81         // validates that we have a congruent set of BAM files that are aligned against the same reference sequences\r
82         void ValidateReaders() const;\r
83 \r
84         // ----------------------\r
85         // BAM index operations\r
86         // ----------------------\r
87 \r
88         // creates index for BAM files which lack them, saves to files (default = bamFilename + ".bai")\r
89         bool CreateIndexes(void);\r
90 \r
91         //const int GetReferenceID(const string& refName) const;\r
92 \r
93         // utility\r
94         void PrintFilenames(void);\r
95         void DumpAlignmentIndex(void);\r
96 \r
97     // private implementation\r
98     private:\r
99 \r
100         // the set of readers and alignments which we operate on, maintained throughout the life of this class\r
101         vector<pair<BamReader*, BamAlignment*> > readers;\r
102 \r
103         // readers and alignments sorted by reference id and position, to keep track of the lowest (next) alignment\r
104         // when a reader reaches EOF, its entry is removed from this index\r
105         AlignmentIndex alignments;\r
106 \r
107         vector<string> fileNames;\r
108 };\r
109 \r
110 } // namespace BamTools\r
111 \r
112 #endif // BAMMULTIREADER_H\r