1 // ***************************************************************************
2 // BamIndex.h (c) 2009 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 13 July 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 // BamIndex base class
29 BamIndex(BamTools::BgzfData* bgzf,
30 BamTools::BamReader* reader,
32 virtual ~BamIndex(void) { }
35 // creates index data (in-memory) from current reader data
36 virtual bool Build(void) =0;
37 // calculates offset(s) for a given region
38 virtual bool GetOffsets(const BamTools::BamRegion& region, const bool isRightBoundSpecified, std::vector<int64_t>& offsets) =0;
39 // loads existing data from file into memory
40 virtual bool Load(const std::string& filename) =0;
41 // returns whether reference has alignments or no
42 virtual bool HasAlignments(const int& referenceID);
43 // writes in-memory index data out to file
44 // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
45 virtual bool Write(const std::string& bamFilename) =0;
48 BamTools::BgzfData* m_BGZF;
49 BamTools::BamReader* m_reader;
50 BamTools::RefVector m_references;
54 // BamDefaultIndex class
56 // implements default (per SAM/BAM spec) index file ops
57 class BamDefaultIndex : public BamIndex {
62 BamDefaultIndex(BamTools::BgzfData* bgzf,
63 BamTools::BamReader* reader,
65 ~BamDefaultIndex(void);
67 // interface (implements BamIndex virtual methods)
69 // creates index data (in-memory) from current reader data
71 // calculates offset(s) for a given region
72 bool GetOffsets(const BamTools::BamRegion& region, const bool isRightBoundSpecified, std::vector<int64_t>& offsets);
73 // loads existing data from file into memory
74 bool Load(const std::string& filename);
75 // writes in-memory index data out to file
76 // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
77 bool Write(const std::string& bamFilename);
79 // internal implementation
81 struct BamDefaultIndexPrivate;
82 BamDefaultIndexPrivate* d;
85 // BamToolsIndex class
87 // implements BamTools-specific index file ops
88 class BamToolsIndex : public BamIndex {
92 BamToolsIndex(BamTools::BgzfData* bgzf,
93 BamTools::BamReader* reader,
97 // interface (implements BamIndex virtual methods)
99 // creates index data (in-memory) from current reader data
101 // calculates offset(s) for a given region
102 bool GetOffsets(const BamTools::BamRegion& region, const bool isRightBoundSpecified, std::vector<int64_t>& offsets);
103 // loads existing data from file into memory
104 bool Load(const std::string& filename);
105 // writes in-memory index data out to file
106 // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
107 bool Write(const std::string& bamFilename);
109 // internal implementation
111 struct BamToolsIndexPrivate;
112 BamToolsIndexPrivate* d;
115 } // namespace BamTools
117 #endif // BAM_INDEX_H