-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathmain.nf
More file actions
198 lines (172 loc) · 7.4 KB
/
main.nf
File metadata and controls
198 lines (172 loc) · 7.4 KB
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
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORT LOCAL MODULES/SUBWORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
include { MULTIQC_MAPPINGS_CONFIG } from '../../modules/local/multiqc_mappings_config'
include { SRA_FASTQ_FTP } from '../../modules/local/sra_fastq_ftp'
include { SRA_IDS_TO_RUNINFO } from '../../modules/local/sra_ids_to_runinfo'
include { SRA_RUNINFO_TO_FTP } from '../../modules/local/sra_runinfo_to_ftp'
include { ASPERA_CLI } from '../../modules/local/aspera_cli'
include { SRA_TO_SAMPLESHEET } from '../../modules/local/sra_to_samplesheet'
include { softwareVersionsToYAML } from '../../subworkflows/nf-core/utils_nfcore_pipeline'
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORT NF-CORE SUBWORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
include { FASTQ_DOWNLOAD_PREFETCH_FASTERQDUMP_SRATOOLS } from '../../subworkflows/nf-core/fastq_download_prefetch_fasterqdump_sratools'
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RUN MAIN WORKFLOW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
workflow SRA {
take:
ids // channel: [ ids ]
main:
ch_versions = Channel.empty()
//
// MODULE: Get SRA run information for public database ids
//
SRA_IDS_TO_RUNINFO (
ids,
params.ena_metadata_fields ?: ''
)
ch_versions = ch_versions.mix(SRA_IDS_TO_RUNINFO.out.versions.first())
//
// MODULE: Parse SRA run information, create file containing FTP links and read into workflow as [ meta, [reads] ]
//
SRA_RUNINFO_TO_FTP (
SRA_IDS_TO_RUNINFO.out.tsv
)
ch_versions = ch_versions.mix(SRA_RUNINFO_TO_FTP.out.versions.first())
SRA_RUNINFO_TO_FTP
.out
.tsv
.splitCsv(header:true, sep:'\t')
.map {
meta ->
def meta_clone = meta.clone()
meta_clone.single_end = meta_clone.single_end.toBoolean()
return meta_clone
}
.unique()
.set { ch_sra_metadata }
if (!params.skip_fastq_download) {
ch_sra_metadata
.branch {
meta ->
def download_method = 'ftp'
// meta.fastq_aspera is a metadata string with ENA fasp links supported by Aspera
// For single-end: 'fasp.sra.ebi.ac.uk:/vol1/fastq/ERR116/006/ERR1160846/ERR1160846.fastq.gz'
// For paired-end: 'fasp.sra.ebi.ac.uk:/vol1/fastq/SRR130/020/SRR13055520/SRR13055520_1.fastq.gz;fasp.sra.ebi.ac.uk:/vol1/fastq/SRR130/020/SRR13055520/SRR13055520_2.fastq.gz'
if (meta.fastq_aspera && params.download_method == 'aspera') {
download_method = 'aspera'
}
if ((!meta.fastq_aspera && !meta.fastq_1) || params.download_method == 'sratools') {
download_method = 'sratools'
}
aspera: download_method == 'aspera'
return [ meta, meta.fastq_aspera.tokenize(';').take(2) ]
ftp: download_method == 'ftp'
return [ meta, [ meta.fastq_1, meta.fastq_2 ] ]
sratools: download_method == 'sratools'
return [ meta, meta.run_accession ]
}
.set { ch_sra_reads }
//
// MODULE: If FTP link is provided in run information then download FastQ directly via FTP and validate with md5sums
//
SRA_FASTQ_FTP (
ch_sra_reads.ftp,
params.sra_fastq_ftp_args ?: ''
)
ch_versions = ch_versions.mix(SRA_FASTQ_FTP.out.versions.first())
//
// SUBWORKFLOW: Download sequencing reads without FTP links using sra-tools.
//
FASTQ_DOWNLOAD_PREFETCH_FASTERQDUMP_SRATOOLS (
ch_sra_reads.sratools,
params.dbgap_key ? file(params.dbgap_key, checkIfExists: true) : []
)
ch_versions = ch_versions.mix(FASTQ_DOWNLOAD_PREFETCH_FASTERQDUMP_SRATOOLS.out.versions.first())
//
// MODULE: If Aspera link is provided in run information then download FastQ directly via Aspera CLI and validate with md5sums
//
ASPERA_CLI (
ch_sra_reads.aspera,
'era-fasp',
params.aspera_cli_args ?: ''
)
ch_versions = ch_versions.mix(ASPERA_CLI.out.versions.first())
// Isolate FASTQ channel which will be added to emit block
SRA_FASTQ_FTP
.out
.fastq
.mix(FASTQ_DOWNLOAD_PREFETCH_FASTERQDUMP_SRATOOLS.out.reads)
.mix(ASPERA_CLI.out.fastq)
.map {
meta, fastq ->
def reads = fastq instanceof List ? fastq.flatten() : [ fastq ]
def meta_clone = meta.clone()
meta_clone.fastq_1 = reads[0] ? "${params.outdir}/fastq/${reads[0].getName()}" : ''
meta_clone.fastq_2 = reads[1] && !meta.single_end ? "${params.outdir}/fastq/${reads[1].getName()}" : ''
return meta_clone
}
.set { ch_sra_metadata }
}
//
// MODULE: Stage FastQ files downloaded by SRA together and auto-create a samplesheet
//
SRA_TO_SAMPLESHEET (
ch_sra_metadata,
params.nf_core_pipeline ?: '',
params.nf_core_rnaseq_strandedness ?: 'auto',
params.sample_mapping_fields
)
// Merge samplesheets and mapping files across all samples
SRA_TO_SAMPLESHEET
.out
.samplesheet
.map { it[1] }
.collectFile(name:'tmp_samplesheet.csv', newLine: true, keepHeader: true, sort: { it.baseName })
.map { it.text.tokenize('\n').join('\n') }
.collectFile(name:'samplesheet.csv', storeDir: "${params.outdir}/samplesheet")
.set { ch_samplesheet }
SRA_TO_SAMPLESHEET
.out
.mappings
.map { it[1] }
.collectFile(name:'tmp_id_mappings.csv', newLine: true, keepHeader: true, sort: { it.baseName })
.map { it.text.tokenize('\n').join('\n') }
.collectFile(name:'id_mappings.csv', storeDir: "${params.outdir}/samplesheet")
.set { ch_mappings }
//
// MODULE: Create a MutiQC config file with sample name mappings
//
ch_sample_mappings_yml = Channel.empty()
if (params.sample_mapping_fields) {
MULTIQC_MAPPINGS_CONFIG (
ch_mappings
)
ch_versions = ch_versions.mix(MULTIQC_MAPPINGS_CONFIG.out.versions)
ch_sample_mappings_yml = MULTIQC_MAPPINGS_CONFIG.out.yml
}
//
// Collate and save software versions
//
softwareVersionsToYAML(ch_versions)
.collectFile(storeDir: "${params.outdir}/pipeline_info", name: 'nf_core_fetchngs_software_mqc_versions.yml', sort: true, newLine: true)
emit:
samplesheet = ch_samplesheet
mappings = ch_mappings
sample_mappings = ch_sample_mappings_yml
sra_metadata = ch_sra_metadata
versions = ch_versions.unique()
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/