diff --git a/CSP2.nf b/CSP2.nf index 8a410bf..9ead7a5 100755 --- a/CSP2.nf +++ b/CSP2.nf @@ -122,196 +122,218 @@ if (help1 == "help") { // Assess run mode if (params.runmode == "") { error "--runmode must be specified..." -} else if (!['align','assemble', 'screen', 'snp'].contains(params.runmode)){ +} else if (!['align','assemble', 'screen', 'snp','conda_init'].contains(params.runmode)){ error "--runmode must be 'align','assemble', 'screen', or 'snp', not ${params.runmode}..." } -// Ensure necessary data is provided given the run mode +// If runmode is conda_init, launch a local process to spurn the generation of the conda environment and exit +if (params.runmode != "conda_init") { + + // Ensure necessary data is provided given the run mode + // Runmode 'assemble' + // - Requires: --reads/--ref_reads + // - Runs SKESA and summarzies output FASTA + if (params.runmode == "assemble"){ + if((params.reads == "") && (params.ref_reads == "")){ + error "Runmode is --assemble but no read data provided via --reads/--ref_reads" + } + } -// Runmode 'assemble' -// - Requires: --reads/--ref_reads -// - Runs SKESA and summarzies output FASTA -if (params.runmode == "assemble"){ - if((params.reads == "") && (params.ref_reads == "")){ - error "Runmode is --assemble but no read data provided via --reads/--ref_reads" - } -} + // Runmode 'align' + // - Requires: --reads/--fasta/--snpdiffs + // - Optional: --ref_reads/--ref_fasta/--ref_id + // - Runs MUMmer, generates .snpdiffs, and alignment summary. + // - If references are provided via --ref_reads/--ref_fasta/--ref_id, non-reference samples are aligned to each reference + // - If no references are provided, alignments are all-vs-all + // - If --snpdiffs are provided, their FASTAs will be autodetected and, if present, used as queries or references as specified by --ref_reads/--ref_fasta/--ref_id + // - Does NOT perform QC filtering + + else if (params.runmode == "align"){ + if((params.fasta == "") && (params.reads == "") && (params.snpdiffs == "")){ + error "Runmode is --align but no query data provided via --fasta/--reads/--snpdiffs" + } + } -// Runmode 'align' -// - Requires: --reads/--fasta/--snpdiffs -// - Optional: --ref_reads/--ref_fasta/--ref_id -// - Runs MUMmer, generates .snpdiffs, and alignment summary. -// - If references are provided via --ref_reads/--ref_fasta/--ref_id, non-reference samples are aligned to each reference -// - If no references are provided, alignments are all-vs-all -// - If --snpdiffs are provided, their FASTAs will be autodetected and, if present, used as queries or references as specified by --ref_reads/--ref_fasta/--ref_id -// - Does NOT perform QC filtering - -else if (params.runmode == "align"){ - if((params.fasta == "") && (params.reads == "") && (params.snpdiffs == "")){ - error "Runmode is --align but no query data provided via --fasta/--reads/--snpdiffs" + // Runmode 'screen' + // - Requires: --reads/--fasta/--snpdiffs + // - Optional: --ref_reads/--ref_fasta/--ref_id + // - Generates .snpdiffs files (if needed), applies QC, and generates alignment summaries and SNP distance estimates + // - If references are provided via --ref_reads/--ref_fasta/--ref_id, non-reference samples are aligned to each reference + // - If no references are provided, alignments are all-vs-all + // - If --snpdiffs are provided, (1) they will be QC filtered and included in the output report and (2) their FASTAs will be autodetected and, if present, used as queries or references as specified by --ref_reads/--ref_fasta/--ref_id + + else if (params.runmode == "screen"){ + if((params.fasta == "") && (params.reads == "") && (params.snpdiffs == "")){ + error "Runmode is --screen but no query data provided via --snpdiffs/--reads/--fasta" + } + } + + // Runmode 'snp' + // - Requires: --reads/--fasta/--snpdiffs + // - Optional: --ref_reads/--ref_fasta/--ref_id + // - If references are not provided, runs RefChooser using all FASTAs to choose references (--n_ref sets how many references to choose) + // - Each query is aligned to each reference, and pairwise SNP distances for all queries are generated based on that reference + // - Generates .snpdiffs files (if needed), applies QC, and generates SNP distance data between all queries based on their alignment to each reference + else if (params.runmode == "snp"){ + if((params.snpdiffs == "") && (params.fasta == "") && (params.reads == "")) { + error "Runmode is --snp but no query data provided via --snpdiffs/--reads/--fasta" + } } -} -// Runmode 'screen' -// - Requires: --reads/--fasta/--snpdiffs -// - Optional: --ref_reads/--ref_fasta/--ref_id -// - Generates .snpdiffs files (if needed), applies QC, and generates alignment summaries and SNP distance estimates -// - If references are provided via --ref_reads/--ref_fasta/--ref_id, non-reference samples are aligned to each reference -// - If no references are provided, alignments are all-vs-all -// - If --snpdiffs are provided, (1) they will be QC filtered and included in the output report and (2) their FASTAs will be autodetected and, if present, used as queries or references as specified by --ref_reads/--ref_fasta/--ref_id - -else if (params.runmode == "screen"){ - if((params.fasta == "") && (params.reads == "") && (params.snpdiffs == "")){ - error "Runmode is --screen but no query data provided via --snpdiffs/--reads/--fasta" + // Set directory structure + if (params.outroot == "") { + output_directory = file(params.out) + } else { + out_root = file(params.outroot) + output_directory = file("${out_root}/${params.out}") } -} -// Runmode 'snp' -// - Requires: --reads/--fasta/--snpdiffs -// - Optional: --ref_reads/--ref_fasta/--ref_id -// - If references are not provided, runs RefChooser using all FASTAs to choose references (--n_ref sets how many references to choose) -// - Each query is aligned to each reference, and pairwise SNP distances for all queries are generated based on that reference -// - Generates .snpdiffs files (if needed), applies QC, and generates SNP distance data between all queries based on their alignment to each reference -else if (params.runmode == "snp"){ - if((params.snpdiffs == "") && (params.fasta == "") && (params.reads == "")) { - error "Runmode is --snp but no query data provided via --snpdiffs/--reads/--fasta" + // If the output directory exists, create a new subdirectory with the default output name ("CSP2_