Skip to content

Commit

Permalink
Properly exit when regions cannot be jumped to
Browse files Browse the repository at this point in the history
  • Loading branch information
morispi committed Sep 8, 2021
1 parent e6b49dd commit 8fe6436
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/alignmentsProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ pair<robin_hood::unordered_set<string>, vector<BamAlignment>> extractAlignmentsA
vector<string> t = splitString(region, ":");
vector<string> p = splitString(t[1], "-");
string region1 = t[0] + ":" + to_string(max(static_cast<uint32_t>(0), static_cast<uint32_t>(stoul(p[0]) - additionalSize))) + "-" + to_string(static_cast<uint32_t>(stoul(p[1]) + additionalSize));
reader.SetRegion(stringToBamRegion(reader, region1));

BamRegion r = stringToBamRegion(reader, region1);
if (!reader.SetRegion(r)) {
fprintf(stderr, "Error while attempting to jump to region %s.\n", region1.c_str());
exit(EXIT_FAILURE);
}
} else {
reader.SetRegion(stringToBamRegion(reader, region));
BamRegion r = stringToBamRegion(reader, region);
if (!reader.SetRegion(r)) {
fprintf(stderr, "Error while attempting to jump to region %s.\n", region.c_str());
exit(EXIT_FAILURE);
}
}


Expand Down Expand Up @@ -90,9 +99,18 @@ pair<robin_hood::unordered_set<string>, vector<BamAlignment>> extractAlignmentsW
vector<string> t = splitString(region, ":");
vector<string> p = splitString(t[1], "-");
string region1 = t[0] + ":" + to_string(max(static_cast<uint32_t>(0), static_cast<uint32_t>(stoul(p[0]) - additionalSize))) + "-" + to_string(static_cast<uint32_t>(stoul(p[1]) + additionalSize));
reader.SetRegion(stringToBamRegion(reader, region1));

BamRegion r = stringToBamRegion(reader, region1);
if (!reader.SetRegion(r)) {
fprintf(stderr, "Error while attempting to jump to region %s.\n", region1.c_str());
exit(EXIT_FAILURE);
}
} else {
reader.SetRegion(stringToBamRegion(reader, region));
BamRegion r = stringToBamRegion(reader, region);
if (!reader.SetRegion(r)) {
fprintf(stderr, "Error while attempting to jump to region %s.\n", region.c_str());
exit(EXIT_FAILURE);
}
}

robin_hood::unordered_set<string> headersSet;
Expand Down Expand Up @@ -121,4 +139,4 @@ pair<robin_hood::unordered_set<string>, vector<BamAlignment>> extractAlignmentsW
}

return make_pair(headersSet, alignments);
}
}

0 comments on commit 8fe6436

Please sign in to comment.