From: Erik Garrison Date: Wed, 7 Jul 2010 19:32:48 +0000 (-0400) Subject: Remove heavy-handed failure mode in BamMultiReader::SetRegion X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2ffdeb8efe1f8e7b3f3152034ee6ea643200dbb3;p=bamtools.git Remove heavy-handed failure mode in BamMultiReader::SetRegion In practice a failure of BamReader::SetRegion means that we can't get alignments from the specified region. It is simpler to ignore failures of SetRegion as they are gracefully handled by UpdateAlignments, which simply doesn't add alignments from the readers which don't have alignments in the target region. This resolves a bug in which bamtools count (and any other utility using BamMultiReader::SetRegion) would crash when provided a target region with no alignments. --- diff --git a/BamMultiReader.cpp b/BamMultiReader.cpp index 6d80323..d1355df 100644 --- a/BamMultiReader.cpp +++ b/BamMultiReader.cpp @@ -179,19 +179,18 @@ bool BamMultiReader::SetRegion(const BamRegion& region) { Region = region; - bool result = true; + // NB: While it may make sense to track readers in which we can + // successfully SetRegion, In practice a failure of SetRegion means "no + // alignments here." It makes sense to simply accept the failure, + // UpdateAlignments(), and continue. + for (vector >::iterator it = readers.begin(); it != readers.end(); ++it) { - BamReader* reader = it->first; - result &= reader->SetRegion(region); - if (!result) { - cerr << "ERROR: could not set region " << reader->GetFilename() << " to " - << region.LeftRefID << ":" << region.LeftPosition << ".." << region.RightRefID << ":" << region.RightPosition - << endl; - exit(1); - } + it->first->SetRegion(region); } - if (result) UpdateAlignments(); - return result; + + UpdateAlignments(); + + return true; }