-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
3214 lines (2830 loc) · 152 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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import itertools
import sys
import re
import json
import traceback
import pathlib
import parse
from urllib.parse import urlparse
import datetime
###############################
###### Preprocess Config ######
###############################
print("Preprocessing config", flush = True)
configfile: "config/default.yml"
# Allow to configure to use conda from the config file
if 'use_conda' in config and config['use_conda']:
workflow.use_conda = True
workflow.global_resources["contigvalidator"] = 1
DATADIR = "data"
if "datadir" in config:
DATADIR = config["datadir"]
print("DATADIR: {}".format(DATADIR))
MAX_THREADS = 56
print(f"Setting MAX_THREADS to {MAX_THREADS}", flush = True)
BUILD_THREADS = 7
print(f"Setting BUILD_THREADS to {BUILD_THREADS}", flush = True)
# Preprocess experiments configuration
genomes = config["genomes"]
corrected_genomes = config["corrected_genomes"]
reports = config["reports"]
aggregated_reports = config["aggregated_reports"]
if aggregated_reports is None:
aggregated_reports = {}
from report_file_parser import *
DEFAULT_ASSEMBLER_ARGUMENTS = {
"wtdbg2": {
"skip_fragment_assembly": "no",
"fragment_correction_steps": "all",
"tig_injection": "none",
"frg_injection": "none",
"frg_injection_stage": "none",
"hodeco_consensus": "none",
},
"mdbg": {
"mdbg_mode": "multik",
},
"hifiasm": {
"contig_algorithm": "builtin",
},
}
for report_name, report_definition in reports.items():
argument_matrix = ArgumentMatrix(report_definition.setdefault("argument_matrix", {}))
report_definition["argument_matrix"] = argument_matrix # use correct type
# print("Matrix of {} has length {}".format(report_name, len(argument_matrix)))
# entries = list(iter(argument_matrix))
# print("Entries in matrix:")
# for entry in entries:
# print(entry)
for arguments in argument_matrix:
genome_arguments = Arguments.from_dict(genomes[arguments["genome"]].setdefault("genome_arguments", {}))
genome_arguments.update(arguments)
arguments = genome_arguments # update method works in-place
arguments.setdefault("read_source", "real")
arguments.setdefault("read_simulation_model_source", "none")
arguments.setdefault("read_downsampling_factor", "none")
arguments.setdefault("homopolymer_compression", "none")
arguments.setdefault("uniquify_ids", "no")
arguments.setdefault("assembler", None)
arguments.setdefault("assembler_arguments", None)
arguments.setdefault("quast_mode", "normal")
arguments.setdefault("filter_nw", "no")
arguments.setdefault("retain_cm", "no")
arguments.setdefault("filter_plasmids", "no")
# hisim produces reads with duplicate ids, so we always need to uniquify those
if arguments["read_source"].startswith("hisim_"):
arguments["uniquify_ids"] = "yes"
columns = []
for column_definition in report_definition["columns"]:
column_arguments = Arguments.from_dict(column_definition)
column = Column(arguments, column_arguments)
assembler_name = column.arguments.assembler_name()
if assembler_name in DEFAULT_ASSEMBLER_ARGUMENTS:
#print(f"assembler_name: {assembler_name}")
assembler_arguments = column.arguments.assembler_arguments()
#print(f"assembler_arguments: {assembler_arguments}")
for key, value in DEFAULT_ASSEMBLER_ARGUMENTS[assembler_name].items():
assembler_arguments.setdefault(key, value)
#print(f"assembler_arguments: {assembler_arguments}")
#print(column, flush = True)
columns.append(column)
report_file = ReportFile(arguments, columns)
report_definition.setdefault("report_files", {})[report_file.name] = report_file
#import pprint
#pp = pprint.PrettyPrinter(indent = 2, width = 200, compact = True)
#pp.pprint(reports)
#pp.pprint(aggregated_reports)
#print("Exiting for debugging")
#sys.exit(0)
# Collect all rust sources
RUST_SOURCES = list(map(str, itertools.chain(pathlib.Path('implementation').glob('**/Cargo.toml'), pathlib.Path('implementation').glob('**/*.rs'))))
import datetime
today = datetime.date.today().isoformat()
print("Finished config preprocessing", flush = True)
#########################
###### Directories ######
#########################
EXTERNAL_SOFTWARE_ROOTDIR = os.path.join(DATADIR, "external-software")
DOWNLOAD_ROOTDIR = os.path.join(DATADIR, "downloads")
GENOME_ROOTDIR = os.path.join(DATADIR, "genomes")
SIMULATION_ROOTDIR = os.path.join(DATADIR, "simulation")
ASSEMBLY_ROOTDIR = os.path.join(DATADIR, "assembly")
EVALUATION_ROOTDIR = os.path.join(DATADIR, "evaluation")
REPORT_ROOTDIR = os.path.join(DATADIR, "reports")
# Genomes
GENOME_ARGUMENT_STRING = "g{genome}-h{homopolymer_compression}"
GENOME_REFERENCE_ARGUMENT_STRING = "reference-n{filter_nw}-c{retain_cm}-p{filter_plasmids}"
GENOME_REFERENCE_SUBDIR = os.path.join(GENOME_ARGUMENT_STRING, GENOME_REFERENCE_ARGUMENT_STRING)
GENOME_REFERENCE = os.path.join(GENOME_ROOTDIR, GENOME_REFERENCE_SUBDIR, "reference.fa")
GENOME_REFERENCE_LENGTH = os.path.join(GENOME_ROOTDIR, GENOME_REFERENCE_SUBDIR, "reference_length.txt")
GENOME_READS_ARGUMENT_STRING = "reads-s{read_source}-m{read_simulation_model_source}-r{read_downsampling_factor}-u{uniquify_ids}"
GENOME_READS_SUBDIR = os.path.join(GENOME_ARGUMENT_STRING, GENOME_READS_ARGUMENT_STRING)
GENOME_READS_DIR = os.path.join(GENOME_ROOTDIR, GENOME_READS_SUBDIR)
GENOME_READS = os.path.join(GENOME_READS_DIR, "reads.fa")
GENOME_SINGLE_LINE_READS = os.path.join(GENOME_ROOTDIR, GENOME_READS_SUBDIR, "single_line_reads.fa")
UNIQUIFY_IDS_LOG = os.path.join(GENOME_ROOTDIR, GENOME_READS_SUBDIR, "uniquify_ids.log")
HOCO_READS_LOG = os.path.join(GENOME_ROOTDIR, GENOME_READS_SUBDIR, "hoco.log")
HOCO_REFERENCE_LOG = os.path.join(GENOME_ROOTDIR, GENOME_REFERENCE_SUBDIR, "hoco.log")
# Simulations
FASTK_ARGUMENT_STRING = "k{fastk_k}"
FASTK_OUTPUT_DIR = os.path.join(SIMULATION_ROOTDIR, "fastk", GENOME_READS_SUBDIR, FASTK_ARGUMENT_STRING)
FASTK_INPUT_READS = os.path.join(FASTK_OUTPUT_DIR, "reads.fa")
FASTK_TABLE = os.path.join(FASTK_OUTPUT_DIR, "reads.ktab")
FASTK_PROFILE = os.path.join(FASTK_OUTPUT_DIR, "reads.prof")
FASTK_HIST = os.path.join(FASTK_OUTPUT_DIR, "reads.hist")
FASTK_SYMMETRIC_TABLE = os.path.join(FASTK_OUTPUT_DIR, "symmetric_reads", "symmetric_reads.ktab")
FASTK_HISTEX_EVALUATION = os.path.join(EVALUATION_ROOTDIR, "histex", GENOME_READS_SUBDIR, FASTK_ARGUMENT_STRING, "histogram.txt")
HISIM_ARGUMENT_STRING = "a{himodel_kmer_threshold}-l{himodel_min_valid}-h{himodel_max_valid}"
HIMODEL_OUTPUT_DIR = os.path.join(SIMULATION_ROOTDIR, "himodel", GENOME_READS_SUBDIR, FASTK_ARGUMENT_STRING, HISIM_ARGUMENT_STRING)
HIMODEL_INPUT_SYMMETRIC_TABLE = os.path.join(HIMODEL_OUTPUT_DIR, "reads.ktab")
HIMODEL_INPUT_PROFILE = os.path.join(HIMODEL_OUTPUT_DIR, "reads.prof")
HIMODEL_MODEL = os.path.join(HIMODEL_OUTPUT_DIR, "reads.model")
HISIM_HAPLOTYPE = os.path.join(GENOME_READS_DIR, "reads.hap{haplotype_index}.fasta")
# Assemblies
ASSEMBLY_ARGUMENT_STRING = "a{assembler}--{assembler_arguments}-"
ASSEMBLY_SUBDIR = os.path.join(GENOME_READS_SUBDIR, ASSEMBLY_ARGUMENT_STRING)
ASSEMBLY_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR)
ASSEMBLED_CONTIGS = os.path.join(ASSEMBLY_OUTPUT_DIR, "contigs.fa")
ASSEMBLY_LOG = os.path.join(ASSEMBLY_OUTPUT_DIR, "assembly.log")
ASSEMBLER_ARGUMENT_STRINGS = {}
WTDBG2_ARGUMENT_STRING = "m{wtdbg2_mode}-s{skip_fragment_assembly}-f{fragment_correction_steps}-t{tig_injection}-f{frg_injection}-s{frg_injection_stage}-d{hodeco_consensus}-c{retain_cm}"
ASSEMBLER_ARGUMENT_STRINGS["wtdbg2"] = WTDBG2_ARGUMENT_STRING
WTDBG2_SUBDIR = safe_format(ASSEMBLY_SUBDIR, assembler = "wtdbg2", assembler_arguments = WTDBG2_ARGUMENT_STRING)
WTDBG2_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, WTDBG2_SUBDIR)
WTDBG2_INJECTABLE_CONTIG_DIR = os.path.join(WTDBG2_OUTPUT_DIR, "injectable_contigs")
WTDBG2_INJECTABLE_FRAGMENT_CONTIG_DIR = os.path.join(WTDBG2_OUTPUT_DIR, "injectable_fragment_contigs")
WTDBG2_OUTPUT_DIR_PACKED = safe_format(os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR), assembler = "wtdbg2")
WTDBG2_LOG = os.path.join(WTDBG2_OUTPUT_DIR, "assembly.log")
WTDBG2_EXTRACT_LOG = os.path.join(WTDBG2_OUTPUT_DIR, "extract.{subfile}.log")
WTDBG2_CONSENSUS_LOG = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2_consensus.log")
WTDBG2_ASSEMBLED_CONTIGS = os.path.join(WTDBG2_OUTPUT_DIR, "contigs.fa")
FLYE_ARGUMENT_STRING = "m{flye_mode}-c{retain_cm}"
ASSEMBLER_ARGUMENT_STRINGS["flye"] = FLYE_ARGUMENT_STRING
FLYE_SUBDIR = safe_format(ASSEMBLY_SUBDIR, assembler = "flye", assembler_arguments = FLYE_ARGUMENT_STRING)
FLYE_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, FLYE_SUBDIR)
FLYE_OUTPUT_DIR_PACKED = safe_format(os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR), assembler = "flye")
FLYE_LOG = os.path.join(FLYE_OUTPUT_DIR, "assembly.log")
FLYE_ASSEMBLED_CONTIGS = os.path.join(FLYE_OUTPUT_DIR, "contigs.fa")
HIFIASM_ARGUMENT_STRING = "c{contig_algorithm}"
ASSEMBLER_ARGUMENT_STRINGS["hifiasm"] = HIFIASM_ARGUMENT_STRING
HIFIASM_SUBDIR = safe_format(ASSEMBLY_SUBDIR, assembler = "hifiasm", assembler_arguments = HIFIASM_ARGUMENT_STRING)
HIFIASM_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, HIFIASM_SUBDIR)
HIFIASM_OUTPUT_DIR_PACKED = safe_format(os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR), assembler = "hifiasm")
HIFIASM_LOG = os.path.join(HIFIASM_OUTPUT_DIR, "assembly.log")
HIFIASM_ASSEMBLED_CONTIGS = os.path.join(HIFIASM_OUTPUT_DIR, "contigs.fa")
MDBG_ARGUMENT_STRING = "m{mdbg_mode}"
ASSEMBLER_ARGUMENT_STRINGS["mdbg"] = MDBG_ARGUMENT_STRING
MDBG_SUBDIR = safe_format(ASSEMBLY_SUBDIR, assembler = "mdbg", assembler_arguments = MDBG_ARGUMENT_STRING)
MDBG_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, MDBG_SUBDIR)
MDBG_OUTPUT_DIR_PACKED = safe_format(os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR), assembler = "mdbg")
MDBG_LOG = os.path.join(MDBG_OUTPUT_DIR, "assembly.log")
MDBG_ASSEMBLED_CONTIGS = os.path.join(MDBG_OUTPUT_DIR, "contigs.fa")
LJA_ARGUMENT_STRING = "none"
ASSEMBLER_ARGUMENT_STRINGS["lja"] = LJA_ARGUMENT_STRING
LJA_SUBDIR = safe_format(ASSEMBLY_SUBDIR, assembler = "lja", assembler_arguments = LJA_ARGUMENT_STRING)
LJA_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, LJA_SUBDIR)
LJA_OUTPUT_DIR_PACKED = safe_format(os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR), assembler = "lja")
LJA_LOG = os.path.join(LJA_OUTPUT_DIR, "assembly.log")
LJA_ASSEMBLED_CONTIGS = os.path.join(LJA_OUTPUT_DIR, "contigs.fa")
CANU_ARGUMENT_STRING = "c{retain_cm}"
ASSEMBLER_ARGUMENT_STRINGS["canu"] = CANU_ARGUMENT_STRING
CANU_SUBDIR = safe_format(ASSEMBLY_SUBDIR, assembler = "canu", assembler_arguments = CANU_ARGUMENT_STRING)
CANU_OUTPUT_DIR = os.path.join(ASSEMBLY_ROOTDIR, CANU_SUBDIR)
CANU_OUTPUT_DIR_PACKED = safe_format(os.path.join(ASSEMBLY_ROOTDIR, ASSEMBLY_SUBDIR), assembler = "canu")
CANU_LOG = os.path.join(CANU_OUTPUT_DIR, "assembly.log")
CANU_ASSEMBLED_CONTIGS = os.path.join(CANU_OUTPUT_DIR, "contigs.fa")
# Evaluations
QUAST_ROOTDIR = os.path.join(EVALUATION_ROOTDIR, "quast-m{quast_mode}")
QUAST_SUBDIR = os.path.join(GENOME_ARGUMENT_STRING, GENOME_REFERENCE_ARGUMENT_STRING, GENOME_READS_ARGUMENT_STRING, ASSEMBLY_ARGUMENT_STRING)
QUAST_OUTPUT_DIR = os.path.join(QUAST_ROOTDIR, QUAST_SUBDIR)
RESOURCES_ROOTDIR = os.path.join(EVALUATION_ROOTDIR, "resources")
RESOURCES_SUBDIR = os.path.join(GENOME_ARGUMENT_STRING, GENOME_REFERENCE_ARGUMENT_STRING, GENOME_READS_ARGUMENT_STRING, ASSEMBLY_ARGUMENT_STRING)
RESOURCES_OUTPUT_DIR = os.path.join(RESOURCES_ROOTDIR, RESOURCES_SUBDIR)
RESOURCES_EVALUATION = os.path.join(RESOURCES_OUTPUT_DIR, "resources.json")
# Reports
REPORT_SUBDIR = os.path.join(REPORT_ROOTDIR, "{report_name}", "{report_file_name}")
REPORT_TEX = os.path.join(REPORT_SUBDIR, "report.tex")
REPORT_COMBINED_EAXMAX_PLOT = os.path.join(REPORT_SUBDIR, "combined_eaxmax_plot.pdf")
REPORT_NAME_FILE = os.path.join(REPORT_SUBDIR, "name.txt")
REPORT_HASHDIR = os.path.join(REPORT_ROOTDIR, "hashdir")
REPORT_PDF = os.path.join(REPORT_SUBDIR, "report.pdf")
AGGREGATED_REPORT_SUBDIR = os.path.join(REPORT_ROOTDIR, "{aggregated_report_name}")
AGGREGATED_REPORT_PDF = os.path.join(AGGREGATED_REPORT_SUBDIR, "aggregated_report.pdf")
UNIQUIFY_IDS_SCRIPT = "scripts/uniquify_fasta_ids.py"
CONVERT_VALIDATION_OUTPUTS_TO_LATEX_SCRIPT = "scripts/convert_validation_outputs_to_latex.py"
CREATE_AGGREGATED_WTDBG2_REPORT_SCRIPT = "scripts/create_aggregated_wtdbg2_report.py"
CREATE_COMBINED_EAXMAX_PLOT_SCRIPT = "scripts/create_combined_eaxmax_plot.py"
DOWNSAMPLE_FASTA_READS_SCRIPT = "scripts/downsample_fasta_reads.py"
FILTER_NW_FROM_REFERENCE_SCRIPT = "scripts/filter_nw_from_reference.py"
RETAIN_CM_IN_REFERENCE_SCRIPT = "scripts/retain_cm_in_reference.py"
FILTER_PLASMIDS_IN_REFERENCE_SCRIPT = "scripts/filter_plasmids_in_reference.py"
COMPUTE_GENOME_REFERENCE_LENGTH_SCRIPT = "scripts/compute_genome_reference_length.py"
WTDBG2_HODECO_SCRIPT = "scripts/wtdbg2_hodeco.py"
EXTERNAL_SOFTWARE_SCRIPTS_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "scripts")
RUST_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "rust_target")
IS_RUST_TESTED_MARKER = os.path.join(RUST_DIR, "is_rust_tested.marker")
IS_RUST_FETCHED_MARKER = os.path.join(RUST_DIR, "is_rust_fetched.marker")
RUST_BINARY = os.path.join(RUST_DIR, "release", "cli")
QUAST_BINARY = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "quast", "quast.py")
WTDBG2_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "wtdbg2")
WTDBG2_BINARY = os.path.join(WTDBG2_DIR, "wtdbg2")
WTDBG2_CONSENSUS_BINARY = os.path.join(WTDBG2_DIR, "wtpoa-cns")
FLYE_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "Flye")
FLYE_BINARY = os.path.join(FLYE_DIR, "bin", "flye")
SIM_IT_BINARY = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "sim-it", "sim-it.pl")
RATATOSK_BINARY = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "Ratatosk", "build", "src", "Ratatosk")
CONTIG_VALIDATOR_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "ContigValidator")
CONVERT_TO_GFA_BINARY = os.path.join(EXTERNAL_SOFTWARE_SCRIPTS_DIR, "convertToGFA.py")
SDSL_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "sdsl-lite")
MDBG_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "rust-mdbg")
MDBG_CARGO_TOML = os.path.join(MDBG_DIR, "Cargo.toml")
MDBG_BINARY = os.path.join(MDBG_DIR, "target", "release", "rust-mdbg")
MDBG_SIMPLIFY = os.path.join(MDBG_DIR, "utils", "magic_simplify")
MDBG_MULTI_K = os.path.join(MDBG_DIR, "utils", "multik")
LJA_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "LJA")
LJA_BINARY = os.path.join(LJA_DIR, "bin", "lja")
HIFIASM_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "hifiasm")
HIFIASM_BINARY = os.path.join(HIFIASM_DIR, "hifiasm")
HOMOPOLYMER_COMPRESS_RS_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "homopolymer-compress-rs")
HOMOPOLYMER_COMPRESS_RS_BINARY = os.path.join(HOMOPOLYMER_COMPRESS_RS_DIR, "target", "release", "homopolymer-compress")
WTDBG2_HOMOPOLYMER_DECOMPRESSION_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "wtdbg2-homopolymer-decompression")
WTDBG2_HOMOPOLYMER_DECOMPRESSION_BINARY = os.path.join(WTDBG2_HOMOPOLYMER_DECOMPRESSION_DIR, "target", "release", "wtdbg2-homopolymer-decompression")
HISIM_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "HI.SIM")
HISIM_MODEL_BINARY = os.path.join(HISIM_DIR, "HImodel")
HISIM_SIM_BINARY = os.path.join(HISIM_DIR, "HIsim")
HISIM_FASTA_BINARY = os.path.join(HISIM_DIR, "HIfasta")
FASTK_DIR = os.path.join(EXTERNAL_SOFTWARE_ROOTDIR, "FASTK")
FASTK_BINARY = os.path.join(FASTK_DIR, "FastK")
FASTK_SYMMEX_BINARY = os.path.join(FASTK_DIR, "Symmex")
FASTK_HISTEX_BINARY = os.path.join(FASTK_DIR, "Histex")
# TODO remove
ALGORITHM_PREFIX_FORMAT = os.path.join(DATADIR, "algorithms", "{arguments}")
#################################
###### Global report rules ######
#################################
localrules: do_nothing
rule do_nothing:
shell: "echo 'No target specified'"
def get_all_report_files():
try:
result = []
for report_name, report_definition in reports.items():
for report_file_name, report_file_definition in report_definition["report_files"].items():
report_file_arguments = report_file_definition.arguments
#print(f"report_name: {report_name}")
#print(f"report_file_arguments: {report_file_arguments}", flush = True)
result.append(REPORT_PDF.format(report_name = report_name, report_file_name = str(report_file_arguments)))
for aggregated_report_name in aggregated_reports.keys():
result.append(AGGREGATED_REPORT_PDF.format(aggregated_report_name = aggregated_report_name))
return result
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
localrules: report_all
rule report_all:
input: get_all_report_files(),
threads: 1
resources: mail_type = "END,FAIL,INVALID_DEPEND,REQUEUE"
def get_test_report_files():
try:
result = []
for report_name, report_definition in reports.items():
if not report_name.startswith("E.coli_HiFi"):
continue
for report_file_name, report_file_definition in report_definition["report_files"].items():
report_file_arguments = report_file_definition.arguments
#print(f"report_file_arguments: {report_file_arguments}", flush = True)
result.append(REPORT_PDF.format(report_name = report_name, report_file_name = str(report_file_arguments)))
for aggregated_report_name in aggregated_reports.keys():
result.append(AGGREGATED_REPORT_PDF.format(aggregated_report_name = aggregated_report_name))
return result
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
localrules: report_test
rule report_test:
input: get_test_report_files(),
threads: 1
resources: mail_type = "END,FAIL,INVALID_DEPEND,REQUEUE"
###############################
###### Report Generation ######
###############################
### Create single report ###
def get_report_file(report_name, report_file_name):
try:
if report_name not in reports:
raise Exception("report_name not in reports: {}".format(report_name))
report_files = reports[report_name]["report_files"]
if report_file_name not in report_files:
raise Exception("report_file_name not in report_files: {}".format(report_file_name))
return report_files[report_file_name]
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_file_quasts(report_name, report_file_name):
try:
report_file = get_report_file(report_name, report_file_name)
quasts = []
for column in report_file.columns:
#print(f"QUAST_OUTPUT_DIR: {QUAST_OUTPUT_DIR}")
#print(f"column.arguments: {column.arguments}", flush = True)
assembler = column.arguments.assembler_name()
assembler_argument_string = ASSEMBLER_ARGUMENT_STRINGS[assembler]
#print(assembler_argument_string, flush = True)
assembler_arguments = column.arguments.assembler_arguments()
#print(f"raw assembler_arguments: {assembler_arguments}", flush = True)
assembler_arguments.setdefault("retain_cm", column.arguments["retain_cm"])
#print(f"completed assembler_arguments: {assembler_arguments}", flush = True)
assembler_arguments = assembler_argument_string.format(**assembler_arguments)
#print(f"serialised assembler_arguments: {assembler_arguments}", flush = True)
quasts.append(safe_format(QUAST_OUTPUT_DIR, assembler = assembler, assembler_arguments = assembler_arguments).format(**column.arguments))
return quasts
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_file_quasts_from_wildcards(wildcards):
try:
return get_report_file_quasts(wildcards.report_name, wildcards.report_file_name)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_file_resources_evaluations_from_wildcards(wildcards):
try:
report_name = wildcards.report_name
report_file_name = wildcards.report_file_name
report_file = get_report_file(report_name, report_file_name)
result = []
for column in report_file.columns:
#print(RESOURCES_EVALUATION)
#print(column.arguments, flush = True)
assembler = column.arguments.assembler_name()
assembler_argument_string = ASSEMBLER_ARGUMENT_STRINGS[assembler]
#print(assembler_argument_string, flush = True)
#print(column.arguments.assembler_arguments(), flush = True)
assembler_arguments = assembler_argument_string.format(**column.arguments.assembler_arguments())
#print(assembler_arguments, flush = True)
result.append(safe_format(RESOURCES_EVALUATION, assembler = assembler, assembler_arguments = assembler_arguments).format(**column.arguments))
return result
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_file_column_shortnames(report_name, report_file_name):
try:
report_file = get_report_file(report_name, report_file_name)
shortnames = []
for column in report_file.columns:
shortnames.append(column.shortname)
return shortnames
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_file_column_shortnames_from_wildcards(wildcards):
try:
return get_report_file_column_shortnames(wildcards.report_name, wildcards.report_file_name)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_genome_names(report_name, report_file_name):
try:
report_file = get_report_file(report_name, report_file_name)
genome_names = set()
for column in report_file.columns:
genome = column.genome
genome_names.add(genome)
return genome_names
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_report_genome_names_from_wildcards(wildcards):
try:
return get_report_genome_names(wildcards.report_name, wildcards.report_file_name)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_single_report_script_column_arguments(report_name, report_file_name):
try:
report_file = get_report_file(report_name, report_file_name)
result = ""
once = True
for column in report_file.columns:
if once:
once = False
else:
result += " "
assembler = column.arguments.assembler_name()
assembler_argument_string = ASSEMBLER_ARGUMENT_STRINGS[assembler]
assembler_arguments = assembler_argument_string.format(**column.arguments.assembler_arguments())
quast_output_dir = safe_format(QUAST_OUTPUT_DIR, assembler = assembler, assembler_arguments = assembler_arguments).format(**column.arguments)
resources_evaluation_file = safe_format(RESOURCES_EVALUATION, assembler = assembler, assembler_arguments = assembler_arguments).format(**column.arguments)
result += f"'{column.shortname}' '' '{quast_output_dir}' '' '{resources_evaluation_file}'"
return result
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_single_report_script_column_arguments_from_wildcards(wildcards):
try:
return get_single_report_script_column_arguments(wildcards.report_name, wildcards.report_file_name)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
rule create_single_report_tex:
input: quasts = get_report_file_quasts_from_wildcards,
combined_eaxmax_plot = REPORT_COMBINED_EAXMAX_PLOT,
resources_evaluations = get_report_file_resources_evaluations_from_wildcards,
script = CONVERT_VALIDATION_OUTPUTS_TO_LATEX_SCRIPT,
output: report = REPORT_TEX,
params: genome_name = lambda wildcards: ", ".join(get_report_genome_names_from_wildcards(wildcards)),
script_column_arguments = get_single_report_script_column_arguments_from_wildcards,
name_file = REPORT_NAME_FILE,
hashdir = REPORT_HASHDIR,
wildcard_constraints:
report_name = "[^/]+",
conda: "config/conda-latex-gen-env.yml"
threads: 1
shell: """
mkdir -p '{params.hashdir}'
echo '{wildcards.report_name} {params.genome_name} {wildcards.report_file_name}' > '{params.name_file}'
python3 '{input.script}' '{params.hashdir}' '{params.name_file}' 'none' 'none' '{input.combined_eaxmax_plot}' '{output}' {params.script_column_arguments}
"""
### Create aggregated report ###
def get_aggregated_report_file_maps(aggregated_report_name):
try:
result = {}
for report_name in aggregated_reports[aggregated_report_name]["reports"]:
result.setdefault(report_name, {}).update(reports[report_name]["report_files"])
return result
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def iterate_aggregated_report_file_source_reports(aggregated_report_name):
try:
aggregated_report_files = get_aggregated_report_file_maps(aggregated_report_name)
for report_name, report_file_map in aggregated_report_files.items():
for report_file_name, report_file_definition in report_file_map.items():
yield (report_name, report_file_name)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def iterate_aggregated_report_file_source_reports_short_names(aggregated_report_name):
try:
aggregated_report_files = get_aggregated_report_file_maps(aggregated_report_name)
for report_name, report_file_map in aggregated_report_files.items():
for report_file_name, report_file_definition in report_file_map.items():
yield (report_name, report_file_definition.shortname)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_aggregated_report_file_source_report_paths(aggregated_report_name):
try:
result = []
for report_name, report_file_name in iterate_aggregated_report_file_source_reports(aggregated_report_name):
result.append(REPORT_PREFIX_FORMAT.format(report_name = report_name, report_file_name = report_file_name) + "report.tex")
return result
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def get_aggregated_report_file_source_report_paths_from_wildcards(wildcards):
try:
return get_aggregated_report_file_source_report_paths(wildcards.aggregated_report_name)
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
rule create_aggregated_report_tex:
input: source_reports = get_aggregated_report_file_source_report_paths_from_wildcards,
script = "scripts/create_aggregated_wtdbg2_report.py",
output: file = AGGREGATED_REPORT_PDF,
params: source_reports_arg = lambda wildcards: "' '".join(get_aggregated_report_file_source_report_paths_from_wildcards(wildcards)),
source_report_names_arg = lambda wildcards: "' '".join([report_name + "/" + report_file_name for report_name, report_file_name in iterate_aggregated_report_file_source_reports_short_names(wildcards.aggregated_report_name)]),
wildcard_constraints:
report_name = "[^/]+",
conda: "config/conda-latex-gen-env.yml"
threads: 1
shell: """
python3 '{input.script}' --source-reports '{params.source_reports_arg}' --source-report-names '{params.source_report_names_arg}' --output '{output.file}'
"""
rule create_combined_eaxmax_graph:
input: quast_csvs = lambda wildcards: [os.path.join(q, "aligned_stats", "EAxmax_plot.csv") for q in get_report_file_quasts_from_wildcards(wildcards)],
script = CREATE_COMBINED_EAXMAX_PLOT_SCRIPT,
output: REPORT_COMBINED_EAXMAX_PLOT,
params: input_quast_csvs = lambda wildcards, input: "' '".join([shortname + "' '" + quast for shortname, quast in zip(get_report_file_column_shortnames_from_wildcards(wildcards), input.quast_csvs)])
wildcard_constraints:
report_name = "[^/]+",
conda: "config/conda-seaborn-env.yml"
threads: 1
shell: """
mkdir -p "$(dirname '{output}')"
python3 '{input.script}' '{params.input_quast_csvs}' '{output}'
"""
rule png_to_pdf:
input: "{file}.png"
output: "{file}.image.pdf"
conda: "config/conda-imagemagick-env.yml"
threads: 1
shell: "convert {input} {output}"
rule latex:
input: "{subpath}report.tex"
output: "{subpath}report.pdf"
conda: "config/conda-latex-env.yml"
threads: 1
shell: """
tectonic '{input}'
"""
# def get_genome_reads_from_wildcards(wildcards):
# try:
# arguments = Arguments.from_str(wildcards.arguments)
# if arguments.read_simulator_name() is None or arguments.read_simulator_name() == "none":
# return GENOME_READS_FORMAT.format(genome = arguments["genome"])
# else:
# return GENOME_SIMULATED_READS_FASTA_FORMAT.format(genome = arguments["genome"], read_simulator_name = arguments.read_simulator_name(), read_simulator_arguments = arguments.read_simulator_arguments())
# except Exception:
# traceback.print_exc()
# sys.exit("Catched exception")
# def get_genome_reference_from_wildcards(wildcards):
# try:
# arguments = Arguments.from_str(wildcards.arguments)
# return GENOME_REFERENCE_FORMAT.format(genome = arguments["genome"])
# except Exception:
# traceback.print_exc()
# sys.exit("Catched exception")
# rule find_wtdbg2_node_errors:
# input: nodes = os.path.join(WTDBG2_OUTPUT_DIR_PACKED, "wtdbg2.1.nodes"),
# reference = GENOME_REFERENCE,
# script = "scripts/find_wtdbg2_node_errors.py",
# output: deviation_histogram = os.path.join(ASSEMBLY_OUTPUT_DIR, "wtdbg2_node_errors", "deviation_histogram.pdf"),
# log: log = os.path.join(ALGORITHM_PREFIX_FORMAT, "wtdbg2_node_errors", "wtdbg2_node_errors.log"),
# params: output_prefix = os.path.join(ALGORITHM_PREFIX_FORMAT, "wtdbg2_node_errors") + "/",
# conda: "config/conda-wtdbg2-node-errors-env.yml"
# threads: 1
# shell: "PYTHONUNBUFFERED=1 '{input.script}' '{input.nodes}' '{input.reference}' '{params.output_prefix}' 2>&1 | tee '{log.log}'"
########################
###### Injections ######
########################
def get_injectable_contigs_rust_cli_command_from_wildcards(wildcards):
try:
injection = wildcards.tig_injection
if "unitigs" == injection:
return "compute-unitigs"
elif "trivial_omnitigs" == injection:
return "compute-trivial-omnitigs --non-scc"
elif "omnitigs" == injection:
return "compute-omnitigs --linear-reduction"
else:
raise Exception(f"Wrong injection command in assembler arguments: {wildcards}")
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
rule compute_injectable_contigs_wtdbg2:
input: nodes = safe_format(os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.nodes"), tig_injection = "none"),
reads = safe_format(os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.reads"), tig_injection = "none"),
dot = safe_format(os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.dot"), tig_injection = "none"),
raw_reads = GENOME_READS,
binary = RUST_BINARY,
output: file = os.path.join(WTDBG2_INJECTABLE_CONTIG_DIR, "contigwalks.ssv"),
latex = os.path.join(WTDBG2_INJECTABLE_CONTIG_DIR, "compute_injectable_contigs.tex"),
log: log = os.path.join(WTDBG2_INJECTABLE_CONTIG_DIR, "compute_injectable_contigs.log"),
params: command = get_injectable_contigs_rust_cli_command_from_wildcards,
threads: 1
resources: mem_mb = 48000
shell: "${{CONDA_PREFIX}}/bin/time -v '{input.binary}' {params.command} --output-as-wtdbg2-node-ids --file-format wtdbg2 --input '{input.nodes}' --input '{input.reads}' --input '{input.raw_reads}' --input '{input.dot}' --output '{output.file}' --latex '{output.latex}' 2>&1 | tee '{log.log}'"
def get_injectable_fragment_contigs_rust_cli_command_from_wildcards(wildcards):
try:
injection = wildcards.frg_injection
if "unitigs" == injection:
return "compute-unitigs"
elif "trivial_omnitigs" == injection:
return "compute-trivial-omnitigs --non-scc"
elif "omnitigs" == injection:
return "compute-omnitigs --linear-reduction"
else:
raise Exception("Wrong injection command in assembler arguments: {wildcards}")
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
rule compute_injectable_fragment_contigs_wtdbg2:
input: dot = lambda wildcards: safe_format(os.path.join(WTDBG2_OUTPUT_DIR, f"wtdbg2.{wildcards.frg_injection_stage}.dot"), frg_injection = "none", frg_injection_stage = "none"),
binary = RUST_BINARY,
output: file = os.path.join(WTDBG2_INJECTABLE_FRAGMENT_CONTIG_DIR, "contigwalks.ssv"),
latex = os.path.join(WTDBG2_INJECTABLE_FRAGMENT_CONTIG_DIR, "compute_injectable_contigs.tex"),
log: log = os.path.join(WTDBG2_INJECTABLE_FRAGMENT_CONTIG_DIR, "compute_injectable_contigs.log"),
params: command = get_injectable_fragment_contigs_rust_cli_command_from_wildcards,
threads: 1
resources: mem_mb = 48000
shell: "${{CONDA_PREFIX}}/bin/time -v '{input.binary}' {params.command} --file-format dot --input '{input.dot}' --output '{output.file}' --latex '{output.latex}' 2>&1 | tee '{log.log}'"
#################################
###### Postprocess Contigs ######
#################################
def get_raw_assembly_file_from_wildcards(wildcards):
try:
arguments = Arguments.from_str(wildcards.arguments)
assembler_name = arguments.assembler_name()
if assembler_name == "flye":
result = ALGORITHM_PREFIX_FORMAT + "flye/assembly.fasta"
elif assembler_name == "wtdbg2":
result = WTDBG2_PREFIX_FORMAT + "wtdbg2.raw.fa"
elif assembler_name == "hifiasm":
result = os.path.join(HIFIASM_PREFIX_FORMAT, "assembly.p_ctg.fa")
elif assembler_name == "reference":
result = GENOME_REFERENCE_FORMAT
else:
raise Exception("Unknown assembler {} in arguments: {}".format(assembler_name, arguments))
arguments.retain_raw_assembly_arguments()
return result.format(genome = arguments.genome(), arguments = str(arguments))
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
localrules: select_assembler
rule select_assembler:
input: raw_assembly_from_assembler = get_raw_assembly_file_from_wildcards,
output: raw_assembly = ALGORITHM_PREFIX_FORMAT + "raw_assembly.fa",
threads: 1
shell: "ln -sr '{input.raw_assembly_from_assembler}' '{output.raw_assembly}'"
def get_raw_gfa_assembly_file_from_wildcards(wildcards):
try:
arguments = Arguments.from_str(wildcards.arguments)
assembler_name = arguments.assembler_name()
if assembler_name == "hifiasm":
result = os.path.join(HIFIASM_PREFIX_FORMAT, "hifiasm", "assembly.r_utg.gfa")
else:
raise Exception("Assembler {} does not support gfa (in arguments: {})".format(assembler_name, arguments))
arguments.retain_raw_assembly_arguments()
return result.format(genome = arguments.genome(), arguments = str(arguments))
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
localrules: select_gfa_assembler
rule select_gfa_assembler:
input: raw_assembly_from_assembler = get_raw_gfa_assembly_file_from_wildcards,
output: raw_assembly = ALGORITHM_PREFIX_FORMAT + "raw_assembly.gfa",
threads: 1
shell: "ln -sr '{input.raw_assembly_from_assembler}' '{output.raw_assembly}'"
def get_assembly_postprocessing_target_file_from_wildcards(wildcards):
try:
try:
arguments = Arguments.from_str(wildcards.arguments)
except json.decoder.JSONDecodeError:
traceback.print_exc()
raise Exception("JSONDecodeError: {}".format(wildcards.arguments))
postprocessor_name = arguments.postprocessor_name()
if postprocessor_name == "contigbreaker":
return ALGORITHM_PREFIX_FORMAT + "contigbreaker/broken_contigs.fa"
elif postprocessor_name == "gfa_trivial_omnitigs":
return os.path.join(ALGORITHM_PREFIX_FORMAT, "gfa_trivial_omnitigs/trivial_omnitigs.fa")
else:
return ALGORITHM_PREFIX_FORMAT + "raw_assembly.fa"
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
localrules: request_assembly_postprocessing
rule request_assembly_postprocessing:
input: get_assembly_postprocessing_target_file_from_wildcards
output: assembly = ALGORITHM_PREFIX_FORMAT + "assembly.fa"
threads: 1
shell: "ln -sr '{input}' '{output}'"
def get_source_genome_properties_from_wildcards(wildcards):
try:
if hasattr(wildcards, "genome"):
genome_name = wildcards.genome
elif hasattr(wildcards, "corrected_genome"):
genome_name = wildcards.corrected_genome
elif hasattr(wildcards, "arguments"):
arguments = Arguments.from_str(wildcards.arguments)
genome_name = arguments.genome()
if genome_name is None:
raise Exception("Arguments has no 'genome' attribute: {}".format(arguments))
else:
raise Exception("Wildcards has no 'genome', 'corrected_genome' or 'arguments' attribute")
if genome_name in genomes:
pass
elif corrected_genomes is not None and genome_name in corrected_genomes:
genome_name = corrected_genomes[genome_name]["source_genome"]
else:
raise Exception("Genome name not found: " + str(genome_name))
return genomes[genome_name]
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def compute_genome_mem_mb_from_wildcards(wildcards, base_mem_mb):
try:
genome_properties = get_source_genome_properties_from_wildcards(wildcards)
if "assembly_mem_factor" in genome_properties:
return int(float(genome_properties["assembly_mem_factor"]) * float(base_mem_mb))
else:
return base_mem_mb
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def compute_genome_time_min_from_wildcards(wildcards, base_time_min):
try:
genome_properties = get_source_genome_properties_from_wildcards(wildcards)
if "assembly_time_factor" in genome_properties:
if hasattr(wildcards, "read_source") and wildcards.read_source.startswith("hisim_"):
return int(float(genome_properties["assembly_time_factor"]) * float(base_time_min)) * 2
else:
return int(float(genome_properties["assembly_time_factor"]) * float(base_time_min))
else:
return base_time_min
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def compute_genome_queue_from_wildcards(wildcards, base_time_min, base_mem_mb = 0):
try:
time = compute_genome_time_min_from_wildcards(wildcards, base_time_min)
mem = compute_genome_mem_mb_from_wildcards(wildcards, base_mem_mb)
cluster = compute_genome_cluster_from_wildcards(wildcards, base_time_min, base_mem_mb)
if cluster == "ukko":
if mem >= 250_000:
if time <= 1440 * 3:
return "bigmem,aurinko"
else:
return "aurinko"
elif time <= 60 * 8:
return "short,medium,bigmem,aurinko"
elif time <= 1440 * 2:
return "medium,bigmem,aurinko"
elif time <= 1440 * 3:
return "bigmem,aurinko"
else:
return "aurinko" # aurinko can handle anything
#else:
# sys.exit("No applicable queue for runtime " + str(time) + " (wildcards: " + str(wildcards) + ")")
elif cluster == "kale":
raise Exception("kale disabled")
if mem >= 380_000:
return "bigmem"
elif time <= 1440:
return "short,medium,long,bigmem"
elif time <= 1440 * 7:
return "medium,long,bigmem"
elif time <= 1440 * 14:
return "long,bigmem"
else:
sys.exit("No applicable queue for runtime " + str(time) + " (wildcards: " + str(wildcards) + ")")
else:
sys.exit("No applicable cluster for runtime " + str(time) + " (wildcards: " + str(wildcards) + ")")
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
def compute_genome_cluster_from_wildcards(wildcards, base_time_min, base_mem_mb = 0):
try:
time = compute_genome_time_min_from_wildcards(wildcards, base_time_min)
mem = compute_genome_mem_mb_from_wildcards(wildcards, base_mem_mb)
#if time <= 1440 * 2:
# return "ukko"
#elif time <= 1440 * 14:
# return "kale"
#else:
# sys.exit("No applicable cluster for runtime " + str(time) + " (wildcards: " + str(wildcards) + ")")
return "ukko" # run everything on ukko for now, using aurinko for long jobs
except Exception:
traceback.print_exc()
sys.exit("Catched exception")
rule run_contigbreaker:
input: contigs = ALGORITHM_PREFIX_FORMAT + "raw_assembly.fa",
reads = GENOME_READS,
script = "tools/contigbreaker/contigbreaker.py"
output: broken_contigs = ALGORITHM_PREFIX_FORMAT + "contigbreaker/broken_contigs.fa",
completed = touch(ALGORITHM_PREFIX_FORMAT + "contigbreaker/broken_contigs.fa.completed"),
threads: MAX_THREADS
resources: mem_mb = lambda wildcards: compute_genome_mem_mb_from_wildcards(wildcards, 60_000),
time_min = lambda wildcards: compute_genome_time_min_from_wildcards(wildcards, 720),
cpus = MAX_THREADS,
queue = lambda wildcards: compute_genome_queue_from_wildcards(wildcards, 720, 60_000),
cluster = lambda wildcards: compute_genome_cluster_from_wildcards(wildcards, 720, 60_000),
conda: "tools/contigbreaker/environment.yml"
shell: "'{input.script}' --threads {threads} --input-contigs '{input.contigs}' --input-reads '{input.reads}' --output-contigs '{output.broken_contigs}'"
rule run_gfa_trivial_omnitigs:
input: contigs = os.path.join(ALGORITHM_PREFIX_FORMAT, "raw_assembly.gfa"),
binary = RUST_BINARY,
output: trivial_omnitigs = os.path.join(ALGORITHM_PREFIX_FORMAT, "gfa_trivial_omnitigs", "trivial_omnitigs.fa"),
log: log = os.path.join(ALGORITHM_PREFIX_FORMAT, "gfa_trivial_omnitigs", "trivial_omnitigs.log"),
threads: 1
resources:
mem_mb = lambda wildcards: compute_genome_mem_mb_from_wildcards(wildcards, 10_000),
time_min = lambda wildcards: compute_genome_time_min_from_wildcards(wildcards, 60),
cpus = 1,
queue = lambda wildcards: compute_genome_queue_from_wildcards(wildcards, 60, 10_000),
cluster = lambda wildcards: compute_genome_cluster_from_wildcards(wildcards, 60, 10_000),
shell: "'{input.binary}' compute-trivial-omnitigs --non-scc --file-format hifiasm --input '{input.contigs}' --output '{output.trivial_omnitigs}' 2>&1 | tee '{log.log}'"
####################
###### wtdbg2 ######
####################
rule wtdbg2:
input: reads = GENOME_READS,
reference_length = safe_format(GENOME_REFERENCE_LENGTH, filter_nw = "no", retain_cm = "no", filter_plasmids = "no"),
binary = WTDBG2_BINARY,
output: original_nodes = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.1.nodes"),
nodes = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.nodes"),
reads = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.reads"),
dot = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.dot.gz"),
ctg_dot = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.ctg.dot.gz"),
clips = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.clps"),
kbm = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.kbm"),
ctg_lay = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.ctg.lay.gz"),
frg_dot = [os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.{}.frg.dot.gz".format(i)) for i in range(1, 11)],
log: log = WTDBG2_LOG,
params: output_prefix = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2"),
fragment_correction_steps = lambda wildcards: f"--fragment-correction-steps {wildcards.fragment_correction_steps}" if wildcards.fragment_correction_steps != "all" else "",
wildcard_constraints:
tig_injection = "none",
frg_injection = "none",
frg_injection_stage = "none",
skip_fragment_assembly = "no",
threads: MAX_THREADS
resources: mem_mb = lambda wildcards: compute_genome_mem_mb_from_wildcards(wildcards, 100_000),
cpus = MAX_THREADS,
time_min = lambda wildcards: compute_genome_time_min_from_wildcards(wildcards, 720),
queue = lambda wildcards: compute_genome_queue_from_wildcards(wildcards, 720, 100_000),
cluster = lambda wildcards: compute_genome_cluster_from_wildcards(wildcards, 720, 100_000),
shell: """
read -r REFERENCE_LENGTH < '{input.reference_length}'
${{CONDA_PREFIX}}/bin/time -v '{input.binary}' -x {wildcards.wtdbg2_mode} -g $REFERENCE_LENGTH -i '{input.reads}' -t {threads} -fo '{params.output_prefix}' --dump-kbm '{output.kbm}' {params.fragment_correction_steps} 2>&1 | tee '{log.log}'
"""
rule wtdbg2_skip_fragment_assembly:
input: reads = GENOME_READS,
reference_length = safe_format(GENOME_REFERENCE_LENGTH, filter_nw = "no", retain_cm = "no", filter_plasmids = "no"),
binary = WTDBG2_BINARY,
output: original_nodes = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.1.nodes"),
nodes = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.nodes"),
reads = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.reads"),
dot = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.3.dot.gz"),
ctg_dot = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.ctg.dot.gz"),
clips = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.clps"),
kbm = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.kbm"),
ctg_lay = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2.ctg.lay.gz"),
log: log = WTDBG2_LOG,
params: output_prefix = os.path.join(WTDBG2_OUTPUT_DIR, "wtdbg2"),
fragment_correction_steps = lambda wildcards: f"--fragment-correction-steps {wildcards.fragment_correction_steps}" if wildcards.fragment_correction_steps != "all" else "",
wildcard_constraints:
tig_injection = "none",
frg_injection = "none",
frg_injection_stage = "none",
skip_fragment_assembly = "yes",
threads: MAX_THREADS
resources: mem_mb = lambda wildcards: compute_genome_mem_mb_from_wildcards(wildcards, 100_000),
cpus = MAX_THREADS,
time_min = lambda wildcards: compute_genome_time_min_from_wildcards(wildcards, 720),
queue = lambda wildcards: compute_genome_queue_from_wildcards(wildcards, 720, 100_000),
cluster = lambda wildcards: compute_genome_cluster_from_wildcards(wildcards, 720, 100_000),
shell: """
read -r REFERENCE_LENGTH < '{input.reference_length}'