From cdeb8e63e9f1d79f748b77d9f80596852e75212b Mon Sep 17 00:00:00 2001 From: tgaspe Date: Tue, 6 Aug 2024 15:08:04 -0300 Subject: [PATCH] adding some tests --- src/bedtools/bedtools_groupby/config.vsh.yaml | 1 - src/bedtools/bedtools_groupby/script.sh | 2 +- src/bedtools/bedtools_groupby/test.sh | 69 ++++++++++++++++--- .../bedtools_groupby/test_data/example.bed | 15 ++++ .../bedtools_groupby/test_data/expected.bed | 3 + 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 src/bedtools/bedtools_groupby/test_data/example.bed create mode 100644 src/bedtools/bedtools_groupby/test_data/expected.bed diff --git a/src/bedtools/bedtools_groupby/config.vsh.yaml b/src/bedtools/bedtools_groupby/config.vsh.yaml index 5c00972a..c4f1a8f9 100644 --- a/src/bedtools/bedtools_groupby/config.vsh.yaml +++ b/src/bedtools/bedtools_groupby/config.vsh.yaml @@ -83,7 +83,6 @@ argument_groups: E.g., "-c 5,4,6 -o sum,mean,count" will give the sum of column 5, the mean of column 4, and the count of column 6. The order of output columns will match the ordering given in the command. - required: true - name: --full type: boolean_true diff --git a/src/bedtools/bedtools_groupby/script.sh b/src/bedtools/bedtools_groupby/script.sh index 7ca8982c..ae8547af 100644 --- a/src/bedtools/bedtools_groupby/script.sh +++ b/src/bedtools/bedtools_groupby/script.sh @@ -21,6 +21,6 @@ bedtools groupby \ -i "$par_input" \ -g "$par_groupby" \ -c "$par_column" \ - -o "$par_operation" \ + ${par_operation:+-o "$par_operation"} \ > "$par_output" \ No newline at end of file diff --git a/src/bedtools/bedtools_groupby/test.sh b/src/bedtools/bedtools_groupby/test.sh index 6d92959a..c78da8a7 100644 --- a/src/bedtools/bedtools_groupby/test.sh +++ b/src/bedtools/bedtools_groupby/test.sh @@ -29,28 +29,81 @@ assert_identical_content() { echo "Creating Test Data..." mkdir -p test_data -# Create and populate featuresA.bed +# Create and populate example.bed +cat << EOF > test_data/example.bed +# Header +chr21 9719758 9729320 variant1 chr21 9719768 9721892 ALR/Alpha 1004 + +chr21 9719758 9729320 variant1 chr21 9721905 9725582 ALR/Alpha 1010 + +chr21 9719758 9729320 variant1 chr21 9725582 9725977 L1PA3 3288 + +chr21 9719758 9729320 variant1 chr21 9726021 9729309 ALR/Alpha 1051 + +chr21 9729310 9757478 variant2 chr21 9729320 9729809 L1PA3 3897 - +chr21 9729310 9757478 variant2 chr21 9729809 9730866 L1P1 8367 + +chr21 9729310 9757478 variant2 chr21 9730866 9734026 ALR/Alpha 1036 - +chr21 9729310 9757478 variant2 chr21 9734037 9757471 ALR/Alpha 1182 - +chr21 9795588 9796685 variant3 chr21 9795589 9795713 (GAATG)n 308 + +chr21 9795588 9796685 variant3 chr21 9795736 9795894 (GAATG)n 683 + +chr21 9795588 9796685 variant3 chr21 9795911 9796007 (GAATG)n 345 + +chr21 9795588 9796685 variant3 chr21 9796028 9796187 (GAATG)n 756 + +chr21 9795588 9796685 variant3 chr21 9796202 9796615 (GAATG)n 891 + +chr21 9795588 9796685 variant3 chr21 9796637 9796824 (GAATG)n 621 + +EOF # Create and populate expected output files for different tests +cat << EOF > test_data/expected.bed +chr21 9719758 9729320 6353 +chr21 9729310 9757478 14482 +chr21 9795588 9796685 3604 +EOF +cat << EOF > test_data/expected_max.bed +chr21 9719758 9729320 variant1 3288 +chr21 9729310 9757478 variant2 8367 +chr21 9795588 9796685 variant3 891 +EOF -# Test 1: Default intersect +# Test 1: without operation option, default operation is sum mkdir test1 cd test1 -# echo "> Run bedtools_intersect on BED files with default intersect" -# "$meta_executable" \ -# --input_a "../test_data/featuresA.bed" \ -# --input_b "../test_data/featuresB.bed" \ -# --output "output.bed" +echo "> Run bedtools groupby on BED file" +"$meta_executable" \ + --input "../test_data/example.bed" \ + --groupby "1,2,3" \ + --column "9" \ + --output "output.bed" # checks assert_file_exists "output.bed" assert_file_not_empty "output.bed" -assert_identical_content "output.bed" "../test_data/expected_default.bed" +assert_identical_content "output.bed" "../test_data/expected.bed" echo "- test1 succeeded -" cd .. +# Test 2: with operation option +mkdir test2 +cd test2 + +echo "> Run bedtools groupby on BED file with max operation" +"$meta_executable" \ + --input "../test_data/example.bed" \ + --groupby "1-4" \ + --column "9" \ + --operation "max" \ + --output "output.bed" + +# checks +assert_file_exists "output.bed" +assert_file_not_empty "output.bed" +assert_identical_content "output.bed" "../test_data/expected_max.bed" +echo "- test2 succeeded -" + +cd .. + +# Test 3: + + + + echo "---- All tests succeeded! ----" diff --git a/src/bedtools/bedtools_groupby/test_data/example.bed b/src/bedtools/bedtools_groupby/test_data/example.bed new file mode 100644 index 00000000..d86e15dd --- /dev/null +++ b/src/bedtools/bedtools_groupby/test_data/example.bed @@ -0,0 +1,15 @@ +# Header +chr21 9719758 9729320 variant1 chr21 9719768 9721892 ALR/Alpha 1004 + +chr21 9719758 9729320 variant1 chr21 9721905 9725582 ALR/Alpha 1010 + +chr21 9719758 9729320 variant1 chr21 9725582 9725977 L1PA3 3288 + +chr21 9719758 9729320 variant1 chr21 9726021 9729309 ALR/Alpha 1051 + +chr21 9729310 9757478 variant2 chr21 9729320 9729809 L1PA3 3897 - +chr21 9729310 9757478 variant2 chr21 9729809 9730866 L1P1 8367 + +chr21 9729310 9757478 variant2 chr21 9730866 9734026 ALR/Alpha 1036 - +chr21 9729310 9757478 variant2 chr21 9734037 9757471 ALR/Alpha 1182 - +chr21 9795588 9796685 variant3 chr21 9795589 9795713 (GAATG)n 308 + +chr21 9795588 9796685 variant3 chr21 9795736 9795894 (GAATG)n 683 + +chr21 9795588 9796685 variant3 chr21 9795911 9796007 (GAATG)n 345 + +chr21 9795588 9796685 variant3 chr21 9796028 9796187 (GAATG)n 756 + +chr21 9795588 9796685 variant3 chr21 9796202 9796615 (GAATG)n 891 + +chr21 9795588 9796685 variant3 chr21 9796637 9796824 (GAATG)n 621 + diff --git a/src/bedtools/bedtools_groupby/test_data/expected.bed b/src/bedtools/bedtools_groupby/test_data/expected.bed new file mode 100644 index 00000000..94f90dc9 --- /dev/null +++ b/src/bedtools/bedtools_groupby/test_data/expected.bed @@ -0,0 +1,3 @@ +chr21 9719758 9729320 6353 +chr21 9729310 9757478 14482 +chr21 9795588 9796685 3604