From 5ca30c98201d6d82ffb6e43d976ff4a4fab0bdf3 Mon Sep 17 00:00:00 2001 From: Venkat Malladi <venkat.malladi@utsouthwestern.edu> Date: Sat, 29 Feb 2020 09:08:27 -0600 Subject: [PATCH] Update for bats testing. --- workflow/main.nf | 2 +- workflow/scripts/plot_profile.sh | 87 +++++++++++++++++++++++++++----- workflow/tests/plot_profile.bats | 19 +++++++ 3 files changed, 94 insertions(+), 14 deletions(-) mode change 100644 => 100755 workflow/scripts/plot_profile.sh create mode 100644 workflow/tests/plot_profile.bats diff --git a/workflow/main.nf b/workflow/main.nf index 045afd4..cb8b1e6 100644 --- a/workflow/main.nf +++ b/workflow/main.nf @@ -496,7 +496,7 @@ process plotProfile { script: """ module load deeptools/2.5.0.1 - bash $baseDir/scripts/plot_profile.sh $gtfFile + bash $baseDir/scripts/plot_profile.sh """ } diff --git a/workflow/scripts/plot_profile.sh b/workflow/scripts/plot_profile.sh old mode 100644 new mode 100755 index b4df3b3..09b15eb --- a/workflow/scripts/plot_profile.sh +++ b/workflow/scripts/plot_profile.sh @@ -1,16 +1,77 @@ #!/bin/bash #plot_profile.sh -bws=$(ls *.bw) -gtf=$(ls *.gtf *.bed) - -computeMatrix reference-point \ - --referencePoint TSS \ - -S $bws \ - -R $gtf \ - --skipZeros \ - -o computeMatrix.gz - -p max/2 - -plotProfile -m computeMatrix.gz \ - -out plotProfile.png \ +raise() +{ + echo "${1}" >&2 +} + +check_tools() { + raise " + Checking for required libraries and components on this system + " + deeptools --version &> version_deeptools.txt + if [ $? -gt 0 ] + then + raise "Missing deeptools" + return 1 + fi +} + +compute_matrix() { + raise " + Computing matrix on ${1} using ${2} + " + + computeMatrix reference-point \ + --referencePoint TSS \ + -S ${1} \ + -R ${2} \ + --skipZeros \ + -o computeMatrix.gz \ + -p max/2 + + if [ $? -gt 0 ] + then + raise "Problem building matrix" + return 1 + fi +} + +plot_profile() { + raise " + Plotting profile + " + + plotProfile -m computeMatrix.gz \ + -out plotProfile.png + + if [ $? -gt 0 ] + then + raise "Problem plotting" + return 1 + fi +} + + +run_main() { + bws=$(ls *.bw) + gtf=$(ls *.gtf *.bed) + + check_tools || exit 1 + + compute_matrix "${bws}" "${gtf}" || return 1 + + plot_profile || return 1 + + raise "ALL COMPLETE" +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]] +then + run_main + if [ $? -gt 0 ] + then + exit 1 + fi +fi diff --git a/workflow/tests/plot_profile.bats b/workflow/tests/plot_profile.bats new file mode 100644 index 0000000..63fd7dd --- /dev/null +++ b/workflow/tests/plot_profile.bats @@ -0,0 +1,19 @@ +#!/opt/bats/libexec/bats-core/ bats + +profile_script="./worflow/scripts/plot_profile.sh" + +setup() { + module load deeptools/2.5.0.1 +} + +@test "Test deeptools present" { + source ${profile_script} + run check_tools + assert_success +} + +@test "Test matrix generation" { + source ${profile_script} + run check_tools + assert_success +} -- GitLab