From 8e67ee2fda266e4c315bbd5688c341f827357251 Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 15 Jul 2010 13:59:42 -0400 Subject: [PATCH] Modified Rewind() to check actual data present when resetting region markers, instead of relying on potentially incorrect RefData::RefHasAlignments --- BamReader.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/BamReader.cpp b/BamReader.cpp index fcd17b1..f67a2e6 100644 --- a/BamReader.cpp +++ b/BamReader.cpp @@ -732,23 +732,23 @@ bool BamReader::BamReaderPrivate::Open(const string& filename, const string& ind // returns BAM file pointer to beginning of alignment data bool BamReader::BamReaderPrivate::Rewind(void) { - // find first reference that has alignments in the BAM file - int refID = 0; - int refCount = References.size(); - for ( ; refID < refCount; ++refID ) { - if ( References.at(refID).RefHasAlignments ) - break; - } - - // reset default region info - Region.LeftRefID = refID; - Region.LeftPosition = 0; - Region.RightRefID = -1; - Region.RightPosition = -1; - IsLeftBoundSpecified = false; - IsRightBoundSpecified = false; + // rewind to first alignment + if ( !mBGZF.Seek(AlignmentsBeginOffset) ) return false; + + // retrieve first alignment data + BamAlignment al; + if ( !GetNextAlignmentCore(al) ) return false; + + // reset default region info using first alignment in file + Region.LeftRefID = al.RefID; + Region.LeftPosition = al.Position; + Region.RightRefID = -1; + Region.RightPosition = -1; + IsLeftBoundSpecified = false; + IsRightBoundSpecified = false; - // return success/failure of seek + // rewind back to before first alignment + // return success/fail of seek return mBGZF.Seek(AlignmentsBeginOffset); } -- 2.39.5