]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/BamIndex.h
Major update to BamTools version 1.0
[bamtools.git] / src / api / BamIndex.h
index d09106a0d040ec7756446f57b3cf08e2087ac511..5ba1469382d70b8f4a050082737f977e929ffec7 100644 (file)
@@ -3,7 +3,7 @@
 // Marth Lab, Department of Biology, Boston College
 // All rights reserved.
 // ---------------------------------------------------------------------------
-// Last modified: 19 November 2010 (DB)
+// Last modified: 24 February 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides basic BAM index interface
 // ***************************************************************************
 namespace BamTools {
 
 class BamReader;
-class BgzfData;
 
 namespace Internal {
-  class BamStandardIndex;
-  class BamToolsIndex;
+    class BamReaderPrivate;
 } // namespace Internal
 
 // --------------------------------------------------  
 // BamIndex base class
 class API_EXPORT BamIndex {
 
-    // specify index-caching behavior
-    //
-    // @FullIndexCaching - store entire index file contents in memory
-    // @LimitedIndexCaching - store only index data for current reference
-    //   being processed
-    // @NoIndexCaching - do not store any index data.  Load as needed to 
-    //   calculate jump offset
-    public: enum BamIndexCacheMode { FullIndexCaching = 0
-                                   , LimitedIndexCaching
-                                   , NoIndexCaching
-                                   };
+    // enums
+    public:
+        // specify index-caching behavior
+        enum IndexCacheMode { FullIndexCaching = 0 // store entire index file contents in memory
+                            , LimitedIndexCaching  // store only index data for current reference
+                            , NoIndexCaching       // do not store any index data between jumps
+                            };
+
+        // list of supported BamIndex types
+        enum IndexType { BAMTOOLS = 0
+                       , STANDARD
+                       };
   
     // ctor & dtor
     public:
-        BamIndex(BamTools::BgzfData* bgzf, BamTools::BamReader* reader);
+        BamIndex(void);
         virtual ~BamIndex(void);
         
     // index interface
     public:
-        // creates index data (in-memory) from current reader data
-        virtual bool Build(void) =0;
+        // creates index data (in-memory) from @reader data
+        virtual bool Build(Internal::BamReaderPrivate* reader) =0;
         // returns supported file extension
-        virtual const std::string Extension(void) const =0;
+        virtual const std::string Extension(void) =0;
         // returns whether reference has alignments or no
         virtual bool HasAlignments(const int& referenceID) const =0;
-        // attempts to use index to jump to region; returns success/fail
+        // attempts to use index data to jump to @region in @reader; returns success/fail
         // a "successful" jump indicates no error, but not whether this region has data
-        //   * thus, the method sets a flag to indicate whether there are alignments 
+        //   * thus, the method sets a flag to indicate whether there are alignments
         //     available after the jump position
-        virtual bool Jump(const BamTools::BamRegion& region, bool* hasAlignmentsInRegion) =0;
+        virtual bool Jump(Internal::BamReaderPrivate* reader,
+                          const BamTools::BamRegion& region,
+                          bool* hasAlignmentsInRegion) =0;
         // loads existing data from file into memory
         virtual bool Load(const std::string& filename);
         // change the index caching behavior
-        virtual void SetCacheMode(const BamIndexCacheMode mode);
+        virtual void SetCacheMode(const BamIndex::IndexCacheMode& mode);
         // writes in-memory index data out to file 
         // N.B. - (this is the original BAM filename, method will modify it to use applicable extension)
         virtual bool Write(const std::string& bamFilename);
-        
+
     // derived-classes MUST provide implementation
     protected:
         // clear all current index offset data in memory
         virtual void ClearAllData(void) =0;
         // return file position after header metadata
-        virtual const off_t DataBeginOffset(void) const =0;
+        virtual off_t DataBeginOffset(void) const =0;
         // return true if all index data is cached
         virtual bool HasFullDataCache(void) const =0;
         // clears index data from all references except the first
@@ -94,7 +95,7 @@ class API_EXPORT BamIndex {
         // write index header data
         virtual bool WriteHeader(void) =0;
 
-    // internal methods
+    // internal methods (but available to derived classes)
     protected:
         // rewind index file to beginning of index data, return true if rewound OK
         bool Rewind(void);
@@ -107,37 +108,11 @@ class API_EXPORT BamIndex {
         // updates in-memory cache of index data, depending on current cache mode
         void UpdateCache(void);
 
-    // factory methods for returning proper BamIndex-derived type based on available index files
-    public:
-      
-        // returns index based on BAM filename 'stub'
-        // checks first for preferred type, returns that type if found
-        // (if not found, attmempts to load other type(s), returns 0 if NONE found)
-        //
-        // ** default preferred type is BamToolsIndex ** use this anytime it exists
-        enum PreferredIndexType { BAMTOOLS = 0, STANDARD };
-        static BamIndex* FromBamFilename(const std::string&   bamFilename,
-                                         BamTools::BgzfData*  bgzf,
-                                         BamTools::BamReader* reader, 
-                                         const BamIndex::PreferredIndexType& type = BamIndex::BAMTOOLS);
-        
-        // returns index based on explicitly named index file (or 0 if not found)
-        static BamIndex* FromIndexFilename(const std::string&   indexFilename,
-                                           BamTools::BgzfData*  bgzf,
-                                           BamTools::BamReader* reader);
-
     // data members
     protected:
-        BamTools::BgzfData*  m_BGZF;
-        BamTools::BamReader* m_reader;
-        BamTools::RefVector  m_references;
-        BamIndex::BamIndexCacheMode m_cacheMode;
         FILE* m_indexStream;
-
-
-    // friends
-    friend class Internal::BamStandardIndex;
-    friend class Internal::BamToolsIndex;
+        std::string m_indexFilename;
+        BamIndex::IndexCacheMode  m_cacheMode;
 };
 
 } // namespace BamTools