]> git.donarmstrong.com Git - bamtools.git/blob - BamMultiReader.h
319d3270819c8d0b0d5ed5c288b97193c6f1107a
[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 \r
17 using namespace std;\r
18 \r
19 // BamTools includes\r
20 #include "BamAux.h"\r
21 #include "BamReader.h"\r
22 \r
23 namespace BamTools {\r
24 \r
25 enum BamReaderState { START, END, CLOSED };\r
26 \r
27 class BamMultiReader {\r
28 \r
29     // constructor / destructor\r
30     public:\r
31         BamMultiReader(void);\r
32         ~BamMultiReader(void);\r
33 \r
34     // public interface\r
35     public:\r
36 \r
37         // positioning\r
38         int CurrentRefID;\r
39         int CurrentLeft;\r
40 \r
41         // ----------------------\r
42         // BAM file operations\r
43         // ----------------------\r
44 \r
45         // close BAM files\r
46         void Close(void);\r
47         // performs random-access jump to reference, position\r
48         bool Jump(int refID, int position = 0);\r
49         // opens BAM files (and optional BAM index files, if provided)\r
50         //void Open(const vector<std::string&> filenames, const vector<std::string&> indexFilenames);\r
51         void Open(const vector<string> filenames);\r
52         // returns file pointers to beginning of alignments\r
53         bool Rewind(void);\r
54 \r
55         // ----------------------\r
56         // access alignment data\r
57         // ----------------------\r
58         // updates the reference id marker to match the lower limit of our readers\r
59         void UpdateReferenceID(void);\r
60 \r
61         // retrieves next available alignment (returns success/fail) from all files\r
62         bool GetNextAlignment(BamAlignment&);\r
63         // ... should this be private?\r
64         bool HasOpenReaders(void);\r
65 \r
66         // ----------------------\r
67         // access auxiliary data\r
68         // ----------------------\r
69 \r
70         // returns unified SAM header text for all files\r
71         const string GetUnifiedHeaderText(void) const;\r
72         // returns number of reference sequences\r
73         const int GetReferenceCount(void) const;\r
74         // returns vector of reference objects\r
75         const BamTools::RefVector GetReferenceData(void) const;\r
76         // returns reference id (used for BamMultiReader::Jump()) for the given reference name\r
77         //const int GetReferenceID(const std::string& refName) const;\r
78 \r
79         // ----------------------\r
80         // BAM index operations\r
81         // ----------------------\r
82 \r
83         // creates index for BAM files which lack them, saves to files (default = bamFilename + ".bai")\r
84         bool CreateIndexes(void);\r
85 \r
86         //const int GetReferenceID(const string& refName) const;\r
87 \r
88         // utility\r
89         void PrintFilenames(void);\r
90         void UpdateAlignments(void);\r
91 \r
92 \r
93     // private implementation\r
94     private:\r
95         // TODO perhaps, for legibility, I should use a struct to wrap them all up\r
96         //      But this may actually make things more confusing, as I'm only\r
97         //      operating on them all simultaneously during GetNextAlignment\r
98         //      calls.\r
99         // all these vectors are ordered the same\r
100         // readers.at(N) refers to the same reader as alignments.at(N) and readerStates.at(N)\r
101         vector<BamReader*> readers; // the set of readers which we operate on\r
102         vector<BamAlignment*> alignments; // the equivalent set of alignments we use to step through the files\r
103         vector<BamReaderState> readerStates; // states of the various readers\r
104         // alignment position?\r
105         vector<string> fileNames;\r
106 };\r
107 \r
108 } // namespace BamTools\r
109 \r
110 #endif // BAMMULTIREADER_H\r