forked from darcyabjones/snptree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
executable file
·215 lines (161 loc) · 4.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
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
#!/usr/bin/env nextflow
params.vcf = "$baseDir/data/filtered_ann.vcf.gz"
params.genes = "$baseDir/data/SN15v9_OM_ChromOnly.gff3"
params.bed = "$baseDir/data/single_97pc_regions.bedgraph"
vcfFile = file(params.vcf)
bedFile = file(params.bed)
process applyFilters {
container "quay.io/biocontainers/bcftools:1.9--h4da6232_0"
input:
file vcf from vcfFile
output:
file "${vcf.baseName}_filtered.vcf" into filteredVcf
"""
bcftools view --types snps ${vcf} \
| bcftools view -f".,PASS" -O v - \
| uniq \
> "${vcf.baseName}_filtered.vcf"
"""
}
process intersectVcfBed {
container "quay.io/biocontainers/bedtools:2.27.1--1"
publishDir "intersectBedVcf"
input:
file vcf from filteredVcf
file bed from bedFile
output:
file "${vcf.baseName}_intersect.vcf" into intersectedVcf
"""
bedtools intersect -a ${vcf} -b ${bed} -u -header | uniq > ${vcf.baseName}_intersect.vcf
"""
}
process selectInformative {
container "quay.io/biocontainers/snpsift:4.3.1t--1"
publishDir "selectInformative"
input:
file vcf from intersectedVcf
output:
file "${vcf.baseName}_informative.vcf" into informativeVcf
"""
SnpSift filter "(ANN[*].EFFECT == 'missense_variant') || (ANN[*].EFFECT == 'synonymous_variant')" ${vcf} > "${vcf.baseName}_informative.vcf"
"""
}
process snpToFasta {
container "quay.io/biocontainers/vcfkit:0.1.6--py27h24bf2e0_2"
publishDir "snpToFasta"
input:
file vcf from informativeVcf
output:
file "${vcf.baseName}.fasta" into informativeFasta
"""
vk phylo fasta ${vcf} > ${vcf.baseName}.fasta
"""
}
process variantFasta {
container "quay.io/biocontainers/biopython:1.70--np112py36_1"
publishDir "snpToFasta"
input:
file vcf from informativeFasta
output:
file "${vcf.baseName}_variant.fasta" into varFasta
"""
#!/usr/bin/env python3
from Bio import AlignIO
msa = AlignIO.read("${vcf}", format="fasta")
to_kill = []
for i, col in enumerate(zip(*msa)):
col = list(filter(lambda x: x in ('A', 'T', 'G', 'C'), col))
if all(col[0] == base for base in col[1:]):
to_kill.append(i)
# Later we add +1 to i so use -1 to get 0.
to_kill.insert(0, -1)
to_kill.append(msa.get_alignment_length())
# Run through the columns and construct new msa excluding killed sites.
sub_msas = None
for i, j in zip(to_kill, to_kill[1:]):
i = i + 1
if i == j:
continue
if sub_msas is None:
sub_msas = msa[:, i:j]
else:
sub_msas += msa[:, i:j]
AlignIO.write(sub_msas, "${vcf.baseName}_variant.fasta", format="fasta")
"""
}
process tree {
container "quay.io/biocontainers/raxml:8.2.10--h470a237_1"
publishDir "tree"
input:
file fasta from varFasta
output:
file "RAxML_bootstrap.${fasta.baseName}" into bootstrapFile
"""
raxmlHPC-PTHREADS \
-T 15 \
-p 12345 \
-b 12345 \
-f d \
-# autoMRE \
-m ASC_GTRCAT \
--asc-corr=lewis \
-s ${fasta} \
-n ${fasta.baseName}
"""
}
process consensus {
container "quay.io/biocontainers/raxml:8.2.10--h470a237_1"
publishDir "tree"
input:
file trees from bootstrapFile
output:
file "RAxML_MajorityRuleExtendedConsensusTree.consensus" into consensusTree
"""
raxmlHPC-PTHREADS \
-T 15 \
-J MRE \
-z ${tree} \
-m ASC_GTRCAT \
--asc-corr=lewis \
-n "consensus"
"""
}
process ml {
container "quay.io/biocontainers/raxml:8.2.10--h470a237_1"
publishDir "tree"
input:
output:
file "RAxML_bestTree.likelihoods" into bestTreeFile
file "RAxML_result.likelihoods.RUN.*" into resultFile
file "RAxML_parsimonyTree.likelihoods.RUN.*" into parsimonyFile
# most likely tree
"""
raxmlHPC-PTHREADS \
-T 16 \
-f d \
-m ASC_GTRCAT \
-asc-corr=lewis \
-n likelihoods \
-s ${fasta} \
-p 12345 \
-# 50
"""
}
process annot {
container "quay.io/biocontainers/raxml:8.2.10--h470a237_1"
publishDir "tree"
input:
output:
file "RAxML_bipartitions.best_annotated" into
file "RAxML_bipartitionsBranchLabels.best_annotated"
"""
raxmlHPC-PTHREADS \
-T 15 \
-f b \
-m ASC_GTRCAT \
--asc-corr=lewis \
-z bootstrapped_trees \
-t best_tree \
-n bs_tree
"""
}