-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
144 lines (118 loc) · 3.84 KB
/
main.nf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env nextflow
// enable dsl2
nextflow.enable.dsl=2
// import modules
include {printHelp} from './modules/help.nf'
include {captureEnv} from './modules/captureEnv.nf'
include {prepRef} from './workflows/prepref.nf'
include {preprocessing} from './workflows/preprocessing.nf'
include {phylo} from './workflows/snp_analysis.nf'
/*
ANSI escape codes to allow colour-coded output messages
This code is from https://github.com/angelovangel
*/
ANSI_GREEN = "\033[1;32m"
ANSI_RED = "\033[1;31m"
ANSI_RESET = "\033[0m"
params.help = ""
if (params.help) {
printHelp()
exit(0)
}
// check mandatory parameters
if ( params.input_dir == null ) {
exit 1, "error: please provide an --input_dir argument. Use --help for an explenation for the parameters."
}
if ( params.output_dir == null ) {
exit 1, "error: please provide an --output_dir argument. Use --help for an explenation for the parameters."
}
if ( params.ref == null ) {
exit 1, "error: please provide a --ref argument. Use --help for an explenation for the parameters."
}
if ( params.pattern == null ) {
exit 1, "error: please provide a --pattern argument. Use --help for an explenation for the parameters."
}
// initialise default parameters
if ( params.yaml == null ) {
yaml = "false"
}
else {
yaml = params.yaml
}
if ( params.read_n_threshold == null ) {
read_n_threshold = 1000000
}
else {
read_n_threshold = params.read_n_threshold
}
if ( params.database == null ) {
database = "/false/"
}
else {
database = params.database
}
if ( params.mincov == null ) {
mincov = 0.8
}
else {
mincov = params.mincov
}
log.info """
===================================================================================================
P A R A P I P E
Parameters used:
---------------------------------------------------------------------------------------------------
--input_dir ${params.input_dir}
--output_dir ${params.output_dir}
--ref ${params.ref}
--pattern ${params.pattern}
--read_n_threshold ${read_n_threshold}
--yaml ${yaml}
--database ${database}
--mincov ${mincov}
Runtime data:
---------------------------------------------------------------------------------------------------
Profile ${workflow.profile}
User ${workflow.userName}
Launch dir ${workflow.launchDir}
"""
.stripIndent()
// main pipeline workflow
workflow {
pattern = params.pattern
reads = params.input_dir + pattern
numfiles = file(reads) // count the number of files
Channel.fromFilePairs(reads, flat: true, checkIfExists: true, size: -1)
.ifEmpty { error "cannot find any files matching ${pattern} in ${params.input_dir}" }
.set{ input_files }
main:
captureEnv(params.input_dir, params.output_dir, params.ref, yaml, database, params.read_n_threshold)
/*******************************
* PREPREF WORKFLOW START *
********************************/
prepRef(params.ref)
/*******************************
* PREPROCESSING WORKFLOW START *
********************************/
preprocessing(input_files, prepRef.out.ref_bt2index, read_n_threshold)
/*******************************
* SNP WORKFLOW START *
********************************/
phylo(input_files, captureEnv.out.env_json, database, preprocessing.out.bam_pre, prepRef.out.refdata, params.ref, preprocessing.out.multiQC_report, yaml, mincov)
}
workflow.onComplete {
if ( workflow.success ) {
log.info """
============================================
${ANSI_GREEN}PARAPIPE completed successfully
"""
.stripIndent()
}
else {
log.info """
===========================================
${ANSI_RED}Finished with errors${ANSI_RESET}
"""
.stripIndent()
}
}