From 3a224754ed07ed3b6d8014440460ffe5ff91d23b Mon Sep 17 00:00:00 2001 From: Konrad Rokicki Date: Wed, 3 May 2023 13:04:17 -0400 Subject: [PATCH 1/6] modified email function so that it does not require multiqc_report --- .../lib/NfcoreTemplate.groovy | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy index 2cb8b41388..74a340978d 100755 --- a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy +++ b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy @@ -94,19 +94,21 @@ class NfcoreTemplate { // On success try attach the multiqc report def mqc_report = null - try { - if (workflow.success) { - mqc_report = multiqc_report.getVal() - if (mqc_report.getClass() == ArrayList && mqc_report.size() >= 1) { - if (mqc_report.size() > 1) { - log.warn "[$workflow.manifest.name] Found multiple reports from process 'MULTIQC', will use only one" + if (multiqc_report) { + try { + if (workflow.success) { + mqc_report = multiqc_report.getVal() + if (mqc_report.getClass() == ArrayList && mqc_report.size() >= 1) { + if (mqc_report.size() > 1) { + log.warn "[$workflow.manifest.name] Found multiple reports from process 'MULTIQC', will use only one" + } + mqc_report = mqc_report[0] } - mqc_report = mqc_report[0] } - } - } catch (all) { - if (multiqc_report) { - log.warn "[$workflow.manifest.name] Could not attach MultiQC report to summary email" + } catch (all) { + if (multiqc_report) { + log.warn "[$workflow.manifest.name] Could not attach MultiQC report to summary email" + } } } @@ -128,8 +130,12 @@ class NfcoreTemplate { def email_html = html_template.toString() // Render the sendmail template - def max_multiqc_email_size = params.max_multiqc_email_size as nextflow.util.MemoryUnit - def smail_fields = [ email: email_address, subject: subject, email_txt: email_txt, email_html: email_html, projectDir: "$projectDir", mqcFile: mqc_report, mqcMaxSize: max_multiqc_email_size.toBytes() ] + def max_multiqc_email_size = params.containsKey("max_multiqc_email_size") ? params.max_multiqc_email_size as nextflow.util.MemoryUnit : 0 + def smail_fields = [ email: email_address, subject: subject, email_txt: email_txt, email_html: email_html, projectDir: "$projectDir", mqcFile : null, mqcMaxSize : null ] + if (mqc_report) { + smail_fields["mqcFile"] = mqc_report + smail_fields["mqcMaxSize"] = max_multiqc_email_size.toBytes() + } def sf = new File("$projectDir/assets/sendmail_template.txt") def sendmail_template = engine.createTemplate(sf).make(smail_fields) def sendmail_html = sendmail_template.toString() @@ -145,8 +151,10 @@ class NfcoreTemplate { } catch (all) { // Catch failures and try with plaintext def mail_cmd = [ 'mail', '-s', subject, '--content-type=text/html', email_address ] - if ( mqc_report.size() <= max_multiqc_email_size.toBytes() ) { - mail_cmd += [ '-A', mqc_report ] + if (mqc_report) { + if ( mqc_report.size() <= max_multiqc_email_size.toBytes() ) { + mail_cmd += [ '-A', mqc_report ] + } } mail_cmd.execute() << email_html log.info "-${colors.purple}[$workflow.manifest.name]${colors.green} Sent summary e-mail to $email_address (mail)-" From e7afe5ce0bd6aa845c5c434bbefa5b8b5270435f Mon Sep 17 00:00:00 2001 From: Konrad Rokicki Date: Wed, 3 May 2023 13:12:48 -0400 Subject: [PATCH 2/6] updated change log with email parameter change --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8921d75fea..94504e8596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # nf-core/tools: Changelog +# v2.9dev + +### Template + +- The `email` method no longer requires a `multiqc_report` parameter + # [v2.8 - Ruthenium Monkey](https://github.com/nf-core/tools/releases/tag/2.8) - [2023-04-27] ### Template From 79743a7822467f1e854e39bca7e68335f25a87ad Mon Sep 17 00:00:00 2001 From: Konrad Rokicki Date: Wed, 3 May 2023 13:13:16 -0400 Subject: [PATCH 3/6] linting --- nf_core/pipeline-template/lib/NfcoreTemplate.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy index 74a340978d..8590f0d35a 100755 --- a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy +++ b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy @@ -130,11 +130,11 @@ class NfcoreTemplate { def email_html = html_template.toString() // Render the sendmail template - def max_multiqc_email_size = params.containsKey("max_multiqc_email_size") ? params.max_multiqc_email_size as nextflow.util.MemoryUnit : 0 + def max_multiqc_email_size = params.containsKey('max_multiqc_email_size') ? params.max_multiqc_email_size as nextflow.util.MemoryUnit : 0 def smail_fields = [ email: email_address, subject: subject, email_txt: email_txt, email_html: email_html, projectDir: "$projectDir", mqcFile : null, mqcMaxSize : null ] if (mqc_report) { - smail_fields["mqcFile"] = mqc_report - smail_fields["mqcMaxSize"] = max_multiqc_email_size.toBytes() + smail_fields['mqcFile'] = mqc_report + smail_fields['mqcMaxSize'] = max_multiqc_email_size.toBytes() } def sf = new File("$projectDir/assets/sendmail_template.txt") def sendmail_template = engine.createTemplate(sf).make(smail_fields) From c9093fe31dc0ba4224fbb078b29c42d2fec80a64 Mon Sep 17 00:00:00 2001 From: Konrad Rokicki Date: Fri, 5 May 2023 13:09:32 -0400 Subject: [PATCH 4/6] simpler implementation --- .../lib/NfcoreTemplate.groovy | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy index 8590f0d35a..2cb8b41388 100755 --- a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy +++ b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy @@ -94,22 +94,20 @@ class NfcoreTemplate { // On success try attach the multiqc report def mqc_report = null - if (multiqc_report) { - try { - if (workflow.success) { - mqc_report = multiqc_report.getVal() - if (mqc_report.getClass() == ArrayList && mqc_report.size() >= 1) { - if (mqc_report.size() > 1) { - log.warn "[$workflow.manifest.name] Found multiple reports from process 'MULTIQC', will use only one" - } - mqc_report = mqc_report[0] + try { + if (workflow.success) { + mqc_report = multiqc_report.getVal() + if (mqc_report.getClass() == ArrayList && mqc_report.size() >= 1) { + if (mqc_report.size() > 1) { + log.warn "[$workflow.manifest.name] Found multiple reports from process 'MULTIQC', will use only one" } - } - } catch (all) { - if (multiqc_report) { - log.warn "[$workflow.manifest.name] Could not attach MultiQC report to summary email" + mqc_report = mqc_report[0] } } + } catch (all) { + if (multiqc_report) { + log.warn "[$workflow.manifest.name] Could not attach MultiQC report to summary email" + } } // Check if we are only sending emails on failure @@ -130,12 +128,8 @@ class NfcoreTemplate { def email_html = html_template.toString() // Render the sendmail template - def max_multiqc_email_size = params.containsKey('max_multiqc_email_size') ? params.max_multiqc_email_size as nextflow.util.MemoryUnit : 0 - def smail_fields = [ email: email_address, subject: subject, email_txt: email_txt, email_html: email_html, projectDir: "$projectDir", mqcFile : null, mqcMaxSize : null ] - if (mqc_report) { - smail_fields['mqcFile'] = mqc_report - smail_fields['mqcMaxSize'] = max_multiqc_email_size.toBytes() - } + def max_multiqc_email_size = params.max_multiqc_email_size as nextflow.util.MemoryUnit + def smail_fields = [ email: email_address, subject: subject, email_txt: email_txt, email_html: email_html, projectDir: "$projectDir", mqcFile: mqc_report, mqcMaxSize: max_multiqc_email_size.toBytes() ] def sf = new File("$projectDir/assets/sendmail_template.txt") def sendmail_template = engine.createTemplate(sf).make(smail_fields) def sendmail_html = sendmail_template.toString() @@ -151,10 +145,8 @@ class NfcoreTemplate { } catch (all) { // Catch failures and try with plaintext def mail_cmd = [ 'mail', '-s', subject, '--content-type=text/html', email_address ] - if (mqc_report) { - if ( mqc_report.size() <= max_multiqc_email_size.toBytes() ) { - mail_cmd += [ '-A', mqc_report ] - } + if ( mqc_report.size() <= max_multiqc_email_size.toBytes() ) { + mail_cmd += [ '-A', mqc_report ] } mail_cmd.execute() << email_html log.info "-${colors.purple}[$workflow.manifest.name]${colors.green} Sent summary e-mail to $email_address (mail)-" From d5d1887b5167e94babe95122739f7033c607828c Mon Sep 17 00:00:00 2001 From: Konrad Rokicki Date: Fri, 5 May 2023 13:14:31 -0400 Subject: [PATCH 5/6] fixed issue with max_multiqc_email_size --- nf_core/pipeline-template/lib/NfcoreTemplate.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy index 2cb8b41388..a1a726d69f 100755 --- a/nf_core/pipeline-template/lib/NfcoreTemplate.groovy +++ b/nf_core/pipeline-template/lib/NfcoreTemplate.groovy @@ -128,7 +128,7 @@ class NfcoreTemplate { def email_html = html_template.toString() // Render the sendmail template - def max_multiqc_email_size = params.max_multiqc_email_size as nextflow.util.MemoryUnit + def max_multiqc_email_size = (params.containsKey('max_multiqc_email_size') ? params.max_multiqc_email_size : 0) as nextflow.util.MemoryUnit def smail_fields = [ email: email_address, subject: subject, email_txt: email_txt, email_html: email_html, projectDir: "$projectDir", mqcFile: mqc_report, mqcMaxSize: max_multiqc_email_size.toBytes() ] def sf = new File("$projectDir/assets/sendmail_template.txt") def sendmail_template = engine.createTemplate(sf).make(smail_fields) From eae38cb93fe1f4ffff3674eaad65d16489de51f8 Mon Sep 17 00:00:00 2001 From: Konrad Rokicki Date: Fri, 5 May 2023 15:09:30 -0400 Subject: [PATCH 6/6] updated CHANGELOG with new fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b54d5f1365..f202c52764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Template -- The `email` method no longer requires a `multiqc_report` parameter +- `params.max_multiqc_email_size` is no longer required - Remove `cleanup = true` from `test_full.config` in pipeline template - Fix usage docs for specifying `params.yaml` - Added stub in modules template ([#2277])(https://github.com/nf-core/tools/pull/2277) [Contributed by @nvnieuwk]