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 // ***************************************************************************
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.
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>
36 class BamReaderPrivate {
40 BamReaderPrivate(BamReader* parent);
41 ~BamReaderPrivate(void);
43 // BamReader interface
48 const std::string Filename(void) const;
49 bool IsOpen(void) const;
50 bool Open(const std::string& filename);
52 bool SetRegion(const BamRegion& region);
54 // access alignment data
55 bool GetNextAlignment(BamAlignment& alignment);
56 bool GetNextAlignmentCore(BamAlignment& alignment);
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;
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);
73 // internal methods, but available as a BamReaderPrivate 'interface'
75 // these methods should only be used by BamTools::Internal classes
76 // (currently only used by the BamIndex subclasses)
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;
93 // general BAM file data
94 int64_t m_alignmentsBeginOffset;
95 std::string m_filename;
96 RefVector m_references;
104 // BamReaderPrivate components
106 BamRandomAccessController m_randomAccessController;
110 } // namespace Internal
111 } // namespace BamTools
113 #endif // BAMREADER_P_H