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