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