Debian Codegraph @

src/cgelib/applications/KMA.py

raw
1 from cgelib.applications.command import _ContentArgument, CommandLineBase
2 from cgelib.applications.command import _SwitchArgument, _SwitchValueArgument
3
4
5 class _KmaBaseCommandline(CommandLineBase):
6 """Base Commandline object for KMA wrappers (PRIVATE).
7 This is provided for subclassing, it deals with shared options
8 common to all the KMA tools (kma, kma_index, kma_update, etc
9 AND kma_shm).
10 """
11
12 def __init__(self, cmd=None, path_exec="", **kwargs):
13 assert cmd is not None
14 extra_parameters = [
15 # Core:
16 _SwitchArgument(
17 ["-h", "h"],
18 "Print USAGE, DESCRIPTION and ARGUMENTS description; "
19 "ignore other arguments.",
20 no_run=True,
21 ),
22 _SwitchArgument(
23 ["-v", "v"],
24 "Print version number; "
25 "ignore other arguments.",
26 no_run=True,
27 ),
28 _ContentArgument(
29 ["", "custom_args"],
30 "Add custom arguments that are not included in the "
31 "kma_application.py file."
32 ),
33 ]
34 try:
35 # Insert extra parameters - at the start just in case there
36 # are any arguments which must come last:
37 self.parameters = extra_parameters + self.parameters
38 except TypeError:
39 # Should we raise an error? The subclass should have set this up!
40 self.parameters = extra_parameters
41 # Do we need a method to add a method for adding arguments in front?
42 CommandLineBase.__init__(self, cmd, path_exec, **kwargs)
43
44 def _validate_incompatibilities(self, incompatibles):
45 """Validate parameters for incompatibilities (PRIVATE).
46 Used by the _validate method.
47 """
48 for a in incompatibles:
49 if self._get_parameter(a):
50 for b in incompatibles[a]:
51 if self._get_parameter(b):
52 raise ValueError("Options %s and %s are incompatible."
53 % (a, b))
54
55
56 class KMACommandline(_KmaBaseCommandline):
57 """Base Commandline object for the wrapper of the KMA aligner.
58 This is provided for subclassing, it deals with shared options
59 common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
60 """
61
62 def __init__(self, cmd="kma", path_exec="", **kwargs):
63 assert cmd is not None
64 self.parameters = [
65 # Input query options:
66 _ContentArgument(
67 ["-i", "input"],
68 "Input file name(s)",
69 filename=True,
70 is_required=True,
71 default="STDIN",
72 alter_options=["input_int", "input_ipe"],
73 incompatible=["input_int", "input_ipe"],
74 allow_multiple=True,
75 ),
76 _ContentArgument(
77 ["-ipe", "input_ipe"],
78 "Input paired end file name(s)",
79 filename=True,
80 is_required=True,
81 alter_options=["input", "input_int"],
82 incompatible=["input", "input_int"],
83 allow_multiple=True,
84 ),
85 _ContentArgument(
86 ["-int", "input_int"],
87 "Input interleaved file name(s)",
88 filename=True,
89 is_required=True,
90 alter_options=["input", "input_ipe"],
91 incompatible=["input", "input_ipe"],
92 allow_multiple=True,
93 ), # Should this be required?
94 _ContentArgument(
95 ["-o", "output"],
96 "Output file",
97 filename=True,
98 is_required=True,
99 default="None",
100 ),
101 _ContentArgument(
102 ["-t_db", "template_db"],
103 "Template DB",
104 filename=True,
105 default="None",
106 is_required=True,
107 ),
108 _ContentArgument(
109 ["-k", "k_size"],
110 "Kmersize (default by db)",
111 filename=False,
112 default="DB defined",
113 is_required=False,
114 ),
115 _ContentArgument(
116 ["-ml", "min_len"],
117 "Minimum alignment length",
118 filename=False,
119 default=16,
120 is_required=False,
121 ),
122 _ContentArgument(
123 ["-p", "p_value"],
124 "p-value",
125 filename=False,
126 default=0.05,
127 is_required=False,
128 ),
129 _ContentArgument(
130 ["-ConClave", "con_clave"],
131 "ConClave version",
132 filename=False,
133 default=1,
134 is_required=False,
135 ),
136 _SwitchArgument(
137 ["-mem_mode", "mem_mode"],
138 "Use kmers to choose best template, and save memory",
139 ),
140 _SwitchValueArgument(
141 ["-proxi", "proxi"],
142 "Use proximity scoring under template mapping",
143 filename=False,
144 default="False/1.0",
145 is_required=False,
146 ),
147 _SwitchArgument(
148 ["-ex_mode", "ex_mode"],
149 "Searh kmers exhaustively",
150 ),
151 _SwitchArgument(
152 ["-ef", "extra_files"],
153 "Output extra files",
154 ),
155 _SwitchValueArgument(
156 ["-vcf", "vcf"],
157 "Make vcf file, 2 to apply FT",
158 filename=False,
159 default="False/0",
160 is_required=False,
161 ),
162 _SwitchValueArgument(
163 ["-sam", "sam"],
164 "Output sam to stdout, 4 to output mapped reads,"
165 "2096 for aligned",
166 filename=False,
167 default="False/1.0",
168 is_required=False,
169 ),
170 _SwitchArgument(
171 ["-nc", "non_consensus"],
172 "No consensus file",
173 ),
174 _SwitchArgument(
175 ["-na", "no_aln"],
176 "No aln file",
177 ),
178 _SwitchArgument(
179 ["-nf", "no_frag"],
180 "No frag file",
181 ),
182 _SwitchArgument(
183 ["-deCon", "deCon"],
184 "Remove contamination",
185 ),
186 _SwitchArgument(
187 ["-dense", "dense"],
188 "Do not allow insertions in assembly",
189 ),
190 _SwitchArgument(
191 ["-sasm", "sasm"],
192 "Skip alignment and assembly",
193 ),
194 _SwitchValueArgument(
195 ["-ref_fsa", "ref_sa"],
196 "Consensus sequence will have 'n' instead of gaps",
197 filename=False,
198 is_required=False,
199 default="False/0",
200 ),
201 _SwitchArgument(
202 ["-matrix", "matrix"],
203 "Outputs assembly matrix",
204 ),
205 _SwitchArgument(
206 ["-a", "best_maps"],
207 "Print all best mappings",
208 ),
209 _ContentArgument(
210 ["-mp", "min_phred"],
211 "Minimum phred score",
212 filename=False,
213 default=20,
214 is_required=False,
215 ),
216 _ContentArgument(
217 ["-5p", "cut_5p"],
218 "Cut a constant number of nucleotides from the 5 prime",
219 filename=False,
220 default=0,
221 is_required=False,
222 ),
223 _ContentArgument(
224 ["-3p", "cut_3p"],
225 "Cut a constant number of nucleotides from the 3 prime",
226 filename=False,
227 default=0,
228 is_required=False,
229 ),
230 _SwitchArgument(
231 ["-Sparse", "sparse"],
232 "Only count kmers",
233 ),
234 _SwitchValueArgument(
235 ["-Mt1", "Mt1"],
236 "Map only to 'num' template",
237 filename=False,
238 is_required=False,
239 default="False/0",
240 ),
241 _ContentArgument(
242 ["-ID", "ID"],
243 "Minimum ID",
244 filename=False,
245 default="1.0%",
246 is_required=False,
247 ),
248 _ContentArgument(
249 ["-ss", "ss"],
250 "Sparse sorting (q,c,d)",
251 filename=False,
252 default="q",
253 checker_function=lambda x: x in ["q", "c", "d"],
254 is_required=False,
255 ),
256 _ContentArgument(
257 ["-pm", "pm"],
258 "Pairing method (p,u,f)",
259 filename=False,
260 default="u",
261 checker_function=lambda x: x in ["p", "u", "f"],
262 is_required=False,
263 ),
264 _ContentArgument(
265 ["-fpm", "fpm"],
266 "Fine Pairing method (p,u,f)",
267 filename=False,
268 checker_function=lambda x: x in ["p", "u", "f"],
269 default="u",
270 is_required=False,
271 ),
272 _ContentArgument(
273 ["-apm", "apm"],
274 "Sets both pm and fpm (p,u,f)",
275 filename=False,
276 default="u",
277 checker_function=lambda x: x in ["p", "u", "f"],
278 is_required=False,
279 ),
280 _ContentArgument(
281 ["-shm", "shm"],
282 "Use shared DB made by kma_shm",
283 filename=False,
284 default="0 (lvl)",
285 is_required=False,
286 ),
287 _SwitchArgument(
288 ["-mmap", "mmap"],
289 "Memory map *.comp.by",
290 ),
291 _ContentArgument(
292 ["-tmp", "tmp"],
293 "Set directory for temporary files.",
294 filename=True,
295 is_required=False,
296 ),
297 _SwitchArgument(
298 ["-1t1", "1t1"],
299 "Force end to end mapping"
300 ),
301 _SwitchArgument(
302 ["-hmm", "hmm"],
303 "Use a HMM to assign template(s) to query sequences"
304 ),
305 _SwitchArgument(
306 ["-ck", "count_k"],
307 "Count kmers instead of pseudo alignment"
308 ),
309 _SwitchArgument(
310 ["-ca", "circular_aln"],
311 "Make circular alignments"
312 ),
313 _SwitchArgument(
314 ["-boot", "bootstrap"],
315 "Bootstrap sequence"
316 ),
317 _SwitchArgument(
318 ["-bc", "bc"],
319 "Base calls should be significantly overrepresented",
320 default=True,
321 incompatible=["bc90"],
322 ),
323 _SwitchArgument(
324 ["-bc90", "bc90"],
325 "Base calls should be both significantly overrepresented, and"
326 " have 90% agreement.",
327 incompatible=["bc"]
328 ),
329 _SwitchArgument(
330 ["-bcNano", "bcNano"],
331 "Call bases at suspicious deletions, made for nanopore."
332 ),
333 _ContentArgument(
334 ["-bcd", "bcd"],
335 "Minimum depth at base.",
336 filename=False,
337 default=1,
338 is_required=False,
339 ),
340 _SwitchArgument(
341 ["-bcg", "bcg"],
342 "Maintain insignificant gaps",
343 ),
344 _SwitchArgument(
345 ["-and", "and"],
346 "Both mrs and p_value thresholds has to reached to in order "
347 "to report a template hit.",
348 ),
349 _ContentArgument(
350 ["-mq", "MinMapQ"],
351 "Minimum mapping quality",
352 filename=False,
353 default=0,
354 is_required=False,
355 ),
356 _ContentArgument(
357 ["-mrs", "MinAlnQ"],
358 "Minimum alignment score, normalized to alignment length",
359 filename=False,
360 default=0.50,
361 is_required=False,
362 ),
363 _ContentArgument(
364 ["-mct", "mct"],
365 "Max overlap between templates",
366 filename=False,
367 default=0.50,
368 is_required=False,
369 ),
370 _ContentArgument(
371 ["-reward", "reward"],
372 "Score for match",
373 filename=False,
374 default=1,
375 is_required=False,
376 ),
377 _ContentArgument(
378 ["-penalty", "penalty"],
379 "Penalty for mismatch",
380 filename=False,
381 default=-2,
382 is_required=False,
383 ),
384 _ContentArgument(
385 ["-gapopen", "gap_open"],
386 "Penalty for gap opening",
387 filename=False,
388 default=-3,
389 is_required=False,
390 ),
391 _ContentArgument(
392 ["-gapextend", "gap_extend"],
393 "Penalty for gap extension",
394 filename=False,
395 default=-1,
396 is_required=False,
397 ),
398 _ContentArgument(
399 ["-per", "reward_pairing"],
400 "Reward for pairing end",
401 filename=False,
402 default=7,
403 is_required=False,
404 ),
405 _ContentArgument(
406 ["-localopen", "local_open"],
407 "Penalty for openning a local chain",
408 filename=False,
409 default=-6,
410 is_required=False,
411 ),
412 _ContentArgument(
413 ["-Npenalty", "n_penalty"],
414 "Penalty matching N",
415 filename=False,
416 default=0,
417 is_required=False,
418 ),
419 _ContentArgument(
420 ["-transition", "transition"],
421 "Penalty for transition",
422 filename=False,
423 default=-2,
424 is_required=False,
425 ),
426 _ContentArgument(
427 ["-transversion", "transversion"],
428 "Penalty for transversion",
429 filename=False,
430 default=-2,
431 is_required=False,
432 ),
433 _SwitchArgument(
434 ["-cge", "cge"],
435 "Set CGE penalties and rewards",
436 ),
437 _ContentArgument(
438 ["-t", "threads"],
439 "Number of threads",
440 filename=False,
441 default=1,
442 is_required=False,
443 ),
444 _SwitchArgument(
445 ["-status", "status"],
446 "Extra status",
447 ),
448 _SwitchArgument(
449 ["-verbose", "verbose"],
450 "Extra verbose",
451 ),
452 _SwitchArgument(
453 ["-c", "citation"],
454 "Citation",
455 no_run=True,
456 ),
457 _SwitchArgument(
458 ["-ont", "ont"],
459 "Set 3rd gen genefinding preset",
460 ),
461 _ContentArgument(
462 ["-md", "md"],
463 "minimum depth",
464 filename=False,
465 default=0.0,
466 is_required=False,
467 ),
468 ]
469 _KmaBaseCommandline.__init__(self, cmd, path_exec, **kwargs)
470
471
472 class KMAIndexCommandline(_KmaBaseCommandline):
473 """Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
474 This is provided for subclassing, it deals with shared options
475 common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
476 """
477
478 def __init__(self, cmd="kma_index", path_exec="", **kwargs):
479 assert cmd is not None
480 self.parameters = [
481 _ContentArgument(
482 ["-i", "input"],
483 "Input/query file name (STDIN: '--')",
484 filename=True,
485 default="None",
486 is_required=False,
487 allow_multiple=True,
488 alter_options=["batch"],
489 incompatible=["batch"],
490
491 ),
492 _ContentArgument(
493 ["-o", "output"],
494 "Output file",
495 filename=False,
496 default="Input file",
497 is_required=False,
498 ),
499 _ContentArgument(
500 ["-batch", "batch"],
501 "Batch input file",
502 filename=True,
503 is_required=False,
504 alter_options=["input"],
505 incompatible=["input"]
506 ),
507 _SwitchValueArgument(
508 ["-deCon", "deCon"],
509 "File with contamination (STDIN: '--')",
510 default="None/False",
511 filename=True,
512 is_required=False,
513 ),
514 _ContentArgument(
515 ["-batchD", "batchD"],
516 "Batch decon file",
517 filename=True,
518 is_required=False,
519 ),
520 _SwitchValueArgument(
521 ["-t_db", "template_db"],
522 "Add to existing DB",
523 filename=True,
524 default="None/False",
525 is_required=False,
526 ),
527 _ContentArgument(
528 ["-k", "k_size"],
529 "Kmersize",
530 filename=False,
531 default=16,
532 is_required=False,
533 ),
534 _ContentArgument(
535 ["-k_t", "k_temp"],
536 "Kmersize for template identification",
537 filename=False,
538 default=16,
539 is_required=False,
540 ),
541 _ContentArgument(
542 ["-k_i", "k_index"],
543 "Kmersize for indexing",
544 filename=False,
545 default=16,
546 is_required=False,
547 ),
548 _ContentArgument(
549 ["-ML", "min_len"],
550 "Minimum length for templates",
551 filename=False,
552 default="kmersize (16)",
553 is_required=False,
554 ),
555 _ContentArgument(
556 ["-CS", "cs"],
557 "Start chain size",
558 filename=False,
559 default="1 M",
560 is_required=False,
561 ),
562 _SwitchArgument(
563 ["-ME", "mega_db"],
564 "Mega DB",
565 ),
566 _SwitchArgument(
567 ["-NI", "no_index"],
568 "Do not dump *.index.b",
569 ),
570 _SwitchValueArgument(
571 ["-Sparse", "sparse"],
572 "Make Sparse DB ('-' for no prefix)",
573 filename=False,
574 default="None/False",
575 is_required=False,
576 ),
577 _ContentArgument(
578 ["-ht", "homology_temp"],
579 "Homology template",
580 filename=False,
581 default=1.0,
582 is_required=False,
583 ),
584 _ContentArgument(
585 ["-hq", "homology_query"],
586 "Homology query",
587 filename=False,
588 default=1.0,
589 is_required=False,
590 ),
591 _SwitchArgument(
592 ["-and", "and"],
593 "Both homolgy thresholds has to be reached",
594 ),
595 _SwitchArgument(
596 ["-nbp", "no_bias"],
597 "No bias print",
598 ),
599 ]
600 _KmaBaseCommandline.__init__(self, cmd, path_exec, **kwargs)
601
602
603 class KMAShmCommandline(_KmaBaseCommandline):
604 """Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
605 This is provided for subclassing, it deals with shared options
606 common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
607 """
608
609 def __init__(self, cmd="kma_shm", path_exec="", **kwargs):
610 assert cmd is not None
611 self.parameters = [
612 _ContentArgument(
613 ["-t_db", "template_db"],
614 "Template DB",
615 filename=True,
616 default=None,
617 is_required=True,
618 ),
619 _SwitchArgument(
620 ["-destroy", "destroy"],
621 "Destroy shared memory",
622 ),
623 _ContentArgument(
624 ["-shmLvl", "shmLvl"],
625 "Level of shared memory",
626 filename=False,
627 default=1,
628 is_required=False,
629 ),
630 _SwitchArgument(
631 ["-shm-h", "shm_h"],
632 "Explain of shared memory",
633 ),
634 ]
635 _KmaBaseCommandline.__init__(self, cmd, path_exec, **kwargs)
636
637
638 class KMASeq2FastaCommandline(_KmaBaseCommandline):
639 """Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
640 This is provided for subclassing, it deals with shared options
641 common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
642 """
643
644 def __init__(self, cmd="kma seq2fasta", path_exec="", **kwargs):
645 assert cmd is not None
646 self.parameters = [
647 _ContentArgument(
648 ["-t_db", "template_db"],
649 "Template DB",
650 filename=True,
651 default=None,
652 is_required=True,
653 ),
654 _SwitchArgument(
655 ["-seqs", "seqs"],
656 "Comma separated list of templates",
657 ),
658 ]
659 _KmaBaseCommandline.__init__(self, cmd, path_exec, **kwargs)
660
661
662 class KMADistCommandline(_KmaBaseCommandline):
663 """Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
664 This is provided for subclassing, it deals with shared options
665 common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
666 """
667
668 def __init__(self, cmd="kma dist", path_exec="", **kwargs):
669 assert cmd is not None
670 self.parameters = [
671 _ContentArgument(
672 ["-t_db", "template_db"],
673 "Template DB",
674 filename=True,
675 is_required=True,
676 ),
677 _ContentArgument(
678 ["-o", "output"],
679 "Output file",
680 filename=True,
681 default="DB",
682 is_required=False,
683 ),
684 _ContentArgument(
685 ["-f", "output_f"],
686 "Output flags",
687 filename=False,
688 default=1,
689 checker_function=lambda x: x in [1, 4],
690 is_required=False,
691 ),
692 _SwitchArgument(
693 ["-fh", "help_flags"],
694 "Help on option '-f'",
695 ),
696 _ContentArgument(
697 ["-d", "distance_method"],
698 "DistanceMethod",
699 filename=False,
700 checker_function=lambda x: x in [1, 2, 4, 8, 16, 32, 64, 128,
701 256, 512, 1024, 2048, 4096],
702 default=1,
703 is_required=False,
704 ),
705 _SwitchArgument(
706 ["-dh", "help_distance"],
707 "Help on option '-d'",
708 ),
709 _SwitchArgument(
710 ["-m", "matrix"],
711 "Allocate matrix on the disk",
712 ),
713 _ContentArgument(
714 ["-tmp", "tmp"],
715 "Set directory for temporary file",
716 filename=True,
717 is_required=False,
718 ),
719 _ContentArgument(
720 ["-t", "threads"],
721 "Number of threads",
722 filename=False,
723 default=1,
724 is_required=False,
725 ),
726 ]
727 _KmaBaseCommandline.__init__(self, cmd, path_exec, **kwargs)
728
729
730 class KMADBCommandline(_KmaBaseCommandline):
731 """Base Commandline object for (new) NCBI BLAST+ wrappers (PRIVATE).
732 This is provided for subclassing, it deals with shared options
733 common to all the BLAST tools (blastn, rpsblast, rpsblast, etc).
734 """
735
736 def __init__(self, cmd="kma db", path_exec="", **kwargs):
737 assert cmd is not None
738 self.parameters = [
739 _ContentArgument(
740 ["-t_db", "template_db"],
741 "Template DB",
742 filename=True,
743 is_required=True,
744 ),
745 ]
746 _KmaBaseCommandline.__init__(self, cmd, path_exec, **kwargs)