-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
executable file
·187 lines (173 loc) · 6.47 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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
/*
* Import sub-workflows
*/
include {helpMessage} from './include/process/help'
include { PREPROCESS } from './include/workflow/vcfpreprocess'
include { ANCESTRAL } from './include/workflow/ancestral'
include { MUTYPER } from './include/workflow/mutyper'
include { RELATE } from './include/workflow/relate'
include { SDM } from './include/workflow/sdm'
include { GONE } from './include/workflow/gone'
include { IBD } from './include/workflow/ibd'
include { CONSTRAINED } from './include/workflow/phylop'
include { get_masks } from './include/process/prerun'
include { chromosomeList } from './include/process/prerun'
// Run workflows
workflow {
// Show help message
if (params.help) {
helpMessage()
exit 0
}
// Print run informations
log.info '''\
=================================================================================
.-') _ .-') _ (`-. ('-. .-') _ _ .-') ('-.
( OO ) ) ( OO ). ( (OO ) _( OO) ( OO) ) ( \\( -O ) ( OO ).-.
,--./ ,--,' (_)---\\_)_.` \\(,------. .-----./ '._ ,------. / . --. /
| \\ | |\\ / _ |(__...--'' | .---' ' .--./|'--...__)| /`. ' | \\-. \\
| \\| | )\\ :` `. | / | | | | | |('-.'--. .--'| / | |.-'-' | |
| . |/ '..`''.)| |_.' |(| '--. /_) |OO ) | | | |_.' | \\| |_.' |
| |\\ | .-._) \\| .___.' | .--' || |`-'| | | | . '.' | .-. |
| | \\ | \\ /| | | `---.(_' '--'\\ | | | |\\ \\ | | | |
`--' `--' `-----' `--' `------' `-----' `--' `--' '--' `--' `--'
=================================================================================
'''
log.info """\
Nextflow Mutation Spectra v${workflow.manifest.version}
=================================================================================
variants : $params.variants
idx : $params.idx
output folder : $params.outdir
hal : $params.hal
reference : $params.reference
target : $params.target
mutyper : $params.mutyper
sdm : $params.sdm
relate : $params.relate
species : $params.species
k : $params.k
Ne subset : $params.ne_subset
Intergen. time : $params.intergen_time
Mut. rate : $params.mutation_rate
Min. pop. size : $params.min_pop_size
imputation sfw : $params.imputation
coding : $params.coding
noncoding : $params.noncoding
annotation : $params.annotation
pops_folder : $params.pops_folder
pop labels file : $params.poplabels
chromosome list : $params.chr_list
cactus url : $params.cactus_url
exons : $params.exon_bed
constrained : $params.constrained
relate dir : $params.relate"""
if (params.neval){
log.info """Ne value : $params.neval"""
}
if (params.ancestral_fna){
log.info """ancestral : $params.ancestral_fna"""
}
if (params.reference_fna){
log.info """reference fasta : $params.reference_fna"""
}
if (params.mask){
log.info """mask : $params.mask"""
}
if (params.beagle){
log.info """beagle path : $params.beagle"""
}
if (params.shapeit){
log.info """shapeit path : $params.shapeit"""
}
if (params.custom_vep){
log.info """VEP gff annot. : $params.gff"""
} else {
log.info """VEP cache : $params.vep_cache"""
}
if (params.ancestral_only){
log.info """
Running generation of ancestral genome only
"""
}
/* Check mandatory params */
if (params.variants && !params.ancestral_only) {
if (!file(params.variants).exists()) { exit 1, 'Vcf file not found!' }
ch_var = Channel.fromPath(params.variants)
} else {
exit 1, 'Vcf file not specified!'
}
if (params.idx && !params.ancestral_only) {
if (!file(params.idx).exists()) { exit 1, 'Vcf file index not found!' }
ch_var_idx = Channel.fromPath(params.idx)
} else {
if (file("${params.vcf}.tbi").exists()) {
ch_var_idx = Channel.fromPath("${params.vcf}.tbi")
} else {
exit 1, 'TBI file not specified!'
}
}
if (!params.hal) { exit 1, 'Hal file not specified and ancestral not specified!' }
if (!params.hal && !params.reference_fna && !params.ancestral_fna) { exit 1, 'Ancestral and reference genomes not specified!' }
if (params.constrained && !params.exon_bed) { exit 1, 'Requested hal4d algorithm, but no bed with exons specified!' }
if (!params.species){ throw new Exception("Parameter --species is required for file naming.") }
// Generate the ancestral fasta
ANCESTRAL()
reference_fna = ANCESTRAL.out.ref_fna
reference_fai = ANCESTRAL.out.ref_fai
ancestral_fna = ANCESTRAL.out.anc_fna
ancestral_fai = ANCESTRAL.out.anc_fai
if (!params.ancestral_only){
// Fetch mask files
if (!params.mask){
get_masks( reference_fna )
ch_masks = get_masks.out
} else {
ch_masks = file(params.mask)
}
// Pre-process the variants of interest
if (!params.vcf_is_filtered){
PREPROCESS ( ch_var, ch_var_idx, reference_fna, reference_fai, ancestral_fna, ancestral_fai, ch_masks )
ch_var_new = PREPROCESS.out.vcf
ch_var_idx_new = PREPROCESS.out.tbi
ch_chr_lists = PREPROCESS.out.chroms
vcf_by_chr = PREPROCESS.out.vcf_by_chr
vcf_chunks_ch = PREPROCESS.out.chunks_ch
// Get constrined elements and remove variants in them
if ( params.constrained ){
CONSTRAINED(ch_var_new, ch_var_idx_new, ch_chr_lists)
ch_var_new = CONSTRAINED.out[0]
ch_var_idx_new = CONSTRAINED.out[1]
}
// Generate IBDs if requested
if (params.compute_ibd){
IBD(ch_var_new, ch_var_idx_new, ch_chr_lists)
}
} else {
ch_var_new = ch_var
ch_var_idx_new = ch_var_idx
chromosomeList( ch_var, ch_var_idx )
ch_chr_lists = chromosomeList.out
| combine(
ch_var_new
| combine( ch_var_idx )
)
}
// Run GONE to calculate Ne, if requested
if (params.gone){
GONE( ch_var_new, ch_var_idx_new )
}
// Run the actual mutation spectra
if (params.relate){
RELATE( ch_var_new, ch_var_idx_new, ancestral_fna, ancestral_fai, ch_chr_lists, ch_masks )
}
if (params.mutyper){
MUTYPER( ancestral_fna, ancestral_fai, ch_masks, vcf_by_chr )
}
if (params.sdm){
SDM( vcf_by_chr, reference_fna, reference_fai, ch_masks, ch_chr_lists )
}
}
}