Newer
Older
###########################################################
#
# Unit tests for sampleFile program
#
############################################################
BT=${BT-../../bin/bedtools}
check()
{
if diff $1 $2; then
echo ok
else
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 " sample.t01...\c"
$BT sample 2>&1 > /dev/null | grep -iv version > obs
check obs sample_help_withoutVersion.txt
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
rm obs
###########################################################
# Test that we throw an error for unrecognized arguments
############################################################
echo " sample.new.t02...\c"
echo "***** ERROR: Unrecognized parameter: -wrongArg *****" > exp
$BT sample -wrongArg 2>&1 > /dev/null | head -2 | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error when no input file is given
############################################################
echo " sample.new.t03...\c"
echo "***** ERROR: input file not specified. *****" > exp
$BT sample -n 10 2>&1 > /dev/null | head -2 | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error for -i without input file
############################################################
echo " sample.new.t04...\c"
echo "***** ERROR: -i option given, but no input file specified. *****" > exp
$BT sample -i 2>&1 > /dev/null | head -2 | 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 " sample.new.t05...\c"
echo "***** ERROR: -n option given, but no number of output records specified. *****" > exp
$BT sample -n 2>&1 > /dev/null | head -2 | tail -1 > obs
check obs exp
rm obs exp
###########################################################
# Test that we throw an error when num output records
# exceeds records in file.
############################################################
echo " 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 " sample.new.t07...\c"
echo 10 > exp
$BT sample -i mainFile.bed -n 10 | wc -l | cut -f1 -d ' '> obs
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
check obs exp
rm obs exp
###########################################################
# Test that the -seed option gives consistent results
############################################################
echo " 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 " 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