Skip to content

Commit 0743931

Browse files
authored
Merge pull request #44 from NBISweden/feature/better_order
Feature/better order
2 parents 631d018 + ca957b7 commit 0743931

File tree

3 files changed

+75
-65
lines changed

3 files changed

+75
-65
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.nextflow.*
2+
results*
3+
slurm-*
4+
CEP-1-7*

main.nf

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ if (!params.project) {
2626
exit 1, 'You need to specify what project to run under, see --help for more information'
2727
}
2828

29-
if (params.run_all) {
30-
params.run_fermikit = true
31-
params.run_manta = true
32-
}
29+
30+
workflowSteps = processWorkflowSteps(params.steps)
3331

3432

3533
startup_message()
@@ -51,16 +49,11 @@ if (!bamindex) {
5149
module "$params.modules.samtools"
5250

5351
// We only need one core for this part
54-
if ( nextflow_running_as_slurmjob() ) {
55-
executor 'local'
56-
}
57-
else {
58-
executor 'slurm'
59-
queue 'core'
60-
time params.short_job
61-
}
52+
executor choose_executor()
53+
queue 'core'
54+
time params.short_job
6255

63-
when: params.run_manta == true
56+
when: 'indexbam' in workflowSteps
6457

6558
script:
6659
"""
@@ -86,7 +79,7 @@ process manta {
8679
module 'bioinfo-tools'
8780
module "$params.modules.manta"
8881

89-
when: params.run_manta == true
82+
when: 'manta' in workflowSteps
9083

9184
script:
9285
"""
@@ -135,16 +128,11 @@ if (!params.fastq) {
135128
module "$params.modules.samtools"
136129

137130
// We only need one core for this part
138-
if ( nextflow_running_as_slurmjob() ) {
139-
executor 'local'
140-
}
141-
else {
142-
executor 'slurm'
143-
queue 'core'
144-
time params.short_job
145-
}
131+
executor choose_executor()
132+
queue 'core'
133+
time params.short_job
146134

147-
when: params.run_fermikit == true
135+
when: 'fastq' in workflowSteps
148136

149137
script:
150138
"""
@@ -172,7 +160,7 @@ process fermikit {
172160
module "$params.modules.vcftools"
173161
module "$params.modules.tabix"
174162

175-
when: params.run_fermikit == true
163+
when: 'fermikit' in workflowSteps
176164

177165
script:
178166
"""
@@ -193,7 +181,6 @@ process fermikit {
193181
// Collect vcfs and beds into one channel
194182
beds = manta_bed.mix( fermi_bed )
195183
vcfs = manta_vcf.mix( fermi_vcf )
196-
.tap { vcfs_snpeff }
197184

198185

199186
mask_files = [
@@ -210,12 +197,13 @@ process mask_beds {
210197
set file(bedfile), file(mask1), file(mask2) from mask_input
211198
output:
212199
file '*_masked.bed' into masked_beds
213-
file '*_masked_*.bed'
214200

215201
publishDir params.outdir, mode: 'copy'
216202

217203
// Does not use many resources, run it locally
218-
executor 'local'
204+
executor choose_executor()
205+
queue 'core'
206+
time params.short_job
219207

220208
module 'bioinfo-tools'
221209
module "$params.modules.bedtools"
@@ -226,27 +214,15 @@ process mask_beds {
226214
cat $bedfile \
227215
| bedtools intersect -v -a stdin -b $mask1 -f 0.25 \
228216
| bedtools intersect -v -a stdin -b $mask2 -f 0.25 > \$MASK_FILE
229-
230-
231-
## In case grep doesn't find anything it will exit with non-zero exit
232-
## status, which will cause slurm to abort the job, we want to continue on
233-
## error here.
234-
set +e
235-
236-
## Create filtered bed files
237-
for WORD in DEL INS DUP; do
238-
grep -w \$WORD \$MASK_FILE > \${BNAME}_masked_\${WORD,,}.bed
239-
done
240-
241-
set -e # Restore exit-settings
242217
"""
243218
}
244219

220+
245221
// To make intersect files we need to combine them into one channel with
246222
// toList(). And also figure out if we have one or two files, therefore the
247223
// tap and count_beds.
248224
masked_beds.tap { count_beds_tmp }
249-
.tap { masked_beds_vep }
225+
.tap { masked_beds }
250226
.toList().set { intersect_input }
251227
count_beds_tmp.count().set { count_beds }
252228

@@ -255,12 +231,14 @@ process intersect_files {
255231
set file(bed1), file(bed2) from intersect_input
256232
val nbeds from count_beds
257233
output:
258-
file "combined*.bed"
234+
file "combined_masked.bed" into intersections
259235

260236
publishDir params.outdir, mode: 'copy'
261237

262238
// Does not use many resources, run it locally
263-
executor 'local'
239+
executor choose_executor()
240+
queue 'core'
241+
time params.short_job
264242

265243
module 'bioinfo-tools'
266244
module "$params.modules.bedtools"
@@ -281,35 +259,35 @@ process intersect_files {
281259
| sort -k1,1V -k2,2n > combined_masked_\${WORD,,}.bed
282260
done
283261
262+
cat <( grep -v -w 'DEL\\|INS\\|DUP' $bed1 ) \
263+
<( grep -v -w 'DEL\\|INS\\|DUP' $bed2 ) \
264+
| sort -k1,1V -k2,2n > combined_masked_OTHER.bed
265+
266+
sort -k1,1V -k2,2n combined_masked_*.bed >> combined_masked.bed
267+
284268
set -e # Restore exit-settings
285269
"""
286270
}
287271

272+
annotate_files = intersections.flatten().mix( masked_beds.tap { masked_beds } )
288273

289-
vep_infiles = masked_beds_vep.mix(vcfs)
290-
291-
// TODO: Figure out running characteristics
292274
process variant_effect_predictor {
293275
input:
294-
file infile from vep_infiles
276+
file infile from annotate_files.tap { annotate_files }
295277
output:
296-
file '*.vep'
278+
file '*.vep' into vep_outfiles
297279

298280
publishDir params.outdir, mode: 'copy'
299281

300-
// We only need one core for this part
301-
if ( nextflow_running_as_slurmjob() ) {
302-
executor 'local'
303-
}
304-
else {
305-
executor 'slurm'
306-
queue 'core'
307-
time params.short_job
308-
}
282+
executor choose_executor()
283+
queue 'core'
284+
time params.short_job
309285

310286
module 'bioinfo-tools'
311287
module "$params.modules.vep"
312288

289+
when: 'vep' in workflowSteps
290+
313291
script:
314292
"""
315293
infile="$infile"
@@ -325,7 +303,7 @@ process variant_effect_predictor {
325303
esac
326304
327305
variant_effect_predictor.pl \
328-
-i "\$infile" \
306+
-i "\$infile" \
329307
--format "\$format" \
330308
-cache --dir "\$vep_cache" \
331309
-o "\$outfile" \
@@ -347,7 +325,6 @@ process variant_effect_predictor {
347325
"""
348326
}
349327

350-
351328
process snpEff() {
352329
input:
353330
file vcf from vcfs_snpeff
@@ -361,7 +338,11 @@ process snpEff() {
361338
module "$params.modules.snpeff"
362339

363340
// Does not use many resources, run it locally
364-
executor 'local'
341+
executor choose_executor()
342+
queue 'core'
343+
time params.short_job
344+
345+
when: 'snpeff' in workflowSteps
365346

366347
script:
367348
"""
@@ -404,9 +385,9 @@ def usage_message() {
404385
log.info ' Optional'
405386
log.info ' --help Show this message and exit'
406387
log.info ' --fastq Input fastqfile (default is bam but with fq as fileending)'
407-
log.info ' --run_manta Run manta (default)'
408-
log.info ' --run_fermikit Run fermikit'
409-
log.info ' --run_all Run all callers'
388+
log.info ' --steps Specify what steps to run, comma separated:'
389+
log.info ' Callers: manta, fermikit, cnvnator (choose one or many)'
390+
log.info ' Annotation: vep OR snpeff'
410391
log.info ' --long_job Running time for long job (callers, fermi and manta)'
411392
log.info ' --short_job Running time for short jobs (bam indexing and bam2fq)'
412393
log.info ' --outdir Directory where resultfiles are stored'
@@ -425,6 +406,7 @@ def startup_message() {
425406
log.info "Work dir : $workDir"
426407
log.info "Output dir : $params.outdir"
427408
log.info "Project : $params.project"
409+
log.info "Will run : " + workflowSteps.join(", ")
428410
log.info ""
429411
}
430412

@@ -473,3 +455,29 @@ def nextflow_running_as_slurmjob() {
473455
}
474456
return false
475457
}
458+
459+
def choose_executor() {
460+
return nextflow_running_as_slurmjob() ? 'local' : 'slurm'
461+
}
462+
463+
def processWorkflowSteps(steps) {
464+
if ( ! steps ) {
465+
return []
466+
}
467+
468+
workflowSteps = steps.split(',').collect { it.trim().toLowerCase() }
469+
470+
if ('vep' in workflowSteps && 'snpeff' in workflowSteps) {
471+
exit 1, 'You can only run one annotator, either "vep" or "snpeff"'
472+
}
473+
474+
if ('manta' in workflowSteps) {
475+
workflowSteps.push( 'indexbam' )
476+
}
477+
478+
if ('fermikit' in workflowSteps) {
479+
workflowSteps.push( 'fastq' )
480+
}
481+
482+
return workflowSteps
483+
}

nextflow.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
params {
2+
steps = 'manta,vep' // Change on commandline --steps x,y,z
23
project = "" // Set project or supply on commandline ( --project )
34
outdir = "results"
45

@@ -26,8 +27,6 @@ params {
2627

2728
long_job = '10h' // used for the callers (fermikit & manta)
2829
short_job = '30m' // used for bam indexing and bam2fq
29-
30-
run_manta = true
3130
}
3231

3332
process {

0 commit comments

Comments
 (0)