]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/BamReader_p.h
Major performance boost to startup & random-access - especially for the
[bamtools.git] / src / api / internal / BamReader_p.h
1 // ***************************************************************************
2 // BamReader_p.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 5 April 2011 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides the basic functionality for reading BAM files
9 // ***************************************************************************
10
11 #ifndef BAMREADER_P_H
12 #define BAMREADER_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/BamAlignment.h>
25 #include <api/BamIndex.h>
26 #include <api/BamReader.h>
27 #include <api/SamHeader.h>
28 #include <api/internal/BamHeader_p.h>
29 #include <api/internal/BamRandomAccessController_p.h>
30 #include <api/internal/BgzfStream_p.h>
31 #include <string>
32
33 namespace BamTools {
34 namespace Internal {
35
36 class BamReaderPrivate {
37
38     // ctor & dtor
39     public:
40         BamReaderPrivate(BamReader* parent);
41         ~BamReaderPrivate(void);
42
43     // BamReader interface
44     public:
45
46         // file operations
47         void Close(void);
48         const std::string Filename(void) const;
49         bool IsOpen(void) const;
50         bool Open(const std::string& filename);
51         bool Rewind(void);
52         bool SetRegion(const BamRegion& region);
53
54         // access alignment data
55         bool GetNextAlignment(BamAlignment& alignment);
56         bool GetNextAlignmentCore(BamAlignment& alignment);
57
58         // access auxiliary data
59         std::string GetHeaderText(void) const;
60         SamHeader GetSamHeader(void) const;
61         int GetReferenceCount(void) const;
62         const RefVector& GetReferenceData(void) const;
63         int GetReferenceID(const std::string& refName) const;
64
65         // index operations
66         bool CreateIndex(const BamIndex::IndexType& type);
67         bool HasIndex(void) const;
68         bool LocateIndex(const BamIndex::IndexType& preferredType);
69         bool OpenIndex(const std::string& indexFilename);
70         void SetIndex(BamIndex* index);
71         void SetIndexCacheMode(const BamIndex::IndexCacheMode& mode);
72
73     // internal methods, but available as a BamReaderPrivate 'interface'
74     //
75     // these methods should only be used by BamTools::Internal classes
76     // (currently only used by the BamIndex subclasses)
77     public:
78         // retrieves header text from BAM file
79         bool LoadHeaderData(void);
80         // retrieves BAM alignment under file pointer
81         // (does no overlap checking or character data parsing)
82         bool LoadNextAlignment(BamAlignment& alignment);
83         // builds reference data structure from BAM file
84         bool LoadReferenceData(void);
85         // seek reader to file position
86         bool Seek(const int64_t& position);
87         // return reader's file position
88         int64_t Tell(void) const;
89
90     // data members
91     public:
92
93         // general BAM file data
94         int64_t     m_alignmentsBeginOffset;
95         std::string m_filename;
96         RefVector   m_references;
97
98         // system data
99         bool m_isBigEndian;
100
101         // parent BamReader
102         BamReader* m_parent;
103
104         // BamReaderPrivate components
105         BamHeader m_header;
106         BamRandomAccessController m_randomAccessController;
107         BgzfStream m_stream;
108 };
109
110 } // namespace Internal
111 } // namespace BamTools
112
113 #endif // BAMREADER_P_H