diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 30b1986eb9a107283e09326d2d0dca51cbad575e..c911d0b3550384fb297634663d0b5bfc7958799d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,13 @@ user_configuration: script: - pytest -m unit --cov=./workflow/scripts +bash_tests: + stage: unit + script: + - module load singularity/3.0.2 + - module load deeptools/2.5.0.1 + - singularity run docker://bats/bats:v1.1.0 --tap workflow/tests/plot_profile.bats + astrocyte: stage: astrocyte script: diff --git a/README.md b/README.md index 5fa408e50bde9f859914207705790addbba62a28..2420017468b5a170ceb596852b717fa6e180661a 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ $ git clone git@git.biohpc.swmed.edu:BICF/Astrocyte/chipseq_analysis.git 9. Annotate all peaks using ChipSeeker 10. Calculate Differential Binding Activity with DiffBind (If more than 1 rep in more than 1 experiment) 11. Use MEME-ChIP to find motifs in original peaks + 12. Plot enrichment of signal around TSS See [FLOWCHART](docs/flowchart.pdf) diff --git a/docs/index.md b/docs/index.md index 3b4a685cfc112291a221c04d7efa4fb85db9545a..e4e3e018513597745e2b2944e42d2ef05ac02277 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,6 +20,7 @@ Report issues to the Bioinformatic Core Facility [BICF](mailto:BICF@UTSouthweste 9. Annotate all peaks using ChipSeeker 10. Calculate Differential Binding Activity with DiffBind (If more than 1 rep in more than 1 experiment) 11. Use MEME-ChIP to find motifs in original peaks + 12. Plot enrichment of signal around TSS ## Workflow Parameters diff --git a/workflow/main.nf b/workflow/main.nf index 765ba3b1d1cd5b1d37d8dc339464d694c46ab8e2..ddebc750796a51060c1a5be040f61efd91b648d5 100644 --- a/workflow/main.nf +++ b/workflow/main.nf @@ -98,9 +98,8 @@ skipMotif = params.skipMotif skipPlotProfile = params.skipPlotProfile references = params.references multiqc = params.multiqc -gtfFile_plotProfile = Channel.fromPath(params.gtf) -gtfFile_annotPeaks = Channel.fromPath(params.gtf) -geneNames = Channel.fromPath(params.geneNames) +gtfFile = params.gtf +geneNames = params.geneNames // Check design file for errors process checkDesignFile { @@ -484,8 +483,7 @@ process plotProfile { input: - file ("*.pooled.fc_signal.bw") from bigwigs.collect() - file gtf from gtfFile_plotProfile + file bigWigList from bigwigs.collect() output: @@ -498,7 +496,7 @@ process plotProfile { script: """ module load deeptools/2.5.0.1 - bash $baseDir/scripts/plotProfile.sh + bash $baseDir/scripts/plot_profile.sh -g $gtfFile """ } @@ -540,8 +538,6 @@ process peakAnnotation { input: file designAnnotatePeaks - file gtf from gtfFile_annotPeaks - file geneNames output: @@ -552,7 +548,7 @@ process peakAnnotation { """ module load R/3.3.2-gccmkl - Rscript $baseDir/scripts/annotate_peaks.R $designAnnotatePeaks $gtf $geneNames + Rscript $baseDir/scripts/annotate_peaks.R $designAnnotatePeaks $gtfFile $geneNames """ } diff --git a/workflow/scripts/plotProfile.sh b/workflow/scripts/plotProfile.sh deleted file mode 100644 index 0f50501c410d2ab0a7549190ba830aa0a90d7602..0000000000000000000000000000000000000000 --- a/workflow/scripts/plotProfile.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -#plotProfile.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 \ diff --git a/workflow/scripts/plot_profile.sh b/workflow/scripts/plot_profile.sh new file mode 100755 index 0000000000000000000000000000000000000000..2481c8965856b507a19798f1c35302dc88724bec --- /dev/null +++ b/workflow/scripts/plot_profile.sh @@ -0,0 +1,105 @@ +#!/bin/bash +#plot_profile.sh + +script_name="plot_profile.sh" + +#Help function +usage() { + echo "-h --Help documentation for $script_name" + echo "-g --File path to gtf/bed files" + echo "Example: $script_name -g 'genome.gtf'" + exit 1 +} + + +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() { + + # Parsing options + OPTIND=1 # Reset OPTIND + while getopts :g:h opt + do + case $opt in + g) gtf=$OPTARG;; + h) usage;; + esac + done + + shift $(($OPTIND -1)) + + # Check for mandatory options + if [[ -z $gtf ]]; then + usage + fi + + bws=$(ls *pooled.fc_signal.bw) + + 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..d5da39f765f273488fcc6dce5675c49cd6e6ba18 --- /dev/null +++ b/workflow/tests/plot_profile.bats @@ -0,0 +1,26 @@ +#!/opt/bats/libexec/bats-core/ bats + +profile_script="./workflow/scripts/plot_profile.sh" + +@test "Test deeptools present" { + source ${profile_script} + run check_tools +} + +@test "Test deeptools computeMatrix" { + source ${profile_script} + run compute_matrix test_data/ENCSR238SGC_pooled.fc_signal.bw /project/shared/bicf_workflow_ref/mouse/GRCm38/gencode.vM20.annotation.gtf + FILE=computeMatrix.gz + if [[ -s "$FILE" ]]; then + echo "$FILE exists and not empty" + fi +} + +@test "Test deeptools plotProfile" { + source ${profile_script} + run plot_profile computeMatrix.gz + FILE=plotProfile.png + if [[ -s "$FILE" ]]; then + echo "$FILE exists and not empty" + fi +} diff --git a/workflow/tests/test_plot_profile.py b/workflow/tests/test_plot_profile.py index 6c9605d6d654f66adec865372223e13ddeaf6b19..0fe03a6fc0d044227f719f903a7339d264b3fe07 100644 --- a/workflow/tests/test_plot_profile.py +++ b/workflow/tests/test_plot_profile.py @@ -11,8 +11,9 @@ test_output_path = os.path.dirname(os.path.abspath(__file__)) + \ @pytest.mark.singleend def test_plot_singleend(): assert os.path.exists(os.path.join(test_output_path, 'plotProfile.png')) - + assert os.path.getsize(os.path.join(test_output_path, 'plotProfile.png')) > 0 @pytest.mark.pairedend def test_plot_pairedend(): - assert os.path.exists(os.path.join(test_output_path, 'computeMatrix.gz')) + assert os.path.exists(os.path.join(test_output_path, 'plotProfile.png')) + assert os.path.getsize(os.path.join(test_output_path, 'plotProfile.png')) > 0