-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
205 lines (158 loc) · 6.38 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
include { EXSCAN } from './workflows/exscan'
help_message = """
exscan.nf - An extended sequence scanner
========================================
Explore key elements in a sequence using HMM profile scanning.
Usage:
nextflow run exscan.nf --fasta <fasta> --hmmdb <hmm_db>
nextflow run exscan.nf -params-file <yaml>
Required Arguments:
--fasta <fasta> : Input fasta file
--hmmdb <hmmdb> : Profile HMM database file
Index files from hmmpress must also be located in the same directory
Alternative to Required Arguments:
-params-file <yaml> : YAML/JSON file with the parameters
Mutually exclusive with --fasta and --hmmdb
Optional Arguments:
--sequence_type <val> : Type of sequences in the input `--fasta` file.
Choices: {dna, protein} [defalut: ${params.sequence_type}]
--dom_ieval_filter <val> : Filter domain alignment by individual E-value [default: ${params.dom_ieval_filter}]
Retains alignments with individual E-values **equal or less** than this value
--min_alignment_len <val> : Minimum length for domain alignments [default: ${params.min_alignment_len}]
Retains alignments with length **equal or more** than this value
--grouping_distance <val> : Group query results within this many base pairs [default: ${params.grouping_distance}]
--gff_intersect <gff> : If provided, any feature in this GFF intersecting
with a domain alignment will be retained.
--keep_only_intersect : Retain only query results that intersect with features
of the provided GFF file.
--outdir <outdir> : Output directory [default: ${params.outdir}]
--help : Print help message and exit
--version : Print version and exit
"""
init_summary = """
E X S C A N P I P E L I N E v${params.manifest.version}
======================================
fasta : ${params.fasta}
hmmdb : ${params.hmmdb}
sequence_type : ${params.sequence_type}
dom_ieval_filter : ${params.dom_ieval_filter}
min_alignment_len : ${params.min_alignment_len}
grouping_distance : ${params.grouping_distance}
gff_intersect : ${params.gff_intersect}
keep_only_intersect : ${params.keep_only_intersect}
outdir : ${params.outdir}
--
Run as : ${workflow.commandLine}
Started at : ${workflow.start}
Config files : ${workflow.configFiles}
--
"""
// container images : ${workflow.containerEngine}:${workflow.container}
// DESC: Validate input arguments and initialize pipeline, printing a small summary
// ARGS: None, uses variables defined at the beginning of the script
// OUTS: `$init_summary` as log message at `INFO` level
// `$help_message` as stdout if `--help` flag is set
// `$version` as stdout if `--version` flag is set
// Proper error message and exit code if required arguments are missing
// RETS: None
def validateParams() {
// `--help` and `--version` flags
if (params.help) {
println help_message
System.exit(0)
}
if (params.version) {
println "${params.manifest.name} v${params.manifest.version}"
System.exit(0)
}
// Check required arguments
if (params.fasta == null) {
println help_message
log.error "Missing required argument: --fasta"
System.exit(1)
}
if (!file(params.fasta).exists()) {
log.error "File not found: ${params.fasta}"
System.exit(1)
}
if (params.hmmdb == null) {
println help_message
log.error "Missing required argument: --hmmdb"
System.exit(1)
}
if (!file(params.hmmdb).exists()) {
log.error "File not found: ${params.hmmdb}"
System.exit(1)
}
if (params.sequence_type != 'dna' && params.sequence_type != 'protein') {
log.error "Invalid fasta type: ${params.sequence_type}. Must be one of {dna, protein}"
System.exit(1)
}
}
// DESC: Handle hmmdb appropriately so it can be mounted correctly
// ARGS: None, uses variables defined at the beginning of the script
// OUTS: `$params.hmmdb_file` and `$params.hmmdb_dir` as new variables
// RETS: None
def handle_hmmdb() {
// hmmscan needs access to the files generated by hmmpress,
// but accepts the hmmdb file as input.
// When using docker for example, if we only mount the hmmdb file,
// hmmscan will not be able to find the index files.
// To solve this, we mount the directory containing the hmmdb file
// and pass the hmmdb file as input to hmmscan.
params.hmmdb_file = params.hmmdb.split('/').last()
params.hmmdb_dir = file(params.hmmdb).getParent()
}
// DESC: Display completion message based on workflow status
// ARGS: None, uses variables defined at the beginning of the script
// OUTS: Completion message at `INFO` or `ERROR` level
// RETS: None
def completionMsg() {
if (workflow.success) {
if (workflow.stats.ignoredCount == 0) {
log.info "Pipeline completed successfully!"
}
else {
log.info "Pipeline completed successully, but with errored processes"
}
}
else {
log.error "Pipeline completed with errors"
}
}
// Main workflow
workflow {
main:
// Validate input parameters
validateParams()
// Handle hmm database paths
handle_hmmdb()
// Initialization Summary - Everything looks good so far
log.info init_summary
ch_versions = Channel.empty()
// WORKFLOW: After validation, main workflow is launched here
EXSCAN(
params.dom_ieval_filter,
params.fasta,
params.sequence_type,
params.gff_intersect,
params.grouping_distance,
params.hmmdb_dir,
params.hmmdb_file,
params.keep_only_intersect,
params.min_alignment_len,
ch_versions,
)
ch_versions = ch_versions.mix(EXSCAN.out.versions)
// Save versions of all tools used in the pipeline
ch_versions.collectFile(
storeDir: "${params.outdir}/pipeline_info/",
name: 'versions.yml',
sort: true,
newLine: true
)
// Display any error encountered during the workflow
workflow.onComplete {
completionMsg()
}
}