]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/BamReader_p.h
Major update to BamTools version 1.0
[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: 24 February 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     // BamReaderPrivate interface
74     public:
75         BgzfStream* Stream(void);
76
77     // 'internal' methods
78     public:
79         // retrieves header text from BAM file
80         bool LoadHeaderData(void);
81         // retrieves BAM alignment under file pointer
82         // (does no overlap checking or character data parsing)
83         bool LoadNextAlignment(BamAlignment& alignment);
84         // builds reference data structure from BAM file
85         bool LoadReferenceData(void);
86
87     // data members
88     public:
89
90         // general BAM file data
91         int64_t     m_alignmentsBeginOffset;
92         std::string m_filename;
93         RefVector   m_references;
94
95         // system data
96         bool m_isBigEndian;
97
98         // parent BamReader
99         BamReader* m_parent;
100
101         // BamReaderPrivate components
102         BamHeader m_header;
103         BamRandomAccessController m_randomAccessController;
104         BgzfStream m_stream;
105 };
106
107 } // namespace Internal
108 } // namespace BamTools
109
110 #endif // BAMREADER_P_H