-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nf
More file actions
151 lines (136 loc) · 5.37 KB
/
main.nf
File metadata and controls
151 lines (136 loc) · 5.37 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
147
148
149
150
151
/*
* Module imports
*/
include { DADA2 } from './modules/dada2'
include { EXPORT } from './modules/export'
include { CUTADAPT } from './modules/cutadapt'
include { QSCORE } from './modules/qscore'
include { MERGE } from './modules/merge'
include { PICRUST2 } from './modules/picrust2'
include { CLASSIFY_SKLEARN } from './modules/classify_sklearn'
include { BETADIVERSITY } from './modules/betadiv.nf'
include { ALPHADIVERSITY } from './modules/alphadiv.nf'
include { VSEARCH_CLUSTER_DENOVO } from './modules/vsearch_cluster_de-novo.nf'
include { PCOA } from './modules/pcoa'
include { CLASSIFY_CONSENSUS_BLAST } from './modules/classify-consensus-blast.nf'
include { CLASSIFY_CONSENSUS_VSEARCH } from './modules/classify-consensus-vsearch.nf'
include { MAFFT } from './modules/mafft.nf'
include { RAXML_RAPID_BOOTSTRAP; RAXML } from './modules/raxml.nf'
include { IQTREE_ULTRAFAST_BOOTSTRAP; IQTREE } from './modules/iqtree.nf'
include { FASTTREE } from './modules/fasttree.nf'
include { MIDPOINTROOT } from './modules/midpoint-root.nf'
// Nextflow highlights
// Hi-lock: (("}" (0 'org-todo prepend)))
// Hi-lock: (("{" (0 'org-todo prepend)))
// Hi-lock: ((")" (0 'log-edit-header prepend)))
// Hi-lock: (("(" (0 'log-edit-header prepend)))
// Hi-lock: (("[Rr]eplaceAll" (0 'transient-amaranth prepend)))
// Hi-lock: (("[Bb]aseName" (0 'transient-amaranth prepend)))
// Hi-lock: (("[Bb]ranchCriteria" (0 'all-the-icons-cyan-alt prepend)))
// Hi-lock: (("[Tt]ap" (0 'all-the-icons-cyan-alt prepend)))
// Hi-lock: (("[Bb]ranch" (0 'all-the-icons-cyan-alt prepend)))
// Hi-lock: (("[Ss]et" (0 'transient-pink prepend)))
// Hi-lock: (("[Ff]latten" (0 'all-the-icons-cyan-alt prepend)))
// Hi-lock: (("[Mm]ap" (0 'all-the-icons-cyan-alt prepend)))
// Hi-lock: (("[Cc]ollect" (0 'all-the-icons-cyan-alt prepend)))
// Hi-lock: (("[Ff]ilter" (0 'all-the-icons-cyan-alt prepend)))
/*
* Main workflow
*/
def separate_merge = branchCriteria {
merged: it[0] =~ /Merged/
extra: it[0] =~ /$params.ignore/
the_rest: !(it[0] =~ /Merged/)
}
iqtree_ch = Channel.empty()
raxml_ch = Channel.empty()
fasttree_ch = Channel.empty()
def get_channel(path) {
return Channel
.fromPath(path)
.map{ it -> [ it.baseName.replaceAll(/-.*/, ''), it ] }
}
Channel.fromPath('samples.tsv')
.splitCsv(header: true, sep: "\t" )
.map { it -> [ it.Name, it.Type, it.Trimto, it.Path ] }
.set { samples_ch }
workflow clean_cluster {
// Clean and merge fastq
CUTADAPT(samples_ch, params.outdirClean)
.set { trimmed_ch }
QSCORE(trimmed_ch, params.outdirClean)
.set { quality_ch }
DADA2(quality_ch.seqs, params.outdirClean)
.set { dd_ch }
dd_ch.table.flatten().filter{ !(it =~ /$params.ignore/) }.filter( ~/.*qza/ ).collect().map { it -> ['Merged', it ]}
.set { mfreqs }
dd_ch.seqs.flatten().filter{ !(it =~ /$params.ignore/) }.filter( ~/.*qza/ ).collect().map { it -> ['Merged', it ]}
.set { mseqs }
MERGE(mfreqs, mseqs, params.outdirClean)
.set { merged_ch }
VSEARCH_CLUSTER_DENOVO(dd_ch.table.mix(merged_ch.table), dd_ch.seqs.mix(merged_ch.seqs),params.outdirOTU, "0.99")
.set { otu_ch }
EXPORT(otu_ch.freqs, otu_ch.seqs, params.outdirOTUExport)
}
workflow phylogeny {
get_channel("$params.outdirOTU/${params.target}*Seqs*")
.tap { all_seq_ch }
.branch(separate_merge)
.set { seq_ch }
if ( params.blast ) {
CLASSIFY_CONSENSUS_BLAST(seq_ch.the_rest.mix(seq_ch.extra),
params.blast_args, params.refSeqs, params.refIDs,
params.outdirClassified)
}
if ( params.vsearch ) {
CLASSIFY_CONSENSUS_VSEARCH(seq_ch.the_rest.mix(seq_ch.extra),
params.vsearch_args, params.refSeqs, params.refIDs,
params.outdirClassified)
}
if ( params.sklearn ){
CLASSIFY_SKLEARN(seq_ch.the_rest.mix(seq_ch.extra),
params.classifier,
params.outdirClassified
)
}
// Construct phylogeny
MAFFT(all_seq_ch, params.outdirAligned)
.set { aligned_ch }
if ( params.fasttree ) {
FASTTREE(aligned_ch, params.outdirTrees)
.tap { fasttree_ch }
}
if ( params.raxml ) {
RAXML(aligned_ch, params.outdirTrees, 'GTRGAMMA')
.tap { raxml_ch }
}
if ( params.iqtree ) {
IQTREE(aligned_ch, params.outdirTrees)
.tap { iqtree_ch }
}
MIDPOINTROOT(iqtree_ch.mix(raxml_ch).mix(fasttree_ch),
params.outdirRooted)
}
workflow diversity {
tree_ch = Channel.empty()
get_channel("$params.outdirRooted/*")
.map { it -> [ it[0], (it =~ /.*-(.*)_.*/)[0][1], it[1] ]}
// Extract the tree builder automatically
.tap { all_ch }.branch(separate_merge)
.set { tree_ch }
// Compute diversity
BETADIVERSITY(tree_ch.merged.mix(tree_ch.extra), params.beta, params.outdirOTU, params.outdirDiversity)
.transpose()
.set { distance_matrices }
ALPHADIVERSITY(tree_ch.the_rest.mix(tree_ch.extra),
params.alpha, params.outdirOTU, params.outdirDiversity)
// Analyze diversity
PCOA(distance_matrices, params.pcoa_dimensions,
params.outdirAnalysis)
}
workflow function_annotation {
get_channel("$params.outdirOTUExport/*biom")
.join(get_channel("$params.outdirOTUExport/*fasta"))
.set { freqs_seqs_ch }
PICRUST2(freqs_seqs_ch, params.outdirFunctions)
}