]> git.donarmstrong.com Git - bamtools.git/commitdiff
Remove heavy-handed failure mode in BamMultiReader::SetRegion
authorErik Garrison <erik.garrison@bc.edu>
Wed, 7 Jul 2010 19:32:48 +0000 (15:32 -0400)
committerErik Garrison <erik.garrison@bc.edu>
Wed, 7 Jul 2010 19:32:48 +0000 (15:32 -0400)
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

index 6d80323e60f5401349abfd5fe1431e10d5b65a7c..d1355df48e524ad292b2c888f56e20bde8a7e0d8 100644 (file)
@@ -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<pair<BamReader*, BamAlignment*> >::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;
 
 }