1 // ***************************************************************************
2 // BamMultiReader_p.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 9 September 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Functionality for simultaneously reading multiple BAM files
8 // *************************************************************************
10 #ifndef BAMMULTIREADER_P_H
11 #define BAMMULTIREADER_P_H
17 // This file is not part of the BamTools API. It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
23 #include <api/SamHeader.h>
24 #include <api/BamMultiReader.h>
31 class IBamMultiMerger;
33 class BamMultiReaderPrivate {
37 typedef std::pair<BamReader*, BamAlignment*> ReaderAlignment;
39 // constructor / destructor
41 BamMultiReaderPrivate(void);
42 ~BamMultiReaderPrivate(void);
49 void CloseFile(const std::string& filename);
50 void CloseFiles(const std::vector<std::string>& filenames);
51 const std::vector<std::string> Filenames(void) const;
52 bool Jump(int refID, int position = 0);
53 bool Open(const std::vector<std::string>& filenames);
54 bool OpenFile(const std::string& filename);
55 void PrintFilenames(void) const;
57 bool SetRegion(const BamRegion& region);
59 // access alignment data
60 bool GetNextAlignment(BamAlignment& al);
61 bool GetNextAlignmentCore(BamAlignment& al);
62 bool HasOpenReaders(void);
63 void SetSortOrder(const BamMultiReader::SortOrder& order);
65 // access auxiliary data
66 SamHeader GetHeader(void) const;
67 std::string GetHeaderText(void) const;
68 int GetReferenceCount(void) const;
69 const BamTools::RefVector GetReferenceData(void) const;
70 int GetReferenceID(const std::string& refName) const;
72 // BAM index operations
73 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
74 bool HasIndexes(void) const;
75 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
76 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
77 void SetIndexCacheMode(const BamIndex::IndexCacheMode mode);
81 IBamMultiMerger* CreateMergerForCurrentSortOrder(void) const;
82 const std::string ExtractReadGroup(const std::string& headerLine) const;
83 bool HasAlignmentData(void) const;
84 bool LoadNextAlignment(BamReader* reader, BamAlignment* alignment);
85 ReaderAlignment OpenReader(const std::string& filename, bool* ok);
86 bool PopNextCachedAlignment(BamAlignment& al, const bool needCharData);
87 bool RewindReaders(void);
88 void SaveNextAlignment(BamReader* reader, BamAlignment* alignment);
89 const std::vector<std::string> SplitHeaderText(const std::string& headerText) const;
90 void UpdateAlignmentCache(void);
91 void ValidateReaders(void) const;
95 std::vector<ReaderAlignment> m_readers;
96 IBamMultiMerger* m_alignments;
97 BamMultiReader::SortOrder m_sortOrder;
100 } // namespace Internal
101 } // namespace BamTools
103 #endif // BAMMULTIREADER_P_H