-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
219 lines (155 loc) · 6.33 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
#!/usr/bin/env nextflow
/*
Authors:
- Katie Evans <[email protected]>
- Mike Sauria <[email protected]>
*/
nextflow.enable.dsl=2
date = new Date().format( 'yyyyMMdd' )
contigs = Channel.of("I","II","III","IV","V","X")
params.cores = 4
// imputation parameters
// try same window for all chromosomes, if errors might need to adjust. ce had different param for X and for autosomes
// "window,overlap"
params.chrI = "5,2"
params.chrII = "5,2"
params.chrIII = "5,2"
params.chrIV = "5,2"
params.chrV = "5,2"
params.chrX = "5,2"
// set debug mode
if(params.debug) {
println """
*** Using debug mode ***
"""
params.vcf = "${workflow.projectDir}/test_data/WI.20201230.hard-filter.vcf.gz"
params.out = "impute-${date}-debug"
params.species = "c_elegans"
} else {
params.out = "impute-${date}"
// Check inputs
if ( params.vcf==null ) error "Parameter --vcf is required. Specify path to the full vcf."
if ( params.species==null) error "Parameter --species is required. Please provide species c_elegans, c_tropicalis or c_briggsae"
}
def log_summary() {
/*
Generates a log
*/
out = '''
########## # ##
## ##### # #
## # #
## # ## ## ### # # # ## # ## ####
## # # # # # # # # # # ### # # #
## # # # # # # # # ### # # #
## # # # # # # # # # # # #
########## # # # ### ### # ### # # #
#
#
#
Subset isotype reference strains from hard-filter vcf, create SNV-only VCF and impute VCF.
''' + """
nextflow -latest andersenlab/impute-nf --debug
nextflow -latest andersenlab/impute-nf --vcf=hard-filtered.vcf --sample_sheet=sample_sheet.tsv --species=c_elegans
parameters description Set/Default
========== =========== ========================
--debug Set to 'true' to test ${params.debug}
--species Species: 'c_elegans', 'c_tropicalis' or 'c_briggsae' ${params.species}
--vcf hard filtered vcf to calculate variant density ${params.vcf}
--out (Optional) output folder name ${params.out}
--chrI | chrII | chrIII, Window and overlap for each chromosome I:${params.chrI} | II:${params.chrII} | III:${params.chrIII} | IV:${params.chrIV} | V:${params.chrV} | X:${params.chrX}
chrIV | chrV | chrX
}
username ${"whoami".execute().in.text}
HELP: http://andersenlab.org/dry-guide/pipelines/pipeline-impute/
----------------------------------------------------------------------------------------------
Git info: $workflow.repository - $workflow.revision [$workflow.commitId]
"""
out
}
log.info(log_summary())
if (params.help) {
exit 1
}
// prepare inputs
input_vcf = Channel.fromPath("${params.vcf}")
input_vcf_index = Channel.fromPath("${params.vcf}.tbi")
workflow {
// impute vcf
input_vcf.combine(input_vcf_index) | subset_snv
contigs.combine(subset_snv.out) | imputation
imputation.out
.flatten()
.toSortedList() | concat_imputed
}
/*==============================================
~ ~ ~ > * Impute hard filter VCF * < ~ ~ ~
==============================================*/
process subset_snv {
publishDir "${params.out}/variation", mode: 'copy'
input:
tuple file(hardvcf), file(hardvcf_index)
output:
tuple file("WI.${date}.hard-filter.isotype.SNV.vcf.gz"), file("WI.${date}.hard-filter.isotype.SNV.vcf.gz.tbi")
"""
bcftools view -O u ${hardvcf} | \
bcftools view -O v --types snps --min-af 0.000001 --max-af 0.999999 | \
vcffixup - | \
bcftools view --threads=${task.cpus} -O z > WI.${date}.hard-filter.isotype.SNV.vcf.gz
bcftools index --tbi WI.${date}.hard-filter.isotype.SNV.vcf.gz
"""
}
// going to need different chr maps for different species.
process imputation {
//errorStrategy 'ignore'
tag {CHROM}
label "ml"
input:
tuple val(CHROM), file(hardvcf), file(hardvcf_index)
output:
tuple file("${CHROM}.b5.vcf.gz"), file("${CHROM}.b5.vcf.gz.csi")
"""
# get window and overlap parameters
if [ ${CHROM} == "I" ]
then
win=`echo "${params.chrI}" | cut -d ',' -f 1`
ov=`echo "${params.chrI}" | cut -d ',' -f 2`
elif [ ${CHROM} == "II" ]
then
win=`echo "${params.chrII}" | cut -d ',' -f 1`
ov=`echo "${params.chrII}" | cut -d ',' -f 2`
elif [ ${CHROM} == "III" ]
then
win=`echo "${params.chrIII}" | cut -d ',' -f 1`
ov=`echo "${params.chrIII}" | cut -d ',' -f 2`
elif [ ${CHROM} == "IV" ]
then
win=`echo "${params.chrIV}" | cut -d ',' -f 1`
ov=`echo "${params.chrIV}" | cut -d ',' -f 2`
elif [ ${CHROM} == "V" ]
then
win=`echo "${params.chrV}" | cut -d ',' -f 1`
ov=`echo "${params.chrV}" | cut -d ',' -f 2`
else
win=`echo "${params.chrX}" | cut -d ',' -f 1`
ov=`echo "${params.chrX}" | cut -d ',' -f 2`
fi
beagle chrom=${CHROM} window=\$win overlap=\$ov impute=true ne=100000 nthreads=${task.cpus} imp-segment=0.5 imp-step=0.01 cluster=0.0005 gt=${hardvcf} map=${workflow.projectDir}/bin/${params.species}/chr${CHROM}.map out=${CHROM}.b5
bcftools index ${CHROM}.b5.vcf.gz
"""
}
process concat_imputed {
//errorStrategy 'ignore'
publishDir "${params.out}/variation/", mode: 'copy'
label "ml"
input:
file("*")
output:
tuple file("WI.${date}.impute.isotype.vcf.gz"), file("WI.${date}.impute.isotype.vcf.gz.tbi")
"""
bcftools concat *.b5.vcf.gz > WI.${date}.impute.isotype.vcf
bgzip WI.${date}.impute.isotype.vcf
bcftools index -t WI.${date}.impute.isotype.vcf.gz
bcftools stats --verbose WI.${date}.impute.isotype.vcf.gz > WI.${date}.impute.isotype.stats.txt
"""
}