X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FBamStandardIndex_p.cpp;h=c492899a20167d4924be71ff25d18c0b55fc0a18;hb=9f1ce8c47aeadb6dc1320b52ee671c3341b97935;hp=ad21fec3a581116c89091bdd5ba90eadf6876c46;hpb=2e049ed7f28881bce09653e60f5aea54bfd7afbf;p=bamtools.git diff --git a/src/api/internal/BamStandardIndex_p.cpp b/src/api/internal/BamStandardIndex_p.cpp index ad21fec..c492899 100644 --- a/src/api/internal/BamStandardIndex_p.cpp +++ b/src/api/internal/BamStandardIndex_p.cpp @@ -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 -#include -#include -#include +#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; @@ -78,8 +78,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 +91,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& candidateBins) @@ -478,7 +479,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;