From 1ec34c31512b530948037ebf34e072a50f0db5fa Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 16 Sep 2010 01:41:03 -0400 Subject: [PATCH] Missed an update to BamToolsIndex code in a previous commit --- src/api/BamIndex.cpp | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/src/api/BamIndex.cpp b/src/api/BamIndex.cpp index fabfbf1..c628b79 100644 --- a/src/api/BamIndex.cpp +++ b/src/api/BamIndex.cpp @@ -841,8 +841,8 @@ struct BamToolsIndex::BamToolsIndexPrivate { // ------------------------- // internal methods - // calculates offset(s) for a given region - bool GetOffsets(const BamRegion& region, const bool isRightBoundSpecified, vector& offsets); + // calculates offset for a given region + bool GetOffset(const BamRegion& region, int64_t& offset); }; bool BamToolsIndex::BamToolsIndexPrivate::Build(void) { @@ -925,13 +925,10 @@ bool BamToolsIndex::BamToolsIndexPrivate::Build(void) { } // N.B. - ignores isRightBoundSpecified -bool BamToolsIndex::BamToolsIndexPrivate::GetOffsets(const BamRegion& region, const bool isRightBoundSpecified, vector& offsets) { +bool BamToolsIndex::BamToolsIndexPrivate::GetOffset(const BamRegion& region, int64_t& offset) { // return false if leftBound refID is not found in index data if ( m_indexData.find(region.LeftRefID) == m_indexData.end() ) return false; - - // clear any prior data - offsets.clear(); const vector referenceOffsets = m_indexData[region.LeftRefID]; if ( referenceOffsets.empty() ) return false; @@ -940,7 +937,7 @@ bool BamToolsIndex::BamToolsIndexPrivate::GetOffsets(const BamRegion& region, co // calculate nearest index to jump to // save first offset - int64_t offset = (*referenceOffsets.begin()).StartOffset; + offset = (*referenceOffsets.begin()).StartOffset; vector::const_iterator indexIter = referenceOffsets.begin(); vector::const_iterator indexEnd = referenceOffsets.end(); for ( ; indexIter != indexEnd; ++indexIter ) { @@ -952,8 +949,7 @@ bool BamToolsIndex::BamToolsIndexPrivate::GetOffsets(const BamRegion& region, co // no index found if ( indexIter == indexEnd ) return false; - //store offset & return success - offsets.push_back(offset); + // return succes return true; } @@ -976,31 +972,15 @@ bool BamToolsIndex::BamToolsIndexPrivate::Jump(const BamRegion& region) { // make sure left-bound position is valid if ( region.LeftPosition > references.at(region.LeftRefID).RefLength ) return false; - vector offsets; - if ( !GetOffsets(region, region.isRightBoundSpecified(), offsets) ) { - fprintf(stderr, "ERROR: Could not jump: unable to calculate offset for specified region.\n"); + // calculate nearest offset to jump to + int64_t offset; + if ( !GetOffset(region, offset) ) { + fprintf(stderr, "ERROR: Could not jump - unable to calculate offset for specified region.\n"); return false; } - // iterate through offsets - BamAlignment bAlignment; - bool result = true; - for ( vector::const_iterator o = offsets.begin(); o != offsets.end(); ++o) { - - // attempt seek & load first available alignment - result &= mBGZF->Seek(*o); - reader->GetNextAlignmentCore(bAlignment); - - // if this alignment corresponds to desired position - // return success of seeking back to 'current offset' - if ( (bAlignment.RefID == region.LeftRefID && bAlignment.Position + bAlignment.Length > region.LeftPosition) || (bAlignment.RefID > region.LeftRefID) ) { - if ( o != offsets.begin() ) --o; - return mBGZF->Seek(*o); - } - } - - if ( !result ) fprintf(stderr, "ERROR: Could not jump: unable to calculate offset for specified region.\n"); - return result; + // attempt seek in file, return success/fail + return mBGZF->Seek(offset); } bool BamToolsIndex::BamToolsIndexPrivate::Load(const string& filename) { -- 2.39.2