From 2ffdeb8efe1f8e7b3f3152034ee6ea643200dbb3 Mon Sep 17 00:00:00 2001 From: Erik Garrison Date: Wed, 7 Jul 2010 15:32:48 -0400 Subject: [PATCH] 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. --- BamMultiReader.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) 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; } -- 2.39.2