From 5014f649e37a5e704a834f3b427c8041267adb23 Mon Sep 17 00:00:00 2001
From: nkindlon <nek3d@virginia.edu>
Date: Wed, 4 Dec 2013 21:29:59 -0500
Subject: [PATCH] Added unit tests for sampleFile program.

---
 test/sample/human.hg19.genome    |  94 +++++++++++++++++++++++
 test/sample/sample-intersect.sh  | 124 +++++++++++++++++++++++++++++++
 test/sample/sample-intersect.sh~ | 124 +++++++++++++++++++++++++++++++
 test/sample/sample_help.txt      |  34 +++++++++
 test/sample/test-sample.sh       | 124 +++++++++++++++++++++++++++++++
 test/test.sh                     |   6 +-
 6 files changed, 505 insertions(+), 1 deletion(-)
 create mode 100644 test/sample/human.hg19.genome
 create mode 100644 test/sample/sample-intersect.sh
 create mode 100644 test/sample/sample-intersect.sh~
 create mode 100644 test/sample/sample_help.txt
 create mode 100644 test/sample/test-sample.sh

diff --git a/test/sample/human.hg19.genome b/test/sample/human.hg19.genome
new file mode 100644
index 00000000..d22ce2d6
--- /dev/null
+++ b/test/sample/human.hg19.genome
@@ -0,0 +1,94 @@
+
+chr1	249250621
+chr10	135534747
+chr11	135006516
+chr11_gl000202_random	40103
+chr12	133851895
+chr13	115169878
+chr14	107349540
+chr15	102531392
+chr16	90354753
+chr17	81195210
+chr17_ctg5_hap1	1680828
+chr17_gl000203_random	37498
+chr17_gl000204_random	81310
+chr17_gl000205_random	174588
+chr17_gl000206_random	41001
+chr18	78077248
+chr18_gl000207_random	4262
+chr19	59128983
+chr19_gl000208_random	92689
+chr19_gl000209_random	159169
+chr1_gl000191_random	106433
+chr1_gl000192_random	547496
+chr2	243199373
+chr20	63025520
+chr21	48129895
+chr21_gl000210_random	27682
+chr22	51304566
+chr3	198022430
+chr4	191154276
+chr4_ctg9_hap1	590426
+chr4_gl000193_random	189789
+chr4_gl000194_random	191469
+chr5	180915260
+chr6	171115067
+chr6_apd_hap1	4622290
+chr6_cox_hap2	4795371
+chr6_dbb_hap3	4610396
+chr6_mann_hap4	4683263
+chr6_mcf_hap5	4833398
+chr6_qbl_hap6	4611984
+chr6_ssto_hap7	4928567
+chr7	159138663
+chr7_gl000195_random	182896
+chr8	146364022
+chr8_gl000196_random	38914
+chr8_gl000197_random	37175
+chr9	141213431
+chr9_gl000198_random	90085
+chr9_gl000199_random	169874
+chr9_gl000200_random	187035
+chr9_gl000201_random	36148
+chrM	16571
+chrUn_gl000211	166566
+chrUn_gl000212	186858
+chrUn_gl000213	164239
+chrUn_gl000214	137718
+chrUn_gl000215	172545
+chrUn_gl000216	172294
+chrUn_gl000217	172149
+chrUn_gl000218	161147
+chrUn_gl000219	179198
+chrUn_gl000220	161802
+chrUn_gl000221	155397
+chrUn_gl000222	186861
+chrUn_gl000223	180455
+chrUn_gl000224	179693
+chrUn_gl000225	211173
+chrUn_gl000226	15008
+chrUn_gl000227	128374
+chrUn_gl000228	129120
+chrUn_gl000229	19913
+chrUn_gl000230	43691
+chrUn_gl000231	27386
+chrUn_gl000232	40652
+chrUn_gl000233	45941
+chrUn_gl000234	40531
+chrUn_gl000235	34474
+chrUn_gl000236	41934
+chrUn_gl000237	45867
+chrUn_gl000238	39939
+chrUn_gl000239	33824
+chrUn_gl000240	41933
+chrUn_gl000241	42152
+chrUn_gl000242	43523
+chrUn_gl000243	43341
+chrUn_gl000244	39929
+chrUn_gl000245	36651
+chrUn_gl000246	38154
+chrUn_gl000247	36422
+chrUn_gl000248	39786
+chrUn_gl000249	38502
+chrX	155270560
+chrY	59373566
diff --git a/test/sample/sample-intersect.sh b/test/sample/sample-intersect.sh
new file mode 100644
index 00000000..f7f5f11d
--- /dev/null
+++ b/test/sample/sample-intersect.sh
@@ -0,0 +1,124 @@
+###########################################################
+#
+#  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 | cat - > obs
+check obs sample_help.txt
+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 --delimiter=' '> obs
+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
+
+
+
+
+
diff --git a/test/sample/sample-intersect.sh~ b/test/sample/sample-intersect.sh~
new file mode 100644
index 00000000..9356193f
--- /dev/null
+++ b/test/sample/sample-intersect.sh~
@@ -0,0 +1,124 @@
+###########################################################
+#
+#  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 | cat - > obs
+check obs sample_help.txt
+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 --delimiter=' '> obs
+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 > exp
+check obs exp
+rm obs exp
+
+rm mainFile.bed
+
+
+
+
+
diff --git a/test/sample/sample_help.txt b/test/sample/sample_help.txt
new file mode 100644
index 00000000..b291966a
--- /dev/null
+++ b/test/sample/sample_help.txt
@@ -0,0 +1,34 @@
+
+Tool:    bedtools sample (aka sampleFile)
+Version: v2.17.0-144-gb1aa9ab-dirty
+Summary: Take sample of input file(s) using reservoir sampling algorithm.
+
+Usage:   bedtools sample [OPTIONS] -i <bed/gff/vcf/bam>
+
+WARNING:	The current sample algorithm will hold all requested sample records in memory prior to output.
+		The user must ensure that there is adequate memory for this.
+
+Options: 
+	-n	The number of records to generate.
+		- Default = 1,000,000.
+		- (INTEGER)
+
+	-seed	Supply an integer seed for the shuffling.
+		- By default, the seed is chosen automatically.
+		- (INTEGER)
+
+	-ubam	Write uncompressed BAM output. Default writes compressed BAM.
+
+	-bed	When using BAM input (-abam), write output as BED. The default
+		is to write output in BAM when using -abam.
+
+	-s	Require same strandedness.  That is, only give records
+		that have the same strand. Use '-s forward' or '-s reverse'
+		for forward or reverse strand records, respectively.
+		- By default, records are reported without respect to strand.
+
+	-header	Print the header from the input file prior to results.
+
+Notes: 
+	TBD: Enter other usage notes here.
+
diff --git a/test/sample/test-sample.sh b/test/sample/test-sample.sh
new file mode 100644
index 00000000..f7f5f11d
--- /dev/null
+++ b/test/sample/test-sample.sh
@@ -0,0 +1,124 @@
+###########################################################
+#
+#  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 | cat - > obs
+check obs sample_help.txt
+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 --delimiter=' '> obs
+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
+
+
+
+
+
diff --git a/test/test.sh b/test/test.sh
index f624846b..7eafcc55 100644
--- a/test/test.sh
+++ b/test/test.sh
@@ -29,7 +29,7 @@ echo " Testing bedtools getfasta:"
 cd getfasta; sh test-getfasta.sh; cd ..
 
 echo " Testing bedtools intersect:"
-cd intersect; sh test-intersect.sh; sh new_test-intersect.sh cd ..
+cd intersect; sh test-intersect.sh; sh new_test-intersect.sh; cd ..
 
 echo " Testing bedtools jaccard:"
 cd jaccard; sh test-jaccard.sh; cd ..
@@ -51,3 +51,7 @@ cd slop; sh test-slop.sh; cd ..
 
 echo " Testing bedtools subtract:"
 cd subtract; sh test-subtract.sh; cd ..
+
+echo " Testing bedtools sample:"
+cd sample; sh test-sample.sh; cd ..
+
-- 
GitLab