-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmain.nf
183 lines (163 loc) · 5.39 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
#!/usr/bin/env nextflow
// Developer notes
//
// This template workflow provides a basic structure to copy in order
// to create a new workflow. Current recommended practices are:
// i) create a simple command-line interface.
// ii) include an abstract workflow scope named "pipeline" to be used
// in a module fashion
// iii) a second concrete, but anonymous, workflow scope to be used
// as an entry point when using this workflow in isolation.
import groovy.json.JsonBuilder
nextflow.enable.dsl = 2
include { fastq_ingress } from './lib/fastqingress'
OPTIONAL_FILE = file("$projectDir/data/OPTIONAL_FILE")
process getVersions {
label "wftemplate"
cpus 1
output:
path "versions.txt"
script:
"""
python -c "import pysam; print(f'pysam,{pysam.__version__}')" >> versions.txt
fastcat --version | sed 's/^/fastcat,/' >> versions.txt
"""
}
process getParams {
label "wftemplate"
cpus 1
output:
path "params.json"
script:
String paramsJSON = new JsonBuilder(params).toPrettyString()
"""
# Output nextflow params object to JSON
echo '$paramsJSON' > params.json
"""
}
process makeReport {
label "wftemplate"
input:
val metadata
path per_read_stats
path "versions/*"
path "params.json"
output:
path "wf-template-*.html"
script:
String report_name = "wf-template-report.html"
String metadata = new JsonBuilder(metadata).toPrettyString()
String stats_args = \
(per_read_stats.name == OPTIONAL_FILE.name) ? "" : "--stats $per_read_stats"
"""
echo '${metadata}' > metadata.json
workflow-glue report $report_name \
--versions versions \
$stats_args \
--params params.json \
--metadata metadata.json
"""
}
// See https://github.com/nextflow-io/nextflow/issues/1636. This is the only way to
// publish files from a workflow whilst decoupling the publish from the process steps.
// The process takes a tuple containing the filename and the name of a sub-directory to
// put the file into. If the latter is `null`, puts it into the top-level directory.
process output {
// publish inputs to output directory
label "wftemplate"
publishDir (
params.out_dir,
mode: "copy",
saveAs: { dirname ? "$dirname/$fname" : fname }
)
input:
tuple path(fname), val(dirname)
output:
path fname
"""
"""
}
// Creates a new directory named after the sample alias and moves the fastcat results
// into it.
process collectFastqIngressResultsInDir {
label "wftemplate"
input:
// both the fastcat seqs as well as stats might be `OPTIONAL_FILE` --> stage in
// different sub-directories to avoid name collisions
tuple val(meta), path(concat_seqs, stageAs: "seqs/*"), path(fastcat_stats,
stageAs: "stats/*")
output:
// use sub-dir to avoid name clashes (in the unlikely event of a sample alias
// being `seq` or `stats`)
path "out/*"
script:
String outdir = "out/${meta["alias"]}"
String metaJson = new JsonBuilder(meta).toPrettyString()
String concat_seqs = \
(concat_seqs.fileName.name == OPTIONAL_FILE.name) ? "" : concat_seqs
String fastcat_stats = \
(fastcat_stats.fileName.name == OPTIONAL_FILE.name) ? "" : fastcat_stats
"""
mkdir -p $outdir
echo '$metaJson' > metamap.json
mv metamap.json $concat_seqs $fastcat_stats $outdir
"""
}
// workflow module
workflow pipeline {
take:
reads
main:
per_read_stats = reads.map {
it[2] ? it[2].resolve('per-read-stats.tsv') : null
}
| collectFile ( keepHeader: true )
| ifEmpty ( OPTIONAL_FILE )
software_versions = getVersions()
workflow_params = getParams()
metadata = reads.map { it[0] }.toList()
report = makeReport(
metadata, per_read_stats, software_versions.collect(), workflow_params
)
reads
// replace `null` with path to optional file
| map { [ it[0], it[1] ?: OPTIONAL_FILE, it[2] ?: OPTIONAL_FILE ] }
| collectFastqIngressResultsInDir
emit:
fastq_ingress_results = collectFastqIngressResultsInDir.out
report
workflow_params
// TODO: use something more useful as telemetry
telemetry = workflow_params
}
// entrypoint workflow
WorkflowMain.initialise(workflow, params, log)
workflow {
if (params.disable_ping == false) {
Pinguscript.ping_post(workflow, "start", "none", params.out_dir, params)
}
samples = fastq_ingress([
"input":params.fastq,
"sample":params.sample,
"sample_sheet":params.sample_sheet,
"analyse_unclassified":params.analyse_unclassified,
"fastcat_stats": params.wf.fastcat_stats,
"fastcat_extra_args": "",
"required_sample_types": [] ])
pipeline(samples)
pipeline.out.fastq_ingress_results
| map { [it, "fastq_ingress_results"] }
| concat (
pipeline.out.report.concat(pipeline.out.workflow_params)
| map { [it, null] }
)
| output
}
if (params.disable_ping == false) {
workflow.onComplete {
Pinguscript.ping_post(workflow, "end", "none", params.out_dir, params)
}
workflow.onError {
Pinguscript.ping_post(workflow, "error", "$workflow.errorMessage", params.out_dir, params)
}
}