BamTools 2.5.2
Loading...
Searching...
No Matches
BamMultiReader.h
Go to the documentation of this file.
1// ***************************************************************************
2// BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett
3// Marth Lab, Department of Biology, Boston College
4// ---------------------------------------------------------------------------
5// Last modified: 14 January 2013 (DB)
6// ---------------------------------------------------------------------------
7// Convenience class for reading multiple BAM files.
8// ***************************************************************************
9
10#ifndef BAMMULTIREADER_H
11#define BAMMULTIREADER_H
12
13#include <map>
14#include <sstream>
15#include <string>
16#include <utility>
17#include "api/BamReader.h"
18#include "api/api_global.h"
19
20namespace BamTools {
21
22namespace Internal {
23class BamMultiReaderPrivate;
24} // namespace Internal
25
26class API_EXPORT BamMultiReader
27{
28
29 // enums
30public:
31 // possible merge order strategies
33 {
34 RoundRobinMerge = 0,
36 MergeByName
37 };
38
39 // constructor / destructor
40public:
43
44 // public interface
45public:
46 // ----------------------
47 // BAM file operations
48 // ----------------------
49
50 // closes all open BAM files
51 bool Close();
52 // close only the requested BAM file
53 bool CloseFile(const std::string& filename);
54 // returns list of filenames for all open BAM files
55 const std::vector<std::string> Filenames() const;
56 // returns curent merge order strategy
57 BamMultiReader::MergeOrder GetMergeOrder() const;
58 // returns true if multireader has any open BAM files
59 bool HasOpenReaders() const;
60 // performs random-access jump within current BAM files
61 bool Jump(int refID, int position = 0);
62 // opens BAM files
63 bool Open(const std::vector<std::string>& filenames);
64 // opens a single BAM file, adding to any other current BAM files
65 bool OpenFile(const std::string& filename);
66 // returns file pointers to beginning of alignments
67 bool Rewind();
68 // sets an explicit merge order, regardless of the BAM files' SO header tag
69 bool SetExplicitMergeOrder(BamMultiReader::MergeOrder order);
70 // sets the target region of interest
71 bool SetRegion(const BamRegion& region);
72 // sets the target region of interest
73 bool SetRegion(const int& leftRefID, const int& leftPosition, const int& rightRefID,
74 const int& rightPosition);
75
76 // ----------------------
77 // access alignment data
78 // ----------------------
79
80 // retrieves next available alignment
81 bool GetNextAlignment(BamAlignment& alignment);
82 // retrieves next available alignment (without populating the alignment's string data fields)
83 bool GetNextAlignmentCore(BamAlignment& alignment);
84
85 // ----------------------
86 // access auxiliary data
87 // ----------------------
88
89 // returns unified SAM header for all files
90 SamHeader GetHeader() const;
91 // returns unified SAM header text for all files
92 std::string GetHeaderText() const;
93 // returns number of reference sequences
94 int GetReferenceCount() const;
95 // returns all reference sequence entries.
96 const BamTools::RefVector GetReferenceData() const;
97 // returns the ID of the reference with this name.
98 int GetReferenceID(const std::string& refName) const;
99
100 // ----------------------
101 // BAM index operations
102 // ----------------------
103
104 // creates index files for current BAM files
105 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
106 // returns true if all BAM files have index data available
107 bool HasIndexes() const;
108 // looks for index files that match current BAM files
109 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
110 // opens index files for current BAM files.
111 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
112
113 // ----------------------
114 // error handling
115 // ----------------------
116
117 // returns a human-readable description of the last error that occurred
118 std::string GetErrorString() const;
119
120 // private implementation
121private:
122 Internal::BamMultiReaderPrivate* d;
123};
124
125} // namespace BamTools
126
127#endif // BAMMULTIREADER_H
The main BAM alignment data structure.
Definition BamAlignment.h:34
IndexType
Definition BamIndex.h:41
Convenience class for reading multiple BAM files.
Definition BamMultiReader.h:27
MergeOrder
Definition BamMultiReader.h:33
@ MergeByCoordinate
Merge strategy when BAM files are sorted by position ('coordinate')
Definition BamMultiReader.h:35
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