-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSnakefile
250 lines (228 loc) · 9.09 KB
/
Snakefile
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
###########################################################################
# Genome annotation pipeline using Funannotate in Snakemake
# Snakemake/5.13.0
###########################################################################
from os.path import join
from snakemake.io import expand, glob_wildcards
from Bio import SeqIO
result_dir = config["result_dir"]
input_dir = config["input_dir"]
repeat_file = config["repeat_file"]
protein_file = config["protein_file"]
transcript_file = config["transcript_file"]
alt_transcript_file = config["alt_transcript_file"]
funannotate_dir = config["funannotate_dir"]
augustus="caenorhabditis",
#SAMPLE = ["pilon124_round3_chromosomesnumbered"]
SAMPLE = list(glob_wildcards(join(input_dir, "{ids}.fasta")))[0]
#ID = glob_wildcards(join(fastq_dir, "{ids}.fastq.gz"))
print(SAMPLE)
rule All:
input:
# Repeats
#expand(join(input_dir,"{samples}-families.fa"),samples=SAMPLE),
#expand(join(result_dir,"{samples}/{samples}-families.fa"),samples=SAMPLE),
#expand(join(result_dir,"{samples}/{samples}.cleaned.sorted.fasta.masked"),samples=SAMPLE),
#expand(join(result_dir,"{samples}/{samples}.cleaned.sorted.fasta.out.gff"),samples=SAMPLE),
# Funannotate - preprocessing
#expand(join(result_dir,"{samples}/{samples}.cleaned.sorted.fasta"),samples=SAMPLE),
#expand(join(result_dir,"{samples}/{samples}.CSM.fasta"),samples=SAMPLE),
# Maker ctrl files
expand(join(result_dir,"{samples}/maker_opts_rnd1.ctl"),samples=SAMPLE),
expand(join(result_dir,"{samples}/maker_opts_rnd2.ctl"),samples=SAMPLE),
expand(join(result_dir,"{samples}/maker_opts_rnd3.ctl"),samples=SAMPLE),
expand(join(result_dir,"{samples}/rnd1.maker.output/rnd1_master_datastore_index.log"),samples=SAMPLE),
expand(join(result_dir,"{samples}/rnd2.maker.output/rnd2_master_datastore_index.log"),samples=SAMPLE),
expand(join(result_dir,"{samples}/rnd3.maker.output/rnd3_master_datastore_index.log"),samples=SAMPLE),
# Maker GFFs
expand(join(result_dir,"{samples}/rnd1.maker.output/rnd1.all.gff"),samples=SAMPLE),
expand(join(result_dir,"{samples}/rnd1.maker.output/snap/rnd1.snap.hmm"),samples=SAMPLE),
expand(join(result_dir,"{samples}/rnd2.maker.output/rnd2.all.gff"),samples=SAMPLE),
expand(join(result_dir,"{samples}/rnd3.maker.output/rnd3.all.gff"),samples=SAMPLE),
#rule RepeatModeler:
# input:
# fa=join(input_dir,"{samples}.fasta"),
# output:
# fa=join(input_dir,"{samples}-families.fa"),
# rep=join(result_dir,"{samples}/{samples}-families.fa"),
# params:
# rname="RepeatModeler",
# dir=input_dir,
# id="{samples}",
# opdir=join(result_dir,"{samples}"),
# threads:
# 48
# shell:
# """
# mkdir -p {params.opdir}
# cd {params.dir}
# module load repeatmodeler
# BuildDatabase -name {params.id} {input.fa}
# RepeatModeler -database {params.id} -pa {threads} -LTRStruct >& {params.id}.out
# cp {output.fa} {output.rep}
# """
#rule RepeatMasker:
# input:
# fa=join(result_dir,"{samples}/{samples}.cleaned.sorted.fasta"),
# rep=join(result_dir,"{samples}/{samples}-families.fa"),
# output:
# fa=join(result_dir,"{samples}/{samples}.cleaned.sorted.fasta.masked"),
# gff=join(result_dir,"{samples}/{samples}.cleaned.sorted.fasta.out.gff"),
# params:
# rname="RepeatMasker",
# dir=join(result_dir,"{samples}"),
# #rep=repeat_file,
# threads="48",
# shell:
# """
# cd {params.dir}
# module load repeatmasker
# RepeatMasker -u -s -poly -engine rmblast -pa {params.threads} -gff -no_is -gccalc -norna -lib {input.rep} {input.fa}
# """
rule maker_opts1:
input:
fa=join(result_dir,"{samples}/{samples}.fasta"),
output:
ctl=join(result_dir,"{samples}/maker_opts_rnd1.ctl"),
params:
rname="maker_opts1",
protein=protein_file,
transcript=transcript_file,
alt_transcript=alt_transcript_file,
augustus=augustus,
scripts_path=join(result_dir,"param_files"),
outdir=join(result_dir,"{samples}"),
shell:
"""
mkdir -p {params.outdir}
python3 {params.scripts_path}/generate_opts1.py {output.ctl} {input.fa} {params.protein} {params.transcript} {params.augustus} {params.alt_transcript}
"""
rule maker_rnd1:
input:
fa=join(result_dir,"{samples}/{samples}.fasta"),
ctl=join(result_dir,"{samples}/maker_opts_rnd1.ctl"),
output:
log=join(result_dir,"{samples}/rnd1.maker.output/rnd1_master_datastore_index.log"),
params:
rname="maker_rnd1",
outid="rnd1",
outdir=join(result_dir,"{samples}"),
bopts=join(result_dir,"param_files/maker_bopts.log"),
exe=join(result_dir,"param_files/maker_exe.log"),
shell:
"""
module load maker
cd {params.outdir}
mpiexec -np 80 maker -RM_off -base {params.outid} {input.ctl} {params.bopts} {params.exe}
"""
rule make_gff1:
input:
log=join(result_dir,"{samples}/rnd1.maker.output/rnd1_master_datastore_index.log"),
output:
gff=join(result_dir,"{samples}/rnd1.maker.output/rnd1.all.gff"),
snap=join(result_dir,"{samples}/rnd1.maker.output/snap/rnd1.snap.hmm"),
params:
rname="make_gff1",
outdir=join(result_dir,"{samples}"),
shell:
"""
module load maker snap
cd {params.outdir}/rnd1.maker.output/
gff3_merge -d {input.log}
mkdir -p {params.outdir}/rnd1.maker.output/snap
cd {params.outdir}/rnd1.maker.output/snap
maker2zff -x 0.5 -l 50 -c 0 -e 0 -o 0 -d {input.log}
fathom genome.ann genome.dna -gene-stats > gene-stats.log
fathom genome.ann genome.dna -validate > validate.log
fathom genome.ann genome.dna -categorize 1000 > categorize.log
fathom uni.ann uni.dna -export 1000 -plus > uni-plus.log
mkdir -p params
cd params
forge ../export.ann ../export.dna > ../forge.log
cd ..
hmm-assembler.pl genome params > {output.snap}
"""
rule maker_opts2:
input:
fa=join(result_dir,"{samples}/{samples}.fasta"),
gff=join(result_dir,"{samples}/rnd1.maker.output/rnd1.all.gff"),
snap=join(result_dir,"{samples}/rnd1.maker.output/snap/rnd1.snap.hmm"),
output:
ctl2=join(result_dir,"{samples}/maker_opts_rnd2.ctl"),
ctl3=join(result_dir,"{samples}/maker_opts_rnd3.ctl"),
params:
rname="maker_opts2",
protein=protein_file,
transcript=transcript_file,
scripts_path=join(result_dir,"param_files"),
outdir=join(result_dir,"{samples}"),
shell:
"""
mkdir -p {params.outdir}
python3 {params.scripts_path}/generate_opts2.py {output.ctl2} {input.fa} {input.gff} {input.snap} {params.protein} {params.transcript}
python3 {params.scripts_path}/generate_opts3.py {output.ctl3} {input.fa} {input.gff} {input.snap} {params.protein} {params.transcript}
"""
rule maker_rnd2:
input:
fa=join(result_dir,"{samples}/{samples}.fasta"),
ctl=join(result_dir,"{samples}/maker_opts_rnd2.ctl"),
output:
log=join(result_dir,"{samples}/rnd2.maker.output/rnd2_master_datastore_index.log"),
params:
rname="maker_rnd2",
outid="rnd2",
outdir=join(result_dir,"{samples}"),
bopts=join(result_dir,"param_files/maker_bopts.log"),
exe=join(result_dir,"param_files/maker_exe.log"),
shell:
"""
module load maker
cd {params.outdir}
valgrind mpiexec -c 1 -np 40 maker -RM_off -base {params.outid} {input.ctl} {params.bopts} {params.exe}
"""
rule make_gff2:
input:
log=join(result_dir,"{samples}/rnd2.maker.output/rnd2_master_datastore_index.log"),
output:
gff=join(result_dir,"{samples}/rnd2.maker.output/rnd2.all.gff"),
params:
rname="make_gff2",
outdir=join(result_dir,"{samples}"),
shell:
"""
module load maker snap
cd {params.outdir}/rnd2.maker.output/
gff3_merge -d {input.log}
"""
rule maker_rnd3:
input:
fa=join(result_dir,"{samples}/{samples}.fasta"),
ctl=join(result_dir,"{samples}/maker_opts_rnd3.ctl"),
output:
log=join(result_dir,"{samples}/rnd3.maker.output/rnd3_master_datastore_index.log"),
params:
rname="maker_rnd3",
outid="rnd2",
outdir=join(result_dir,"{samples}"),
bopts=join(result_dir,"param_files/maker_bopts.log"),
exe=join(result_dir,"param_files/maker_exe.log"),
shell:
"""
module load maker
cd {params.outdir}
valgrind mpiexec -c 1 -np 40 maker -RM_off -base {params.outid} {input.ctl} {params.bopts} {params.exe}
"""
rule make_gff3:
input:
log=join(result_dir,"{samples}/rnd3.maker.output/rnd3_master_datastore_index.log"),
output:
gff=join(result_dir,"{samples}/rnd3.maker.output/rnd3.all.gff"),
params:
rname="make_gff3",
outdir=join(result_dir,"{samples}"),
shell:
"""
module load maker snap
cd {params.outdir}/rnd3.maker.output/
gff3_merge -d {input.log}
"""