-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.nf
294 lines (252 loc) · 11.3 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env nextflow
/*
========================================================================================
nf-core/DGE
========================================================================================
nf-core/DGE Analysis Pipeline.
#### Homepage / Documentation
https://github.com/nf-core/DGE
----------------------------------------------------------------------------------------
*/
def helpMessage() {
log.info """
=======================================================
,--./,-.
___ __ __ __ ___ /,-._.--~\'
|\\ | |__ __ / ` / \\ |__) |__ } {
| \\| | \\__, \\__/ | \\ |___ \\`-._,-`-,
`._,._,\'
nf-core/DGE v${workflow.manifest.version}
=======================================================
Usage:
The typical command for running the pipeline is as follows:
nextflow_dge --inputdir results_rnaseq --metadata metadata.txt --outdir results_DGE
Mandatory arguments:
--inputdir Path to nextflow_rnaseq results folder [results]
--metadata Path to metadata. This should be a txt file where the first column are the sample IDs,
and the other (1 or more) columns displays the conditions for each sample. The samples
must match those in the featureCounts matrix data located in inputdir [metadata.txt]
Options - kallisto mode:
--kallisto Run DESeq2 on kallisto abundance files instead of on featureCounts matrix. Requires specifying the assembly [null]
--assembly Required when in kallisto mode, should be the same assembly used when running kallisto. Possible values are hg19, hg38, or mm10 [null]
Options - deseq2 model:
--design Specifies DESeq2 design. If defined, --condition, --treatment and --control must also be defined [null]
--condition Specifies 'condition' for the DESeq2 contrast. Requires --design to be specified [null]
--treatment Specifies 'treatment' for the DESeq2 contrast. Requires --design to be specified [null]
--control Specifies 'control' for the DESeq2 contrast. Requires --design to be specified [null]
--rlog Apply a 'regularized log' transformation instead of the default 'vst' [null]
--skipShrink Do not apply LFC shrinkage [null]
Options - gsea:
--skip_gsea Skip GSEA step, otherwise it will run GSEA on each result file [false]
--gmx File with gene sets in GMX format. If not specified, it will use the hallmark gene sets from MSigDB (HUGO names). Ignored if --gmx_ensembl is present [null]
--gmx_ensembl Use the human hallmark gene sets with Ensembl IDs. If specified, the --gmx argument will be ignored [null]
--min_set NUM Ignore gene sets that contain less than NUM genes [15]"
--max_set NUM Ignore gene sets that contain more than NUM genes [500]"
--perm NUM Number of permutations [1000]"
Options - other:
--outdir The output directory where the results will be saved [results_DGE]
--pval Pval threshold to display gene labels in the volcano plot [1e-50]
--fc FC threshold to display gene labels in the volcano plot [3]
""".stripIndent()
}
// Show help message
params.help = false
if (params.help){
helpMessage()
exit 0
}
// Configurable variables and validate inputs
params.inputdir="results"
params.metadata="metadata.txt"
params.outdir = "results_DGE"
params.kallisto = false
params.assembly = false
params.design = false
params.condition = false
params.treatment = false
params.control = false
params.rlog = false
params.skipShrink = false
params.skip_gsea = false
params.perm = 1000
params.min_set = 15
params.max_set = 500
params.pval = 1e-50
params.fc = 3
if( !params.inputdir ){
exit 1, "No inputdir specified! Specify path with --inputdir."
}
inputdir = file(params.inputdir)
if( !inputdir.exists() ) exit 1, "Inputdir folder not found: ${params.inputdir}. Specify path with --inputdir."
if( !params.metadata ){
exit 1, "No metadata specified!"
}
metadata = file(params.metadata)
if( !metadata.exists() ) exit 1, "Metadata file not found: ${params.metadata}. Specify path with --metadata."
if ((params.design) && (!params.condition || !params.treatment || !params.control)){
exit 1, "Invalid arguments: --design \'${params.design}\' requires --condition, --treatment and --control. Please specify all of them or run the pipeline without specifying any design"
}
if ((params.condition) && (!params.design || !params.treatment || !params.control)){
exit 1, "Invalid arguments: --condition \'${params.condition}\' requires --design, --treatment and --control. Please specify all of them or run the pipeline without specifying any design"
}
if ((params.treatment) && (!params.design || !params.condition || !params.control)){
exit 1, "Invalid arguments: --treatment \'${params.treatment}\' requires --design, --condition and --control. Please specify all of them or run the pipeline without specifying any design"
}
if ((params.control) && (!params.design || !params.treatment || !params.condition)){
exit 1, "Invalid arguments: --control \'${params.control}\' requires --design, --condition and --treatment. Please specify all of them or run the pipeline without specifying any design"
}
if (params.kallisto && !params.assembly){
exit 1, "Running the pipeline in kallisto mode requires specifying an assembly. Valid options: 'hg19', 'hg38', 'mm10'"
}
if (params.kallisto && (params.assembly!= 'hg19' && params.assembly != 'hg38' && params.assembly != 'mm10')){
exit 1, "Invalid assembly option: ${params.assembly}. Valid options: 'hg19', 'hg38', 'mm10'"
}
if(params.kallisto && params.assembly){
params.tx2gene = params.assembly ? params.genomes[ params.assembly ].tx2gene ?: false : false
tx2gene = file(params.tx2gene)
if( !tx2gene.exists() ) exit 1, "tx2gene file not found: ${params.tx2gene}"
}else{
tx2gene='-'
}
if(!params.skip_gsea){
if (params.assembly && params.assembly != 'hg19' && params.assembly != 'hg38'){
if (!params.gmx){
exit 1, "GSEA can only be run, with default hallmarks gene set, on human (assembly hg19 or hg38). You are indicating that your assembly is ${params.assembly}. Please correct the assembly if this was a mistake, or use --skip_gsea to skip the GSEA step, or add a --gmx gene set file for your species"
}
}else{
if (params.gmx_ensembl){
gmx = file(params.gmxensembl)
}else{
gmx = file(params.gmx)
}
if( !gmx.exists() ) exit 1, "GMX file not found: ${params.gmx}"
}
}else{
gmx='-'
}
// Header
println "========================================================"
println " ,--./,-. "
println " ___ __ __ __ ___ /,-._.--~\' "
println " |\\ | |__ __ / `/ \\ |__)|__ } { "
println " | \\| | \\__ \\__/ | \\|___ \\`-._,-`-, "
println " `._,._,\' "
println " "
println " D G E P I P E L I N E "
println "========================================================"
println "['Pipeline Name'] = nf-core/DGE"
println "['Pipeline Version'] = $workflow.manifest.version"
println "['Inputdir'] = $params.inputdir"
if(params.design != "-"){
println "['DESeq2 design'] = $params.design"
println "['DESeq2 condition'] = $params.condition"
println "['DESeq2 treatment'] = $params.treatment"
println "['DESeq2 control'] = $params.control"
}else{
println "['DESeq2 design'] = No design specified"
}
if(params.rlog){
println "['DESeq2 transform'] = rlog"
}else{
println "['DESeq2 transform'] = vst"
}
if(params.skipShrink){
println "['lfcShrink'] = Skip lfcShrink step"
}
if(params.kallisto){
println "['Read counts mode'] = kallisto"
println "['Assembly'] = $params.assembly"
}else{
println "['Read counts mode'] = featureCounts"
}
if(!params.skip_gsea){
println "['GSEA step'] = True"
println "['GMX set'] = $gmx"
if(!params.assembly){
println "['Species'] = *Assuming Human*"
}
}else{
println "['GSEA step'] = False"
}
if(params.pval != "-"){
println "['Volcano plot Pval threshold'] = $params.pval"
}
if(params.fc != "-"){
println "['Volcano plot FC threshold'] = $params.fc"
}
println "['Output dir'] = $params.outdir"
println "['Working dir'] = $workflow.workDir"
println "['Container Engine'] = $workflow.containerEngine"
println "['Current home'] = $HOME"
println "['Current user'] = $USER"
println "['Current path'] = $PWD"
println "['Working dir'] = $workflow.workDir"
println "['Script dir'] = $workflow.projectDir"
println "['Config Profile'] = $workflow.profile"
println "========================================================"
/*
* STEP 1 - DESeq2
*/
process deseq2 {
publishDir "${params.outdir}", mode: 'copy',
saveAs: {filename ->
if (filename.indexOf("_MAplot.png") > 0) "deseq2_PlotsAndFiles/MAplots/$filename"
else if (filename.indexOf("_VolcanoPlot.png") > 0) "deseq2_PlotsAndFiles/volcanoPlots/$filename"
else if (filename.indexOf("_heatmap.png") > 0) "deseq2_PlotsAndFiles/heatmapPlots/$filename"
else if (filename.indexOf(".txt") > 0) "deseq2_PlotsAndFiles/files/$filename"
else if (filename == "PCAplot.png") "deseq2_PlotsAndFiles/$filename"
else "$filename"
}
output:
file "*.txt" into stats_for_gsea
file "*{_MAplot.png,_VolcanoPlot.png,_heatmap.png}"
file "PCAplot.png"
file "deseq2_report"
script:
"""
cat > deseq2.conf << EOF
[deseq2]
INPUTDIR = $inputdir
METADATA = $metadata
DESIGN = $params.design
CONDITION = $params.condition
TREATMENT = $params.treatment
CONTROL = $params.control
RLOG = $params.rlog
SHRINK = $params.skipShrink
PVAL = $params.pval
FC = $params.fc
KALLISTO = $params.kallisto
TX2GENE = $tx2gene
EOF
run_deseq2.R $inputdir $metadata deseq2.conf
mv *_AllPlot.png deseq2_report/figuresDESeq2_nextflow_pipeline_results/.
cp PCAplot.png *_heatmap.png deseq2_report/figuresDESeq2_nextflow_pipeline_results/.
"""
}
/*
* STEP 2 - GSEA
*/
process gsea {
tag "$contrast"
publishDir "${params.outdir}/gsea_results/$contrast", mode: 'copy'
when:
!params.skip_gsea
input:
file stats from stats_for_gsea.flatten()
output:
file "gsea.*"
script:
contrast = stats.toString() - ~/_results.txt$/
"""
echo $stats
get_metric.pl $stats $contrast
run_gsea.pl --rnk ${contrast}.rnk --gmx $gmx --perm $params.perm --min_set $params.min_set --max_set $params.max_set
mv gsea_results*/* .
plot_gsea.R gsea_table.txt $params.perm
"""
}
workflow.onComplete {
println ( workflow.success ? "Done! Wrapping up..." : "Oops .. something went wrong" )
log.info "[nf-core/test] Pipeline Complete"
}