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
94 bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
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
Provides read access to BAM files.
Definition BamReader.h:26
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