diff --git a/workflow/main.nf b/workflow/main.nf
index 045afd4559cf0f5e3124d8e0d9c34f34ca96b4d1..cb8b1e61cecd3a141da26df31c1b6b06fe38177b 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 b4df3b30c5b453aeda43f57a3b7d1176f492e4f7..09b15eb347bcd975cf7faea05bdafd82d15b788d
--- 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 0000000000000000000000000000000000000000..63fd7dd72b49eaa6867a23d9ec7b420bea8fdcbd
--- /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
+}