-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
106 lines (85 loc) · 4.45 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
nextflow.enable.dsl=2
def printErr = System.err.&println
// import modules that depend on input mode:
include { imeta_study } from './modules/imeta_study.nf'
include { imeta_samples_csv } from './modules/imeta_samples_csv.nf'
include { gsheet_to_csv } from './modules/gsheet_to_csv.nf'
// module specific to google_spreadsheet input mode:
include { join_gsheet_metadata } from './modules/join_gsheet_metadata.nf'
include { iget_study_cram } from './modules/iget_study_cram.nf'
// include workflow common to all input modes:
include { run_from_irods_tsv } from './subworkflows/local/run_from_irods_tsv.nf'
// validate inputs
if (params.run_crams_to_fastq & !params.run_merge_crams) {
printErr("Error: Crams must be merged prior to conversion to fastq. Enable `run_merge_crams` option")
exit 1
}
workflow {
if (params.run_mode == "study_id") {
if (!params.input_study_runs) {
params.input_study_runs = []
}
imeta_study(params.input_studies, params.input_study_runs, params.filter_manual_qc)
samples_irods_tsv = imeta_study.out.irods_samples_tsv
work_dir_to_remove = imeta_study.out.work_dir_to_remove
}
else if (params.run_mode == "csv_samples_id") {
samples_irods_tsv = Channel.fromPath(params.input_samples_csv)
}
else if (params.run_mode == "google_spreadsheet") {
i1 = Channel.from(params.input_gsheet_name)
i2 = Channel.fromPath(params.input_google_creds)
i3 = Channel.from(params.output_csv_name)
i31 = Channel.from(params.input_sheet_name)
gsheet_to_csv(i1,i2,i3,i31)
i4 = Channel.from(params.google_spreadsheet_mode.input_gsheet_column)
imeta_samples_csv(gsheet_to_csv.out.samples_csv, i4)
samples_irods_tsv = imeta_samples_csv.out.irods_samples_tsv
work_dir_to_remove = imeta_samples_csv.out.work_dir_to_remove.mix(gsheet_to_csv.out.work_dir_to_remove)
}
// common to all input modes:
run_from_irods_tsv(samples_irods_tsv)
// list work dirs to remove (because they are Irods searches, so need to always rerun on each NF run):
// these are removed on workflow.onComplete if (params.on_complete_uncache_irods_search), see below.
//run_from_irods_tsv.out.ch_work_dir_to_remove.mix(work_dir_to_remove)
// .filter { it != "dont_remove" }
// .collectFile(name: 'irods_work_dirs_to_remove.csv', newLine: true, sort: true,
// storeDir:params.outdir)
if (params.run_mode == "google_spreadsheet") {
// combine all samples tables (google spreadsheet, irods + cellranger metadata, cellranger /lustre file paths),
// by joining on common sample column:
// the resulting combined tables can be fed directly as input to the Vireo deconvolution pipeline or QC pipeline.
join_gsheet_metadata(gsheet_to_csv.out.samples_csv,
run_from_irods_tsv.out.ch_cellranger_metadata_tsv,
run_from_irods_tsv.out.ch_file_paths_10x_tsv)
}
}
workflow.onError {
log.info "Pipeline execution stopped with the following message: ${workflow.errorMessage}" }
workflow.onComplete {
log.info "Pipeline completed at: $workflow.complete"
log.info "Command line: $workflow.commandLine"
log.info "Execution status: ${ workflow.success ? 'OK' : 'failed' }"
if (params.on_complete_uncache_irods_search) {
log.info "You have selected \"on_complete_uncache_irods_search = true\"; will therefore attempt to remove Irods work dirs to forcefully uncache them even if successful."
if (! file("${params.outdir}/irods_work_dirs_to_remove.csv").isEmpty()) {
log.info "file ${params.outdir}/irods_work_dirs_to_remove.csv exists and not empty ..."
file("${params.outdir}/irods_work_dirs_to_remove.csv")
.eachLine { work_dir ->
if (file(work_dir).isDirectory()) {
log.info "removing work dir $work_dir ..."
file(work_dir).deleteDir()
}
}
}
}
if (params.on_complete_remove_workdir_failed_tasks) {
log.info "You have selected \"on_complete_remove_workdir_failed_tasks = true\"; will therefore remove work dirs of all tasks that failed (.exitcode file not 0)."
// work dir and other paths are hardcoded here ... :
def proc = "bash ${projectDir}/bin/del_work_dirs_failed.sh ${workDir}".execute()
def b = new StringBuffer()
proc.consumeProcessErrorStream(b)
log.info proc.text
log.info b.toString()
}
}