Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
694afec
Adding in the first bits on that one
apeltzer Feb 5, 2021
5f31576
Check conda channels
apeltzer Feb 5, 2021
20f7d57
Fixed CI, this should work alreadyd well
apeltzer Feb 5, 2021
a041256
No more help checks, this should be fine
apeltzer Feb 7, 2021
d0a60df
Adding in enable_conda for automatic conda channel chceking :wq!
apeltzer Feb 7, 2021
fc48d9b
Proper DOI
apeltzer Feb 7, 2021
3cd8e9c
Hopefully helps with summary_parsm
apeltzer Feb 7, 2021
f464b62
Add TODO
apeltzer Feb 7, 2021
c18a049
Fixed all issues - please check
apeltzer Feb 8, 2021
6d237ed
Add extra deps required for validation of schema
apeltzer Feb 11, 2021
4c784e8
Fix issue in schema + main
apeltzer Feb 11, 2021
a2ac8eb
Forgot a piece of code
apeltzer Feb 12, 2021
c49cf6d
Switching over to newest new schema lib
apeltzer Feb 15, 2021
cf80f35
Adjusted to latest version in tools
apeltzer Feb 18, 2021
045734a
Fix for log_colours
apeltzer Feb 18, 2021
f73d74f
Adjust checks to only contain generic stuff
apeltzer Feb 25, 2021
b845ba6
Add in headers
apeltzer Feb 25, 2021
83b1e5d
Add in headers
apeltzer Feb 25, 2021
b19640c
Replace main.nf header equals to dashes to make merge conflicts easier
jfy133 Feb 25, 2021
eec51b8
Fix nextflow config and schema inconsistencies
jfy133 Feb 25, 2021
f9fd270
Readd previously deleted stuff
jfy133 Feb 25, 2021
1461dfd
Add previously removed CI test
jfy133 Feb 25, 2021
fa8e153
Guess we're good now
apeltzer Mar 12, 2021
f1c6c5b
Merge branch 'add-fancy-help-json-for-james' of https://github.com/nf…
apeltzer Mar 12, 2021
00f5782
Should be fine now
apeltzer Mar 12, 2021
06ef70d
Drop that trimmed too
apeltzer Mar 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### `Added`

- [#676](https://github.com/nf-core/eager/issues/676) - Added Lib Checks and automatic help message / summary message formatting

### `Fixed`

- [#666](https://github.com/nf-core/eager/issues/666) - Fixed input file staging for `print_nuclear_contamination`
Expand Down
85 changes: 85 additions & 0 deletions lib/Checks.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import org.yaml.snakeyaml.Yaml

/*
* This file holds several functions used to perform standard checks for the nf-core pipeline template.
*/

class Checks {

static void check_conda_channels(log) {
Yaml parser = new Yaml()
def channels = []
try {
def config = parser.load("conda config --show channels".execute().text)
channels = config.channels
} catch(NullPointerException | IOException e) {
log.warn "Could not verify conda channel configuration."
return
}

// Check that all channels are present
def required_channels = ['conda-forge', 'bioconda', 'defaults']
def conda_check_failed = !required_channels.every { ch -> ch in channels }

// Check that they are in the right order
conda_check_failed |= !(channels.indexOf('conda-forge') < channels.indexOf('bioconda'))
conda_check_failed |= !(channels.indexOf('bioconda') < channels.indexOf('defaults'))

if (conda_check_failed) {
log.warn "=============================================================================\n" +
" There is a problem with your Conda configuration!\n\n" +
" You will need to set-up the conda-forge and bioconda channels correctly.\n" +
" Please refer to https://bioconda.github.io/user/install.html#set-up-channels\n" +
" NB: The order of the channels matters!\n" +
"==================================================================================="
}
}

static void aws_batch(workflow, params) {
if (workflow.profile.contains('awsbatch')) {
assert (params.awsqueue && params.awsregion) : "Specify correct --awsqueue and --awsregion parameters on AWSBatch!"
// Check outdir paths to be S3 buckets if running on AWSBatch
// related: https://github.com/nextflow-io/nextflow/issues/813
assert params.outdir.startsWith('s3:') : "Outdir not on S3 - specify S3 Bucket to run on AWSBatch!"
// Prevent trace files to be stored on S3 since S3 does not support rolling files.
assert !params.tracedir.startsWith('s3:') : "Specify a local tracedir or run without trace! S3 cannot be used for tracefiles."
}
}

static void hostname(workflow, params, log) {
Map colors = Headers.log_colours(params.monochrome_logs)
if (params.hostnames) {
def hostname = "hostname".execute().text.trim()
params.hostnames.each { prof, hnames ->
hnames.each { hname ->
if (hostname.contains(hname) && !workflow.profile.contains(prof)) {
log.info "=${colors.yellow}====================================================${colors.reset}=\n" +
"${colors.yellow}WARN: You are running with `-profile $workflow.profile`\n" +
" but your machine hostname is ${colors.white}'$hostname'${colors.reset}.\n" +
" ${colors.yellow_bold}Please use `-profile $prof${colors.reset}`\n" +
"=${colors.yellow}====================================================${colors.reset}="
}
}
}
}
}

// Citation string
private static String citation(workflow) {
return "If you use ${workflow.manifest.name} for your analysis please cite:\n\n" +
"* The pipeline\n" +
" https://doi.org/10.1101/2020.06.11.145615\n\n" +
"* The nf-core framework\n" +
" https://dx.doi.org/10.1038/s41587-020-0439-x\n" +
" https://rdcu.be/b1GjZ\n\n" +
"* Software dependencies\n" +
" https://github.com/${workflow.manifest.name}/blob/master/CITATIONS.md"
}







}
129 changes: 129 additions & 0 deletions lib/Completion.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Functions to be run on completion of pipeline
*/

class Completion {
static void email(workflow, params, summary_params, projectDir, log, multiqc_report=[]) {

// Set up the e-mail variables
def subject = "[$workflow.manifest.name] Successful: $workflow.runName"

if (!workflow.success) {
subject = "[$workflow.manifest.name] FAILED: $workflow.runName"
}

def summary = [:]
for (group in summary_params.keySet()) {
summary << summary_params[group]
}

def misc_fields = [:]
misc_fields['Date Started'] = workflow.start
misc_fields['Date Completed'] = workflow.complete
misc_fields['Pipeline script file path'] = workflow.scriptFile
misc_fields['Pipeline script hash ID'] = workflow.scriptId
if (workflow.repository) misc_fields['Pipeline repository Git URL'] = workflow.repository
if (workflow.commitId) misc_fields['Pipeline repository Git Commit'] = workflow.commitId
if (workflow.revision) misc_fields['Pipeline Git branch/tag'] = workflow.revision
misc_fields['Nextflow Version'] = workflow.nextflow.version
misc_fields['Nextflow Build'] = workflow.nextflow.build
misc_fields['Nextflow Compile Timestamp'] = workflow.nextflow.timestamp

def email_fields = [:]
email_fields['version'] = workflow.manifest.version
email_fields['runName'] = workflow.runName
email_fields['success'] = workflow.success
email_fields['dateComplete'] = workflow.complete
email_fields['duration'] = workflow.duration
email_fields['exitStatus'] = workflow.exitStatus
email_fields['errorMessage'] = (workflow.errorMessage ?: 'None')
email_fields['errorReport'] = (workflow.errorReport ?: 'None')
email_fields['commandLine'] = workflow.commandLine
email_fields['projectDir'] = workflow.projectDir
email_fields['summary'] = summary << misc_fields

// 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"
}
mqc_report = mqc_report[0]
}
}
} catch (all) {
log.warn "[$workflow.manifest.name] Could not attach MultiQC report to summary email"
}

// Check if we are only sending emails on failure
def email_address = params.email
if (!params.email && params.email_on_fail && !workflow.success) {
email_address = params.email_on_fail
}

// Render the TXT template
def engine = new groovy.text.GStringTemplateEngine()
def tf = new File("$projectDir/assets/email_template.txt")
def txt_template = engine.createTemplate(tf).make(email_fields)
def email_txt = txt_template.toString()

// Render the HTML template
def hf = new File("$projectDir/assets/email_template.html")
def html_template = engine.createTemplate(hf).make(email_fields)
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 sf = new File("$projectDir/assets/sendmail_template.txt")
def sendmail_template = engine.createTemplate(sf).make(smail_fields)
def sendmail_html = sendmail_template.toString()

// Send the HTML e-mail
Map colors = Headers.log_colours(params.monochrome_logs)
if (email_address) {
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.info "-${colors.purple}[$workflow.manifest.name]${colors.green} Sent summary e-mail to $email_address (sendmail)-"
} 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 ]
}
mail_cmd.execute() << email_html
log.info "-${colors.purple}[$workflow.manifest.name]${colors.green} Sent summary e-mail to $email_address (mail)-"
}
}

// Write summary e-mail HTML to a file
def output_d = new File("${params.outdir}/pipeline_info/")
if (!output_d.exists()) {
output_d.mkdirs()
}
def output_hf = new File(output_d, "pipeline_report.html")
output_hf.withWriter { w -> w << email_html }
def output_tf = new File(output_d, "pipeline_report.txt")
output_tf.withWriter { w -> w << email_txt }
}

static void summary(workflow, params, log, fail_percent_mapped=[:], pass_percent_mapped=[:]) {
Map colors = Headers.log_colours(params.monochrome_logs)

if (workflow.success) {
if (workflow.stats.ignoredCount == 0) {
log.info "-${colors.purple}[$workflow.manifest.name]${colors.green} Pipeline completed successfully${colors.reset}-"
} else {
log.info "-${colors.purple}[$workflow.manifest.name]${colors.red} Pipeline completed successfully, but with errored process(es) ${colors.reset}-"
}
} else {
Checks.hostname(workflow, params, log)
log.info "-${colors.purple}[$workflow.manifest.name]${colors.red} Pipeline completed with errors${colors.reset}-"
}
}
}
43 changes: 43 additions & 0 deletions lib/Headers.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file holds several functions used to render the nf-core ANSI header.
*/

class Headers {

private static Map log_colours(Boolean monochrome_logs) {
Map colorcodes = [:]
colorcodes['reset'] = monochrome_logs ? '' : "\033[0m"
colorcodes['dim'] = monochrome_logs ? '' : "\033[2m"
colorcodes['black'] = monochrome_logs ? '' : "\033[0;30m"
colorcodes['green'] = monochrome_logs ? '' : "\033[0;32m"
colorcodes['yellow'] = monochrome_logs ? '' : "\033[0;33m"
colorcodes['yellow_bold'] = monochrome_logs ? '' : "\033[1;93m"
colorcodes['blue'] = monochrome_logs ? '' : "\033[0;34m"
colorcodes['purple'] = monochrome_logs ? '' : "\033[0;35m"
colorcodes['cyan'] = monochrome_logs ? '' : "\033[0;36m"
colorcodes['white'] = monochrome_logs ? '' : "\033[0;37m"
colorcodes['red'] = monochrome_logs ? '' : "\033[1;91m"
return colorcodes
}

static String dashed_line(monochrome_logs) {
Map colors = log_colours(monochrome_logs)
return "-${colors.dim}----------------------------------------------------${colors.reset}-"
}

static String nf_core(workflow, monochrome_logs) {
Map colors = log_colours(monochrome_logs)
String.format(
"""\n
${dashed_line(monochrome_logs)}
${colors.green},--.${colors.black}/${colors.green},-.${colors.reset}
${colors.blue} ___ __ __ __ ___ ${colors.green}/,-._.--~\'${colors.reset}
${colors.blue} |\\ | |__ __ / ` / \\ |__) |__ ${colors.yellow}} {${colors.reset}
${colors.blue} | \\| | \\__, \\__/ | \\ |___ ${colors.green}\\`-._,-`-,${colors.reset}
${colors.green}`._,._,\'${colors.reset}
${colors.purple} ${workflow.manifest.name} v${workflow.manifest.version}${colors.reset}
${dashed_line(monochrome_logs)}
""".stripIndent()
)
}
}
Loading