forked from jts/ncov2019-artic-nf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
118 lines (102 loc) · 4.37 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
#!/usr/bin/env nextflow
// enable dsl2
nextflow.enable.dsl = 2
// include modules
include {printHelp} from './modules/help.nf'
include {makeFastqSearchPath} from './modules/util.nf'
// import subworkflows
include {articNcovNanopore} from './workflows/articNcovNanopore.nf'
include {ncovIllumina} from './workflows/illuminaNcov.nf'
include {ncovIlluminaCram} from './workflows/illuminaNcov.nf'
if (params.help){
printHelp()
exit 0
}
if (params.profile) {
error "ERROR: Profile should have a single dash: -profile"
}
if ( params.illumina ) {
if ( !params.directory ) {
error "ERROR: Please supply a directory containing fastqs or CRAMs with --directory. Specify --cram if supplying a CRAMs directory. Use --help to print help"
}
} else if ( params.nanopolish ) {
if (! params.basecalled_fastq ) {
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."
}
if (! params.fast5_pass ) {
error "ERROR: Please supply a directory containing fast5 files with --fast5_pass (this is the fast5_pass directory)"
}
if (! params.sequencing_summary ) {
error "ERROR: Please supply the path to the sequencing_summary.txt file from your run with --sequencing_summary"
}
} else if ( params.medaka ) {
if (! params.basecalled_fastq ) {
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."
}
if (!params.medaka_model) {
error "ERROR: No medaka model provided with --medaka_model"
}
} else {
error "ERROR: Please select a workflow with --nanopolish, --illumina or --medaka, or use --help to print help"
}
if ( ! params.prefix ) {
error "ERROR: Please supply a prefix for your output files with --prefix. Use --help to print help"
} else {
if ( params.prefix =~ /\// ){
error "ERROR: The --prefix that you supplied contains a \"/\", please replace it with another character"
}
}
// main workflow
workflow {
if ( params.illumina ) {
if (params.cram) {
Channel.fromPath( "${params.directory}/**.cram" )
.map { file -> tuple(file.baseName, file) }
.set{ ch_cramFiles }
}
else {
fastqSearchPath = makeFastqSearchPath( params.illuminaPrefixes, params.illuminaSuffixes, params.fastq_exts )
Channel.fromFilePairs( fastqSearchPath, flat: true)
.filter{ !( it[0] =~ /Undetermined/ ) }
.set{ ch_filePairs }
}
}
else {
// Check to see if we have barcodes
nanoporeBarcodeDirs = file("${params.basecalled_fastq}/barcode*", type: 'dir', maxdepth: 1 )
nanoporeNoBarcode = file("${params.basecalled_fastq}/*.fastq", type: 'file', maxdepth: 1)
if( nanoporeBarcodeDirs ) {
// Yes, barcodes!
Channel.fromPath( nanoporeBarcodeDirs )
.filter( ~/.*barcode[0-9]{1,4}$/ )
.filter{ d ->
def count = 0
for (x in d.listFiles()) {
if (x.isFile()) {
count += x.countFastq()
}
}
count > params.minReadsPerBarcode
}.set{ ch_fastqDirs }
} else if ( nanoporeNoBarcode ){
// No, no barcodes
Channel.fromPath( "${params.basecalled_fastq}", type: 'dir', maxDepth: 1 )
.set{ ch_fastqDirs }
} else {
error "ERROR: Couldn't detect whether your Nanopore run was barcoded or not. Use --basecalled_fastq to point to the unmodified guppy output directory."
}
}
main:
if ( params.nanopolish || params.medaka ) {
articNcovNanopore(ch_fastqDirs)
} else if ( params.illumina ) {
if ( params.cram ) {
ncovIlluminaCram(ch_cramFiles)
}
else {
ncovIllumina(ch_filePairs)
}
} else {
error "ERROR: Please select a workflow with --nanopolish, --illumina or --medaka"
}
}