1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
set -e;
###########################################################
#
# Unit tests for sampleFile program
#
############################################################
BT=${BT-../../bin/bedtools}
FAILURES=0;
check()
{
if diff $1 $2; then
echo ok
else
FAILURES=$(expr $FAILURES + 1);
echo fail
fi
}
###########################################################
#
# Create a 1,000 record BED6 file named "mainFile.bed".
# Give it a one line header, to test the -header option.
#
###########################################################
echo "#This is the mainFile from which samples will be taken." > mainFile.bed
$BT random -l 1000 -n 1000 -g human.hg19.genome >> mainFile.bed
###########################################################
# Test that help is printed when no args are given
############################################################
echo -e " sample.t01...\c"
echo \
"***** ERROR: No input file given. Exiting. *****" > exp
$BT sample 2>&1 > /dev/null | tail -1 > obs
check obs exp
rm obs
###########################################################
# Test that we throw an error for unrecognized arguments
############################################################
echo -e " sample.new.t02...\c"
echo "***** ERROR: Unrecognized parameter: -wrongArg *****" > exp
$BT sample -i mainFile.bed -wrongArg 2>&1 > /dev/null | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error when no input file was given.
############################################################
echo -e " sample.new.t03...\c"
echo "***** ERROR: No input file given. Exiting. *****" > exp;
$BT sample -n 10 2>&1 > /dev/null | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error for -i without input file
############################################################
echo -e " sample.new.t04...\c"
echo "***** ERROR: -i option given, but no input file specified. *****" > exp
$BT sample -i 2>&1 > /dev/null | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error for -n given without
# number of output records sepcified.
############################################################
echo -e " sample.new.t05...\c"
echo "***** ERROR: -n option given, but no number of output records specified. *****" > exp
$BT sample -n 2>&1 > /dev/null | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error when num output records
# exceeds records in file.
############################################################
echo -e " sample.new.t06...\c"
echo "***** ERROR: Input file has fewer records than the requested number of output records. *****" > exp
$BT sample -i mainFile.bed 2>&1 > /dev/null | head -2 | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we get the requested number of records
############################################################
echo -e " sample.new.t07...\c"
echo "10" > exp
# BSD wc adds leading whitespace, and BSD sed -i param requires extension
$BT sample -i mainFile.bed -n 10 | wc -l | sed 's/^[ \t]*//' > obs
check obs exp
rm obs exp
###########################################################
# Test that the -seed option gives consistent results
############################################################
echo -e " sample.new.t08...\c"
$BT sample -i mainFile.bed -n 50 -seed 4 > obs
$BT sample -i mainFile.bed -n 50 -seed 4 > exp
check obs exp
rm obs exp
###########################################################
# Test that -header option gives header
############################################################
echo -e " sample.new.t09...\c"
echo "#This is the mainFile from which samples will be taken." > exp
$BT sample -i mainFile.bed -n 10 -header | head -1 > obs
check obs exp
rm obs exp
rm mainFile.bed
[[ $FAILURES -eq 0 ]] || exit 1;
|