-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nf
More file actions
146 lines (117 loc) · 6.02 KB
/
main.nf
File metadata and controls
146 lines (117 loc) · 6.02 KB
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
#!/usr/bin/env nextflow
// Copyright 2021 Edinburgh Genome Foundry, University of Edinburgh
//
// This file is part of Sequeduct.
//
// Sequeduct is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// Sequeduct is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Sequeduct. If not, see <https:www.gnu.org/licenses/>.
nextflow.enable.dsl=2
include { demultiplex_workflow } from "$projectDir/nextflow/sequeduct_demultiplex.nf"
include { singleplex_workflow } from "$projectDir/nextflow/sequeduct_demultiplex.nf"
include { combine_samplesheets } from "$projectDir/nextflow/sequeduct_demultiplex.nf"
include { preview_workflow } from "$projectDir/nextflow/sequeduct_preview.nf"
include { analysis_workflow } from "$projectDir/nextflow/sequeduct_analysis.nf"
include { review_denovo } from "$projectDir/nextflow/sequeduct_review.nf"
include { assemble_denovo } from "$projectDir/nextflow/sequeduct_assembly.nf"
///////////////////////////////////////////////////////////////////////////////
workflow demultiplex {
Channel
.fromPath(params.sample_sheet)
.splitCsv(header: true)
.map { row ->
def barcode_dir = row['Barcode_dir'] // a barcode is present only once
def barcode_path = file("${params.fastq_dir}/${barcode_dir}")
def fastq_files = barcode_path.listFiles() // multiple FASTQ in each barcode
def sample = row['Sample'] // entry may contain multiple samples
// def entry = "${barcode_dir}_${sample}" // unique key for each sample sheet entry
def genbank_paths = sample.tokenize(';') // separator character
for (int i = 0; i < genbank_paths.size(); i++) {
genbank_path = genbank_paths[i]
genbank_paths[i] = file("${params.reference_dir}/${genbank_path}.gb")
}
return [barcode_dir, barcode_path, fastq_files, sample, genbank_paths]
}
.branch {
multi_genbank: it[4].size() > 1
single_genbank: it[4].size() <= 1
}
.set { plex_branches_ch }
singleplex_workflow(plex_branches_ch.single_genbank)
demultiplex_workflow(plex_branches_ch.multi_genbank)
combine_samplesheets(singleplex_workflow.out, demultiplex_workflow.out)
}
///////////////////////////////////////////////////////////////////////////////
workflow preview {
Channel
.fromPath(params.sample_sheet)
.splitCsv(header: true)
.unique { row -> row['Barcode_dir'] }
.map { row ->
def barcode_out = row['Barcode_dir'] + '_plots'
def barcode_dir = row['Barcode_dir'] // a barcode is present only once -- no pooling
def barcode_path = file("${params.fastq_dir}/${barcode_dir}")
def fastq_files = barcode_path.listFiles() // multiple FASTQ in each barcode
return [barcode_out, barcode_path, fastq_files]
}
.set { input_ch }
preview_workflow(input_ch)
}
///////////////////////////////////////////////////////////////////////////////
workflow analysis {
Channel
.fromPath(params.sample_sheet)
.splitCsv(header: true)
.map { row ->
def barcode_dir = row['Barcode_dir'] // a barcode is present only once -- no pooling
def sample = row['Sample'] // a sample may be present multiple times, in different barcodes
def entry = "${barcode_dir}_${sample}" // unique key for each sample sheet entry
def genbank_path = file("${params.reference_dir}/${sample}.gb")
def barcode_path = file("${params.fastq_dir}/${barcode_dir}")
def fastq_files = barcode_path.listFiles() // multiple FASTQ in each barcode
return [entry, barcode_dir, barcode_path, fastq_files, sample, genbank_path]
}
.set { entries_ch }
Channel
.fromPath(params.sample_sheet)
.splitCsv(header: true)
.unique { row -> row['Sample'] }
.map { row -> file(params.reference_dir + '/' + row['Sample'] + '.gb') }
.set { genbank_ch }
analysis_workflow(entries_ch, genbank_ch)
}
///////////////////////////////////////////////////////////////////////////////
workflow review {
Channel
.fromPath(params.results_csv)
.splitCsv(header: true)
.filter { item -> item[params.denovo_columname] == params.denovo_true}
.map { row ->
def barcode = row['Barcode'] // a barcode is present only once -- no pooling
def sample = row['Sample'] // a sample may be present multiple times, in different barcodes
def entry = "${barcode}_${sample}" // unique key for each sample sheet entry
def result = row["Result"]
def genbank_path = file("${params.reference_dir}/${sample}.gb")
def fastq_path = file("${params.fastq_filtered_dir}/${barcode}.fastq")
return [entry, barcode, sample, result, genbank_path, fastq_path]
}
.set { entries_de_novo_ch }
review_denovo(entries_de_novo_ch)
}
///////////////////////////////////////////////////////////////////////////////
workflow assembly {
Channel
.fromPath(params.assembly_sheet)
.splitCsv(header: true)
.map { row ->
def barcode = row['Barcode_dir'] // a barcode is present only once -- no pooling
def length = row['Length'] // estimated length in kbp for canu genomeSize parameter
def barcode_path = file("${params.fastq_dir}/${barcode}")
def fastq_files = barcode_path.listFiles()
return [barcode, barcode_path, fastq_files, length]
}
.set { entries_assembly_ch }
assemble_denovo(entries_assembly_ch)
}