1 // ***************************************************************************
2 // BamIndex.h (c) 2009 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 17 August 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides index functionality - both for the default (standardized) BAM
9 // index format (.bai) as well as a BamTools-specific (nonstandard) index
11 // ***************************************************************************
25 // --------------------------------------------------
26 // BamIndex base class
30 BamIndex(BamTools::BgzfData* bgzf,
31 BamTools::BamReader* reader,
33 virtual ~BamIndex(void) { }
36 // creates index data (in-memory) from current reader data
37 virtual bool Build(void) =0;
38 // calculates offset(s) for a given region
39 virtual bool GetOffsets(const BamTools::BamRegion& region, const bool isRightBoundSpecified, std::vector<int64_t>& offsets) =0;
40 // loads existing data from file into memory
41 virtual bool Load(const std::string& filename) =0;
42 // returns whether reference has alignments or no
43 virtual bool HasAlignments(const int& referenceID);
44 // writes in-memory index data out to file
45 // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
46 virtual bool Write(const std::string& bamFilename) =0;
49 BamTools::BgzfData* m_BGZF;
50 BamTools::BamReader* m_reader;
51 BamTools::RefVector m_references;
55 // --------------------------------------------------
56 // BamDefaultIndex class
58 // implements default (per SAM/BAM spec) index file ops
59 class BamDefaultIndex : public BamIndex {
64 BamDefaultIndex(BamTools::BgzfData* bgzf,
65 BamTools::BamReader* reader,
67 ~BamDefaultIndex(void);
69 // interface (implements BamIndex virtual methods)
71 // creates index data (in-memory) from current reader data
73 // calculates offset(s) for a given region
74 bool GetOffsets(const BamTools::BamRegion& region, const bool isRightBoundSpecified, std::vector<int64_t>& offsets);
75 // loads existing data from file into memory
76 bool Load(const std::string& filename);
77 // writes in-memory index data out to file
78 // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
79 bool Write(const std::string& bamFilename);
81 // internal implementation
83 struct BamDefaultIndexPrivate;
84 BamDefaultIndexPrivate* d;
87 // --------------------------------------------------
88 // BamToolsIndex class
90 // implements BamTools-specific index file ops
91 class BamToolsIndex : public BamIndex {
95 BamToolsIndex(BamTools::BgzfData* bgzf,
96 BamTools::BamReader* reader,
100 // interface (implements BamIndex virtual methods)
102 // creates index data (in-memory) from current reader data
104 // calculates offset(s) for a given region
105 bool GetOffsets(const BamTools::BamRegion& region, const bool isRightBoundSpecified, std::vector<int64_t>& offsets);
106 // loads existing data from file into memory
107 bool Load(const std::string& filename);
108 // writes in-memory index data out to file
109 // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
110 bool Write(const std::string& bamFilename);
112 // internal implementation
114 struct BamToolsIndexPrivate;
115 BamToolsIndexPrivate* d;
118 } // namespace BamTools
120 #endif // BAM_INDEX_H