]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/BamMultiReader.h
Implemented proper -byname sorting (finally).
[bamtools.git] / src / api / BamMultiReader.h
index d30a0d37c5a23dcb4a3d6148f17b7416c086baf0..6de73731d81b71bb349704af88bddb09a9caa7af 100644 (file)
@@ -3,7 +3,7 @@
 // Marth Lab, Department of Biology, Boston College\r
 // All rights reserved.\r
 // ---------------------------------------------------------------------------\r
-// Last modified: 19 November 2010 (DB)\r
+// Last modified: 23 December 2010 (DB)\r
 // ---------------------------------------------------------------------------\r
 // Functionality for simultaneously reading multiple BAM files\r
 // ***************************************************************************\r
@@ -20,8 +20,9 @@
 \r
 namespace BamTools {\r
 \r
-// index mapping reference/position pairings to bamreaders and their alignments\r
-typedef std::multimap<std::pair<int, int>, std::pair<BamReader*, BamAlignment*> > AlignmentIndex;\r
+namespace Internal {\r
+    class BamMultiReaderPrivate;\r
+} // namespace Internal\r
 \r
 class API_EXPORT BamMultiReader {\r
 \r
@@ -33,58 +34,56 @@ class API_EXPORT BamMultiReader {
     // public interface\r
     public:\r
 \r
-        // positioning\r
-        int CurrentRefID;\r
-        int CurrentLeft;\r
-\r
-        // region under analysis, specified using SetRegion\r
-        BamRegion Region;\r
-\r
         // ----------------------\r
         // BAM file operations\r
         // ----------------------\r
 \r
         // close BAM files\r
         void Close(void);\r
-\r
         // opens BAM files (and optional BAM index files, if provided)\r
         // @openIndexes - triggers index opening, useful for suppressing\r
         // error messages during merging of files in which we may not have\r
         // indexes.\r
         // @coreMode - setup our first alignments using GetNextAlignmentCore();\r
         // also useful for merging\r
-        // @preferStandardIndex - look for standard BAM index ".bai" first.  If false, \r
-        // will look for BamTools index ".bti".  \r
-        bool Open(const std::vector<std::string>& filenames, bool openIndexes = true, bool coreMode = false, bool preferStandardIndex = false);\r
-\r
+        // @preferStandardIndex - look for standard BAM index ".bai" first.  If false,\r
+        // will look for BamTools index ".bti".\r
+        bool Open(const std::vector<std::string>& filenames,\r
+                  bool openIndexes = true,\r
+                  bool coreMode = false,\r
+                  bool preferStandardIndex = false);\r
         // returns whether underlying BAM readers ALL have an index loaded\r
         // this is useful to indicate whether Jump() or SetRegion() are possible\r
         bool IsIndexLoaded(void) const;\r
-        \r
         // performs random-access jump to reference, position\r
         bool Jump(int refID, int position = 0);\r
-\r
+        // list files associated with this multireader\r
+        void PrintFilenames(void) const;\r
         // sets the target region\r
         bool SetRegion(const BamRegion& region);\r
-        bool SetRegion(const int&, const int&, const int&, const int&); // convenience function to above\r
-\r
+        bool SetRegion(const int& leftRefID,\r
+                       const int& leftBound,\r
+                       const int& rightRefID,\r
+                       const int& rightBound);\r
         // returns file pointers to beginning of alignments\r
         bool Rewind(void);\r
 \r
         // ----------------------\r
         // access alignment data\r
         // ----------------------\r
-        // updates the reference id marker to match the lower limit of our readers\r
-        void UpdateReferenceID(void);\r
 \r
         // retrieves next available alignment (returns success/fail) from all files\r
-        bool GetNextAlignment(BamAlignment&);\r
+        bool GetNextAlignment(BamAlignment& alignment);\r
         // retrieves next available alignment (returns success/fail) from all files\r
         // and populates the support data with information about the alignment\r
         // *** BUT DOES NOT PARSE CHARACTER DATA FROM THE ALIGNMENT\r
-        bool GetNextAlignmentCore(BamAlignment&);\r
+        bool GetNextAlignmentCore(BamAlignment& alignment);\r
         // ... should this be private?\r
         bool HasOpenReaders(void);\r
+        // set sort order for merging BAM files (i.e. which alignment from the files is 'next'?)\r
+        // default behavior is to sort by position, use this method to handle BAMs sorted by read name\r
+        enum SortOrder { SortedByPosition = 0, SortedByReadName};\r
+        void SetSortOrder(const SortOrder& order);\r
 \r
         // ----------------------\r
         // access auxiliary data\r
@@ -98,8 +97,6 @@ class API_EXPORT BamMultiReader {
         const BamTools::RefVector GetReferenceData(void) const;\r
         // returns reference id (used for BamMultiReader::Jump()) for the given reference name\r
         const int GetReferenceID(const std::string& refName) const;\r
-        // validates that we have a congruent set of BAM files that are aligned against the same reference sequences\r
-        void ValidateReaders() const;\r
 \r
         // ----------------------\r
         // BAM index operations\r
@@ -107,28 +104,12 @@ class API_EXPORT BamMultiReader {
 \r
         // creates index for BAM files which lack them, saves to files (default = bamFilename + ".bai")\r
         bool CreateIndexes(bool useStandardIndex = true);\r
-\r
         // sets the index caching mode for the readers\r
         void SetIndexCacheMode(const BamIndex::BamIndexCacheMode mode);\r
 \r
-        //const int GetReferenceID(const string& refName) const;\r
-\r
-        // utility\r
-        void PrintFilenames(void);\r
-        void DumpAlignmentIndex(void);\r
-        void UpdateAlignments(void); // updates our alignment cache\r
-\r
     // private implementation\r
     private:\r
-\r
-        // the set of readers and alignments which we operate on, maintained throughout the life of this class\r
-        std::vector<std::pair<BamReader*, BamAlignment*> > readers;\r
-\r
-        // readers and alignments sorted by reference id and position, to keep track of the lowest (next) alignment\r
-        // when a reader reaches EOF, its entry is removed from this index\r
-        AlignmentIndex alignments;\r
-\r
-        std::vector<std::string> fileNames;\r
+        Internal::BamMultiReaderPrivate* d;\r
 };\r
 \r
 } // namespace BamTools\r