]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/bam/BamMultiReader_p.h
Added explicit merge order to BamMultiReader
[bamtools.git] / src / api / internal / bam / BamMultiReader_p.h
1 // ***************************************************************************
2 // BamMultiReader_p.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 14 January 2013 (DB)
6 // ---------------------------------------------------------------------------
7 // Functionality for simultaneously reading multiple BAM files
8 // *************************************************************************
9
10 #ifndef BAMMULTIREADER_P_H
11 #define BAMMULTIREADER_P_H
12
13 //  -------------
14 //  W A R N I N G
15 //  -------------
16 //
17 // This file is not part of the BamTools API.  It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
20 //
21 // We mean it.
22
23 #include "api/SamHeader.h"
24 #include "api/BamMultiReader.h"
25 #include "api/internal/bam/BamMultiMerger_p.h"
26 #include <string>
27 #include <vector>
28
29 namespace BamTools {
30 namespace Internal {
31
32 class BamMultiReaderPrivate {
33
34     // typedefs
35     public:
36         typedef std::pair<BamReader*, BamAlignment*> ReaderAlignment;
37
38     // constructor / destructor
39     public:
40         BamMultiReaderPrivate(void);
41         ~BamMultiReaderPrivate(void);
42
43     // public interface
44     public:
45
46         // file operations
47         bool Close(void);
48         bool CloseFile(const std::string& filename);
49         const std::vector<std::string> Filenames(void) const;
50         bool Jump(int refID, int position = 0);
51         bool Open(const std::vector<std::string>& filenames);
52         bool OpenFile(const std::string& filename);
53         bool Rewind(void);
54         bool SetRegion(const BamRegion& region);
55
56         // access alignment data
57         BamMultiReader::MergeOrder GetMergeOrder(void) const;
58         bool GetNextAlignment(BamAlignment& al);
59         bool GetNextAlignmentCore(BamAlignment& al);
60         bool HasOpenReaders(void);
61         void SetExplicitMergeOrder(BamMultiReader::MergeOrder order);
62
63         // access auxiliary data
64         SamHeader GetHeader(void) const;
65         std::string GetHeaderText(void) const;
66         int GetReferenceCount(void) const;
67         const BamTools::RefVector GetReferenceData(void) const;
68         int GetReferenceID(const std::string& refName) const;
69
70         // BAM index operations
71         bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
72         bool HasIndexes(void) const;
73         bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
74         bool OpenIndexes(const std::vector<std::string>& indexFilenames);
75
76         // error handling
77         std::string GetErrorString(void) const;
78
79     // 'internal' methods
80     public:
81
82         bool CloseFiles(const std::vector<std::string>& filenames);
83         IMultiMerger* CreateAlignmentCache(void);
84         bool PopNextCachedAlignment(BamAlignment& al, const bool needCharData);
85         bool RewindReaders(void);
86         void SaveNextAlignment(BamReader* reader, BamAlignment* alignment);
87         void SetErrorString(const std::string& where, const std::string& what) const; //
88         bool UpdateAlignmentCache(void);
89         bool ValidateReaders(void) const;
90
91     // data members
92     public:
93         std::vector<MergeItem> m_readers;
94         IMultiMerger* m_alignmentCache;
95
96         bool m_hasUserMergeOrder;
97         BamMultiReader::MergeOrder m_mergeOrder;
98
99         mutable std::string m_errorString;
100 };
101
102 } // namespace Internal
103 } // namespace BamTools
104
105 #endif // BAMMULTIREADER_P_H