Commit f11d75ad authored by Jules Sabban's avatar Jules Sabban
Browse files

#4 write workflow

parent 22c5ebab
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
/*
Copyright INRAE 2021
This software is a computer program whose purpose is to
analyze high-throughput sequencing data.
You can use, modify and/ or redistribute the software under the terms
of license (see the LICENSE file for more details).
The software is distributed in the hope that it will be useful,
but "AS IS" WITHOUT ANY WARRANTY OF ANY KIND.
Users are therefore encouraged to test the software's suitability as regards
their requirements in conditions enabling the security of their systems and/or data.
The fact that you are presently reading this means that you have had knowledge
of the license and that you accept its terms.
This script is based on :
- the nf-core guidelines . See https://nf-co.re/ for more information
- the Curie institute template https://github.com/bioinfo-pf-curie/geniac-template/
*/
/*
========================================================================================
NAMED WORKFLOW FOR PIPELINE
========================================================================================
*/
include { techno_qc } from './workflows/techno_qc.nf'
workflow QC_ANALYSIS {
techno_qc()
}
/*
========================================================================================
RUN ALL WORKFLOWS
========================================================================================
*/
workflow {
QC_ANALYSIS()
}
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
def helpMessage() {
log.info"""
Usage:
The typical command for running the pipeline is as follows:
nextflow run get-nf/template --inputdir '/path/to/data' --samplesheet 'samples.csv' -profile docker
Mandatory arguments:
--inputdir Path to input directory
-profile Configuration profile to use. Can use multiple (comma separated)
Available: conda, docker, singularity, path, genotoul, test and more.
Options:
--samplesheet Default inputdir/samples.csv eg: SAMPLE_ID,SAMPLE_NAME,path/to/R1/fastq/file,path/to/R2/fastq/file (for paired-end only)
--contaminant Name of iGenomes // To be discussed ????
--outdir 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
--email_on_fail Same as --email, except only send mail if the workflow is not successful
--maxMultiqcEmailFileSize Theshold size for MultiQC report to be attached in notification email. If file generated by pipeline exceeds the threshold, it will not be attached (Default: 25MB)
-name [str] Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.
=======================================================
Available profiles
-profile test Run the test dataset
-profile conda Build a new conda environment before running the pipeline. Use `--condaCacheDir` to define the conda cache path
-profile path Use the installation path defined for all tools. Use `--globalPath` to define the installation path
-profile docker Use the Docker images for each process
-profile singularity Use the singularity images for each process
-profile genologin Run the workflow on the cluster, instead of locally
""".stripIndent()
}
// Show help message
if (params.help) {
helpMessage()
exit 0
}
// NOTE - THIS IS NOT USED IN THIS PIPELINE, EXAMPLE ONLY
/*
* Create a channel for input read files
*/
// If you want to use the channel below in a process, define the following:
// input:
// file dir from inputDirCh
//
ch_inputdir = params.inputdir ? Channel.fromPath(params.inputdir, checkIfExists: true) : Channel.empty()
// Create a channel for input read files
if(params.samplesheet){
if(params.single_end){
ch_read_files=Channel
.from(file("${params.samplesheet}"))
.splitCsv(header: false)
.map{ row -> [ row[0], [file(row[2])]] }
}else{
ch_read_files=Channel
.from(file("${params.samplesheet}"))
.splitCsv(header: false)
.map{ row -> [ row[0], [file(row[2]), file(row[3])]] }
}
params.reads=false
} else {
exit 1, "Expect a samplesheet and an input dir !"
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
params.custom_runName = params.name
if (!(workflow.runName ==~ /[a-z]+_[a-z]+/)) {
params.custom_runName = workflow.runName
}
// Stage config files
ch_multiqc_config = Channel.fromPath("${params.multiqc_config}", checkIfExists: true)
ch_output_docs = Channel.fromPath("$projectDir/docs/output.md", checkIfExists: true)
params.summary = [:]
if (workflow.revision) params.summary['Pipeline Release'] = workflow.revision
params.summary['Run Name'] = params.custom_runName ?: workflow.runName
// TODO nf-core: Report custom parameters here
params.summary['Input dir'] = params.inputdir
params.summary['Sample sheet'] = params.samplesheet
params.summary['Data Type'] = params.single_end ? 'Single-End' : 'Paired-End'
params.summary['Max Resources'] = "$params.max_memory memory, $params.max_cpus cpus, $params.max_time time per job"
if (workflow.containerEngine) params.summary['Container'] = "$workflow.containerEngine - $workflow.container"
params.summary['Output dir'] = params.outdir
params.summary['Launch dir'] = workflow.launchDir
params.summary['Working dir'] = workflow.workDir
params.summary['Script dir'] = workflow.projectDir
params.summary['User'] = workflow.userName
if (workflow.profile == 'awsbatch') {
params.summary['AWS Region'] = params.awsregion
params.summary['AWS Queue'] = params.awsqueue
}
params.summary['Config Profile'] = workflow.profile
if (params.email || params.email_on_fail) {
params.summary['E-mail Address'] = params.email
params.summary['E-mail on failure'] = params.email_on_fail
}
log.info "-\033[2m--------------------------------------------------\033[0m-"
log.info "-\033[2m----------------"+ workflow.manifest.name +" --\033[0m-"
log.info "-\033[2m--------------------------------------------------\033[0m-"
log.info params.summary.collect { k,v -> "${k.padRight(18)}: $v" }.join("\n")
log.info "-\033[2m--------------------------------------------------\033[0m-"
// -------------------------------------------------
// INCLUDES
// -------------------------------------------------
include { report } from '../subworklows/local/wf_report.nf'
workflow techno_qc {
report(ch_output_docs)
}
/*
* Completion e-mail notification
*/
workflow.onComplete {
// Set up the e-mail variables
def name_wf = workflow.manifest.name
def subject = "[$name_wf] Successful: $workflow.runName"
if (!workflow.success) {
subject = "[$name_wf] FAILED: $workflow.runName"
}
def email_fields = [:]
email_fields['version'] = workflow.manifest.version
email_fields['runName'] = params.custom_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'] = params.summary
println(workflow)
email_fields['summary']['Date Started'] = 11 // workflow.start
email_fields['summary']['Date Completed'] = 11 // workflow.complete
email_fields['summary']['Pipeline script file path'] = 'aaa' //workflow.scriptFile
email_fields['summary']['Pipeline script hash ID'] = 'aaa' //workflow.scriptId
if (workflow.repository) email_fields['summary']['Pipeline repository Git URL'] = workflow.repository
if (workflow.commitId) email_fields['summary']['Pipeline repository Git Commit'] = workflow.commitId
if (workflow.revision) email_fields['summary']['Pipeline Git branch/tag'] = workflow.revision
if (workflow.container) email_fields['summary']['Docker image'] = workflow.container
email_fields['summary']['Nextflow Version'] = workflow.nextflow.version
email_fields['summary']['Nextflow Build'] = workflow.nextflow.build
email_fields['summary']['Nextflow Compile Timestamp'] = workflow.nextflow.timestamp
// Check if we are only sending emails on failure
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("$baseDir/assets/email_template.txt")
def txt_template = engine.createTemplate(tf).make(email_fields)
def email_txt = txt_template.toString()
// Send the HTML e-mail
if (email_address) {
// Catch failures and try with plaintext
try {
def sending = [ 'echo', '-e' , email_txt ].execute() | [ 'mail', '-s', subject, email_address ].execute()
log.debug "[$name_wf] Sent summary e-mail to $email_address (mail)"
} catch (all) {
log.error "[$name_wf] ERROR ON EMAIL SENDING TO $email_address !!"
}
log.info "$email_txt"
}
// 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_tf = new File( output_d, "pipeline_report.txt" )
output_tf.withWriter { w -> w << email_txt }
c_green = params.monochrome_logs ? '' : "\033[0;32m";
c_purple = params.monochrome_logs ? '' : "\033[0;35m";
c_red = params.monochrome_logs ? '' : "\033[0;31m";
c_reset = params.monochrome_logs ? '' : "\033[0m";
if (workflow.stats.ignoredCount > 0 && workflow.success) {
log.info "-${c_purple}Warning, pipeline completed, but with errored process(es) ${c_reset}"
log.info "-${c_red}Number of ignored errored process(es) : ${workflow.stats.ignoredCount} ${c_reset}"
log.info "-${c_green}Number of successfully ran process(es) : ${workflow.stats.succeedCount} ${c_reset}"
}
if (workflow.success) {
log.info "-${c_purple}[${name_wf}]${c_green} Pipeline completed successfully${c_reset}"
} else {
log.info "-${c_purple}[${name_wf}]${c_red} Pipeline completed with errors${c_reset}"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment