]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/BamMultiReader_p.h
Cleaned up intra-API includes & moved version numbers to 2.0.0
[bamtools.git] / src / api / internal / BamMultiReader_p.h
index 942f60b3da6d3835435eb81735002e94029ba243..01d12304f57c5ef6d113e07fc7ca7242a5c87e4f 100644 (file)
@@ -1,9 +1,8 @@
 // ***************************************************************************
 // BamMultiReader_p.h (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
-// All rights reserved.
 // ---------------------------------------------------------------------------
-// Last modified: 17 January 2011 (DB)
+// Last modified: 10 October 2011 (DB)
 // ---------------------------------------------------------------------------
 // Functionality for simultaneously reading multiple BAM files
 // *************************************************************************
 //
 // We mean it.
 
-#include <api/BamMultiReader.h>
+#include "api/SamHeader.h"
+#include "api/BamMultiReader.h"
+#include "api/internal/BamMultiMerger_p.h"
 #include <string>
 #include <vector>
 
 namespace BamTools {
 namespace Internal {
 
-class IBamMultiMerger;
-
 class BamMultiReaderPrivate {
 
+    // typedefs
+    public:
+        typedef std::pair<BamReader*, BamAlignment*> ReaderAlignment;
+
     // constructor / destructor
     public:
         BamMultiReaderPrivate(void);
@@ -41,53 +44,54 @@ class BamMultiReaderPrivate {
     public:
 
         // file operations
-        void Close(void);
-        bool Open(const std::vector<std::string>& filenames,
-                  bool openIndexes = true,
-                  bool coreMode = false,
-                  bool preferStandardIndex = false);
-        bool IsIndexLoaded(void) const;
+        bool Close(void);
+        bool CloseFile(const std::string& filename);
+        const std::vector<std::string> Filenames(void) const;
         bool Jump(int refID, int position = 0);
-        void PrintFilenames(void) const;
-        bool SetRegion(const BamRegion& region);
+        bool Open(const std::vector<std::string>& filenames);
+        bool OpenFile(const std::string& filename);
         bool Rewind(void);
+        bool SetRegion(const BamRegion& region);
 
         // access alignment data
         bool GetNextAlignment(BamAlignment& al);
         bool GetNextAlignmentCore(BamAlignment& al);
         bool HasOpenReaders(void);
-        void SetSortOrder(const BamMultiReader::SortOrder& order);
 
         // access auxiliary data
-        const std::string GetHeaderText(void) const;
-        const int GetReferenceCount(void) const;
+        SamHeader GetHeader(void) const;
+        std::string GetHeaderText(void) const;
+        int GetReferenceCount(void) const;
         const BamTools::RefVector GetReferenceData(void) const;
-        const int GetReferenceID(const std::string& refName) const;
+        int GetReferenceID(const std::string& refName) const;
 
         // BAM index operations
-        bool CreateIndexes(bool useStandardIndex = true);
-        void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);
-
-    // internal methods
-    private:
-        IBamMultiMerger* CreateMergerForCurrentSortOrder(void) const;
-        const std::string ExtractReadGroup(const std::string& headerLine) const;
-        bool LoadNextAlignment(BamAlignment& al, bool coreMode);
-        void SaveNextAlignment(BamTools::BamReader* reader, BamTools::BamAlignment* alignment);
-        const std::vector<std::string> SplitHeaderText(const std::string& headerText) const;
-        // updates our alignment cache
-        void UpdateAlignments(void);
-        // validates that we have a congruent set of BAM files that are aligned against the same reference sequences
-        void ValidateReaders(void) const;
+        bool CreateIndexes(const BamIndex::IndexType& type = BamIndex::STANDARD);
+        bool HasIndexes(void) const;
+        bool LocateIndexes(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
+        bool OpenIndexes(const std::vector<std::string>& indexFilenames);
+        void SetIndexCacheMode(const BamIndex::IndexCacheMode mode);
 
-    // data members
+        // error handling
+        std::string GetErrorString(void) const;
+
+    // 'internal' methods
     public:
-        typedef std::pair<BamReader*, BamAlignment*> ReaderAlignment;
-        std::vector<ReaderAlignment> m_readers;
 
-        IBamMultiMerger* m_alignments;
-        bool m_isCoreMode;
-        BamMultiReader::SortOrder m_sortOrder;
+        bool CloseFiles(const std::vector<std::string>& filenames);
+        IMultiMerger* CreateAlignmentCache(void) const;
+        bool PopNextCachedAlignment(BamAlignment& al, const bool needCharData);
+        bool RewindReaders(void);
+        void SaveNextAlignment(BamReader* reader, BamAlignment* alignment);
+        void SetErrorString(const std::string& where, const std::string& what) const; //
+        bool UpdateAlignmentCache(void);
+        bool ValidateReaders(void) const;
+
+    // data members
+    public:
+        std::vector<MergeItem> m_readers;
+        IMultiMerger* m_alignmentCache;
+        mutable std::string m_errorString;
 };
 
 } // namespace Internal