]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/BamRandomAccessController_p.cpp
Updated CMakeLists.txt files
[bamtools.git] / src / api / internal / BamRandomAccessController_p.cpp
index 437b609940455c2907061e2e2f9ec7003d5b508a..c223ed762d9e5cb23b322fb6f90c4b7a3810e499 100644 (file)
@@ -2,16 +2,16 @@
 // BamRandomAccessController_p.cpp (c) 2011 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 7 October 2011(DB)
+// Last modified: 10 October 2011(DB)
 // ---------------------------------------------------------------------------
 // Manages random access operations in a BAM file
 // **************************************************************************
 
-#include <api/BamIndex.h>
-#include <api/internal/BamException_p.h>
-#include <api/internal/BamRandomAccessController_p.h>
-#include <api/internal/BamReader_p.h>
-#include <api/internal/BamIndexFactory_p.h>
+#include "api/BamIndex.h"
+#include "api/internal/BamException_p.h"
+#include "api/internal/BamRandomAccessController_p.h"
+#include "api/internal/BamReader_p.h"
+#include "api/internal/BamIndexFactory_p.h"
 using namespace BamTools;
 using namespace BamTools::Internal;
 
@@ -21,7 +21,6 @@ using namespace std;
 
 BamRandomAccessController::BamRandomAccessController(void)
     : m_index(0)
-    , m_indexCacheMode(BamIndex::LimitedIndexCaching)
     , m_hasAlignmentsInRegion(true)
 { }
 
@@ -79,9 +78,9 @@ BamRandomAccessController::AlignmentState(const BamAlignment& alignment) const {
         // if alignment starts at or after left bound position
         if ( alignment.Position >= m_region.LeftPosition) {
 
-            if ( m_region.isRightBoundSpecified() &&            // right bound is specified AND
-                 m_region.LeftRefID == m_region.RightRefID &&   // left & right bounds on same reference AND
-                 alignment.Position > m_region.RightPosition )  // alignment starts after right bound position
+            if ( m_region.isRightBoundSpecified() &&             // right bound is specified AND
+                 m_region.LeftRefID == m_region.RightRefID &&    // left & right bounds on same reference AND
+                 alignment.Position >= m_region.RightPosition )  // alignment starts on or after right bound position
                 return AfterRegion;
 
             // otherwise, alignment overlaps region
@@ -92,7 +91,7 @@ BamRandomAccessController::AlignmentState(const BamAlignment& alignment) const {
         else {
 
             // if alignment overlaps left bound position
-            if ( alignment.GetEndPosition() >= m_region.LeftPosition )
+            if ( alignment.GetEndPosition() > m_region.LeftPosition )
                 return OverlapsRegion;
             else
                 return BeforeRegion;
@@ -116,15 +115,15 @@ BamRandomAccessController::AlignmentState(const BamAlignment& alignment) const {
             // alignment is on right bound reference
             else {
 
-                // if alignment starts on or before right bound position
-                if ( alignment.Position <= m_region.RightPosition )
+                // if alignment starts before right bound position
+                if ( alignment.Position < m_region.RightPosition )
                     return OverlapsRegion;
                 else
                     return AfterRegion;
             }
         }
 
-        // otherwise, alignment starts after left bound and there is no right bound
+        // otherwise, alignment starts after left bound and there is no right bound given
         else return OverlapsRegion;
     }
 }
@@ -174,11 +173,8 @@ bool BamRandomAccessController::CreateIndex(BamReaderPrivate* reader,
         return false;
     }
 
-    // save new index
+    // save new index & return success
     SetIndex(newIndex);
-
-    // set new index's cache mode & return success
-    newIndex->SetCacheMode(m_indexCacheMode);
     return true;
 }
 
@@ -226,9 +222,6 @@ bool BamRandomAccessController::OpenIndex(const string& indexFilename, BamReader
         return false;
     }
 
-    // set cache mode
-    index->SetCacheMode(m_indexCacheMode);
-
     // attempt to load data from index file
     if ( !index->Load(indexFilename) ) {
         const string indexError = index->GetErrorString();
@@ -257,12 +250,6 @@ void BamRandomAccessController::SetIndex(BamIndex* index) {
     m_index = index;
 }
 
-void BamRandomAccessController::SetIndexCacheMode(const BamIndex::IndexCacheMode& mode) {
-    m_indexCacheMode = mode;
-    if ( m_index )
-        m_index->SetCacheMode(mode);
-}
-
 bool BamRandomAccessController::SetRegion(const BamRegion& region, const int& referenceCount) {
 
     // store region