]> git.donarmstrong.com Git - bamtools.git/blob - src/api/BamReader.cpp
c357b9dfceef5858eded4222b9ec022710f449e0
[bamtools.git] / src / api / BamReader.cpp
1 // ***************************************************************************
2 // BamReader.cpp (c) 2009 Derek Barnett, Michael Str�mberg
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 22 November 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides the basic functionality for reading BAM files
9 // ***************************************************************************
10
11 #include <api/BamReader.h>
12 #include <api/internal/BamReader_p.h>
13 using namespace BamTools;
14 using namespace BamTools::Internal;
15
16 #include <algorithm>
17 #include <iostream>
18 #include <iterator>
19 #include <string>
20 #include <vector>
21 using namespace std;
22
23 // constructor
24 BamReader::BamReader(void) {
25     d = new BamReaderPrivate(this);
26 }
27
28 // destructor
29 BamReader::~BamReader(void) {
30     delete d;
31     d = 0;
32 }
33
34 // file operations
35 void BamReader::Close(void) { d->Close(); }
36 bool BamReader::HasIndex(void) const { return d->HasIndex; }
37 bool BamReader::IsIndexLoaded(void) const { return HasIndex(); }
38 bool BamReader::IsOpen(void) const { return d->mBGZF.IsOpen; }
39 bool BamReader::Jump(int refID, int position)  { return d->SetRegion( BamRegion(refID, position) ); }
40 bool BamReader::Open(const std::string& filename,
41                      const std::string& indexFilename,
42                      const bool lookForIndex,
43                      const bool preferStandardIndex)
44 {
45     return d->Open(filename, indexFilename, lookForIndex, preferStandardIndex);
46 }
47 bool BamReader::Rewind(void) { return d->Rewind(); }
48 bool BamReader::SetRegion(const BamRegion& region) { return d->SetRegion(region); }
49 bool BamReader::SetRegion(const int& leftRefID, const int& leftBound, const int& rightRefID, const int& rightBound) {
50     return d->SetRegion( BamRegion(leftRefID, leftBound, rightRefID, rightBound) );
51 }
52
53 // access alignment data
54 bool BamReader::GetNextAlignment(BamAlignment& bAlignment) { return d->GetNextAlignment(bAlignment); }
55 bool BamReader::GetNextAlignmentCore(BamAlignment& bAlignment) { return d->GetNextAlignmentCore(bAlignment); }
56
57 // access auxiliary data
58 const string BamReader::GetHeaderText(void) const { return d->GetHeaderText(); }
59 int BamReader::GetReferenceCount(void) const { return d->References.size(); }
60 const RefVector& BamReader::GetReferenceData(void) const { return d->References; }
61 int BamReader::GetReferenceID(const string& refName) const { return d->GetReferenceID(refName); }
62 const std::string BamReader::GetFilename(void) const { return d->Filename; }
63
64 // index operations
65 bool BamReader::CreateIndex(bool useStandardIndex) { return d->CreateIndex(useStandardIndex); }
66 void BamReader::SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode) { d->SetIndexCacheMode(mode); }