From 5cf969db8786f7e1710c836fe27d843a727994d0 Mon Sep 17 00:00:00 2001 From: tgaspe Date: Wed, 14 Aug 2024 23:08:27 +0200 Subject: [PATCH] Adding $TMPDIR to test.sh --- src/bedtools/bedtools_bamtobed/test.sh | 77 +++++++++++++------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/bedtools/bedtools_bamtobed/test.sh b/src/bedtools/bedtools_bamtobed/test.sh index 6a47d240..3ea8b59d 100644 --- a/src/bedtools/bedtools_bamtobed/test.sh +++ b/src/bedtools/bedtools_bamtobed/test.sh @@ -23,21 +23,25 @@ assert_identical_content() { } ############################################# -mkdir -p data +echo "Creating Test Data..." +TMPDIR=$(mktemp -d "$meta_temp_dir/XXXXXX") +function clean_up { + [[ -d "$TMPDIR" ]] && rm -r "$TMPDIR" +} +trap clean_up EXIT # Generate expected files for comparison -printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\n" > data/expected.bed -printf "chr2:172936693-172938111\t128\t228\tchr2:172936693-172938111\t428\t528\tmy_read\t60\t+\t-\n" > data/expected.bedpe -printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\t128\t228\t255,0,0\t1\t100\t0\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\t428\t528\t255,0,0\t1\t100\t0\n" > data/expected.bed12 -printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t0\t+\nchr2:172936693-172938111\t428\t528\tmy_read/2\t0\t-\n" > data/expected_ed.bed -printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\t128\t228\t250,250,250\t1\t100\t0\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\t428\t528\t250,250,250\t1\t100\t0\n" > data/expected_color.bed12 -printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\t100M\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\t100M\n" > data/expected_cigar.bed -printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t85\t+\nchr2:172936693-172938111\t428\t528\tmy_read/2\t85\t-\n" > data/expected_tag.bed +printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\n" > "$TMPDIR/expected.bed" +printf "chr2:172936693-172938111\t128\t228\tchr2:172936693-172938111\t428\t528\tmy_read\t60\t+\t-\n" > "$TMPDIR/expected.bedpe" +printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\t128\t228\t255,0,0\t1\t100\t0\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\t428\t528\t255,0,0\t1\t100\t0\n" > "$TMPDIR/expected.bed12" +printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t0\t+\nchr2:172936693-172938111\t428\t528\tmy_read/2\t0\t-\n" > "$TMPDIR/expected_ed.bed" +printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\t128\t228\t250,250,250\t1\t100\t0\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\t428\t528\t250,250,250\t1\t100\t0\n" > "$TMPDIR/expected_color.bed12" +printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t60\t+\t100M\nchr2:172936693-172938111\t428\t528\tmy_read/2\t60\t-\t100M\n" > "$TMPDIR/expected_cigar.bed" +printf "chr2:172936693-172938111\t128\t228\tmy_read/1\t85\t+\nchr2:172936693-172938111\t428\t528\tmy_read/2\t85\t-\n" > "$TMPDIR/expected_tag.bed" # Test 1: -mkdir test1 -cd test1 +mkdir "$TMPDIR/test1" && pushd "$TMPDIR/test1" > /dev/null echo "> Run bedtools bamtobed on BAM file" "$meta_executable" \ @@ -47,14 +51,13 @@ echo "> Run bedtools bamtobed on BAM file" # checks assert_file_exists "output.bed" assert_file_not_empty "output.bed" -assert_identical_content "output.bed" "../data/expected.bed" +assert_identical_content "output.bed" "../expected.bed" echo "- test1 succeeded -" -cd .. +popd > /dev/null # Test 2: -mkdir test2 -cd test2 +mkdir "$TMPDIR/test2" && pushd "$TMPDIR/test2" > /dev/null echo "> Run bedtools bamtobed on BAM file with -bedpe" "$meta_executable" \ @@ -65,14 +68,13 @@ echo "> Run bedtools bamtobed on BAM file with -bedpe" # checks assert_file_exists "output.bedpe" assert_file_not_empty "output.bedpe" -assert_identical_content "output.bedpe" "../data/expected.bedpe" +assert_identical_content "output.bedpe" "../expected.bedpe" echo "- test2 succeeded -" -cd .. +popd > /dev/null # Test 3: -mkdir test3 -cd test3 +mkdir "$TMPDIR/test3" && pushd "$TMPDIR/test3" > /dev/null echo "> Run bedtools bamtobed on BAM file with -bed12" "$meta_executable" \ @@ -83,14 +85,13 @@ echo "> Run bedtools bamtobed on BAM file with -bed12" # checks assert_file_exists "output.bed12" assert_file_not_empty "output.bed12" -assert_identical_content "output.bed12" "../data/expected.bed12" +assert_identical_content "output.bed12" "../expected.bed12" echo "- test3 succeeded -" -cd .. +popd > /dev/null # Test 4: -mkdir test4 -cd test4 +mkdir "$TMPDIR/test4" && pushd "$TMPDIR/test4" > /dev/null echo "> Run bedtools bamtobed on BAM file with -ed" "$meta_executable" \ @@ -101,14 +102,13 @@ echo "> Run bedtools bamtobed on BAM file with -ed" # checks assert_file_exists "output_ed.bed" assert_file_not_empty "output_ed.bed" -assert_identical_content "output_ed.bed" "../data/expected_ed.bed" +assert_identical_content "output_ed.bed" "../expected_ed.bed" echo "- test4 succeeded -" -cd .. +popd > /dev/null # Test 5: -mkdir test5 -cd test5 +mkdir "$TMPDIR/test5" && pushd "$TMPDIR/test5" > /dev/null echo "> Run bedtools bamtobed on BAM file with -color" "$meta_executable" \ @@ -120,14 +120,13 @@ echo "> Run bedtools bamtobed on BAM file with -color" # checks assert_file_exists "output_color.bed12" assert_file_not_empty "output_color.bed12" -assert_identical_content "output_color.bed12" "../data/expected_color.bed12" +assert_identical_content "output_color.bed12" "../expected_color.bed12" echo "- test5 succeeded -" -cd .. +popd > /dev/null # Test 6: -mkdir test6 -cd test6 +mkdir "$TMPDIR/test6" && pushd "$TMPDIR/test6" > /dev/null echo "> Run bedtools bamtobed on BAM file with -cigar" "$meta_executable" \ @@ -138,14 +137,13 @@ echo "> Run bedtools bamtobed on BAM file with -cigar" # checks assert_file_exists "output_cigar.bed" assert_file_not_empty "output_cigar.bed" -assert_identical_content "output_cigar.bed" "../data/expected_cigar.bed" +assert_identical_content "output_cigar.bed" "../expected_cigar.bed" echo "- test6 succeeded -" -cd .. +popd > /dev/null # Test 7: -mkdir test7 -cd test7 +mkdir "$TMPDIR/test7" && pushd "$TMPDIR/test7" > /dev/null echo "> Run bedtools bamtobed on BAM file with -tag" "$meta_executable" \ @@ -156,14 +154,13 @@ echo "> Run bedtools bamtobed on BAM file with -tag" # checks assert_file_exists "output_tag.bed" assert_file_not_empty "output_tag.bed" -assert_identical_content "output_tag.bed" "../data/expected_tag.bed" +assert_identical_content "output_tag.bed" "../expected_tag.bed" echo "- test7 succeeded -" -cd .. +popd > /dev/null # Test 8: -mkdir test8 -cd test8 +mkdir "$TMPDIR/test8" && pushd "$TMPDIR/test8" > /dev/null echo "> Run bedtools bamtobed on BAM file with other options" "$meta_executable" \ @@ -177,10 +174,10 @@ echo "> Run bedtools bamtobed on BAM file with other options" # checks assert_file_exists "output.bed" assert_file_not_empty "output.bed" -assert_identical_content "output.bed" "../data/expected.bedpe" +assert_identical_content "output.bed" "../expected.bedpe" echo "- test8 succeeded -" -cd .. +popd > /dev/null echo "---- All tests succeeded! ----" exit 0