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

New tests for slop and flank. Fixed chrom end bug in flank.

parent 2f55ceda
No related branches found
No related tags found
No related merge requests found
...@@ -103,14 +103,15 @@ void BedFlank::AddFlank(BED &bed, int leftFlank, int rightFlank) { ...@@ -103,14 +103,15 @@ void BedFlank::AddFlank(BED &bed, int leftFlank, int rightFlank) {
// make the left flank (if necessary) // make the left flank (if necessary)
if (rightFlank > 0) { if (rightFlank > 0) {
if ( (static_cast<int>(right.end) + (rightFlank+1)) <= static_cast<int>(chromSize)) if ( (static_cast<int>(right.end) + static_cast<int>(rightFlank+1))
<= static_cast<int>(chromSize))
{ {
right.start = right.end; right.start = right.end;
right.end += (rightFlank); right.end += (rightFlank);
} }
else { else {
right.start = right.end; right.start = right.end;
right.end += chromSize; right.end = chromSize;
} }
// report the right flank // report the right flank
_bed->reportBedNewLine(right); _bed->reportBedNewLine(right);
......
...@@ -124,8 +124,8 @@ int flank_main(int argc, char* argv[]) { ...@@ -124,8 +124,8 @@ int flank_main(int argc, char* argv[]) {
cerr << endl << "*****" << endl << "*****ERROR: Need both -l and -r. " << endl << "*****" << endl; cerr << endl << "*****" << endl << "*****ERROR: Need both -l and -r. " << endl << "*****" << endl;
showHelp = true; showHelp = true;
} }
if (forceStrand && (!(haveLeft) || !(haveRight))) { if (forceStrand && ((!(haveLeft) || !(haveRight)) && (!haveBoth))) {
cerr << endl << "*****" << endl << "*****ERROR: Must supply -l and -r with -s. " << endl << "*****" << endl; cerr << endl << "*****" << endl << "*****ERROR: Must supply -l and -r or just -b with -s. " << endl << "*****" << endl;
showHelp = true; showHelp = true;
} }
......
...@@ -124,11 +124,10 @@ int slop_main(int argc, char* argv[]) { ...@@ -124,11 +124,10 @@ int slop_main(int argc, char* argv[]) {
cerr << endl << "*****" << endl << "*****ERROR: Need both -l and -r. " << endl << "*****" << endl; cerr << endl << "*****" << endl << "*****ERROR: Need both -l and -r. " << endl << "*****" << endl;
showHelp = true; showHelp = true;
} }
if (forceStrand && (!(haveLeft) || !(haveRight))) { if (forceStrand && ((!(haveLeft) || !(haveRight)) && (!haveBoth))) {
cerr << endl << "*****" << endl << "*****ERROR: Must supply -l and -r with -s. " << endl << "*****" << endl; cerr << endl << "*****" << endl << "*****ERROR: Must supply -l and -r or just -b with -s. " << endl << "*****" << endl;
showHelp = true; showHelp = true;
} }
if (!showHelp) { if (!showHelp) {
BedSlop *bc = new BedSlop(bedFile, genomeFile, forceStrand, leftSlop, rightSlop, fractional, printHeader); BedSlop *bc = new BedSlop(bedFile, genomeFile, forceStrand, leftSlop, rightSlop, fractional, printHeader);
delete bc; delete bc;
......
chr1 100 200 a1 1 +
chr1 100 200 a2 2 -
BT=../../bin/bedtools
check()
{
if diff $1 $2; then
echo ok
return 1
else
echo fail
return 0
fi
}
# cat a.bed
# chr1 100 200 a1 1 +
# chr1 100 200 a2 2 -
###########################################################
# test matching flanks via -b
###########################################################
echo " flank.t1...\c"
echo \
"chr1 95 100 a1 1 +
chr1 200 205 a1 1 +
chr1 95 100 a2 2 -
chr1 200 205 a2 2 -" > exp
$BT flank -i a.bed -b 5 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test matching flanks via -l and -r
###########################################################
echo " flank.t2...\c"
echo \
"chr1 95 100 a1 1 +
chr1 200 205 a1 1 +
chr1 95 100 a2 2 -
chr1 200 205 a2 2 -" > exp
$BT flank -i a.bed -l 5 -r 5 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -l flank (-r == 0)
###########################################################
echo " flank.t3...\c"
echo \
"chr1 95 100 a1 1 +
chr1 95 100 a2 2 -" > exp
$BT flank -i a.bed -l 5 -r 0 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -r flank (-l == 0)
###########################################################
echo " flank.t4...\c"
echo \
"chr1 200 205 a1 1 +
chr1 200 205 a2 2 -" > exp
$BT flank -i a.bed -l 0 -r 5 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -l flank (-r == 0) with -s
###########################################################
echo " flank.t5...\c"
echo \
"chr1 95 100 a1 1 +
chr1 200 205 a2 2 -" > exp
$BT flank -i a.bed -l 5 -r 0 -s -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -r flank (-l == 0) with -s
###########################################################
echo " flank.t6...\c"
echo \
"chr1 200 205 a1 1 +
chr1 95 100 a2 2 -" > exp
$BT flank -i a.bed -l 0 -r 5 -s -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test -b with -s
###########################################################
echo " flank.t7...\c"
echo \
"chr1 95 100 a1 1 +
chr1 200 205 a1 1 +
chr1 95 100 a2 2 -
chr1 200 205 a2 2 -" > exp
$BT flank -i a.bed -b 5 -s -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the start of the chrom
###########################################################
echo " flank.t8...\c"
echo \
"chr1 0 100 a1 1 +
chr1 200 400 a1 1 +
chr1 0 100 a2 2 -
chr1 200 400 a2 2 -" > exp
$BT flank -i a.bed -b 200 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the end of the chrom
###########################################################
echo " flank.t9...\c"
echo \
"chr1 200 1000 a1 1 +
chr1 200 1000 a2 2 -" > exp
$BT flank -i a.bed -l 0 -r 1000 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the start and end of the chrom
###########################################################
echo " flank.t10...\c"
echo \
"chr1 0 100 a1 1 +
chr1 200 1000 a1 1 +
chr1 0 100 a2 2 -
chr1 200 1000 a2 2 -" > exp
$BT flank -i a.bed -b 2000 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the start and end of the chrom with -s
###########################################################
echo " flank.t11...\c"
echo \
"chr1 0 100 a1 1 +
chr1 200 1000 a1 1 +
chr1 0 100 a2 2 -
chr1 200 1000 a2 2 -" > exp
$BT flank -i a.bed -b 2000 -s -g tiny.genome > obs
check obs exp
rm obs exp
\ No newline at end of file
chr1 1000
chr1 100 200 a1 1 +
chr1 100 200 a2 2 -
BT=../../bin/bedtools
check()
{
if diff $1 $2; then
echo ok
return 1
else
echo fail
return 0
fi
}
# cat a.bed
# chr1 100 200 a1 1 +
# chr1 100 200 a2 2 -
###########################################################
# test matching flanks via -b
###########################################################
echo " slop.t1...\c"
echo \
"chr1 95 205 a1 1 +
chr1 95 205 a2 2 -" > exp
$BT slop -i a.bed -b 5 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test matching flanks via -l and -r
###########################################################
echo " slop.t2...\c"
echo \
"chr1 95 205 a1 1 +
chr1 95 205 a2 2 -" > exp > exp
$BT slop -i a.bed -l 5 -r 5 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -l flank (-r == 0)
###########################################################
echo " slop.t3...\c"
echo \
"chr1 95 200 a1 1 +
chr1 95 200 a2 2 -" > exp
$BT slop -i a.bed -l 5 -r 0 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -r flank (-l == 0)
###########################################################
echo " slop.t4...\c"
echo \
"chr1 100 205 a1 1 +
chr1 100 205 a2 2 -" > exp
$BT slop -i a.bed -l 0 -r 5 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -l flank (-r == 0) with -s
###########################################################
echo " slop.t5...\c"
echo \
"chr1 95 200 a1 1 +
chr1 100 205 a2 2 -" > exp
$BT slop -i a.bed -l 5 -r 0 -s -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test just a -r flank (-l == 0) with -s
###########################################################
echo " slop.t6...\c"
echo \
"chr1 100 205 a1 1 +
chr1 95 200 a2 2 -" > exp
$BT slop -i a.bed -l 0 -r 5 -s -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test -b with -s
###########################################################
echo " slop.t7...\c"
echo \
"chr1 95 205 a1 1 +
chr1 95 205 a2 2 -" > exp
$BT slop -i a.bed -b 5 -s -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the start of the chrom
###########################################################
echo " slop.t8...\c"
echo \
"chr1 0 400 a1 1 +
chr1 0 400 a2 2 -" > exp
$BT slop -i a.bed -b 200 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the end of the chrom
###########################################################
echo " slop.t9...\c"
echo \
"chr1 100 1000 a1 1 +
chr1 100 1000 a2 2 -" > exp
$BT slop -i a.bed -l 0 -r 1000 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the start and end of the chrom
###########################################################
echo " slop.t10...\c"
echo \
"chr1 0 1000 a1 1 +
chr1 0 1000 a2 2 -" > exp
$BT slop -i a.bed -b 2000 -g tiny.genome > obs
check obs exp
rm obs exp
###########################################################
# test going beyond the start and end of the chrom with -s
###########################################################
echo " slop.t11...\c"
echo \
"chr1 0 1000 a1 1 +
chr1 0 1000 a2 2 -" > exp
$BT slop -i a.bed -b 2000 -s -g tiny.genome > obs
check obs exp
rm obs exp
\ No newline at end of file
chr1 1000
...@@ -13,6 +13,16 @@ cd bamtobed ...@@ -13,6 +13,16 @@ cd bamtobed
sh test-bamtobed.sh sh test-bamtobed.sh
cd .. cd ..
echo " Testing bedtools coverage:"
cd coverage
sh test-coverage.sh
cd ..
echo " Testing bedtools flank:"
cd flank
sh test-flank.sh
cd ..
echo " Testing bedtools genomecov:" echo " Testing bedtools genomecov:"
cd genomecov cd genomecov
sh test-genomecov.sh sh test-genomecov.sh
...@@ -32,3 +42,8 @@ echo " Testing bedtools merge:" ...@@ -32,3 +42,8 @@ echo " Testing bedtools merge:"
cd merge cd merge
sh test-merge.sh sh test-merge.sh
cd .. cd ..
echo " Testing bedtools slop:"
cd slop
sh test-slop.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