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 {
38 typedef std::pair<BamReader*, BamAlignment*> ReaderAlignment;
40 // constructor / destructor
42 BamMultiReaderPrivate(void);
43 ~BamMultiReaderPrivate(void);
50 void CloseFile(const std::string& filename);
51 void CloseFiles(const std::vector<std::string>& filenames);
52 const std::vector<std::string> Filenames(void) const;
53 bool Jump(int refID, int position = 0);
54 bool Open(const std::vector<std::string>& filenames);
55 bool OpenFile(const std::string& filename);
56 void PrintFilenames(void) const;
58 bool SetRegion(const BamRegion& region);
60 // access alignment data
61 bool GetNextAlignment(BamAlignment& al);
62 bool GetNextAlignmentCore(BamAlignment& al);
63 bool HasOpenReaders(void);
64 void SetSortOrder(const BamMultiReader::SortOrder& order);
66 // access auxiliary data
67 SamHeader GetHeader(void) const;
68 std::string GetHeaderText(void) const;
69 int GetReferenceCount(void) const;
70 const BamTools::RefVector GetReferenceData(void) const;
71 int GetReferenceID(const std::string& refName) const;
73 // BAM index operations
74 bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
75 bool HasIndexes(void) const;
76 bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
77 bool OpenIndexes(const std::vector<std::string>& indexFilenames);
78 void SetIndexCacheMode(const BamIndex::IndexCacheMode mode);
82 IBamMultiMerger* CreateMergerForCurrentSortOrder(void) const;
83 const std::string ExtractReadGroup(const std::string& headerLine) const;
84 bool HasAlignmentData(void) const;
85 bool LoadNextAlignment(BamReader* reader, BamAlignment* alignment);
86 ReaderAlignment OpenReader(const std::string& filename, bool* ok);
87 bool PopNextCachedAlignment(BamAlignment& al, const bool needCharData);
88 bool RewindReaders(void);
89 void SaveNextAlignment(BamReader* reader, BamAlignment* alignment);
90 const std::vector<std::string> SplitHeaderText(const std::string& headerText) const;
91 void UpdateAlignmentCache(void);
92 void ValidateReaders(void) const;
96 std::vector<ReaderAlignment> m_readers;
97 IBamMultiMerger* m_alignments;
98 BamMultiReader::SortOrder m_sortOrder;
101 } // namespace Internal
102 } // namespace BamTools
104 #endif // BAMMULTIREADER_P_H