-
Notifications
You must be signed in to change notification settings - Fork 2
/
Snakefile
752 lines (667 loc) · 23.4 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
from glob import glob
import pandas as pd
from snakemake.utils import min_version
min_version("6.0")
if config.get("run_score_assemblies", False):
module score_assemblies:
snakefile:
# "score-assemblies/Snakefile"
github("pmenzel/score-assemblies", path="Snakefile", branch="master")
config:
config
use rule * from score_assemblies as score_assemblies_*
ruleorder: proovframe_diamond_index > score_assemblies_diamond_ref_makedb
filtlong_min_read_length = "1000"
if config.get("filtlong_min_read_length", False):
filtlong_min_read_length = config["filtlong_min_read_length"]
print("filtlong min. read length = " + str(filtlong_min_read_length))
medaka_model = None
if config.get("medaka_model", False):
medaka_model = config["medaka_model"]
print("Medaka model = " + medaka_model)
map_medaka_model = None
if config.get("map_medaka_model", False):
medaka_model_file = config["map_medaka_model"]
table = pd.read_csv(medaka_model_file, sep="\t", lineterminator="\n", header=None)
map_medaka_model = dict(zip(table[0], table[1]))
# this option is needed by Canu
target_genome_size = None
if config.get("genome_size", False):
target_genome_size = config["genome_size"]
print("Target genome size = " + str(target_genome_size) + "M")
wildcard_constraints:
sample=r"[^_]+",
assembly=r"[^_]+",
sample_assembly=r"[^/]+",
num=r"[0-9]+",
def get_ont_fq(wildcards):
if "filtlong" in wildcards.sample:
return "fastq-ont/" + wildcards.sample + ".fastq"
elif "rasusa" in wildcards.sample:
return "fastq-ont/" + wildcards.sample + ".fastq"
else:
return glob("fastq-ont/" + wildcards.sample + ".fastq*")
# use split("+")[0] here for removing the +filtlong... or +rasusa... suffices from sample names for Illumina reads
def get_R1_fq(wildcards):
return glob("fastq-illumina/" + wildcards.sample.split("+")[0] + "_R1.fastq*")
def get_R2_fq(wildcards):
return glob("fastq-illumina/" + wildcards.sample.split("+")[0] + "_R2.fastq*")
(references,) = glob_wildcards(r"references/{ref,[^/\\]+}.fa")
(references_protein,) = glob_wildcards(r"references-protein/{ref,[^/\\]+}.faa")
(sample_assemblies,) = glob_wildcards(r"assemblies/{sample_assembly,[^/]+}/")
# ignore symlinks in assemblies/folder, e.g. sample_flye.fa -> assemblies/sample_flye/output.fa
sample_assemblies = [a for a in sample_assemblies if not re.search(r"\.fa", a)]
# if config files with list of assemblies is given, then use this instead of folders in assemblies/
if config.get("assemblies", False):
sample_assemblies = list(set(config["assemblies"]))
# if any desired assembly requires homopolish then at least one reference genome should be provided
if not references and [
string for string in sample_assemblies if "homopolish" in string
]:
quit(
"Error: must provide at least one reference genome sequence when using homopolish"
)
# if any desired assembly requires proovframe then at least one reference proteome should be provided
if not references_protein and [
string for string in sample_assemblies if "proovframe" in string
]:
quit(
"Error: must provide at least one reference protein file when using proovframe"
)
# if any desired assembly uses Canu then need to provide target genome size
if not target_genome_size and [
string for string in sample_assemblies if "_canu" in string
]:
quit(
"Error: must provide target genome size when using Canu assembler, use option (e.g. for 5.2Mb): --config genome_size=5.2"
)
list_outputs = expand(
"assemblies/{sample_assembly}/output.fa", sample_assembly=sample_assemblies
)
list_outputs_links = expand(
"assemblies/{sample_assembly}.fa", sample_assembly=sample_assemblies
)
# remove homopolish and proovframe assemblies from default list
list_outputs = [
i for i in list_outputs if not re.search(r"homopolish|proovframe", i, re.IGNORECASE)
]
list_outputs_links = [
i
for i in list_outputs_links
if not re.search("homopolish|proovframe", i, re.IGNORECASE)
]
# make lists for homopolish, one entry for each reference genome
list_outputs_homopolish = expand(
"assemblies/{sample_assembly}/output_{ref}.fa",
ref=references,
sample_assembly=[
i for i in sample_assemblies if re.search(r"homopolish$", i, re.IGNORECASE)
],
)
list_outputs_links_homopolish = expand(
"assemblies/{sample_assembly}{ref}.fa",
ref=references,
sample_assembly=[
i for i in sample_assemblies if re.search(r"homopolish$", i, re.IGNORECASE)
],
)
# make lists for proovframe, one entry for each reference protein file
list_outputs_proovframe = expand(
"assemblies/{sample_assembly}/output_{ref}.fa",
ref=references_protein,
sample_assembly=[
i for i in sample_assemblies if re.search(r"proovframe$", i, re.IGNORECASE)
],
)
list_outputs_links_proovframe = expand(
"assemblies/{sample_assembly}{ref}.fa",
ref=references_protein,
sample_assembly=[
i for i in sample_assemblies if re.search(r"proovframe$", i, re.IGNORECASE)
],
)
rule all:
input:
list_outputs,
list_outputs_links,
list_outputs_homopolish,
list_outputs_links_homopolish,
list_outputs_proovframe,
list_outputs_links_proovframe,
rule rasusaMB:
conda:
"env/conda-rasusa.yaml"
threads: 1
input:
fq=get_ont_fq,
output:
"fastq-ont/{sample}+rasusaMB{num}.fastq",
log:
"fastq-ont/{sample}_rasusaMB{num}_log.txt",
benchmark:
"benchmark/{sample}_rasusaMB{num}.txt"
shell:
"""
rasusa --bases {wildcards.num}m -i {input} -o {output} 2>{log}
"""
rule filtlong:
conda:
"env/conda-filtlong.yaml"
threads: 1
input:
fq=get_ont_fq,
output:
"fastq-ont/{sample}+filtlong.fastq",
log:
"fastq-ont/{sample}_filtlong_log.txt",
benchmark:
"benchmark/{sample}_filtlong.txt"
shell:
"""
filtlong --min_length {filtlong_min_read_length} {input} > {output} 2>{log}
"""
rule filtlongMB:
conda:
"env/conda-filtlong.yaml"
threads: 1
input:
fq=get_ont_fq,
output:
"fastq-ont/{sample}+filtlongMB{num}.fastq",
log:
"fastq-ont/{sample}_filtlongMB{num}_log.txt",
benchmark:
"benchmark/{sample}_filtlongMB{num}.txt"
shell:
"""
filtlong --min_length {filtlong_min_read_length} -t {wildcards.num}000000 {input} > {output} 2>{log}
"""
# for keeping num PerCent of the bases
rule filtlongPC:
conda:
"env/conda-filtlong.yaml"
threads: 1
input:
fq=get_ont_fq,
output:
"fastq-ont/{sample}+filtlongPC{num}.fastq",
log:
"fastq-ont/{sample}_filtlongPC{num}_log.txt",
benchmark:
"benchmark/{sample}_filtlongPC{num}.txt"
shell:
"""
filtlong --min_length {filtlong_min_read_length} --keep_percent {wildcards.num} {input} > {output} 2>{log}
"""
rule filtlongMBql:
conda:
"env/conda-filtlong.yaml"
threads: 1
wildcard_constraints:
mb="[0-9]+",
qweight="[0-9]+",
lweight="[0-9]+",
input:
fq=get_ont_fq,
output:
"fastq-ont/{sample}+filtlongMB{mb},{qweight},{lweight}.fastq",
log:
"fastq-ont/{sample}_filtlongMB{mb},{qweight},{lweight}_log.txt",
benchmark:
"benchmark/{sample}_filtlongMB{mb},{qweight},{lweight}.txt"
shell:
"""
filtlong --min_length {filtlong_min_read_length} --mean_q_weight {wildcards.qweight} --length_weight {wildcards.lweight} -t {wildcards.mb}000000 {input} > {output} 2>{log}
"""
rule filtlongMBqln:
conda:
"env/conda-filtlong.yaml"
threads: 1
wildcard_constraints:
mb="[0-9]+",
readlen="[0-9]+",
qweight="[0-9]+",
lweight="[0-9]+",
input:
fq=get_ont_fq,
output:
"fastq-ont/{sample}+filtlongMB{mb},{qweight},{lweight},{readlen}.fastq",
log:
"fastq-ont/{sample}_filtlongMB{mb},{qweight},{lweight},{readlen}_log.txt",
benchmark:
"benchmark/{sample}_filtlongMB{mb},{qweight},{lweight},{readlen}.txt"
shell:
"""
filtlong --min_length {wildcards.readlen} --mean_q_weight {wildcards.qweight} --length_weight {wildcards.lweight} -t {wildcards.mb}000000 {input} > {output} 2>{log}
"""
rule miniasm:
conda:
"env/conda-miniasm.yaml"
threads: 5
resources:
mem_mb=12000,
input:
fqont=get_ont_fq,
output:
fa="assemblies/{sample}_miniasm/output.fa",
paf=temp("assemblies/{sample}_miniasm/minimap2_overlap.paf"),
gfa="assemblies/{sample}_miniasm/minimap2_miniasm.gfa",
link="assemblies/{sample}_miniasm.fa",
log:
"assemblies/{sample}_miniasm/log.txt",
benchmark:
"benchmark/{sample}_miniasm.txt"
shell:
"""
minimap2 -x ava-ont -t {threads} {input} {input} > {output.paf} 2>{log}
miniasm -f {input} {output.paf} > {output.gfa} 2>>{log}
perl -lsane 'print ">$F[1]\n$F[2]" if $F[0] =~ /S/;' {output.gfa} > {output.fa} 2>>{log}
ln -sr {output.fa} {output.link}
"""
rule unicycler:
conda:
"env/conda-unicycler.yaml"
threads: 10
resources:
mem_mb=12000,
input:
fqont=get_ont_fq,
fq1=get_R1_fq,
fq2=get_R2_fq,
output:
fa="assemblies/{sample}_unicycler/output.fa",
link="assemblies/{sample}_unicycler.fa",
log:
"assemblies/{sample}_unicycler/log.txt",
benchmark:
"benchmark/{sample}_unicycler.txt"
shell:
"""
# del spades folder if already exists (e.g. when workflow was canceled), so that it does not warn about it upon restart
[ -d "assemblies/{wildcards.sample}_unicycler/spades_assembly" ] && rm -r "assemblies/{wildcards.sample}_unicycler/spades_assembly" >{log}
unicycler -1 {input.fq1} -2 {input.fq2} -l {input.fqont} -t {threads} --keep 0 -o assemblies/{wildcards.sample}_unicycler/ >>{log} 2>&1
cp assemblies/{wildcards.sample}_unicycler/assembly.fasta {output.fa} 2>>{log}
ln -sr {output.fa} {output.link}
"""
# flye with default number of polishing rounds (=1 in flye v2.9)
rule flye:
conda:
"env/conda-flye.yaml"
threads: 5
resources:
mem_mb=12000,
input:
fq=get_ont_fq,
output:
fa="assemblies/{sample}_flye/output.fa",
link="assemblies/{sample}_flye.fa",
log:
"assemblies/{sample}_flye/log.txt",
benchmark:
"benchmark/{sample}_flye.txt"
shell:
"""
flye --nano-raw {input.fq} -o assemblies/{wildcards.sample}_flye/ -t {threads} 2>{log}
mv assemblies/{wildcards.sample}_flye/assembly.fasta {output.fa}
ln -sr {output.fa} {output.link}
"""
rule flyeX:
conda:
"env/conda-flye.yaml"
threads: 5
resources:
mem_mb=12000,
input:
fq=get_ont_fq,
output:
fa="assemblies/{sample}_flye{num}/output.fa",
link="assemblies/{sample}_flye{num}.fa",
log:
"assemblies/{sample}_flye{num}/log.txt",
benchmark:
"benchmark/{sample}_flye{num}.txt"
shell:
"""
flye --nano-raw {input.fq} -o assemblies/{wildcards.sample}_flye{wildcards.num}/ -t {threads} -i {wildcards.num} 2>{log}
mv assemblies/{wildcards.sample}_flye{wildcards.num}/assembly.fasta {output.fa}
ln -sr {output.fa} {output.link}
"""
# flye for high quality ONT reads (from flye 2.9), with default number of polishing rounds (=1 in flye v2.9)
rule flyehq:
conda:
"env/conda-flye.yaml"
threads: 5
resources:
mem_mb=12000,
input:
fq=get_ont_fq,
output:
fa="assemblies/{sample}_flyehq/output.fa",
link="assemblies/{sample}_flyehq.fa",
log:
"assemblies/{sample}_flyehq/log.txt",
benchmark:
"benchmark/{sample}_flyehq.txt"
shell:
"""
flye --nano-hq {input.fq} -o assemblies/{wildcards.sample}_flyehq/ -t {threads} 2>{log}
mv assemblies/{wildcards.sample}_flyehq/assembly.fasta {output.fa}
ln -sr {output.fa} {output.link}
"""
rule flyehqX:
conda:
"env/conda-flye.yaml"
threads: 5
resources:
mem_mb=12000,
input:
fq=get_ont_fq,
output:
fa="assemblies/{sample}_flyehq{num}/output.fa",
link="assemblies/{sample}_flyehq{num}.fa",
log:
"assemblies/{sample}_flyehq{num}/log.txt",
benchmark:
"benchmark/{sample}_flyehq{num}.txt"
shell:
"""
flye --nano-hq {input.fq} -o assemblies/{wildcards.sample}_flyehq{wildcards.num}/ -t {threads} -i {wildcards.num} 2>{log}
mv assemblies/{wildcards.sample}_flyehq{wildcards.num}/assembly.fasta {output.fa}
ln -sr {output.fa} {output.link}
"""
# for running raven with default number of racon-polishing rounds (=2 in raven v0.0.8)
rule raven:
conda:
"env/conda-raven.yaml"
threads: 5
resources:
mem_mb=5000,
input:
fq=get_ont_fq,
output:
fa="assemblies/{sample}_raven/output.fa",
link="assemblies/{sample}_raven.fa",
log:
"assemblies/{sample}_raven/log.txt",
benchmark:
"benchmark/{sample}_raven.txt"
shell:
"""
raven --disable-checkpoints -t {threads} {input.fq} >{output.fa} 2>{log}
ln -sr {output.fa} {output.link}
"""
# for running raven with racon polishing X times
rule ravenX:
conda:
"env/conda-raven.yaml"
threads: 5
resources:
mem_mb=5000,
input:
fq=get_ont_fq,
output:
fa="assemblies/{sample}_raven{num}/output.fa",
link="assemblies/{sample}_raven{num}.fa",
log:
"assemblies/{sample}_raven{num}/log.txt",
benchmark:
"benchmark/{sample}_raven{num}.txt"
shell:
"""
raven --disable-checkpoints -p {wildcards.num} -t {threads} {input.fq} >{output.fa} 2>{log}
ln -sr {output.fa} {output.link}
"""
rule canu:
conda:
"env/conda-canu.yaml"
threads: 5
resources:
mem_mb=12000,
shadow:
"minimal"
input:
fqont=get_ont_fq,
output:
fa="assemblies/{sample}_canu/output.fa",
link="assemblies/{sample}_canu.fa",
log:
"assemblies/{sample}_canu/log.txt",
benchmark:
"benchmark/{sample}_canu.txt"
shell:
"""
canu -nanopore -d assemblies/{wildcards.sample}_canu/ -p output useGrid=false maxThreads={threads} genomeSize={target_genome_size}m {input.fqont} >>{log} 2>&1
cp assemblies/{wildcards.sample}_canu/output.contigs.fasta {output.fa} 2>>{log}
ln -sr {output.fa} {output.link}
"""
# for running racon once
rule racon:
conda:
"env/conda-racon.yaml"
threads: 5
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
fq=get_ont_fq,
output:
fa="assemblies/{sample}_{assembly}+racon/output.fa",
link="assemblies/{sample}_{assembly}+racon.fa",
sam=temp("assemblies/{sample}_{assembly}+racon/map.sam"),
log:
"assemblies/{sample}_{assembly}+racon/log.txt",
benchmark:
"benchmark/{sample}_{assembly}+racon.txt"
shell:
"""
minimap2 -ax map-ont -t {threads} {input.prev_fa} {input.fq} > {output.sam} 2>{log}
racon --threads {threads} --include-unpolished {input.fq} {output.sam} {input.prev_fa} > {output.fa} 2>>{log}
ln -sr {output.fa} {output.link}
"""
# for running racon multiple iterations
rule raconX:
conda:
"env/conda-racon.yaml"
threads: 5
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
fq=get_ont_fq,
output:
fa="assemblies/{sample}_{assembly}+racon{num}/output.fa",
link="assemblies/{sample}_{assembly}+racon{num}.fa",
log:
"assemblies/{sample}_{assembly}+racon{num}/log.txt",
benchmark:
"benchmark/{sample}_{assembly}+racon{num}.txt"
shell:
"""
DIR_temp=$(mktemp -d --suffix=.raconX)
trap "rm -r $DIR_temp" EXIT
cp {input.prev_fa} $DIR_temp/prev.fa
for i in `seq 1 {wildcards.num}`
do
echo "Polishing round $i / {wildcards.num}" >>{log}
minimap2 -ax map-ont -t {threads} $DIR_temp/prev.fa {input.fq} > $DIR_temp/map.sam 2>>{log}
racon --threads {threads} --include-unpolished {input.fq} $DIR_temp/map.sam $DIR_temp/prev.fa > $DIR_temp/polished.fa 2>>{log}
mv $DIR_temp/polished.fa $DIR_temp/prev.fa
done
mv $DIR_temp/prev.fa {output.fa}
ln -sr {output.fa} {output.link}
"""
def get_model_for_sample(wildcards):
if medaka_model is not None:
return "-m " + medaka_model
else:
if map_medaka_model is not None:
sample_base = wildcards.sample.split("+", 1)[0]
if map_medaka_model.get(sample_base, False):
return "-m " + map_medaka_model.get(sample_base, False)
else:
return ""
else:
return ""
rule medaka:
conda:
"env/conda-medaka.yaml"
threads: 5
resources:
mem_mb=12000,
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
fq=get_ont_fq,
output:
fa="assemblies/{sample}_{assembly}+medaka/output.fa",
link="assemblies/{sample}_{assembly}+medaka.fa",
params:
model=get_model_for_sample,
log:
"assemblies/{sample}_{assembly}+medaka/log.txt",
benchmark:
"benchmark/{sample}_{assembly}+medaka.txt"
shell:
"""
medaka_consensus -f -i {input.fq} -d {input.prev_fa} -o assemblies/{wildcards.sample}_{wildcards.assembly}+medaka -t {threads} {params.model} >{log} 2>&1
mv assemblies/{wildcards.sample}_{wildcards.assembly}+medaka/consensus.fasta assemblies/{wildcards.sample}_{wildcards.assembly}+medaka/output.fa
ln -sr {output.fa} {output.link}
"""
rule pilon:
conda:
"env/conda-pilon.yaml"
threads: 5
resources:
mem_mb=12000,
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
fq1=get_R1_fq,
fq2=get_R2_fq,
output:
bam=temp("assemblies/{sample}_{assembly}+pilon/map.bam"),
fa="assemblies/{sample}_{assembly}+pilon/output.fa",
link="assemblies/{sample}_{assembly}+pilon.fa",
log:
"assemblies/{sample}_{assembly}+pilon/log.txt",
benchmark:
"benchmark/{sample}_{assembly}+pilon.txt"
shell:
"""
bwa index -p assemblies/{wildcards.sample}_{wildcards.assembly}+pilon/bwa_index {input.prev_fa} >{log} 2>&1
bwa mem -t {threads} assemblies/{wildcards.sample}_{wildcards.assembly}+pilon/bwa_index {input.fq1} {input.fq2} 2>>{log} | samtools sort -o {output.bam} - 2>>{log}
samtools index {output.bam} 2>>{log}
pilon -Xmx60G --genome {input.prev_fa} --frags {output.bam} --outdir assemblies/{wildcards.sample}_{wildcards.assembly}+pilon/ --output pilon --changes >>{log} 2>&1
mv assemblies/{wildcards.sample}_{wildcards.assembly}+pilon/pilon.fasta {output.fa}
ln -sr {output.fa} {output.link}
"""
rule polca:
conda:
"env/conda-masurca.yaml"
threads: 5
resources:
mem_mb=5000,
shadow:
"minimal"
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
fq1=get_R1_fq,
fq2=get_R2_fq,
output:
fa="assemblies/{sample}_{assembly}+polca/output.fa",
link="assemblies/{sample}_{assembly}+polca.fa",
log:
"assemblies/{sample}_{assembly}+polca/log.txt",
benchmark:
"benchmark/{sample}_{assembly}+polca.txt"
shell:
"""
polca.sh -t {threads} -a {input.prev_fa} -r '{input.fq1} {input.fq2}' >{log} 2>&1
mv output.fa.PolcaCorrected.fa {output.fa}
ln -sr {output.fa} {output.link}
"""
rule polypolish:
conda:
"env/conda-polypolish.yaml"
threads: 5
resources:
mem_mb=4000,
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
fq1=get_R1_fq,
fq2=get_R2_fq,
output:
samR1=temp("assemblies/{sample}_{assembly}+polypolish/alignments_R1.sam"),
samR2=temp("assemblies/{sample}_{assembly}+polypolish/alignments_R2.sam"),
filtered_samR1=temp("assemblies/{sample}_{assembly}+polypolish/filtered_R1.sam"),
filtered_samR2=temp("assemblies/{sample}_{assembly}+polypolish/filtered_R2.sam"),
fa="assemblies/{sample}_{assembly}+polypolish/output.fa",
link="assemblies/{sample}_{assembly}+polypolish.fa",
log:
"assemblies/{sample}_{assembly}+polypolish/log.txt",
benchmark:
"benchmark/{sample}_{assembly}+polypolish.txt"
shell:
"""
bwa index -p assemblies/{wildcards.sample}_{wildcards.assembly}+polypolish/bwa_index {input.prev_fa} >{log} 2>&1
bwa mem -a -t {threads} assemblies/{wildcards.sample}_{wildcards.assembly}+polypolish/bwa_index {input.fq1} > {output.samR1} 2>>{log}
bwa mem -a -t {threads} assemblies/{wildcards.sample}_{wildcards.assembly}+polypolish/bwa_index {input.fq2} > {output.samR2} 2>>{log}
polypolish_insert_filter.py --in1 {output.samR1} --in2 {output.samR2} --out1 {output.filtered_samR1} --out2 {output.filtered_samR2} >>{log} 2>&1
polypolish {input.prev_fa} {output.filtered_samR1} {output.filtered_samR2} > {output.fa} 2>>{log}
ln -sr {output.fa} {output.link}
"""
rule homopolish:
conda:
"env/conda-homopolish.yaml"
threads: 1
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
ref="references/{ref}.fa",
output:
fa="assemblies/{sample}_{assembly}+homopolish/output_{ref}.fa",
link="assemblies/{sample}_{assembly}+homopolish{ref}.fa",
log:
"assemblies/{sample}_{assembly}+homopolish/{ref}_log.txt",
benchmark:
"benchmark/{sample}_{assembly}+homopolish-{ref}.txt"
shell:
"""
DIR_temp=$(mktemp -d --suffix=.raconX)
trap "rm -r $DIR_temp" EXIT
homopolish polish -a {input.prev_fa} -m R9.4.pkl -o $DIR_temp -l {input.ref} >{log} 2>&1
cp $DIR_temp/*_homopolished.fasta {output.fa}
ln -sr {output.fa} {output.link}
"""
rule proovframe_diamond_index:
conda:
"env/conda-proovframe.yaml"
threads: 5
input:
"references-protein/{ref}.faa",
output:
"references-protein/{ref}.dmnd",
log:
"references-protein/{ref}-diamond-index.txt",
benchmark:
"benchmark/{ref}diamond-index.txt"
shell:
"""
diamond makedb -p {threads} --in {input} --db {output} >{log} 2>&1
"""
rule proovframe:
conda:
"env/conda-proovframe.yaml"
threads: 1
resources:
mem_mb=4000,
input:
prev_fa="assemblies/{sample}_{assembly}/output.fa",
ref="references-protein/{ref}.dmnd",
output:
fa="assemblies/{sample}_{assembly}+proovframe/output_{ref}.fa",
tsv="assemblies/{sample}_{assembly}+proovframe/output_{ref}.tsv",
link="assemblies/{sample}_{assembly}+proovframe{ref}.fa",
log:
"assemblies/{sample}_{assembly}+proovframe/{ref}_log.txt",
benchmark:
"benchmark/{sample}_{assembly}+proovframe-{ref}.txt"
shell:
"""
proovframe map -d {input.ref} -o {output.tsv} {input.prev_fa} >{log} 2>&1
proovframe fix -o {output.fa} {input.prev_fa} {output.tsv} >>{log} 2>&1
ln -sr {output.fa} {output.link}
"""