]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/bam/BamMultiReader_p.h
9d7c39ae0c2717b8c4d0a4aa27caa7493b2d8ace
[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: 25 October 2011 (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         bool GetNextAlignment(BamAlignment& al);
58         bool GetNextAlignmentCore(BamAlignment& al);
59         bool HasOpenReaders(void);
60
61         // access auxiliary data
62         SamHeader GetHeader(void) const;
63         std::string GetHeaderText(void) const;
64         int GetReferenceCount(void) const;
65         const BamTools::RefVector GetReferenceData(void) const;
66         int GetReferenceID(const std::string& refName) const;
67
68         // BAM index operations
69         bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
70         bool HasIndexes(void) const;
71         bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
72         bool OpenIndexes(const std::vector<std::string>& indexFilenames);
73
74         // error handling
75         std::string GetErrorString(void) const;
76
77     // 'internal' methods
78     public:
79
80         bool CloseFiles(const std::vector<std::string>& filenames);
81         IMultiMerger* CreateAlignmentCache(void) const;
82         bool PopNextCachedAlignment(BamAlignment& al, const bool needCharData);
83         bool RewindReaders(void);
84         void SaveNextAlignment(BamReader* reader, BamAlignment* alignment);
85         void SetErrorString(const std::string& where, const std::string& what) const; //
86         bool UpdateAlignmentCache(void);
87         bool ValidateReaders(void) const;
88
89     // data members
90     public:
91         std::vector<MergeItem> m_readers;
92         IMultiMerger* m_alignmentCache;
93         mutable std::string m_errorString;
94 };
95
96 } // namespace Internal
97 } // namespace BamTools
98
99 #endif // BAMMULTIREADER_P_H