-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.nf
324 lines (258 loc) · 12.5 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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env nextflow
/*
========================================================================================
czbiohub/sicilian
========================================================================================
czbiohub/sicilian Analysis Pipeline.
#### Homepage / Documentation
https://github.com/czbiohub/sicilian
----------------------------------------------------------------------------------------
*/
nextflow.enable.dsl = 2
////////////////////////////////////////////////////
/* -- PRINT HELP -- */
////////////////////////////////////////////////////
def json_schema = "$projectDir/nextflow_schema.json"
if (params.help) {
def command = "nextflow run czbiohub/sicilian --input samplesheet.csv --genome GRCh37 -profile docker"
log.info Schema.params_help(workflow, params, json_schema, command)
exit 0
}
////////////////////////////////////////////////////
/* -- VALIDATE PARAMETERS -- */
////////////////////////////////////////////////////+
if (params.validate_params) {
NfcoreSchema.validateParameters(params, json_schema, log)
}
////////////////////////////////////////////////////
/* -- GENOME PARAMETER VALUES -- */
////////////////////////////////////////////////////
params.fasta = Checks.get_genome_attribute(params, 'fasta')
params.gtf = Checks.get_genome_attribute(params, 'gtf')
params.star_index = Checks.get_genome_attribute(params, 'star')
////////////////////////////////////////////////////
/* -- PRINT PARAMETER SUMMARY -- */
////////////////////////////////////////////////////
def summary_params = Schema.params_summary_map(workflow, params, json_schema)
log.info Schema.params_summary_log(workflow, params, json_schema)
////////////////////////////////////////////////////
/* -- PARAMETER CHECKS -- */
////////////////////////////////////////////////////
// Check that conda channels are set-up correctly
if (params.enable_conda) {
Checks.check_conda_channels(log)
}
// Check AWS batch settings
Checks.aws_batch(workflow, params)
// Check the hostnames against configured profiles
Checks.hostname(workflow, params, log)
// Check genome key exists if provided
Checks.genome_exists(params, log)
////////////////////////////////////////////////////
/* -- LOCAL PARAMETER VALUES -- */
////////////////////////////////////////////////////
params.summary_params = [:]
////////////////////////////////////////////////////
/* -- VALIDATE INPUTS -- */
////////////////////////////////////////////////////
// Check input path parameters to see if they exist
checkPathParamList = [
params.input,
// params.multiqc_config,
params.gtf,
]
for (param in checkPathParamList) { if (param) { file(param, checkIfExists: true) } }
/*
========================================================================================
SICILIAN-SPECIFIC FILES
========================================================================================
*/
//
// Create channel for domain file
//
ch_domain = file(params.domain, checkIfExists: true)
/*
========================================================================================
CONFIG FILES
========================================================================================
*/
ch_multiqc_config = Channel.fromPath("$projectDir/assets/multiqc_config.yaml", checkIfExists: true)
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config) : Channel.empty()
/*
========================================================================================
SET MODULE PARAMETERS
========================================================================================
*/
// Don't overwrite global params.modules, create a copy instead and use that within the main script.
def modules = params.modules.clone()
def umitools_whitelist_options = modules['umitools_whitelist']
umitools_whitelist_options.args += params.umitools_bc_pattern ? " --bc-pattern='${params.umitools_bc_pattern}'" : ''
def umitools_extract_options = modules['umitools_extract']
umitools_extract_options.args += params.umitools_bc_pattern ? Utils.joinModuleArgs(["--bc-pattern='${params.umitools_bc_pattern}'"]) : ''
if (params.save_umi_intermeds) { umitools_extract_options.publish_files.put('fastq.gz','') }
def star_genomegenerate_options = modules['star_genomegenerate']
if (!params.save_reference) { star_genomegenerate_options['publish_files'] = false }
def gffread_options = modules['gffread']
if (!params.save_reference) { gffread_options['publish_files'] = false }
def sicilian_createannotator_options = modules['sicilian_createannotator']
def star_align_options = modules['star_align']
def sicilian_classinput_options = modules['sicilian_classinput']
sicilian_classinput_options.args += params.tenx ? Utils.joinModuleArgs(['--UMI_bar']) : ''
def sicilian_glm_options = modules['sicilian_glm']
def sicilian_annsplices_options = modules['sicilian_annsplices']
def sicilian_consolidate_options = modules['sicilian_consolidate']
def sicilian_process_ci_10x_options = modules['sicilian_process_ci_10x']
def sicilian_postprocess_options = modules['sicilian_postprocess']
def publish_genome_options = params.save_reference ? [publish_dir: 'genome'] : [publish_files: false]
def publish_index_options = params.save_reference ? [publish_dir: 'genome/index'] : [publish_files: false]
def multiqc_options = modules['multiqc']
multiqc_options.args += params.multiqc_title ? Utils.joinModuleArgs(["--title \"$params.multiqc_title\""]) : ''
/*
========================================================================================
IMPORT LOCAL MODULES/SUBWORKFLOWS
========================================================================================
*/
include { INPUT_CHECK } from './subworkflows/local/input_check' addParams( options: [:] )
include { UMITOOLS_WHITELIST } from './modules/local/umitools_whitelist' addParams( options: umitools_whitelist_options )
include { GET_SOFTWARE_VERSIONS } from './modules/local/get_software_versions' addParams( options: [publish_files : ['csv':'']] )
include { PREPARE_GENOME } from './subworkflows/local/prepare_genome' addParams(
genome_options: publish_genome_options,
index_options: publish_index_options,
gffread_options: gffread_options,
star_index_options: star_genomegenerate_options,
sicilian_createannotator_options: sicilian_createannotator_options )
include { SICILIAN } from './subworkflows/local/sicilian' addParams(
classinput_options: sicilian_classinput_options,
glm_options: sicilian_glm_options,
annsplices_options: sicilian_annsplices_options,
consolidate_options: sicilian_consolidate_options,
process_ci_10x_options: sicilian_process_ci_10x_options,
postprocess_options: sicilian_postprocess_options
)
/*
========================================================================================
IMPORT NF-CORE MODULES/SUBWORKFLOWS
========================================================================================
*/
//
// MODULE: Installed directly from nf-core/modules
//
include { MULTIQC } from './modules/nf-core/software/multiqc/main.nf' addParams( options: multiqc_options )
include { UMITOOLS_EXTRACT } from './modules/nf-core/software/umitools/extract/main.nf' addParams( options: umitools_extract_options )
include { STAR_ALIGN } from './modules/nf-core/software/star/align/main.nf' addParams( options: star_align_options )
////////////////////////////////////////////////////
/* -- RUN MAIN WORKFLOW -- */
////////////////////////////////////////////////////
// Info required for completion email and summary
def multiqc_report = []
def pass_percent_mapped = [:]
def fail_percent_mapped = [:]
////////////////////////////////////////////////////
/* -- RUN MAIN WORKFLOW -- */
////////////////////////////////////////////////////
workflow {
ch_software_versions = Channel.empty()
// ch_software_versions = ch_software_versions.mix(PREPARE_GENOME.out.gffread_version.ifEmpty(null))
//
// SUBWORKFLOW: Read in samplesheet, validate and stage input files
//
INPUT_CHECK ()
ch_reads = INPUT_CHECK.out.reads
ch_reads.dump( tag: 'ch_reads' )
//
// SUBWORKFLOW: Uncompress and prepare reference genome files
//
PREPARE_GENOME ()
ch_software_versions = ch_software_versions.mix(PREPARE_GENOME.out.star_version.ifEmpty(null))
ch_software_versions = ch_software_versions.mix(PREPARE_GENOME.out.gffread_version.ifEmpty(null))
ch_star_multiqc = Channel.empty()
if (!params.skip_star) {
if (!params.skip_umitools) {
/*
* MODULE: Create a whitelist of UMIs from the data
*/
UMITOOLS_WHITELIST (
ch_reads,
)
ch_software_versions = ch_software_versions.mix(UMITOOLS_WHITELIST.out.version.ifEmpty(null))
/*
* MODULE: Extract cell and molecular barcodes from R1 and insert into read name of R2
*/
UMITOOLS_EXTRACT ( ch_reads, UMITOOLS_WHITELIST.out.whitelist ).reads.set { umi_reads }
ch_software_versions = ch_software_versions.mix(UMITOOLS_EXTRACT.out.version.ifEmpty(null))
} else {
umi_reads = ch_reads
}
STAR_ALIGN (
umi_reads,
PREPARE_GENOME.out.star_index,
PREPARE_GENOME.out.gtf,
)
ch_software_versions = ch_software_versions.mix(STAR_ALIGN.out.version.first().ifEmpty(null))
ch_bam = STAR_ALIGN.out.bam
ch_sj_out_tab = STAR_ALIGN.out.sj_out_tab
ch_chimeric_junction = STAR_ALIGN.out.chimeric_out_junction
ch_reads_per_gene = STAR_ALIGN.out.reads_per_gene
ch_star_multiqc = STAR_ALIGN.out.log_final
} else {
// Skipping alignment, because already have all the files from the input
ch_bam = INPUT_CHECK.out.bam
ch_sj_out_tab = INPUT_CHECK.out.sj_out_tab
ch_chimeric_junction = INPUT_CHECK.out.chimeric_out_junction
ch_reads_per_gene = INPUT_CHECK.out.reads_per_gene
}
SICILIAN (
ch_bam,
ch_sj_out_tab,
ch_reads_per_gene,
ch_chimeric_junction,
PREPARE_GENOME.out.gtf,
ch_domain,
PREPARE_GENOME.out.sicilian_annotator,
PREPARE_GENOME.out.sicilian_exon_bounds,
PREPARE_GENOME.out.sicilian_splices,
INPUT_CHECK.out.class_input,
INPUT_CHECK.out.glm_output,
)
ch_software_versions = ch_software_versions.mix(SICILIAN.out.version.ifEmpty(null))
ch_software_versions
.flatten()
.dump(tag: 'ch_software_versions__flatten')
.map { it -> if (it) [ it.baseName, it ] }
.dump(tag: 'ch_software_versions__flatten__map')
.groupTuple()
.dump(tag: 'ch_software_versions__flatten__map__grouptuple')
.map { it[1][0] }
.dump(tag: 'ch_software_versions__flatten__map__grouptuple__map')
.collect()
.dump(tag: 'ch_software_versions__flatten__map__grouptuple__map__collect')
.set { ch_software_versions }
GET_SOFTWARE_VERSIONS (
ch_software_versions
)
/*
* MultiQC
*/
if (!params.skip_multiqc) {
workflow_summary = Schema.params_summary_multiqc(workflow, summary_params)
ch_workflow_summary = Channel.value(workflow_summary)
MULTIQC (
ch_multiqc_config.collect(),
ch_multiqc_custom_config.collect().ifEmpty([]),
GET_SOFTWARE_VERSIONS.out.yaml.collect(),
ch_workflow_summary.collectFile(name: 'workflow_summary_mqc.yaml'),
ch_star_multiqc.collect{it[1]}.ifEmpty([]).view(),
)
multiqc_report = MULTIQC.out.report.toList()
}
}
////////////////////////////////////////////////////
/* -- COMPLETION EMAIL -- */
////////////////////////////////////////////////////
workflow.onComplete {
Completion.email(workflow, params, params.summary_params, projectDir, log, multiqc_report, fail_percent_mapped)
Completion.summary(workflow, params, log, fail_percent_mapped, pass_percent_mapped)
}
////////////////////////////////////////////////////
/* -- THE END -- */
////////////////////////////////////////////////////