From 7cf8c4d23d881383c1b15e25ea44f91f5c9fa78a Mon Sep 17 00:00:00 2001
From: Venkat Malladi <venkat.malladi@utsouthwestern.edu>
Date: Sat, 31 Oct 2020 21:13:03 -0500
Subject: [PATCH] Update config for email.

---
 .gitlab-ci.yml           | 12 ++++++------
 README.md                |  3 ++-
 workflow/nextflow.config |  3 ++-
 workflow/rna-seq.nf      | 15 +++++++++++++--
 4 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 63a773a..20659ed 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -130,7 +130,7 @@ dedupData:
   - singularity run 'docker://bicf/gudmaprbkdedup:2.0.0' samtools sort -@ 20 -O BAM -o Q-Y5F6_1M.se.sorted.deduped.bam ./test_data/bam/small/Q-Y5F6_1M.se.deduped.bam
   - singularity run 'docker://bicf/gudmaprbkdedup:2.0.0' samtools index -@ 20 -b ./test_data/bam/small/Q-Y5F6_1M.se.sorted.deduped.bam Q-Y5F6_1M.se.sorted.deduped.bam.bai
   - >
-    for i in {"chr8","chr4","chrY"}; do 
+    for i in {"chr8","chr4","chrY"}; do
       echo "samtools view -b Q-Y5F6_1M.se.sorted.deduped.bam ${i} > Q-Y5F6_1M.se.sorted.deduped.${i}.bam; samtools index -@ 20 -b Q-Y5F6_1M.se.sorted.deduped.${i}.bam Q-Y5F6_1M.se.sorted.deduped.${i}.bam.bai;";
       done | singularity run 'docker://bicf/gudmaprbkdedup:2.0.0' parallel -j 20 -k
   - pytest -m dedupData
@@ -145,7 +145,7 @@ countData:
   script:
   - ln -s /project/BICF/BICF_Core/shared/gudmap/references/GRCh38.p12.v31/geneID.tsv
   - ln -s /project/BICF/BICF_Core/shared/gudmap/references/GRCh38.p12.v31/Entrez.tsv
-  - singularity run 'docker://bicf/subread2:2.0.0' featureCounts -T 20 -a /project/BICF/BICF_Core/shared/gudmap/references/GRCh38.p12.v31/genome.gtf -G /project/BICF/BICF_Core/shared/gudmap/references/GRCh38.p12.v31/genome.fna -g 'gene_name' --extraAttributes 'gene_id' -o Q-Y5F6_1M.se.countData -s 1 -R SAM --primary --ignoreDup ./test_data/bam/small/Q-Y5F6_1M.se.sorted.deduped.bam 
+  - singularity run 'docker://bicf/subread2:2.0.0' featureCounts -T 20 -a /project/BICF/BICF_Core/shared/gudmap/references/GRCh38.p12.v31/genome.gtf -G /project/BICF/BICF_Core/shared/gudmap/references/GRCh38.p12.v31/genome.fna -g 'gene_name' --extraAttributes 'gene_id' -o Q-Y5F6_1M.se.countData -s 1 -R SAM --primary --ignoreDup ./test_data/bam/small/Q-Y5F6_1M.se.sorted.deduped.bam
   - singularity run 'docker://bicf/subread2:2.0.0' Rscript ./workflow/scripts/calculateTPM.R --count ./test_data/counts/small/Q-Y5F6_1M.se.countData
   - singularity run 'docker://bicf/subread2:2.0.0' Rscript ./workflow/scripts/convertGeneSymbols.R --repRID Q-Y5F6_1M.se
   - assignedReads=$(grep -m 1 'Assigned' *.summary | grep -oe '\([0-9.]*\)')
@@ -283,7 +283,7 @@ integration_se:
   script:
   - hostname
   - ulimit -a
-  - nextflow -q run ./workflow/rna-seq.nf --deriva ./test_data/auth/credential.json --bdbag ./test_data/auth/cookies.txt --repRID 16-1ZX4 -with-dag dag.png --ci true
+  - nextflow -q run ./workflow/rna-seq.nf --deriva ./test_data/auth/credential.json --bdbag ./test_data/auth/cookies.txt --repRID 16-1ZX4 -with-dag dag.png --ci true --email 'venkat.malladi@utsouthwestern.edu,Gervaise.Henry@UTSouthwestern.edu'
   - find . -type f -name "multiqc_data.json" -exec cp {} ./SE_multiqc_data.json \;
   artifacts:
     name: "$CI_JOB_NAME"
@@ -366,7 +366,7 @@ override_fastq:
     max: 1
     when:
       - always
-    
+
 override_species:
   stage: integration
   only: [merge_requests]
@@ -388,7 +388,7 @@ override_species:
     max: 1
     when:
       - always
-  
+
 
 consistency:
   stage: consistency
@@ -413,4 +413,4 @@ consistency:
       - assignedPE.txt
       - assignedExpectSE.txt
       - assignedExpectPE.txt
-    expire_in: 7 days
\ No newline at end of file
+    expire_in: 7 days
diff --git a/README.md b/README.md
index e3134bf..021a60b 100644
--- a/README.md
+++ b/README.md
@@ -43,6 +43,7 @@ To Run:
     * **biohpc_max** = process on high power BioHPC cluster nodes (=> 128GB nodes), for resource testing
     * **aws_ondemand** = AWS Batch on-demand instant requests
     * **aws_spot** = AWS Batch spot instance requests
+  * `-email`x email notification on failure
 * NOTES:
   * once deriva-auth is run and authenticated, the two files above are saved in ```~/.deriva/``` (see official documents from [deriva](https://github.com/informatics-isi-edu/deriva-client#installer-packages-for-windows-and-macosx) on the lifetime of the credentials)
   * reference version consists of Genome Reference Consortium version, patch release and GENCODE annotation release # (leaving the params blank will use the default version tied to the pipeline version)
@@ -126,4 +127,4 @@ Please cite in publications: Pipeline was developed by BICF from funding provide
 Pipeline Directed Acyclic Graph
 -------------------------------
 
-![dag](docs/dag.png "DAG")
\ No newline at end of file
+![dag](docs/dag.png "DAG")
diff --git a/workflow/nextflow.config b/workflow/nextflow.config
index 218cf2a..f9fcef9 100644
--- a/workflow/nextflow.config
+++ b/workflow/nextflow.config
@@ -82,7 +82,7 @@ timeline {
   enabled = false
   file = 'timeline.html'
 }
-	
+
 report {
   enabled = false
   file = 'report.html'
@@ -94,6 +94,7 @@ tower {
 }
 
 manifest {
+  name = 'gudmap_rbk/rna-seq'
   homePage = 'https://git.biohpc.swmed.edu/gudmap_rbk/rna-seq'
   description = 'This pipeline was created to be a standard mRNA-sequencing analysis pipeline which integrates with the GUDMAP and RBK consortium data-hub.'
   mainScript = 'rna-seq.nf'
diff --git a/workflow/rna-seq.nf b/workflow/rna-seq.nf
index 3099e99..0ca7965 100644
--- a/workflow/rna-seq.nf
+++ b/workflow/rna-seq.nf
@@ -18,6 +18,8 @@ params.refMoVersion = "38.p6.vM22"
 params.refHuVersion = "38.p12.v31"
 params.refERCCVersion = "92"
 params.outDir = "${baseDir}/../output"
+params.email = ""
+
 
 // Define override input variable
 params.refSource = "biohpc"
@@ -25,6 +27,7 @@ params.inputBagForce = ""
 params.fastqsForce = ""
 params.speciesForce = ""
 
+
 // Parse input variables
 deriva = Channel
   .fromPath(params.deriva)
@@ -46,6 +49,7 @@ logsDir = "${outDir}/Logs"
 inputBagForce = params.inputBagForce
 fastqsForce = params.fastqsForce
 speciesForce = params.speciesForce
+email = params.email
 
 // Define fixed files
 derivaConfig = Channel.fromPath("${baseDir}/conf/replicate_export_config.json")
@@ -1241,16 +1245,23 @@ process outputBag {
   """
 }
 
+
 workflow.onError = {
+  subject = "$$workflow.manifest.name FAILED: $params.repRID"
+
   def msg = """\
 
       Pipeline error summary
       ---------------------------
       RID         : ${params.repRID}
+      Version     : ${workflow.manifest.version}
+      Duration    : ${workflow.duration}
+      Nf Version  : ${workflow.nextflow.version}
       Message     : ${workflow.errorMessage}
       exit status : ${workflow.exitStatus}
       """
       .stripIndent()
-
-  sendMail(to: 'venkat.malladi@utsouthwestern.edu', subject: 'GUDMAP RNA-seq error execution', body: msg)
+  if (email != '') {
+    sendMail(to: email, subject: subject , body: msg)
+  }
 }
-- 
GitLab