From dc7614e9c8eb07be5d9ba80a67ce7cc2ac7e709e Mon Sep 17 00:00:00 2001 From: derek Date: Fri, 17 Jun 2011 00:09:49 -0400 Subject: [PATCH] Removed pessimistic warnings when jumping to regions with no data, using the standard index format (not actually an error case, so no need to alarm users with scary messages) --- src/api/internal/BamStandardIndex_p.cpp | 42 +++++++++++-------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/api/internal/BamStandardIndex_p.cpp b/src/api/internal/BamStandardIndex_p.cpp index c148d5d..6cb7b0a 100644 --- a/src/api/internal/BamStandardIndex_p.cpp +++ b/src/api/internal/BamStandardIndex_p.cpp @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 10 May 2011 (DB) +// Last modified: 16 June 2011 (DB) // --------------------------------------------------------------------------- // Provides index operations for the standardized BAM index format (".bai") // *************************************************************************** @@ -149,8 +149,8 @@ bool BamStandardIndex::CalculateCandidateOffsets(const BaiReferenceSummary& refS } } - // return success/failure on calculating at least 1 offset - return ( !offsets.empty() ); + // return success + return true; } uint64_t BamStandardIndex::CalculateMinOffset(const BaiReferenceSummary& refSummary, @@ -428,8 +428,9 @@ bool BamStandardIndex::GetOffsets(const BamRegion& region, vector& offs const uint64_t& minOffset = CalculateMinOffset(refSummary, begin); // attempt to use reference summary, minOffset, & candidateBins to calculate offsets + // no data should not be error if ( !CalculateCandidateOffsets(refSummary, minOffset, candidateBins, offsets) ) { - cerr << "Could not caluclate candidate offsets for region" << endl; + cerr << "BamStandardIndex ERROR: could not calculate candidate offsets for requested region" << endl; return false; } @@ -458,34 +459,35 @@ bool BamStandardIndex::IsFileOpen(void) const { // available after the jump position bool BamStandardIndex::Jump(const BamRegion& region, bool* hasAlignmentsInRegion) { + // clear out flag + *hasAlignmentsInRegion = false; + // skip if reader is not valid or is not open if ( m_reader == 0 || !m_reader->IsOpen() ) return false; // calculate offsets for this region - // if failed, print message, set flag, and return failure vector offsets; if ( !GetOffsets(region, offsets) ) { cerr << "BamStandardIndex ERROR: could not jump" << ", unable to retrieve offsets for region" << endl; - *hasAlignmentsInRegion = false; return false; } - // if no offsets retrieved, set flag - if ( offsets.empty() ) - *hasAlignmentsInRegion = false; - // iterate through candidate offsets BamAlignment al; - bool result = true; vector::const_iterator offsetIter = offsets.begin(); vector::const_iterator offsetEnd = offsets.end(); for ( ; offsetIter != offsetEnd; ++offsetIter) { - // attempt seek & load first available alignment - // set flag to true if data exists - result &= m_reader->Seek(*offsetIter); + // attempt seek + if ( !m_reader->Seek(*offsetIter) ) { + cerr << "BamStandardIndex ERROR: could not jump" + << ", there was a problem seeking in BAM file" << endl; + return false; + } + + // load first available alignment, setting flag to true if data exists *hasAlignmentsInRegion = m_reader->LoadNextAlignment(al); // if this alignment corresponds to desired position @@ -500,15 +502,9 @@ bool BamStandardIndex::Jump(const BamRegion& region, bool* hasAlignmentsInRegion } } - // if error in jumping, print message & set flag - if ( !result ) { - cerr << "BamStandardIndex ERROR: could not jump" - << ", there was a problem seeking in BAM file" << endl; - *hasAlignmentsInRegion = false; - } - - // return success/failure - return result; + // return success (no offset data is not an error, + // but hasAlignments flag will be marked accordingly) + return true; } // loads existing data from file into memory -- 2.39.5