BamTools 2.5.3
Loading...
Searching...
No Matches
BamReader.h
Go to the documentation of this file.
1// ***************************************************************************
2// BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg
3// Marth Lab, Department of Biology, Boston College
4// ---------------------------------------------------------------------------
5// Last modified: 18 November 2012 (DB)
6// ---------------------------------------------------------------------------
7// Provides read access to BAM files.
8// ***************************************************************************
9
10#ifndef BAMREADER_H
11#define BAMREADER_H
12
13#include <string>
14#include "api/BamAlignment.h"
15#include "api/BamIndex.h"
16#include "api/SamHeader.h"
17#include "api/api_global.h"
18
19namespace BamTools {
20
21namespace Internal {
22class BamReaderPrivate;
23} // namespace Internal
24
25class API_EXPORT BamReader
26{
27
28 // constructor / destructor
29public:
30 BamReader();
31 ~BamReader();
32
33 // public interface
34public:
35 // ----------------------
36 // BAM file operations
37 // ----------------------
38
39 // closes the current BAM file
40 bool Close();
41 // returns filename of current BAM file
42 const std::string GetFilename() const;
43 // returns true if a BAM file is open for reading
44 bool IsOpen() const;
45 // performs random-access jump within BAM file
46 bool Jump(int refID, int position = 0);
47 // opens a BAM file
48 bool Open(const std::string& filename);
49 // returns internal file pointer to beginning of alignment data
50 bool Rewind();
51 // sets the target region of interest
52 bool SetRegion(const BamRegion& region);
53 // sets the target region of interest
54 bool SetRegion(const int& leftRefID, const int& leftPosition, const int& rightRefID,
55 const int& rightPosition);
56 int64_t Tell() const;
57
58 // ----------------------
59 // access alignment data
60 // ----------------------
61
62 // retrieves next available alignment
63 bool GetNextAlignment(BamAlignment& alignment);
64 // retrieves next available alignmnet (without populating the alignment's string data fields)
65 bool GetNextAlignmentCore(BamAlignment& alignment);
66
67 // ----------------------
68 // access header data
69 // ----------------------
70
71 // returns a read-only reference to SAM header data
72 const SamHeader& GetConstSamHeader() const;
73 // returns an editable copy of SAM header data
74 SamHeader GetHeader() const;
75 // returns SAM header data, as SAM-formatted text
76 std::string GetHeaderText() const;
77
78 // ----------------------
79 // access reference data
80 // ----------------------
81
82 // returns the number of reference sequences
83 int GetReferenceCount() const;
84 // returns all reference sequence entries
85 const RefVector& GetReferenceData() const;
86 // returns the ID of the reference with this name
87 int GetReferenceID(const std::string& refName) const;
88
89 // ----------------------
90 // BAM index operations
91 // ----------------------
92
93 // creates an index file for current BAM file, using the requested index type
95 // returns true if index data is available
96 bool HasIndex() const;
97 // looks in BAM file's directory for a matching index file
98 bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
99 // opens a BAM index file
100 bool OpenIndex(const std::string& indexFilename);
101 // sets a custom BamIndex on this reader
102 void SetIndex(BamIndex* index);
103
104 // ----------------------
105 // error handling
106 // ----------------------
107
108 // returns a human-readable description of the last error that occurred
109 std::string GetErrorString() const;
110
111 // private implementation
112private:
113 Internal::BamReaderPrivate* d;
114};
115
116} // namespace BamTools
117
118#endif // BAMREADER_H
The main BAM alignment data structure.
Definition BamAlignment.h:34
Provides methods for generating & loading BAM index files.
Definition BamIndex.h:35
IndexType
Definition BamIndex.h:41
@ STANDARD
Definition BamIndex.h:43
bool CreateIndex(const BamIndex::IndexType &type=BamIndex::STANDARD)
Creates an index file for current BAM file.
Definition BamReader.cpp:61
const std::string GetFilename() const
Returns name of current BAM file.
Definition BamReader.cpp:106
bool SetRegion(const BamRegion &region)
Sets a target region of interest.
Definition BamReader.cpp:373
bool IsOpen() const
Returns true if a BAM file is open for reading.
Definition BamReader.cpp:234
bool HasIndex() const
Returns true if index data is available.
Definition BamReader.cpp:226
bool Close()
Closes the current BAM file.
Definition BamReader.cpp:49
const RefVector & GetReferenceData() const
Returns all reference sequence entries.
Definition BamReader.cpp:206
int GetReferenceID(const std::string &refName) const
Returns the ID of the reference with this name.
Definition BamReader.cpp:218
int GetReferenceCount() const
Returns number of reference sequences.
Definition BamReader.cpp:197
std::string GetHeaderText() const
Returns SAM header data, as SAM-formatted text.
Definition BamReader.cpp:141
std::string GetErrorString() const
Returns a human-readable description of the last error that occurred.
Definition BamReader.cpp:91
bool LocateIndex(const BamIndex::IndexType &preferredType=BamIndex::STANDARD)
Looks in BAM file's directory for a matching index file.
Definition BamReader.cpp:275
void SetIndex(BamIndex *index)
Sets a custom BamIndex on this reader.
Definition BamReader.cpp:345
int64_t Tell() const
Definition BamReader.cpp:404
bool Open(const std::string &filename)
Opens a BAM file.
Definition BamReader.cpp:291
bool GetNextAlignment(BamAlignment &alignment)
Retrieves next available alignment.
Definition BamReader.cpp:170
bool Jump(int refID, int position=0)
Performs a random-access jump within BAM file.
Definition BamReader.cpp:251
bool OpenIndex(const std::string &indexFilename)
Opens a BAM index file.
Definition BamReader.cpp:304
SamHeader GetHeader() const
Returns SAM header data.
Definition BamReader.cpp:125
bool GetNextAlignmentCore(BamAlignment &alignment)
Retrieves next available alignment, without populating the alignment's string data fields.
Definition BamReader.cpp:189
BamReader()
constructor
Definition BamReader.cpp:28
bool Rewind()
Returns the internal file pointer to the first alignment record.
Definition BamReader.cpp:321
const SamHeader & GetConstSamHeader() const
Returns const reference to SAM header data.
Definition BamReader.cpp:78
Contains all BamTools classes & methods.
Definition Sort.h:24
std::vector< RefData > RefVector
convenience typedef for vector of RefData entries
Definition BamAux.h:75
Represents a sequential genomic region.
Definition BamAux.h:90
Represents the SAM-formatted text header that is part of the BAM file header.
Definition SamHeader.h:24