Skip to content

Commit

Permalink
Merge pull request nf-core#14 from SciLifeLab/master
Browse files Browse the repository at this point in the history
 Use input channel for output docs rendering;  Updated e-mail code
  • Loading branch information
chuan-wang authored Oct 30, 2017
2 parents a2c4e41 + bcf63f5 commit f39682d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion assets/email_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<body>
<div style="font-family: Helvetica, Arial, sans-serif; padding: 30px; max-width: 800px; margin: 0 auto;">

<img src="cid:ngipipelinelogo">
<img src="cid:ngichipseqlogo">

<h1>NGI-ChIPseq: ChIP-Seq Best Practice v${version}</h1>
<h2>Run Name: $runName</h2>
Expand Down
56 changes: 40 additions & 16 deletions assets/sendmail_template.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
To: $email
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/alternative;boundary="ngimethylseqmimeboundary"
Content-Type: multipart/related;boundary="ngimimeboundary"

--ngimethylseqmimeboundary
Content-Type: text/plain; charset=utf-8

$email_txt

--ngimethylseqmimeboundary
--ngimimeboundary
Content-Type: text/html; charset=utf-8

$email_html

--ngimethylseqmimeboundary
--ngimimeboundary
Content-Type: image/png;name="NGI-ChIPseq_logo.png"
Content-Transfer-Encoding: base64
Content-ID: <ngipipelinelogo>
Content-ID: <ngichipseqlogo>
Content-Disposition: inline; filename="NGI-ChIPseq_logo.png"

<% out << new File("$baseDir/assets/NGI-ChIPseq_logo.png").bytes.encodeBase64().toString() %>

--ngimethylseqmimeboundary
<% out << new File("$baseDir/assets/NGI-ChIPseq_logo.png").
bytes.
encodeBase64().
toString().
tokenize( '\n' )*.
toList()*.
collate( 76 )*.
collect { it.join() }.
flatten().
join( '\n' ) %>

--ngimimeboundary
Content-Type: image/png;name="SciLifeLab_logo.png"
Content-Transfer-Encoding: base64
Content-ID: <scilifelablogo>
Content-Disposition: inline; filename="SciLifeLab_logo.png"

<% out << new File("$baseDir/assets/SciLifeLab_logo.png").bytes.encodeBase64().toString() %>

--ngimethylseqmimeboundary
<% out << new File("$baseDir/assets/SciLifeLab_logo.png").
bytes.
encodeBase64().
toString().
tokenize( '\n' )*.
toList()*.
collate( 76 )*.
collect { it.join() }.
flatten().
join( '\n' ) %>

--ngimimeboundary
Content-Type: image/png;name="NGI_logo.png"
Content-Transfer-Encoding: base64
Content-ID: <ngilogo>
Content-Disposition: inline; filename="NGI_logo.png"

<% out << new File("$baseDir/assets/NGI_logo.png").bytes.encodeBase64().toString() %>
<% out << new File("$baseDir/assets/NGI_logo.png").
bytes.
encodeBase64().
toString().
tokenize( '\n' )*.
toList()*.
collate( 76 )*.
collect { it.join() }.
flatten().
join( '\n' ) %>

--ngimimeboundary--
3 changes: 3 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ The output directory where the results will be saved.
### `--email`
Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits. If set in your user config file (`~/.nextflow/config`) then you don't need to speicfy this on the command line for every run.

### `--plaintext_email`
Set to receive plain-text e-mails instead of HTML formatted.

### `-name`
Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.

Expand Down
19 changes: 15 additions & 4 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ params.saveAlignedIntermediates = false
params.broad = false
params.outdir = './results'
params.email = false
params.plaintext_email = false

// Validate inputs
macsconfig = file(params.macsconfig)
Expand Down Expand Up @@ -86,6 +87,7 @@ params.three_prime_clip_r2 = 0
// Config / R locations
params.multiqc_config = "$baseDir/conf/multiqc_config.yaml"
multiqc_config = file(params.multiqc_config)
output_docs = file("$baseDir/docs/output.md")
params.rlocation = false
if (params.rlocation){
nxtflow_libs = file(params.rlocation)
Expand Down Expand Up @@ -612,14 +614,15 @@ process output_documentation {

input:
val prefix from multiqc_prefix
file output from output_docs

output:
file "results_description.html"

script:
def rlocation = params.rlocation ?: ''
"""
markdown_to_html.r $baseDir/docs/output.md results_description.html $rlocation
markdown_to_html.r $output results_description.html $rlocation
"""
}

Expand Down Expand Up @@ -678,17 +681,25 @@ workflow.onComplete {
// Send the HTML e-mail
if (params.email) {
try {
if( params.plaintext_email ){ throw GroovyException('Send plaintext e-mail, not HTML') }
// Try to send HTML e-mail using sendmail
[ 'sendmail', '-t' ].execute() << sendmail_html
log.debug "[NGI-ChIPseq] Sent summary e-mail using sendmail"
log.info "[NGI-ChIPseq] Sent summary e-mail to $params.email (sendmail)"
} catch (all) {
// Catch failures and try with plaintext
[ 'mail', '-s', subject, params.email ].execute() << email_txt
log.debug "[NGI-ChIPseq] Sendmail failed, failing back to sending summary e-mail using mail"
log.info "[NGI-ChIPseq] Sent summary e-mail to $params.email (mail)"
}
log.info "[NGI-ChIPseq] Sent summary e-mail to $params.email"
}

// Switch the embedded MIME images with base64 encoded src
ngichipseqlogo = new File("$baseDir/assets/NGI-ChIPseq_logo.png").bytes.encodeBase64().toString()
scilifelablogo = new File("$baseDir/assets/SciLifeLab_logo.png").bytes.encodeBase64().toString()
ngilogo = new File("$baseDir/assets/NGI_logo.png").bytes.encodeBase64().toString()
email_html = email_html.replaceAll(~/cid:ngichipseqlogo/, "data:image/png;base64,$ngichipseqlogo")
email_html = email_html.replaceAll(~/cid:scilifelablogo/, "data:image/png;base64,$scilifelablogo")
email_html = email_html.replaceAll(~/cid:ngilogo/, "data:image/png;base64,$ngilogo")

// Write summary e-mail HTML to a file
def output_d = new File( "${params.outdir}/Documentation/" )
if( !output_d.exists() ) {
Expand Down

0 comments on commit f39682d

Please sign in to comment.