Commit 4cbfb094 authored by Jake Biesinger's avatar Jake Biesinger
Browse files

Bugfix: fix segfault when -t first or -t last used with -iu or -id

closestBed does some extra filtering of the hits returned by BedFile::allHits, but
it was previously assumed that each hit from allHits would be counted by closestBed.

This fix adds a check for the -t to make sure there are some hits in closestB and
updates numOverlaps when hits are filtered.

Maybe it would be better to add orientation-specific search to BedFile::allHits
instead of in closestBed?
parent 4f2fd3be
......@@ -116,13 +116,18 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
|| (_strandedDistMode == "a" && a.strand != "-")
|| (_strandedDistMode == "b" && h->strand == "-")) {
// hit is "upstream" of A
if (_ignoreUpstream)
if (_ignoreUpstream) {
numOverlaps--;
continue;
else
}
else {
curDistance = -curDistance;
}
}
else if (_ignoreDownstream)
else if (_ignoreDownstream) {
numOverlaps--;
continue;
}
}
if (abs(curDistance) < minDistance) {
......@@ -146,13 +151,18 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
if ((_strandedDistMode == "a" && a.strand == "-")
|| (_strandedDistMode == "b" && h->strand != "-")) {
// hit is "upstream" of A
if (_ignoreUpstream)
if (_ignoreUpstream) {
numOverlaps--;
continue;
else
}
else{
curDistance = -curDistance;
}
}
else if (_ignoreDownstream)
else if (_ignoreDownstream){
numOverlaps--;
continue;
}
}
if (abs(curDistance) < minDistance) {
minDistance = abs(curDistance);
......@@ -187,7 +197,7 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
// report the closest feature(s) in B to the current A feature.
// obey the user's reporting request (_tieMode)
if (numOverlaps > 0) {
if (closestB.size() == 1 || _tieMode == "first") {
if (closestB.size() == 1 || (_tieMode == "first" && closestB.size() > 0)) {
_bedA->reportBedTab(a);
if (_reportDistance == true) {
_bedB->reportBedTab(closestB[0]);
......@@ -209,7 +219,7 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
_bedB->reportBedNewLine(*b);
}
}
else if (_tieMode == "last") {
else if (_tieMode == "last" && closestB.size() > 0) {
_bedA->reportBedTab(a);
if (_reportDistance == true) {
_bedB->reportBedTab(closestB[closestB.size()-1]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment