forked from nf-core/chipseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_genome.nf
227 lines (205 loc) · 8.37 KB
/
prepare_genome.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
//
// Uncompress and prepare reference genome files
//
include {
GUNZIP as GUNZIP_FASTA ;
GUNZIP as GUNZIP_GTF ;
GUNZIP as GUNZIP_GFF ;
GUNZIP as GUNZIP_GENE_BED ;
GUNZIP as GUNZIP_BLACKLIST
} from '../../modules/nf-core/gunzip/main'
include {
UNTAR as UNTAR_BWA_INDEX ;
UNTAR as UNTAR_BOWTIE2_INDEX ;
UNTAR as UNTAR_STAR_INDEX
} from '../../modules/nf-core/untar/main'
include { UNTARFILES } from '../../modules/nf-core/untarfiles/main'
include { GFFREAD } from '../../modules/nf-core/gffread/main'
include { CUSTOM_GETCHROMSIZES } from '../../modules/nf-core/custom/getchromsizes/main'
include { BWA_INDEX } from '../../modules/nf-core/bwa/index/main'
include { BOWTIE2_BUILD } from '../../modules/nf-core/bowtie2/build/main'
include { CHROMAP_INDEX } from '../../modules/nf-core/chromap/index/main'
include { GTF2BED } from '../../modules/local/gtf2bed'
include { GENOME_BLACKLIST_REGIONS } from '../../modules/local/genome_blacklist_regions'
include { STAR_GENOMEGENERATE } from '../../modules/local/star_genomegenerate'
workflow PREPARE_GENOME {
take:
genome // string: genome name
genomes // map: genome attributes
prepare_tool_index // string: tool to prepare index for
fasta // path: path to genome fasta file
gtf // file: /path/to/genome.gtf
gff // file: /path/to/genome.gff
blacklist // file: /path/to/blacklist.bed
gene_bed // file: /path/to/gene.bed
bwa_index // file: /path/to/bwa/index/
bowtie2_index // file: /path/to/bowtie2/index/
chromap_index // file: /path/to/chromap/index/
star_index // file: /path/to/star/index/
main:
ch_versions = Channel.empty()
//
// Uncompress genome fasta file if required
//
ch_fasta = Channel.empty()
if (fasta.endsWith('.gz')) {
ch_fasta = GUNZIP_FASTA([[:], fasta]).gunzip.map { it[1] }
ch_versions = ch_versions.mix(GUNZIP_FASTA.out.versions)
}
else {
ch_fasta = Channel.value(file(fasta, checkIfExists: true))
}
//
// Uncompress GTF annotation file or create from GFF3 if required
//
if (gtf) {
if (gtf.endsWith('.gz')) {
ch_gtf = GUNZIP_GTF([[:], gtf]).gunzip.map { it[1] }
ch_versions = ch_versions.mix(GUNZIP_GTF.out.versions)
} else {
ch_gtf = Channel.value(file(gtf, checkIfExists: true))
}
} else if (gff) {
if (gff.endsWith('.gz')) {
ch_gff = GUNZIP_GFF([[:], file(gff, checkIfExists: true)]).gunzip.map { it[1] }
ch_versions = ch_versions.mix(GUNZIP_GFF.out.versions).map { [ [:], it ] }
} else {
ch_gff = Channel.value(file(gff, checkIfExists: true)).map{ [ [:], it ] }
}
ch_gtf = GFFREAD(ch_gff, []).gtf.map { it[1] }
ch_versions = ch_versions.mix(GFFREAD.out.versions)
}
//
// Uncompress blacklist file if required
//
ch_blacklist = Channel.empty()
if (blacklist) {
if (blacklist.endsWith('.gz')) {
ch_blacklist = GUNZIP_BLACKLIST([[:], blacklist]).gunzip.map { it[1] }
ch_versions = ch_versions.mix(GUNZIP_BLACKLIST.out.versions)
} else {
ch_blacklist = Channel.value(file(blacklist))
}
}
//
// Uncompress gene BED annotation file or create from GTF if required
//
// If --gtf is supplied along with --genome
// Make gene bed from supplied --gtf instead of using iGenomes one automatically
def make_bed = false
if (!gene_bed) {
make_bed = true
} else if (genome && gtf) {
if (genomes[genome].gtf != gtf) {
make_bed = true
}
}
if (make_bed) {
ch_gene_bed = GTF2BED(ch_gtf).bed
ch_versions = ch_versions.mix(GTF2BED.out.versions)
} else {
if (gene_bed.endsWith('.gz')) {
ch_gene_bed = GUNZIP_GENE_BED([[:], gene_bed]).gunzip.map { it[1] }
ch_versions = ch_versions.mix(GUNZIP_GENE_BED.out.versions)
} else {
ch_gene_bed = Channel.value(file(gene_bed))
}
}
//
// Create chromosome sizes file
//
CUSTOM_GETCHROMSIZES(ch_fasta.map { [[:], it] })
ch_chrom_sizes = CUSTOM_GETCHROMSIZES.out.sizes.map { it[1] }
ch_fai = CUSTOM_GETCHROMSIZES.out.fai.map { it[1] }
ch_versions = ch_versions.mix(CUSTOM_GETCHROMSIZES.out.versions)
//
// Prepare genome intervals for filtering by removing regions in blacklist file
//
ch_genome_filtered_bed = Channel.empty()
GENOME_BLACKLIST_REGIONS(
ch_chrom_sizes,
ch_blacklist.ifEmpty([])
)
ch_genome_filtered_bed = GENOME_BLACKLIST_REGIONS.out.bed
ch_versions = ch_versions.mix(GENOME_BLACKLIST_REGIONS.out.versions)
//
// Uncompress BWA index or generate from scratch if required
//
ch_bwa_index = Channel.empty()
if (prepare_tool_index == 'bwa') {
if (bwa_index) {
if (bwa_index.endsWith('.tar.gz')) {
ch_bwa_index = UNTAR_BWA_INDEX([[:], bwa_index]).untar
ch_versions = ch_versions.mix(UNTAR_BWA_INDEX.out.versions)
} else {
ch_bwa_index = [[:], file(bwa_index)]
}
} else {
ch_bwa_index = BWA_INDEX(ch_fasta.map { [[:], it] }).index
ch_versions = ch_versions.mix(BWA_INDEX.out.versions)
}
}
//
// Uncompress Bowtie2 index or generate from scratch if required
//
ch_bowtie2_index = Channel.empty()
if (prepare_tool_index == 'bowtie2') {
if (bowtie2_index) {
if (bowtie2_index.endsWith('.tar.gz')) {
ch_bowtie2_index = UNTAR_BOWTIE2_INDEX([[:], bowtie2_index]).untar
ch_versions = ch_versions.mix(UNTAR_BOWTIE2_INDEX.out.versions)
} else {
ch_bowtie2_index = [[:], file(bowtie2_index)]
}
} else {
ch_bowtie2_index = BOWTIE2_BUILD(ch_fasta.map { [[:], it] }).index
ch_versions = ch_versions.mix(BOWTIE2_BUILD.out.versions)
}
}
//
// Uncompress CHROMAP index or generate from scratch if required
//
ch_chromap_index = Channel.empty()
if (prepare_tool_index == 'chromap') {
if (chromap_index) {
if (chromap_index.endsWith('.tar.gz')) {
ch_chromap_index = UNTARFILES([[:], chromap_index]).files
ch_versions = ch_versions.mix(UNTARFILES.out.versions)
} else {
ch_chromap_index = [[:], file(chromap_index)]
}
} else {
ch_chromap_index = CHROMAP_INDEX(ch_fasta.map { [[:], it] }).index
ch_versions = ch_versions.mix(CHROMAP_INDEX.out.versions)
}
}
//
// Uncompress STAR index or generate from scratch if required
//
ch_star_index = Channel.empty()
if (prepare_tool_index == 'star') {
if (star_index) {
if (star_index.endsWith('.tar.gz')) {
ch_star_index = UNTAR_STAR_INDEX([[:], star_index]).untar.map { it[1] }
ch_versions = ch_versions.mix(UNTAR_STAR_INDEX.out.versions)
} else {
ch_star_index = Channel.value(file(star_index))
}
} else {
ch_star_index = STAR_GENOMEGENERATE(ch_fasta, ch_gtf).index
ch_versions = ch_versions.mix(STAR_GENOMEGENERATE.out.versions)
}
}
emit:
fasta = ch_fasta // path: genome.fasta
fai = ch_fai // path: genome.fai
gtf = ch_gtf // path: genome.gtf
gene_bed = ch_gene_bed // path: gene.bed
chrom_sizes = ch_chrom_sizes // path: genome.sizes
filtered_bed = ch_genome_filtered_bed // path: *.include_regions.bed
bwa_index = ch_bwa_index // path: bwa/index/
bowtie2_index = ch_bowtie2_index // path: bowtie2/index/
chromap_index = ch_chromap_index // path: genome.index
star_index = ch_star_index // path: star/index/
versions = ch_versions.ifEmpty(null) // channel: [ versions.yml ]
}