-
Notifications
You must be signed in to change notification settings - Fork 54
/
get_organelle_from_reads.py
executable file
·4621 lines (4446 loc) · 280 KB
/
get_organelle_from_reads.py
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
#!/usr/bin/env python
import datetime
import shutil
from copy import deepcopy
from math import log, exp
try:
from math import inf
except ImportError:
inf = float("inf")
from argparse import ArgumentParser
import GetOrganelleLib
from GetOrganelleLib.seq_parser import *
from GetOrganelleLib.pipe_control_func import *
import time
import random
import subprocess
import sys
import os
PATH_OF_THIS_SCRIPT = os.path.split(os.path.realpath(__file__))[0]
import platform
SYSTEM_NAME = ""
if platform.system() == "Linux":
SYSTEM_NAME = "linux"
elif platform.system() == "Darwin":
SYSTEM_NAME = "macOS"
else:
sys.stdout.write("Error: currently GetOrganelle is not supported for " + platform.system() + "! ")
exit()
GO_LIB_PATH = os.path.split(GetOrganelleLib.__file__)[0]
GO_DEP_PATH = os.path.realpath(os.path.join(GO_LIB_PATH, "..", "GetOrganelleDep", SYSTEM_NAME))
UTILITY_PATH = os.path.join(PATH_OF_THIS_SCRIPT, "Utilities")
_GO_PATH = GO_PATH
_LBL_DB_PATH = LBL_DB_PATH
_SEQ_DB_PATH = SEQ_DB_PATH
MAJOR_VERSION, MINOR_VERSION = sys.version_info[:2]
if MAJOR_VERSION == 2 and MINOR_VERSION >= 7:
PYTHON_VERSION = "2.7+"
elif MAJOR_VERSION == 3 and MINOR_VERSION >= 5:
PYTHON_VERSION = "3.5+"
else:
sys.stdout.write("Python version have to be 2.7+ or 3.5+")
sys.exit(0)
MAX_RATIO_RL_WS = 0.75
AUTO_MIN_WS = 49
AUTO_MIN_WS_ANIMAL_MT = 41
AUTO_MIN_WS_PLANT_MT = 55
GLOBAL_MIN_WS = 29
BASE_COV_SAMPLING_PERCENT = 0.06
GUESSING_FQ_GZIP_COMPRESSING_RATIO = 3.58
GUESSING_FQ_SEQ_INFLATE_TO_FILE = 3.22
SUPPORTED_ORGANELLE_TYPES = ["embplant_pt", "embplant_mt", "embplant_nr", "other_pt", "animal_mt", "fungus_mt", "fungus_nr"]
ORGANELLE_EXPECTED_GRAPH_SIZES = {"embplant_pt": 130000,
"embplant_mt": 390000,
"embplant_nr": 13000,
"fungus_nr": 13000,
"other_pt": 39000,
"animal_mt": 13000,
"fungus_mt": 65000}
READ_LINE_TO_INF = int(HEAD_MAXIMUM_LINES/4)
def get_options(description, version):
version = version
usage = "\n### Embryophyta plant plastome, 2*(1G raw data, 150 bp) reads\n" + str(os.path.basename(__file__)) + \
" -1 sample_1.fq -2 sample_2.fq -s cp_seed.fasta -o plastome_output " \
" -R 15 -k 21,45,65,85,105 -F embplant_pt\n" \
"### Embryophyta plant mitogenome\n" + str(os.path.basename(__file__)) + \
" -1 sample_1.fq -2 sample_2.fq -s mt_seed.fasta -o mitogenome_output " \
" -R 30 -k 21,45,65,85,105 -F embplant_mt"
parser = ArgumentParser(usage=usage, description=description, add_help=False)
# simple help mode
if "-h" in sys.argv:
parser.add_argument("-1", dest="fq_file_1", help="Input file with forward paired-end reads (*.fq/.gz/.tar.gz).")
parser.add_argument("-2", dest="fq_file_2", help="Input file with reverse paired-end reads (*.fq/.gz/.tar.gz).")
parser.add_argument("-u", dest="unpaired_fq_files", help="Input file(s) with unpaired (single-end) reads. ")
parser.add_argument("-o", dest="output_base", help="Output directory.")
parser.add_argument("-s", dest="seed_file", help="Input fasta format file as initial seed. "
"Default: " + os.path.join(SEQ_DB_PATH, "*.fasta"))
parser.add_argument("-w", dest="word_size", help="Word size (W) for extension. Default: auto-estimated")
parser.add_argument("-R", dest="max_rounds", help="Maximum extension rounds (suggested: >=2). "
"Default: 15 (embplant_pt)")
parser.add_argument("-F", dest="organelle_type",
help="Target organelle genome type(s): "
"embplant_pt/other_pt/embplant_mt/embplant_nr/animal_mt/fungus_mt/fungus_nr/anonym/"
"embplant_pt,embplant_mt/other_pt,embplant_mt,fungus_mt")
parser.add_argument("--max-reads", type=float,
help="Maximum number of reads to be used per file. "
"Default: 1.5E7 (-F embplant_pt/embplant_nr/fungus_mt/fungus_nr); "
"7.5E7 (-F embplant_mt/other_pt/anonym); 3E8 (-F animal_mt)")
parser.add_argument("--fast", dest="fast_strategy",
help="=\"-R 10 -t 4 -J 5 -M 7 --max-n-words 3E7 --larger-auto-ws "
"--disentangle-time-limit 360\"")
parser.add_argument("-k", dest="spades_kmer", default="21,55,85,115",
help="SPAdes kmer settings. Default: %(default)s")
parser.add_argument("-t", dest="threads", type=int, default=1,
help="Maximum threads to use. Default: %(default)s")
parser.add_argument("-P", dest="pre_grouped", default=int(2E5), help="Pre-grouping value. Default: %(default)s")
parser.add_argument("-v", "--version", action="version",
version="GetOrganelle v{version}".format(version=version))
parser.add_argument("-h", dest="simple_help", default=False, action="store_true",
help="print brief introduction for frequently-used options.")
parser.add_argument("--help", dest="verbose_help", default=False, action="store_true",
help="print verbose introduction for all options.")
parser.print_help()
sys.stdout.write("\n")
exit()
else:
# verbose help mode
# group 1
group_inout = parser.add_argument_group("IN-OUT OPTIONS", "Options on inputs and outputs")
# group_inout = OptionGroup(parser, "IN-OUT OPTIONS", "Options on inputs and outputs")
group_inout.add_argument("-1", dest="fq_file_1",
help="Input file with forward paired-end reads (format: fastq/fastq.gz/fastq.tar.gz).")
group_inout.add_argument("-2", dest="fq_file_2",
help="Input file with reverse paired-end reads (format: fastq/fastq.gz/fastq.tar.gz).")
group_inout.add_argument("-u", dest="unpaired_fq_files",
help="Input file(s) with unpaired (single-end) reads (format: fastq/fastq.gz/fastq.tar.gz). "
"files could be comma-separated lists such as 'seq1.fq,seq2.fq'.")
group_inout.add_argument("-o", dest="output_base",
help="Output directory. Overwriting files if directory exists.")
group_inout.add_argument("-s", dest="seed_file", default=None,
help="Seed sequence(s). Input fasta format file as initial seed. "
"A seed sequence in GetOrganelle is only used for identifying initial "
"organelle reads. The assembly process is purely de novo. "
"Should be a list of files split by comma(s) on a multi-organelle mode, "
"with the same list length to organelle_type (followed by '-F'). "
"Default: '" + os.path.join(SEQ_DB_PATH, "*.fasta") + "' "
"(* depends on the value followed with flag '-F')")
group_inout.add_argument("-a", dest="anti_seed",
help="Anti-seed(s). Not suggested unless what you really know what you are doing. "
"Input fasta format file as anti-seed, where the extension process "
"stop. Typically serves as excluding plastid reads when extending mitochondrial "
"reads, or the other way around. You should be cautious about using this option, "
"because if the anti-seed includes some word in the target but not in the seed, "
"the result would have gaps. For example, use the embplant_mt and embplant_pt "
"from the same plant-species as seed and anti-seed.")
group_inout.add_argument("--max-reads", dest="maximum_n_reads", type=float, default=1.5E7,
help="Hard bound for maximum number of reads to be used per file. "
"A input larger than " + str(
READ_LINE_TO_INF) + " will be treated as infinity (INF). "
"Default: 1.5E7 (-F embplant_pt/embplant_nr/fungus_mt/fungus_nr); "
"7.5E7 (-F embplant_mt/other_pt/anonym); 3E8 (-F animal_mt)")
group_inout.add_argument("--reduce-reads-for-coverage", dest="reduce_reads_for_cov", type=float, default=500,
help="Soft bound for maximum number of reads to be used according to "
"target-hitting base coverage. "
"If the estimated target-hitting base coverage is too high and "
"over this VALUE, GetOrganelle automatically reduce the number of reads to "
"generate a final assembly with base coverage close to this VALUE. "
"This design could greatly save computational resources in many situations. "
"A mean base coverage over 500 is extremely sufficient for most cases. "
"This VALUE must be larger than 10. Set this VALUE to inf to disable reducing. "
"Default: %(default)s.")
group_inout.add_argument("--max-ignore-percent", dest="maximum_ignore_percent", type=float, default=0.01,
help="The maximum percent of bases to be ignore in extension, due to low quality. "
"Default: %(default)s")
group_inout.add_argument("--phred-offset", dest="phred_offset", default=-1, type=int,
help="Phred offset for spades-hammer. Default: GetOrganelle-autodetect")
group_inout.add_argument("--min-quality-score", dest="min_quality_score", type=int, default=1,
help="Minimum quality score in extension. This value would be automatically decreased "
"to prevent ignoring too much raw data (see --max-ignore-percent)."
"Default: %(default)s ('\"' in Phred+33; 'A' in Phred+64/Solexa+64)")
group_inout.add_argument("--prefix", dest="prefix", default="",
help="Add extra prefix to resulting files under the output directory.")
group_inout.add_argument("--out-per-round", dest="fg_out_per_round", action="store_true", default=False,
help="Enable output per round. Choose to save memory but cost more time per round.")
group_inout.add_argument("--zip-files", dest="zip_files", action="store_true", default=False,
help="Choose to compress fq/sam files using gzip.")
group_inout.add_argument("--keep-temp", dest="keep_temp_files", action="store_true", default=False,
help="Choose to keep the running temp/index files.")
group_inout.add_argument("--config-dir", dest="get_organelle_path", default=None,
help="The directory where the configuration file and default databases were placed. "
"The default value also can be changed by adding 'export GETORG_PATH=your_favor' "
"to the shell script (e.g. ~/.bash_profile or ~/.bashrc) "
"Default: " + GO_PATH)
# group 2
group_scheme = parser.add_argument_group("SCHEME OPTIONS", "Options on running schemes.")
group_scheme.add_argument("-F", dest="organelle_type",
help="This flag should be followed with embplant_pt (embryophyta plant plastome), "
"other_pt (non-embryophyta plant plastome), embplant_mt "
"(plant mitogenome), embplant_nr (plant nuclear ribosomal RNA), animal_mt "
"(animal mitogenome), fungus_mt (fungus mitogenome), "
"fungus_nr (fungus nuclear ribosomal RNA)"
"or embplant_mt,other_pt,fungus_mt "
"(the combination of any of above organelle genomes split by comma(s), "
"which might be computationally more intensive than separate runs), "
"or anonym (uncertain organelle genome type). "
"The anonym should be used with customized seed and label databases "
"('-s' and '--genes'). "
"For easy usage and compatibility of old versions, following redirection "
"would be automatically fulfilled without warning:\t"
"\nplant_cp->embplant_pt; plant_pt->embplant_pt; "
"\nplant_mt->embplant_mt; plant_nr->embplant_nr")
group_scheme.add_argument("--fast", dest="fast_strategy", default=False, action="store_true",
help="=\"-R 10 -t 4 -J 5 -M 7 --max-n-words 3E7 --larger-auto-ws "
"--disentangle-time-limit 360\" "
"This option is suggested for homogeneously and highly covered data (very fine data). "
"You can overwrite the value of a specific option listed above by adding "
"that option along with the \"--fast\" flag. "
"You could try GetOrganelle with this option for a list of samples and run a second "
"time without this option for the rest with incomplete results. ")
group_scheme.add_argument("--memory-save", dest="memory_save", default=False, action="store_true",
help="=\"--out-per-round -P 0 --remove-duplicates 0\" "
"You can overwrite the value of a specific option listed above by adding "
"that option along with the \"--memory-save\" flag. A larger '-R' value is suggested "
"when \"--memory-save\" is chosen.")
group_scheme.add_argument("--memory-unlimited", dest="memory_unlimited", default=False, action="store_true",
help="=\"-P 1E7 --index-in-memory --remove-duplicates 2E8 "
"--min-quality-score -5 --max-ignore-percent 0\" "
"You can overwrite the value of a specific option listed above by adding "
"that option along with the \"--memory-unlimited\" flag. ")
# group 3
group_extending = parser.add_argument_group("EXTENDING OPTIONS",
"Options on the performance of extending process")
group_extending.add_argument("-w", dest="word_size", type=float,
help="Word size (W) for pre-grouping (if not assigned by '--pre-w') and extending "
"process. This script would try to guess (auto-estimate) a proper W "
"using an empirical function based on average read length, reads quality, "
"target genome coverage, and other variables that might influence the extending "
"process. You could assign the ratio (1>input>0) of W to "
"read_length, based on which this script would estimate the W for you; "
"or assign an absolute W value (read length>input>=35). Default: auto-estimated.")
group_extending.add_argument("--pre-w", dest="pregroup_word_size", type=float,
help="Word size (W) for pre-grouping. Used to reproduce result when word size is "
"a certain value during pregrouping process and later changed during reads "
"extending process. Similar to word size. Default: the same to word size.")
group_extending.add_argument("-R", "--max-rounds", dest="max_rounds", type=int, # default=inf,
help="Maximum number of extending rounds (suggested: >=2). "
"Default: 15 (-F embplant_pt), 30 (-F embplant_mt/other_pt), "
"10 (-F embplant_nr/animal_mt/fungus_mt/fungus_nr), inf (-P 0).")
group_extending.add_argument("--max-n-words", dest="maximum_n_words", type=float, default=4E8,
help="Maximum number of words to be used in total."
"Default: 4E8 (-F embplant_pt), 2E8 (-F embplant_nr/fungus_mt/fungus_nr/animal_mt), "
"2E9 (-F embplant_mt/other_pt)")
group_extending.add_argument("-J", dest="jump_step", type=int, default=3,
help="The length of step for checking words in reads during extending process "
"(integer >= 1). When you have reads of high quality, the larger the number is, "
"the faster the extension will be, "
"the more risk of missing reads in low coverage area. "
"Choose 1 to choose the slowest but safest extension strategy. Default: %(default)s")
group_extending.add_argument("-M", dest="mesh_size", type=int, default=2,
help="(Beta parameter) "
"The length of step for building words from seeds during extending process "
"(integer >= 1). When you have reads of high quality, the larger the number is, "
"the faster the extension will be, "
"the more risk of missing reads in low coverage area. "
"Another usage of this mesh size is to choose a larger mesh size coupled with a "
"smaller word size, which makes smaller word size feasible when memory is limited."
"Choose 1 to choose the slowest but safest extension strategy. Default: %(default)s")
group_extending.add_argument("--bowtie2-options", dest="bowtie2_options", default="--very-fast -t",
help="Bowtie2 options, such as '--ma 3 --mp 5,2 --very-fast -t'. Default: %(default)s.")
group_extending.add_argument("--larger-auto-ws", dest="larger_auto_ws", default=False, action="store_true",
help="By using this flag, the empirical function for estimating W would tend to "
"produce a relative larger W, which would speed up the matching in extending, "
"reduce the memory cost in extending, but increase the risk of broken final "
"graph. Suggested when the data is good with high and homogenous coverage.")
mixed_organelles = ("other_pt", "embplant_mt", "fungus_mt")
group_extending.add_argument("--target-genome-size", dest="target_genome_size", default='130000', type=str,
help="Hypothetical value(s) of target genome size. This is only used for estimating "
"word size when no '-w word_size' is given. "
"Should be a list of INTEGER numbers split by comma(s) on a multi-organelle mode, "
"with the same list length to organelle_type (followed by '-F'). "
"Default: " +
" or ".join(
[str(
ORGANELLE_EXPECTED_GRAPH_SIZES[this_type]) + " (-F " + this_type + ")"
for this_type in SUPPORTED_ORGANELLE_TYPES]) + " or " +
",".join([str(ORGANELLE_EXPECTED_GRAPH_SIZES[this_type])
for this_type in mixed_organelles]) +
" (-F " + ",".join(mixed_organelles) + ")")
group_extending.add_argument("--max-extending-len", dest="max_extending_len", type=str,
help="Maximum extending length(s) derived from the seed(s). "
"A single value could be a non-negative number, or inf (infinite) "
"or auto (automatic estimation). "
"This is designed for properly stopping the extending from getting too long and "
"saving computational resources. However, empirically, a maximum extending length "
"value larger than 6000 would not be helpful for saving computational resources. "
"This value would not be precise in controlling output size, especially "
"when pre-group (followed by '-P') is turn on."
"In the auto mode, the maximum extending length is estimated based on the sizes of "
"the gap regions that not covered in the seed sequences. A sequence of a closely "
"related species would be preferred for estimating a better maximum extending "
"length value. If you are using limited loci, e.g. rbcL gene as the seed for "
"assembling the whole plastome (with extending length ca. 75000 >> 6000), "
"you should set maximum extending length to inf. "
"Should be a list of numbers/auto/inf split by comma(s) on a multi-organelle mode, "
"with the same list length to organelle_type (followed by '-F'). "
"Default: inf. ")
# group 4
group_assembly = parser.add_argument_group("ASSEMBLY OPTIONS", "These options are about the assembly and "
"graph disentangling")
group_assembly.add_argument("-k", dest="spades_kmer", default="21,55,85,115",
help="SPAdes kmer settings. Use the same format as in SPAdes. illegal kmer values "
"would be automatically discarded by GetOrganelle. "
"Default: %(default)s")
group_assembly.add_argument("--spades-options", dest="other_spades_options", default="",
help="Other SPAdes options. Use double quotation marks to include all "
"the arguments and parameters.")
group_assembly.add_argument("--no-spades", dest="run_spades", action="store_false", default=True,
help="Disable SPAdes.")
group_assembly.add_argument("--ignore-k", dest="ignore_kmer_res", default=40, type=int,
help="A kmer threshold below which, no slimming/disentangling would be executed"
" on the result. Default: %(default)s")
group_assembly.add_argument("--genes", dest="genes_fasta",
help="Followed with a customized database (a fasta file or the base name of a "
"blast database) containing or made of ONE set of protein coding genes "
"and ribosomal RNAs extracted from ONE reference genome that you want to assemble. "
"Should be a list of databases split by comma(s) on a multi-organelle mode, "
"with the same list length to organelle_type (followed by '-F'). "
"This is optional for any organelle mentioned in '-F' but required for 'anonym'. "
"By default, certain database(s) in " + str(LBL_DB_PATH) + " would be used "
"contingent on the organelle types chosen (-F). "
"The default value become invalid when '--genes' or '--ex-genes' is used.")
group_assembly.add_argument("--ex-genes", dest="exclude_genes",
help="This is optional and Not suggested, since non-target contigs could contribute "
"information for better downstream coverage-based clustering. "
"Followed with a customized database (a fasta file or the base name of a "
"blast database) containing or made of protein coding genes "
"and ribosomal RNAs extracted from reference genome(s) that you want to exclude. "
"Could be a list of databases split by comma(s) but "
"NOT required to have the same list length to organelle_type (followed by '-F'). "
"The default value will become invalid when '--genes' or '--ex-genes' is used.")
group_assembly.add_argument("--disentangle-df", dest="disentangle_depth_factor", default=5.0, type=float,
help="Depth factor for differentiate genome type of contigs. "
"The genome type of contigs are determined by blast. "
"Default: %(default)s")
group_assembly.add_argument("--disentangle-tf", dest="disentangle_type_factor", type=float, default=3.,
help="Type factor for identifying contig type tag when multiple tags exist in one contig. "
"Default:%(default)s")
group_assembly.add_argument("--contamination-depth", dest="contamination_depth", default=3., type=float,
help="Depth factor for confirming contamination in parallel contigs. Default: %(default)s")
group_assembly.add_argument("--contamination-similarity", dest="contamination_similarity", default=0.9,
type=float,
help="Similarity threshold for confirming contaminating contigs. Default: %(default)s")
group_assembly.add_argument("--no-degenerate", dest="degenerate", default=True, action="store_false",
help="Disable making consensus from parallel contig based on nucleotide degenerate table.")
group_assembly.add_argument("--degenerate-depth", dest="degenerate_depth", default=1.5, type=float,
help="Depth factor for confirming parallel contigs. Default: %(default)s")
group_assembly.add_argument("--degenerate-similarity", dest="degenerate_similarity", default=0.98, type=float,
help="Similarity threshold for confirming parallel contigs. Default: %(default)s")
group_assembly.add_argument("--disentangle-time-limit", dest="disentangle_time_limit", default=1800, type=int,
help="Time limit (second) for each try of disentangling a graph file as a circular "
"genome. Disentangling a graph as contigs is not limited. Default: %(default)s")
group_assembly.add_argument("--expected-max-size", dest="expected_max_size", default='250000', type=str,
help="Expected maximum target genome size(s) for disentangling. "
"Should be a list of INTEGER numbers split by comma(s) on a multi-organelle mode, "
"with the same list length to organelle_type (followed by '-F'). "
"Default: 250000 (-F embplant_pt/fungus_mt), "
"25000 (-F embplant_nr/animal_mt/fungus_nr), 1000000 (-F embplant_mt/other_pt),"
"1000000,1000000,250000 (-F other_pt,embplant_mt,fungus_mt)")
group_assembly.add_argument("--expected-min-size", dest="expected_min_size", default=10000, type=str,
help="Expected minimum target genome size(s) for disentangling. "
"Should be a list of INTEGER numbers split by comma(s) on a multi-organelle mode, "
"with the same list length to organelle_type (followed by '-F'). "
"Default: %(default)s for all.")
group_assembly.add_argument("--reverse-lsc", dest="reverse_lsc", default=False, action="store_true",
help="For '-F embplant_pt' with complete circular result, "
"by default, the direction of the starting contig (usually "
"the LSC region) is determined as the direction with less ORFs. Choose this option "
"to reverse the direction of the starting contig when result is circular. "
"Actually, both directions are biologically equivalent to each other. The "
"reordering of the direction is only for easier downstream analysis.")
group_assembly.add_argument("--max-paths-num", dest="max_paths_num", default=1000, type=int,
help="Repeats would dramatically increase the number of potential isomers (paths). "
"This option was used to export a certain amount of paths out of all possible paths "
"per assembly graph. Default: %(default)s")
# group 5
group_computational = parser.add_argument_group("ADDITIONAL OPTIONS", "")
group_computational.add_argument("-t", dest="threads", type=int, default=1,
help="Maximum threads to use.")
group_computational.add_argument("-P", dest="pre_grouped", type=float, default=2E5,
help="The maximum number (integer) of high-covered reads to be pre-grouped "
"before extending process. pre_grouping is suggested when the whole genome "
"coverage is shallow but the organ genome coverage is deep. "
"The default value is 2E5. "
"For personal computer with 8G memory, we suggest no more than 3E5. "
"A larger number (ex. 6E5) would run faster but exhaust memory "
"in the first few minutes. Choose 0 to disable this process.")
group_computational.add_argument("--which-blast", dest="which_blast", default="",
help="Assign the path to BLAST binary files if not added to the path. "
"Default: try \"" + os.path.realpath(GO_DEP_PATH) +
"/ncbi-blast\" first, then $PATH")
group_computational.add_argument("--which-bowtie2", dest="which_bowtie2", default="",
help="Assign the path to Bowtie2 binary files if not added to the path. "
"Default: try \"" + os.path.realpath(GO_DEP_PATH) +
"/bowtie2\" first, then $PATH")
group_computational.add_argument("--which-spades", dest="which_spades", default="",
help="Assign the path to SPAdes binary files if not added to the path. "
"Default: try \"" + os.path.realpath(GO_DEP_PATH) +
"/SPAdes\" first, then $PATH")
group_computational.add_argument("--which-bandage", dest="which_bandage", default="",
help="Assign the path to bandage binary file if not added to the path. "
"Default: try $PATH")
group_computational.add_argument("--continue", dest="script_resume", default=False, action="store_true",
help="Several check points based on files produced, rather than on the log file, "
"so keep in mind that this script will NOT detect the difference "
"between this input parameters and the previous ones.")
group_computational.add_argument("--overwrite", dest="script_overwrite", default=False, action="store_true",
help="Overwrite previous file if existed. ")
group_computational.add_argument("--index-in-memory", dest="index_in_memory", action="store_true",
default=False,
help="Keep index in memory. Choose save index in memory than in disk.")
group_computational.add_argument("--remove-duplicates", dest="rm_duplicates", default=1E7, type=float,
help="By default this script use unique reads to extend. Choose the number of "
"duplicates (integer) to be saved in memory. A larger number (ex. 2E7) would "
"run faster but exhaust memory in the first few minutes. "
"Choose 0 to disable this process. "
"Note that whether choose or not will not disable "
"the calling of replicate reads. Default: %(default)s.")
group_computational.add_argument("--flush-step", dest="echo_step", default=54321,
help="Flush step (INTEGER OR INF) for presenting progress. "
"For running in the background, you could set this to inf, "
"which would disable this. Default: %(default)s")
group_computational.add_argument("--random-seed", dest="random_seed", default=12345, type=int,
help="Default: %(default)s")
group_computational.add_argument("--verbose", dest="verbose_log", action="store_true", default=False,
help="Verbose output. Choose to enable verbose running log_handler.")
parser.add_argument("-v", "--version", action="version",
version="GetOrganelle v{version}".format(version=version))
parser.add_argument("-h", dest="simple_help", default=False, action="store_true",
help="print brief introduction for frequently-used options.")
parser.add_argument("--help", dest="verbose_help", default=False, action="store_true",
help="print verbose introduction for all options.")
if "--help" in sys.argv:
parser.print_help()
exit()
# if "--help" in sys.argv:
# parser.add_option_group(group_inout)
# parser.add_option_group(group_scheme)
# parser.add_option_group(group_extending)
# parser.add_option_group(group_assembly)
# parser.add_option_group(group_computational)
#
# elif "-h" in sys.argv:
# for not_often_used in ("-a", "--max-ignore-percent", "--reduce-reads-for-coverage", "--phred-offset",
# "--min-quality-score", "--prefix", "--out-per-round", "--zip-files", "--keep-temp",
# "--config-dir",
# "--memory-save", "--memory-unlimited", "--pre-w", "--max-n-words",
# "-J", "-M", "--bowtie2-options",
# "--larger-auto-ws", "--target-genome-size", "--spades-options", "--no-spades",
# "--ignore-k", "--genes", "--ex-genes", "--disentangle-df",
# "--contamination-depth", "--contamination-similarity", "--no-degenerate",
# "--degenerate-depth", "--degenerate-similarity", "--disentangle-time-limit",
# "--expected-max-size", "--expected-min-size", "--reverse-lsc", "--max-paths-num",
# "--which-blast", "--which-bowtie2", "--which-spades", "--which-bandage",
# "--continue", "--overwrite", "--index-in-memory",
# "--remove-duplicates", "--flush-step", "--verbose"):
# parser.remove_option(not_often_used)
#
# else:
# parser.add_option_group(group_inout)
# parser.add_option_group(group_scheme)
# parser.add_option_group(group_extending)
# parser.add_option_group(group_assembly)
# parser.add_option_group(group_computational)
# redirect organelle types before parsing arguments
redirect_organelle_types = {"plant_cp": "embplant_pt",
"plant_pt": "embplant_pt",
"plant_mt": "embplant_mt",
"plant_nr": "embplant_nr"}
for go_arg, candidate_arg in enumerate(sys.argv):
if go_arg > 1 and sys.argv[go_arg - 1] in {"-F", "-E"}:
if candidate_arg in redirect_organelle_types:
sys.argv[go_arg] = redirect_organelle_types[candidate_arg]
elif "," in candidate_arg:
new_arg = []
for sub_arg in candidate_arg.split(","):
if sub_arg in redirect_organelle_types:
new_arg.append(redirect_organelle_types[sub_arg])
else:
new_arg.append(sub_arg)
sys.argv[go_arg] = ",".join(new_arg)
#
try:
options = parser.parse_args()
except Exception as e:
sys.stderr.write("\n############################################################################\n" + str(e))
sys.stderr.write("\n\"-h\" for more usage\n")
exit()
else:
# if pos_args:
# sys.stderr.write("\n############################################################################"
# "\nUnrecognized options: " + "\", \"".join(pos_args) + "\n")
# exit()
if not ((options.fq_file_1 and options.fq_file_2) or options.unpaired_fq_files):
sys.stderr.write("\n############################################################################"
"\nERROR: Insufficient arguments!\n")
sys.stderr.write("Missing/Illegal input reads file(s) (followed after '-1&-2' and/or '-u')!\n")
exit()
if not options.output_base:
sys.stderr.write("\n############################################################################"
"\nERROR: Insufficient arguments!\n")
sys.stderr.write("Missing option: output directory (followed after '-o')!\n")
exit()
if not options.organelle_type:
sys.stderr.write("\n############################################################################"
"\nERROR: Insufficient arguments!\n")
sys.stderr.write("Missing option: organelle type (followed after '-F')!\n")
exit()
else:
options.organelle_type = options.organelle_type.split(",")
if int(bool(options.fq_file_1)) + int(bool(options.fq_file_2)) == 1:
sys.stderr.write("\n############################################################################"
"\nERROR: unbalanced paired reads!\n\n")
exit()
global _GO_PATH, _LBL_DB_PATH, _SEQ_DB_PATH
if options.get_organelle_path:
_GO_PATH = os.path.expanduser(options.get_organelle_path)
if os.path.isdir(_GO_PATH):
_LBL_DB_PATH = os.path.join(_GO_PATH, LBL_NAME)
_SEQ_DB_PATH = os.path.join(_GO_PATH, SEQ_NAME)
else:
sys.stderr.write("\n############################################################################"
"\nERROR: path " + _GO_PATH + " invalid!\n")
exit()
def _check_default_db(this_sub_organelle, extra_type=""):
if not ((os.path.isfile(os.path.join(_LBL_DB_PATH, this_sub_organelle + ".fasta")) or options.genes_fasta)
and
(os.path.isfile(os.path.join(_SEQ_DB_PATH, this_sub_organelle + ".fasta")) or options.seed_file)):
sys.stderr.write("\n############################################################################"
"\nERROR: default " + this_sub_organelle + "," * int(bool(extra_type)) + extra_type +
" database not added yet!\n"
"These two types must be used together!\n" * int(bool(extra_type)) +
"\nInstall it(them) by: get_organelle_config.py -a " + this_sub_organelle +
"," * int(bool(extra_type)) + extra_type +
"\nor\nInstall all types by: get_organelle_config.py -a all\n")
exit()
for sub_organelle_t in options.organelle_type:
if sub_organelle_t not in {"embplant_pt", "other_pt", "embplant_mt", "embplant_nr", "animal_mt",
"fungus_mt", "fungus_nr", "anonym"}:
sys.stderr.write("\n############################################################################"
"\nERROR: \"-F\" MUST be one of 'embplant_pt', 'other_pt', 'embplant_mt', "
"'embplant_nr', 'animal_mt', 'fungus_mt', 'fungus_nr', 'anonym', "
"or a combination of above split by comma(s)!\n\n")
exit()
elif sub_organelle_t == "anonym":
if not options.seed_file or not options.genes_fasta:
sys.stderr.write("\n############################################################################"
"\nERROR: \"-s\" and \"--genes\" must be specified when \"-F anonym\"!\n\n")
exit()
else:
if sub_organelle_t in ("embplant_pt", "embplant_mt"):
for go_t, check_sub in enumerate(["embplant_pt", "embplant_mt"]):
_check_default_db(check_sub, ["embplant_pt", "embplant_mt"][not go_t])
else:
_check_default_db(sub_organelle_t)
organelle_type_len = len(options.organelle_type)
if not options.seed_file:
use_default_seed = True
options.seed_file = [os.path.join(_SEQ_DB_PATH, sub_o + ".fasta") for sub_o in options.organelle_type]
else:
use_default_seed = False
options.seed_file = str(options.seed_file).split(",")
if len(options.seed_file) != organelle_type_len:
sys.stderr.write("\n############################################################################"
"\nERROR: -F is followed with " + str(organelle_type_len) + " organelle types, " +
"while -s is followed with " + str(len(options.seed_file)) + " file(s)!\n")
exit()
for check_file in [options.fq_file_1, options.fq_file_2, options.anti_seed] + options.seed_file:
if check_file:
if not os.path.exists(check_file):
sys.stderr.write("\n############################################################################"
"\nERROR: " + check_file + " not found!\n\n")
exit()
if os.path.getsize(check_file) == 0:
sys.stderr.write("\n############################################################################"
"\nERROR: " + check_file + " is empty!\n\n")
exit()
if options.unpaired_fq_files:
options.unpaired_fq_files = options.unpaired_fq_files.split(",")
for fastq_file in options.unpaired_fq_files:
if not os.path.exists(fastq_file):
sys.stderr.write("\n############################################################################"
"\nERROR: " + fastq_file + " not found!\n\n")
exit()
else:
options.unpaired_fq_files = []
if options.jump_step < 1:
sys.stderr.write("\n############################################################################"
"\nERROR: Jump step MUST be an integer that >= 1\n")
exit()
if options.mesh_size < 1:
sys.stderr.write("\n############################################################################"
"\nERROR: Mesh size MUST be an integer that >= 1\n")
exit()
if options.fq_file_1 == options.fq_file_2 and options.fq_file_1:
sys.stderr.write("\n############################################################################"
"\nERROR: 1st fastq file is the same with 2nd fastq file!\n")
exit()
if options.memory_save and options.memory_unlimited:
sys.stderr.write("\n############################################################################"
"\nERROR: \"--memory-save\" and \"--memory-unlimited\" are not compatible!\n")
assert options.threads > 0
if options.reduce_reads_for_cov < 10:
sys.stderr.write("\n############################################################################"
"\nERROR: value after \"--reduce-reads-for-coverage\" must be larger than 10!\n")
exit()
if options.echo_step == "inf":
options.echo_step = inf
elif type(options.echo_step) == int:
pass
elif type(options.echo_step) == str:
try:
options.echo_step = int(float(options.echo_step))
except ValueError:
sys.stderr.write("\n############################################################################"
"\n--flush-step should be followed by positive integer or inf!\n")
exit()
assert options.echo_step > 0
assert options.max_paths_num > 0
assert options.phred_offset in (-1, 64, 33)
assert options.script_resume + options.script_overwrite < 2, "'--overwrite' conflicts with '--continue'"
options.prefix = os.path.basename(options.prefix)
if os.path.isdir(options.output_base):
if options.script_resume:
previous_attributes = LogInfo(options.output_base, options.prefix).__dict__
else:
if options.script_overwrite:
try:
shutil.rmtree(options.output_base)
except OSError as e:
sys.stderr.write(
"\n############################################################################"
"\nRemoving existed " + options.output_base + " failed! "
"\nPlease manually remove it or use a new output directory!\n")
os.mkdir(options.output_base)
else:
sys.stderr.write("\n############################################################################"
"\n" + options.output_base + " existed! "
"\nPlease use a new output directory, or use '--continue'/'--overwrite'\n")
exit()
previous_attributes = {}
else:
options.script_resume = False
os.mkdir(options.output_base)
previous_attributes = {}
# if options.script_resume and os.path.isdir(options.output_base):
# previous_attributes = LogInfo(options.output_base, options.prefix).__dict__
# else:
# previous_attributes = {}
# options.script_resume = False
# if not os.path.isdir(options.output_base):
# os.mkdir(options.output_base)
# options.script_resume = False
log_handler = simple_log(logging.getLogger(), options.output_base, options.prefix + "get_org.")
log_handler.info("")
log_handler.info(description)
log_handler.info("Python " + str(sys.version).replace("\n", " "))
log_handler.info("PLATFORM: " + " ".join(platform.uname()))
# log versions of dependencies
lib_versions_info = []
lib_not_available = []
lib_versions_info.append("GetOrganelleLib " + GetOrganelleLib.__version__)
try:
import numpy as np
except ImportError:
lib_not_available.append("numpy")
else:
lib_versions_info.append("numpy " + np.__version__)
# try:
# import sympy
# except ImportError:
# lib_not_available.append("sympy")
# else:
# lib_versions_info.append("sympy " + sympy.__version__)
try:
import gekko
except ImportError:
lib_not_available.append("gekko")
else:
lib_versions_info.append("gekko " + gekko.__version__)
try:
import psutil
except ImportError:
pass
else:
lib_versions_info.append("psutil " + psutil.__version__)
log_handler.info("PYTHON LIBS: " + "; ".join(lib_versions_info))
options.which_bowtie2 = detect_bowtie2_path(options.which_bowtie2, GO_DEP_PATH)
if options.run_spades:
options.which_spades = detect_spades_path(options.which_spades, GO_DEP_PATH)
options.which_blast = detect_blast_path(options.which_blast, GO_DEP_PATH)
dep_versions_info = []
dep_versions_info.append(detect_bowtie2_version(options.which_bowtie2))
if options.run_spades:
dep_versions_info.append(detect_spades_version(options.which_spades))
dep_versions_info.append(detect_blast_version(options.which_blast))
if executable(os.path.join(options.which_bandage, "Bandage -v")):
dep_versions_info.append(detect_bandage_version(options.which_bandage))
log_handler.info("DEPENDENCIES: " + "; ".join(dep_versions_info))
# log database
log_handler.info("GETORG_PATH=" + _GO_PATH)
existing_seed_db, existing_label_db = get_current_db_versions(db_type="both", seq_db_path=_SEQ_DB_PATH,
lbl_db_path=_LBL_DB_PATH, silent=True)
if use_default_seed:
log_seed_types = deepcopy(options.organelle_type)
if "embplant_pt" in log_seed_types and "embplant_mt" not in log_seed_types:
log_seed_types.append("embplant_mt")
if "embplant_mt" in log_seed_types and "embplant_pt" not in log_seed_types:
log_seed_types.append("embplant_pt")
log_handler.info("SEED DB: " + single_line_db_versions(existing_seed_db, log_seed_types))
if not options.genes_fasta:
log_label_types = deepcopy(options.organelle_type)
if "embplant_pt" in log_label_types and "embplant_mt" not in log_label_types:
log_label_types.append("embplant_mt")
if "embplant_mt" in log_label_types and "embplant_pt" not in log_label_types:
log_label_types.append("embplant_pt")
log_handler.info("LABEL DB: " + single_line_db_versions(existing_label_db, log_label_types))
# working directory
log_handler.info("WORKING_DIR=" + os.getcwd())
log_handler.info(" ".join(["\"" + arg + "\"" if " " in arg else arg for arg in sys.argv]) + "\n")
# if options.run_spades:
# space is forbidden for both spades and blast
for fq_file in [options.fq_file_1, options.fq_file_2] * int(bool(options.fq_file_1 and options.fq_file_2))\
+ options.unpaired_fq_files:
assert is_valid_path(os.path.basename(fq_file)), \
"Invalid characters (e.g. space, non-ascii) for SPAdes in file name: " + os.path.basename(fq_file)
for fq_file in [options.output_base, options.prefix]:
assert is_valid_path(os.path.realpath(fq_file)), \
"Invalid characters (e.g. space, non-ascii) for SPAdes in path: " + os.path.realpath(fq_file)
log_handler = timed_log(log_handler, options.output_base, options.prefix + "get_org.")
if options.word_size is None:
pass
elif 0 < options.word_size < 1:
pass
elif options.word_size >= GLOBAL_MIN_WS:
options.word_size = int(options.word_size)
else:
log_handler.error("Illegal word size (\"-w\") value!")
exit()
if options.pregroup_word_size:
if 0 < options.pregroup_word_size < 1:
pass
elif options.pregroup_word_size >= GLOBAL_MIN_WS:
options.pregroup_word_size = int(options.pregroup_word_size)
else:
log_handler.error("Illegal word size (\"--pre-w\") value!")
exit()
if options.fast_strategy:
if "-R" not in sys.argv and "--max-rounds" not in sys.argv:
options.max_rounds = 10
if "-t" not in sys.argv:
options.threads = 4
if "-J" not in sys.argv:
options.jump_step = 5
if "-M" not in sys.argv:
options.mesh_size = 7
if "--max-n-words" not in sys.argv:
options.maximum_n_words = 3E7
options.larger_auto_ws = True
if "--disentangle-time-limit" not in sys.argv:
options.disentangle_time_limit = 360
if options.memory_save:
if "-P" not in sys.argv:
options.pre_grouped = 0
if "--remove-duplicates" not in sys.argv:
options.rm_duplicates = 0
if options.memory_unlimited:
if "-P" not in sys.argv:
options.pre_grouped = 1E7
if "--remove-duplicates" not in sys.argv:
options.rm_duplicates = 2E8
if "--min-quality-score" not in sys.argv:
options.min_quality_score = -5
if "--max-ignore-percent" not in sys.argv:
options.maximum_ignore_percent = 0
# using the default
if "--max-reads" not in sys.argv:
if "embplant_mt" in options.organelle_type or "anonym" in options.organelle_type:
options.maximum_n_reads *= 5
elif "animal_mt" in options.organelle_type:
options.maximum_n_reads *= 20
if options.maximum_n_reads > READ_LINE_TO_INF:
options.maximum_n_reads = inf
else:
options.maximum_n_reads = int(options.maximum_n_reads)
if "--max-n-words" not in sys.argv:
if "embplant_mt" in options.organelle_type or "anonym" in options.organelle_type:
options.maximum_n_words *= 5
elif "embplant_nr" in options.organelle_type or "fungus_mt" in options.organelle_type or\
"fungus_nr" in options.organelle_type:
options.maximum_n_words /= 2
elif "animal_mt" in options.organelle_type:
options.maximum_n_words /= 2
if "--genes" not in sys.argv:
options.genes_fasta = [] # None] * organelle_type_len
else:
temp_val_len = len(str(options.genes_fasta).split(","))
if temp_val_len != organelle_type_len:
log_handler.error("-F is followed with " + str(organelle_type_len) + " organelle types, " +
"while --genes is followed with " + str(temp_val_len) + " value(s)!\n")
exit()
temp_vals = []
for sub_genes in str(options.genes_fasta).split(","):
# if sub_genes == "":
# temp_vals.append(sub_genes)
if not os.path.exists(sub_genes):
log_handler.error(sub_genes + " not found!")
exit()
else:
temp_vals.append(sub_genes)
options.genes_fasta = temp_vals
if "--ex-genes" not in sys.argv:
options.exclude_genes = []
else:
temp_vals = []
for sub_genes in str(options.exclude_genes).split(","):
if not (os.path.exists(sub_genes) or os.path.exists(remove_db_postfix(sub_genes) + ".nhr")):
log_handler.error(sub_genes + " not found!")
exit()
else:
temp_vals.append(sub_genes)
options.exclude_genes = temp_vals
if "--target-genome-size" not in sys.argv:
raw_default_value = int(str(options.target_genome_size))
options.target_genome_size = []
for go_t, sub_organelle_t in enumerate(options.organelle_type):
if sub_organelle_t == "embplant_mt":
options.target_genome_size.append(int(raw_default_value * 3))
elif sub_organelle_t == "fungus_mt":
options.target_genome_size.append(int(raw_default_value / 2))
elif sub_organelle_t in ("embplant_nr", "animal_mt", "fungus_nr"):
options.target_genome_size.append(int(raw_default_value / 10))
elif sub_organelle_t == "anonym":
ref_seqs = read_fasta(options.genes_fasta[go_t])[1]
options.target_genome_size.append(2 * sum([len(this_seq) for this_seq in ref_seqs]))
log_handler.info(
"Setting '--target-genome-size " + ",".join([str(t_s) for t_s in options.target_genome_size]) +
"' for estimating the word size value for anonym type.")
else:
options.target_genome_size.append(raw_default_value)
else:
temp_val_len = len(str(options.target_genome_size).split(","))
if temp_val_len != organelle_type_len:
log_handler.error("-F is followed with " + str(organelle_type_len) + " organelle types, " +
"while --target-genome-size is followed with " + str(temp_val_len) + " value(s)!\n")
exit()
try:
options.target_genome_size = [int(sub_size) for sub_size in str(options.target_genome_size).split(",")]
except ValueError:
log_handler.error("Invalid --target-genome-size value(s): " + str(options.target_genome_size))
exit()
if "--expected-max-size" not in sys.argv:
raw_default_value = int(str(options.expected_max_size))
options.expected_max_size = []
for got_t, sub_organelle_t in enumerate(options.organelle_type):
if sub_organelle_t == "embplant_pt":
options.expected_max_size.append(raw_default_value)
elif sub_organelle_t in ("embplant_mt", "other_pt"):
options.expected_max_size.append(int(raw_default_value * 4))
elif sub_organelle_t == "fungus_mt":
options.expected_max_size.append(raw_default_value)
elif sub_organelle_t in ("embplant_nr", "fungus_nr", "animal_mt"):
options.expected_max_size.append(int(raw_default_value / 10))
elif sub_organelle_t == "anonym":
if options.genes_fasta:
ref_seqs = read_fasta(options.genes_fasta[got_t])[1]
options.expected_max_size.append(10 * sum([len(this_seq) for this_seq in ref_seqs]))
log_handler.info(
"Setting '--expected-max-size " + ",".join([str(t_s) for t_s in options.expected_max_size]) +
"' for estimating the word size value for anonym type.")
else:
options.expected_max_size.append(inf)
else:
temp_val_len = len(str(options.expected_max_size).split(","))
if temp_val_len != organelle_type_len:
log_handler.error("-F is followed with " + str(organelle_type_len) + " organelle types, " +
"while --expected-max-size is followed with " + str(temp_val_len) + " value(s)!\n")
exit()
try:
options.expected_max_size = [int(sub_size) for sub_size in str(options.expected_max_size).split(",")]
except ValueError:
log_handler.error("Invalid --expected-max-size value(s): " + str(options.expected_max_size))
exit()
if "--expected-min-size" not in sys.argv:
raw_default_value = int(str(options.expected_min_size))
options.expected_min_size = []
for sub_organelle_t in options.organelle_type:
options.expected_min_size.append(raw_default_value)
else:
temp_val_len = len(str(options.expected_min_size).split(","))
if temp_val_len != organelle_type_len:
log_handler.error("-F is followed with " + str(organelle_type_len) + " organelle types, " +
"while --expected-min-size is followed with " + str(temp_val_len) + " value(s)!\n")
exit()
try:
options.expected_min_size = [int(sub_size) for sub_size in str(options.expected_min_size).split(",")]
except ValueError:
log_handler.error("Invalid --expected-min-size value(s): " + str(options.expected_min_size))
exit()
if "--max-extending-len" not in sys.argv:
options.max_extending_len = [] # -1 means auto
for go_t, seed_f in enumerate(options.seed_file):
# using auto as the default when using default seed files
# if os.path.realpath(seed_f) == os.path.join(_SEQ_DB_PATH, options.organelle_type[go_t] + ".fasta"):
# options.max_extending_len.append(-1)
# else:
# options.max_extending_len.append(inf)
options.max_extending_len.append(inf)
else:
temp_val_len = len(str(options.max_extending_len).split(","))
if temp_val_len != organelle_type_len:
log_handler.error("-F is followed with " + str(organelle_type_len) + " organelle types, " +
"while --max-extending-len is followed with " + str(temp_val_len) + " value(s)!\n")
exit()
try:
options.max_extending_len = [-1 if sub_size == "auto" else float(sub_size)
for sub_size in str(options.max_extending_len).split(",")]
except ValueError:
log_handler.error("Invalid --max-extending-len value(s): " + str(options.max_extending_len))
exit()
for sub_organelle_t in options.organelle_type:
if sub_organelle_t in ("fungus_mt", "animal_mt", "anonym"):
global MAX_RATIO_RL_WS
MAX_RATIO_RL_WS = 0.8
break
if not executable(os.path.join(options.which_bowtie2, "bowtie2")):
log_handler.error(os.path.join(options.which_bowtie2, "bowtie2") + " not accessible!")
exit()
if not executable(os.path.join(options.which_bowtie2, "bowtie2-build") + " --large-index"):
log_handler.error(os.path.join(options.which_bowtie2, "bowtie2-build") + " not accessible!")
exit()
# if not executable(os.path.join(options.which_bowtie2, "bowtie2-build-l")):
# log_handler.error(os.path.join(options.which_bowtie2, "bowtie2-build-l") + " not accessible!")
# exit()
run_slim = False
run_disentangle = False
if options.run_spades:
if options.which_spades:
if not executable(os.path.join(options.which_spades, "spades.py -h")):
raise Exception("spades.py not found/executable in " + options.which_spades + "!")
else:
run_slim = True
run_disentangle = True
else:
options.which_spades = ""
if not executable("spades.py -h"):
log_handler.error("spades.py not found in the PATH. "
"Adding SPAdes binary dir to the PATH or using \"--which-spades\" to fix this. "
"Now only get the reads and skip assembly.")
options.run_spades = False
else:
run_slim = True
run_disentangle = True
if not executable(os.path.join(options.which_blast, "blastn")):
log_handler.error(os.path.join(options.which_blast, "blastn") +
" not accessible! Slimming/Disentangling disabled!!\n")
run_slim = False
run_disentangle = False
if options.genes_fasta and not executable(os.path.join(options.which_blast, "makeblastdb")):
log_handler.error(os.path.join(options.which_blast, "makeblastdb") +
" not accessible! Slimming/Disentangling disabled!!\n")
run_slim = False
run_disentangle = False
if lib_not_available:
log_handler.error("/".join(lib_not_available) + " not available! Disentangling disabled!!\n")
run_disentangle = False
options.rm_duplicates = int(options.rm_duplicates)
options.pre_grouped = int(options.pre_grouped)
if not options.rm_duplicates and options.pre_grouped:
log_handler.warning("removing duplicates was inactive, so that the pre-grouping was disabled.")
options.pre_grouped = False
if options.max_rounds and options.max_rounds < 1:
log_handler.warning("illegal maximum rounds! Set to infinite")
options.max_rounds = inf
if not options.max_rounds:
if not options.pre_grouped:
options.max_rounds = inf
else:
options.max_rounds = 1
for sub_organelle_t in options.organelle_type:
if sub_organelle_t in {"embplant_mt", "other_pt"}:
options.max_rounds = max(options.max_rounds, 30)