]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/BamStandardIndex_p.cpp
Updated CMakeLists.txt files
[bamtools.git] / src / api / internal / BamStandardIndex_p.cpp
index ad21fec3a581116c89091bdd5ba90eadf6876c46..8b23f749b43ca4af6203afa857ea58ea009ed069 100644 (file)
@@ -2,15 +2,15 @@
 // BamStandardIndex.cpp (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 6 October 2011 (DB)
+// Last modified: 10 October 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides index operations for the standardized BAM index format (".bai")
 // ***************************************************************************
 
-#include <api/BamAlignment.h>
-#include <api/internal/BamException_p.h>
-#include <api/internal/BamReader_p.h>
-#include <api/internal/BamStandardIndex_p.h>
+#include "api/BamAlignment.h"
+#include "api/internal/BamException_p.h"
+#include "api/internal/BamReader_p.h"
+#include "api/internal/BamStandardIndex_p.h"
 using namespace BamTools;
 using namespace BamTools::Internal;
 
@@ -62,7 +62,6 @@ BamStandardIndex::RaiiWrapper::~RaiiWrapper(void) {
 // ctor
 BamStandardIndex::BamStandardIndex(Internal::BamReaderPrivate* reader)
     : BamIndex(reader)
-    , m_cacheMode(BamIndex::LimitedIndexCaching)
     , m_bufferLength(0)
 {
      m_isBigEndian = BamTools::SystemIsBigEndian();
@@ -78,8 +77,8 @@ void BamStandardIndex::AdjustRegion(const BamRegion& region, uint32_t& begin, ui
     // retrieve references from reader
     const RefVector& references = m_reader->GetReferenceData();
 
-    // make sure left-bound position is valid
-    if ( region.LeftPosition > references.at(region.LeftRefID).RefLength )
+    // LeftPosition cannot be greater than or equal to reference length
+    if ( region.LeftPosition >= references.at(region.LeftRefID).RefLength )
         throw BamException("BamStandardIndex::AdjustRegion", "invalid region requested");
 
     // set region 'begin'
@@ -91,9 +90,10 @@ void BamStandardIndex::AdjustRegion(const BamRegion& region, uint32_t& begin, ui
         end = (unsigned int)region.RightPosition;
 
     // otherwise, set region 'end' to last reference base
-    else end = (unsigned int)references.at(region.LeftRefID).RefLength - 1;
+    else end = (unsigned int)references.at(region.LeftRefID).RefLength;
 }
 
+// [begin, end)
 void BamStandardIndex::CalculateCandidateBins(const uint32_t& begin,
                                               const uint32_t& end,
                                               set<uint16_t>& candidateBins)
@@ -478,7 +478,7 @@ void BamStandardIndex::GetOffset(const BamRegion& region, int64_t& offset, bool*
         *hasAlignmentsInRegion = m_reader->LoadNextAlignment(al);
 
         // check alignment against region
-        if ( al.GetEndPosition() < region.LeftPosition ) {
+        if ( al.GetEndPosition() <= region.LeftPosition ) {
             offsetFirst = ++offsetIter;
             count -= step+1;
         } else count = step;
@@ -761,12 +761,6 @@ void BamStandardIndex::Seek(const int64_t& position, const int& origin) {
         throw BamException("BamStandardIndex::Seek", "could not seek in BAI file");
 }
 
-// change the index caching behavior
-void BamStandardIndex::SetCacheMode(const BamIndex::IndexCacheMode& mode) {
-    m_cacheMode = mode;
-    // do nothing else here ? cache mode will be ignored from now on, most likely
-}
-
 void BamStandardIndex::SkipBins(const int& numBins) {
     uint32_t binId;
     int32_t numAlignmentChunks;