forked from connor-lab/ncov2019-artic-nf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
144 lines (129 loc) · 5.03 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
// include modules
// ===============================
include { printHelp } from './modules/help.nf'
// import main workflow
// ===============================
include { articNcovNanopore } from './workflows/articNcovNanopore.nf'
// Help
// ===============================
if ( params.help ) {
printHelp()
exit 0
}
// Previous param warnings/exit
def previousParams = [
'medakaModel',
'schemeRepoURL',
'schemeVersion',
'minReadsPerBarcode',
'minReadsGuppyPlex',
'correctN',
'sequencingTechnology',
'csqAfThreshold',
'csqDpThreshold',
]
def overlap = previousParams.intersect(params.keySet())
if ( overlap != [] ) {
log.error("ERROR: Previous params: '$overlap' were given. Please resubmit with the new parameters that can be found when running the help command")
System.exit(1)
}
// Simple profile warning
// ===============================
if ( params.profile ) {
log.error("ERROR: Profile should have a single dash: -profile")
System.exit(1)
}
// Pipeline required input checks
// ===============================
// Nanopolish
if ( params.nanopolish ) {
if (! params.basecalled_fastq ) {
log.error("ERROR: Please supply a directory containing basecalled fastqs with --basecalled_fastq. This is the output directory from guppy_barcoder or guppy_basecaller - usually fastq_pass. This can optionally contain barcodeXX directories, which are auto-detected.")
System.exit(1)
} else if (! params.fast5_pass ) {
log.error("ERROR: Please supply a directory containing fast5 files with --fast5_pass (this is the fast5_pass directory)")
System.exit(1)
} else if (! params.sequencing_summary ) {
log.error("ERROR: Please supply the path to the sequencing_summary.txt file from your run with --sequencing_summary")
System.exit(1)
}
// Medaka
} else if ( params.medaka ) {
if (! params.basecalled_fastq ) {
log.error("ERROR: Please supply a directory containing basecalled fastqs with --basecalled_fastq. This is the output directory from guppy_barcoder or guppy_basecaller - usually fastq_pass. This can optionally contain barcodeXX directories, which are auto-detected.")
System.exit(1)
} else if (! params.medaka_model ) {
log.error("ERROR: Please supply a medaka model with `--medaka_model MODEL` to run the medaka pipeline")
System.exit(1)
}
} else {
log.error("ERROR: Please select a workflow with --nanopolish or --medaka, or use --help to print help")
System.exit(1)
}
// Prefix existance and formatting check
if ( ! params.prefix ) {
log.error("ERROR: Please supply a prefix for your output files with --prefix")
log.error("ERROR: For more information use --help to print help statement")
System.exit(1)
} else {
if ( params.prefix =~ /\// ){
log.error("The --prefix that you supplied contains a \"/\", please replace it with another character")
System.exit(1)
}
}
// Main Workflow
// ===============================
workflow {
// ===============================
// Input barcodes and fastqs check
// ===============================
nanoporeBarcodeDirs = file("${params.basecalled_fastq}/barcode*", type: 'dir', maxdepth: 1 )
nanoporeFastqs = file("${params.basecalled_fastq}/*.fastq*", type: 'file', maxdepth: 1)
// If barcodes, check number of reads and then go to pass/filtered branches
if ( nanoporeBarcodeDirs ) {
Channel.fromPath( nanoporeBarcodeDirs )
.filter( ~/.*barcode[0-9]{1,4}$/ )
.map{ dir ->
def count = 0
for ( x in dir.listFiles() ) {
if ( x.isFile() ) {
count += x.countFastq()
}
}
return [ dir.baseName, file(dir), count ]
}.set{ ch_initial_fastq_dirs }
// No barcodes, check number of reads in single file and then go to pass/filtered branches
} else if ( nanoporeFastqs ) {
Channel.fromPath( nanoporeFastqs )
.map{ in_f ->
def count = 0
if (in_f.isFile()) {
count = in_f.countFastq()
}
return [ in_f.baseName.replaceAll(~/\.fastq.*$/, ''), file(in_f), count ]
}.set{ ch_initial_fastq_dirs }
} else {
log.error("ERROR: Couldn't detect whether your Nanopore run was barcoded or not. Use --basecalled_fastq to point to either the guppy output directory or a directory of flat fastq files.")
System.exit(1)
}
// Final input pathes and filtering
ch_initial_fastq_dirs
.branch{ it ->
pass: it[2] > params.min_reads_per_barcode
return [ it[0], it[1] ]
filtered: it[2] <= params.min_reads_per_barcode
return [ it[0], it[1] ]
}
.set{ ch_fastqs }
// Execute Main Named process
main:
articNcovNanopore(
ch_fastqs.pass,
ch_fastqs.filtered
)
}
// :)