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