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
11 #ifndef BAMMULTIREADER_H
\r
12 #define BAMMULTIREADER_H
\r
17 #include <utility> // for pair
\r
20 using namespace std;
\r
22 // BamTools includes
\r
24 #include "BamReader.h"
\r
26 namespace BamTools {
\r
28 // index mapping reference/position pairings to bamreaders and their alignments
\r
29 typedef multimap<pair<int, int>, pair<BamReader*, BamAlignment*> > AlignmentIndex;
\r
32 class BamMultiReader {
\r
34 // constructor / destructor
\r
36 BamMultiReader(void);
\r
37 ~BamMultiReader(void);
\r
46 // ----------------------
\r
47 // BAM file operations
\r
48 // ----------------------
\r
53 // opens BAM files (and optional BAM index files, if provided)
\r
54 // @openIndexes - triggers index opening, useful for suppressing
\r
55 // error messages during merging of files in which we may not have
\r
57 // @coreMode - setup our first alignments using GetNextAlignmentCore();
\r
58 // also useful for merging
\r
59 void Open(const vector<string> filenames, bool openIndexes = true, bool coreMode = false);
\r
61 // performs random-access jump to reference, position
\r
62 bool Jump(int refID, int position = 0);
\r
64 // returns file pointers to beginning of alignments
\r
67 // ----------------------
\r
68 // access alignment data
\r
69 // ----------------------
\r
70 // updates the reference id marker to match the lower limit of our readers
\r
71 void UpdateReferenceID(void);
\r
73 // retrieves next available alignment (returns success/fail) from all files
\r
74 bool GetNextAlignment(BamAlignment&);
\r
75 // retrieves next available alignment (returns success/fail) from all files
\r
76 // and populates the support data with information about the alignment
\r
77 // *** BUT DOES NOT PARSE CHARACTER DATA FROM THE ALIGNMENT
\r
78 bool GetNextAlignmentCore(BamAlignment&);
\r
79 // ... should this be private?
\r
80 bool HasOpenReaders(void);
\r
82 // ----------------------
\r
83 // access auxiliary data
\r
84 // ----------------------
\r
86 // returns unified SAM header text for all files
\r
87 const string GetHeaderText(void) const;
\r
88 // returns number of reference sequences
\r
89 const int GetReferenceCount(void) const;
\r
90 // returns vector of reference objects
\r
91 const BamTools::RefVector GetReferenceData(void) const;
\r
92 // returns reference id (used for BamMultiReader::Jump()) for the given reference name
\r
93 const int GetReferenceID(const std::string& refName) const;
\r
94 // validates that we have a congruent set of BAM files that are aligned against the same reference sequences
\r
95 void ValidateReaders() const;
\r
97 // ----------------------
\r
98 // BAM index operations
\r
99 // ----------------------
\r
101 // creates index for BAM files which lack them, saves to files (default = bamFilename + ".bai")
\r
102 bool CreateIndexes(void);
\r
104 //const int GetReferenceID(const string& refName) const;
\r
107 void PrintFilenames(void);
\r
108 void DumpAlignmentIndex(void);
\r
110 // private implementation
\r
113 // the set of readers and alignments which we operate on, maintained throughout the life of this class
\r
114 vector<pair<BamReader*, BamAlignment*> > readers;
\r
116 // readers and alignments sorted by reference id and position, to keep track of the lowest (next) alignment
\r
117 // when a reader reaches EOF, its entry is removed from this index
\r
118 AlignmentIndex alignments;
\r
120 vector<string> fileNames;
\r
123 } // namespace BamTools
\r
125 #endif // BAMMULTIREADER_H
\r