Skip to content
Snippets Groups Projects
Commit 13dd59af authored by Aaron's avatar Aaron
Browse files

fix off-by-one error in calc. -d for closest

parent 09eb206e
No related branches found
No related tags found
No related merge requests found
......@@ -110,7 +110,7 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
}
// the hit is to the "left" of A
else if (h->end <= a.start) {
curDistance = a.start - h->end;
curDistance = (a.start - h->end) + 1;
if (_signDistance) {
if ((_strandedDistMode == "ref")
|| (_strandedDistMode == "a" && a.strand != "-")
......@@ -146,7 +146,7 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
}
// the hit is to the "right" of A
else if (h->start >= a.end) {
curDistance = h->start - a.end;
curDistance = (h->start - a.end) + 1;
if (_signDistance) {
if ((_strandedDistMode == "a" && a.strand == "-")
|| (_strandedDistMode == "b" && h->strand != "-")) {
......
chr1 10 20
chr1 19 21
chr1 20 21
BT=../../bin/bedtools
check()
{
if diff $1 $2; then
echo ok
return 1
else
echo fail
return 0
fi
}
# cat a.bed
# chr1 20 21
# cat b.bed
# chr1 20 21
# cat b-one-bp-closer.bed
# chr1 19 21
###########################################################
# test 1bp apart; checking for off-by-one errors
###########################################################
echo " closest.t1...\c"
echo \
"chr1 10 20 chr1 20 21 1" > exp
$BT closest -a a.bed -b b.bed -d > obs
check obs exp
rm obs exp
###########################################################
# test reciprocal of t1
###########################################################
echo " closest.t2...\c"
echo \
"chr1 20 21 chr1 10 20 1" > exp
$BT closest -a b.bed -b a.bed -d > obs
check obs exp
rm obs exp
###########################################################
# test 0bp apart; checking for off-by-one errors
###########################################################
echo " closest.t3...\c"
echo \
"chr1 10 20 chr1 19 21 0" > exp
$BT closest -a a.bed -b b-one-bp-closer.bed -d > obs
check obs exp
rm obs exp
###########################################################
# test reciprocal of t3
###########################################################
echo " closest.t4...\c"
echo \
"chr1 19 21 chr1 10 20 0" > exp
$BT closest -a b-one-bp-closer.bed -b a.bed -d > obs
check obs exp
rm obs exp
......@@ -7,6 +7,9 @@ cd bed12tobed6; sh test-bed12tobed6.sh; cd ..
echo " Testing bedtools bamtobed:"
cd bamtobed; sh test-bamtobed.sh; cd ..
echo " Testing bedtools closest:"
cd closest; sh test-closest.sh; cd ..
echo " Testing bedtools cluster:"
cd cluster; sh test-cluster.sh; cd ..
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment