Skip to content

Commit 8fc8342

Browse files
committed
Refactor processes, workflows, output block with static types
Signed-off-by: Ben Sherman <[email protected]>
1 parent 1815dc2 commit 8fc8342

File tree

7 files changed

+124
-65
lines changed

7 files changed

+124
-65
lines changed

main.nf

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,70 @@
1-
#!/usr/bin/env nextflow
1+
#!/usr/bin/env nextflow
22

33
/*
44
* Proof of concept of a RNAseq pipeline implemented with Nextflow
55
*/
6-
6+
nextflow.preview.types = true
77

88
/*
9-
* Default pipeline parameters. They can be overriden on the command line eg.
10-
* given `params.foo` specify on the run command line `--foo some_value`.
9+
* Default pipeline parameters. They can be overridden on the command line, e.g.
10+
* `params.reads` can be specified on the command line as `--reads some_value`.
1111
*/
12-
13-
params.reads = "$baseDir/data/ggal/ggal_gut_{1,2}.fq"
14-
params.transcriptome = "$baseDir/data/ggal/ggal_1_48850000_49020000.Ggal71.500bpflank.fa"
15-
params.outdir = "results"
16-
params.multiqc = "$baseDir/multiqc"
12+
params.reads = "${projectDir}/data/ggal/ggal_gut_{1,2}.fq"
13+
params.transcriptome = "${projectDir}/data/ggal/ggal_1_48850000_49020000.Ggal71.500bpflank.fa"
14+
params.multiqc = "${projectDir}/multiqc"
1715

1816

19-
// import modules
2017
include { RNASEQ } from './modules/rnaseq'
18+
include { FastqPair ; Sample } from './modules/rnaseq'
2119
include { MULTIQC } from './modules/multiqc'
2220

23-
/*
24-
* main script flow
25-
*/
2621
workflow {
22+
main:
23+
log.info """\
24+
R N A S E Q - N F P I P E L I N E
25+
===================================
26+
transcriptome: ${params.transcriptome}
27+
reads : ${params.reads}
28+
outdir : ${workflow.outputDir}
29+
""".stripIndent()
30+
31+
let (index, samples) = params.reads
32+
|> Channel.fromFilePairs( checkIfExists: true ) // Channel<(String,List<Path>)>
33+
|> map { (id, reads) ->
34+
new FastqPair(id, reads[0], reads[1])
35+
} // Channel<FastqPair>
36+
|> RNASEQ( file(params.transcriptome) ) // NamedTuple(index: Path, samples: Channel<Sample>)
37+
38+
let summary = samples
39+
|> flatMap { s -> [ s.fastqc, s.quant ] } // Channel<Path>
40+
|> collect // Bag<Path> (future)
41+
|> MULTIQC( file(params.multiqc) ) // Path (future)
42+
43+
workflow.onComplete {
44+
log.info ( workflow.success
45+
? "\nDone! Open the following report in your browser --> ${workflow.outputDir}/multiqc_report.html\n"
46+
: "Oops .. something went wrong" )
47+
}
48+
49+
publish:
50+
index >> 'index'
51+
samples >> 'samples'
52+
summary >> 'summary'
53+
}
54+
55+
output {
56+
index: Path {
57+
path '.'
58+
}
59+
60+
samples: Sample {
61+
path { sample -> sample.id }
62+
index {
63+
path 'samples.json'
64+
}
65+
}
2766

28-
log.info """\
29-
R N A S E Q - N F P I P E L I N E
30-
===================================
31-
transcriptome: ${params.transcriptome}
32-
reads : ${params.reads}
33-
outdir : ${params.outdir}
34-
"""
35-
36-
read_pairs_ch = channel.fromFilePairs( params.reads, checkIfExists: true )
37-
RNASEQ( params.transcriptome, read_pairs_ch )
38-
MULTIQC( RNASEQ.out, params.multiqc )
67+
summary: Path {
68+
path '.'
69+
}
3970
}

modules/fastqc/main.nf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
params.outdir = 'results'
21

32
process FASTQC {
4-
tag "FASTQC on $sample_id"
3+
tag "FASTQC on $id"
54
conda 'bioconda::fastqc=0.12.1'
6-
publishDir params.outdir, mode:'copy'
75

86
input:
9-
tuple val(sample_id), path(reads)
10-
11-
output:
12-
path "fastqc_${sample_id}_logs", emit: logs
7+
id : String
8+
fastq_1 : Path
9+
fastq_2 : Path
1310

1411
script:
1512
"""
16-
fastqc.sh "$sample_id" "$reads"
13+
fastqc.sh $id "$fastq_1 $fastq_2"
1714
"""
15+
16+
output:
17+
file("fastqc_${id}_logs")
1818
}

modules/index/main.nf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
process INDEX {
33
tag "$transcriptome.simpleName"
44
conda 'bioconda::salmon=1.10.3'
5-
6-
input:
7-
path transcriptome
85

9-
output:
10-
path 'index'
6+
input:
7+
transcriptome : Path
118

129
script:
1310
"""
1411
salmon index --threads $task.cpus -t $transcriptome -i index
1512
"""
13+
14+
output:
15+
file('index')
1616
}

modules/multiqc/main.nf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
params.outdir = 'results'
21

32
process MULTIQC {
43
conda 'bioconda::multiqc=1.25'
5-
publishDir params.outdir, mode:'copy'
64

75
input:
8-
path '*'
9-
path config
10-
11-
output:
12-
path 'multiqc_report.html', emit: report
6+
inputs : Bag<Path>
7+
config : Path
138

149
script:
1510
"""
1611
cp $config/* .
1712
echo "custom_logo: \$PWD/logo.png" >> multiqc_config.yaml
1813
multiqc -o multiqc_report.html .
1914
"""
15+
16+
output:
17+
file('multiqc_report.html')
2018
}

modules/quant/main.nf

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11

22
process QUANT {
3-
tag "$pair_id"
3+
tag "$id"
44
conda 'bioconda::salmon=1.10.3'
55

66
input:
7-
path index
8-
tuple val(pair_id), path(reads)
9-
10-
output:
11-
path pair_id
7+
index : Path
8+
id : String
9+
fastq_1 : Path
10+
fastq_2 : Path
1211

1312
script:
1413
"""
15-
salmon quant --threads $task.cpus --libType=U -i $index -1 ${reads[0]} -2 ${reads[1]} -o $pair_id
14+
salmon quant \
15+
--threads $task.cpus \
16+
--libType=U \
17+
-i $index \
18+
-1 ${fastq_1} \
19+
-2 ${fastq_2} \
20+
-o quant_${id}
1621
"""
22+
23+
output:
24+
file("quant_${id}")
1725
}

modules/rnaseq.nf

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
params.outdir = 'results'
2-
31
include { INDEX } from './index'
42
include { QUANT } from './quant'
53
include { FASTQC } from './fastqc'
64

75
workflow RNASEQ {
86
take:
9-
transcriptome
10-
read_pairs_ch
7+
pairs : Channel<FastqPair>
8+
transcriptome : Path
119

1210
main:
13-
INDEX(transcriptome)
14-
FASTQC(read_pairs_ch)
15-
QUANT(INDEX.out, read_pairs_ch)
11+
transcriptome // Path
12+
|> INDEX // Path (future)
13+
|> set { index } // Path (future)
14+
15+
pairs // Channel<FastqPair>
16+
|> map { pair ->
17+
let (id, fastq_1, fastq_2) = (pair.id, pair.fastq_1, pair.fastq_2)
18+
let fastqc = FASTQC(id, fastq_1, fastq_2)
19+
let quant = QUANT(index, id, fastq_1, fastq_2)
20+
new Sample(id, fastqc, quant)
21+
} // Channel<Sample>
22+
|> set { samples } // Channel<Sample>
23+
24+
emit:
25+
index : Path
26+
samples : Channel<Sample>
27+
}
28+
29+
record FastqPair {
30+
id : String
31+
fastq_1 : Path
32+
fastq_2 : Path
33+
}
1634

17-
emit:
18-
QUANT.out | concat(FASTQC.out) | collect
35+
record Sample {
36+
id : String
37+
fastqc : Path
38+
quant : Path
1939
}

nextflow.config

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ manifest {
1717
}
1818

1919
/*
20-
* default params
20+
* config params
2121
*/
22+
params.outdir = 'results'
2223

23-
params.outdir = "results"
24-
params.reads = "${projectDir}/data/ggal/ggal_gut_{1,2}.fq"
25-
params.transcriptome = "${projectDir}/data/ggal/ggal_1_48850000_49020000.Ggal71.500bpflank.fa"
26-
params.multiqc = "${projectDir}/multiqc"
24+
/*
25+
* configure outputs publishing
26+
*/
27+
outputDir = params.outdir
28+
workflow.output.mode = 'copy'
2729

2830
/*
2931
* defines execution profiles for different environments

0 commit comments

Comments
 (0)