kaptive.serotyping.cli¶
Command line interface commands and exporter for serotyping.
This module provides CLI command implementations for performing in silico serotyping on genome assemblies and converting serialized serotyping results to various tabular, JSON, or graphical output formats.
Classes:
-
[`ResultExporter`][kaptive.serotyping.cli.ResultExporter]–Evaluates output options and dispatches serialization tasks.
-
[`Type`][kaptive.serotyping.cli.Type]–Subcommand for in silico serotyping of genome assemblies.
-
[`Convert`][kaptive.serotyping.cli.Convert]–Subcommand for converting serialized JSON-lines results.
Convert
¶
flowchart TD
kaptive.serotyping.cli.Convert[Convert]
kaptive.cli.Command[Command]
kaptive.cli.Command --> kaptive.serotyping.cli.Convert
click kaptive.serotyping.cli.Convert href "" "kaptive.serotyping.cli.Convert"
click kaptive.cli.Command href "" "kaptive.cli.Command"
🔄 Convert serialized Kaptive results into different formats.
Reads serialized JSON-lines serotyping output records and converts them into tabular TSV, PHA4GE TSV, or sequence FASTA files without re-running the serotyping pipeline.
Methods:
-
__call__–Execute result format conversion from serialized JSON-lines input.
-
add_output_arguments–Add standard report and FASTA file output options to argument group.
-
build–Wire command parser and subcommands into parent argparse hierarchy.
-
get_shared_parser–Return shared parent parser containing options passed to subcommands.
-
register_subcommands–Register child subcommand instances into
subcommandslist. -
setup_arguments–Configure argument parser options for the convert subcommand.
Source code in src/kaptive/cli.py
__call__
¶
Execute result format conversion from serialized JSON-lines input.
Deserializes line-delimited JSON records into SerotypingResult
objects and dispatches them to registered output writers.
Parameters:
Raises:
-
SystemExit–If
orjsonis not installed in the current Python environment.
Source code in src/kaptive/serotyping/cli.py
add_output_arguments
¶
add_output_arguments(opts: _ArgumentGroup, tsv_flags: tuple[str, str] = ('-o', '--out'), include_json: bool = True) -> None
Add standard report and FASTA file output options to argument group.
Parameters:
-
(opts¶_ArgumentGroup) –Target argument group to populate.
-
(tsv_flags¶tuple[str, str], default:('-o', '--out')) –Short and long flag options for TSV report output. Defaults to
("-o", "--out"). -
(include_json¶bool, default:True) –Flag indicating whether to include
--jsonargument option. Defaults toTrue.
Source code in src/kaptive/cli.py
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 | |
build
¶
build(subparsers: _SubParsersAction, parent_parsers: list[ArgumentParser] | None = None) -> None
Wire command parser and subcommands into parent argparse hierarchy.
Parameters:
-
(subparsers¶_SubParsersAction) –Target subparser action registry.
-
(parent_parsers¶list[ArgumentParser] | None, default:None) –Parent shared parsers to inherit.
Source code in src/kaptive/cli.py
get_shared_parser
¶
get_shared_parser() -> ArgumentParser | None
Return shared parent parser containing options passed to subcommands.
Returns:
-
ArgumentParser | None–argparse.ArgumentParser | None: Shared non-help argument parser or
None.
register_subcommands
¶
setup_arguments
¶
Configure argument parser options for the convert subcommand.
Defines the input JSON-lines source parameter and output target flags via
add_output_arguments.
Source code in src/kaptive/serotyping/cli.py
ResultExporter
¶
Evaluates CLI arguments once and sets up a pipeline of output writers.
This eliminates conditional branching inside the processing loop and allows
reusability between the Type and
Convert commands.
Attributes:
-
file_suffix(str) –Default filename suffix used when writing output files (default:
'kaptive_results'). -
writers(list[Callable[[SerotypingResult], None]]) –List of registered writer callback functions.
Inspects output flags in args and registers appropriate serialization callbacks
for TSV, PHA4GE TSV, JSON, locus nucleotide FASTA, gene nucleotide FASTA,
translated protein FASTA, and interactive HTML plots.
The PHA4GE TSV output adheres to the Public Health Alliance for Genomic Epidemiology genotyping specification (https://github.com/pha4ge/genotyping-specification).
Parameters:
-
(cli¶Cli) –Parent
Cliexecution context. -
(args¶Namespace) –Parsed command-line arguments containing output flags.
Raises:
-
SystemExit–If
--jsonis set butorjsonis not installed, or--plotsis set butplotlyis not installed.
Methods:
-
__call__–Pass the serotyping result to all registered output writers.
Source code in src/kaptive/serotyping/cli.py
__call__
¶
Pass the serotyping result to all registered output writers.
Parameters:
-
(result¶SerotypingResult) –The
SerotypingResultinstance to serialize and write out.
Source code in src/kaptive/serotyping/cli.py
Type
¶
flowchart TD
kaptive.serotyping.cli.Type[Type]
kaptive.cli.Command[Command]
kaptive.cli.Command --> kaptive.serotyping.cli.Type
click kaptive.serotyping.cli.Type href "" "kaptive.serotyping.cli.Type"
click kaptive.cli.Command href "" "kaptive.cli.Command"
💉 In silico serotyping of genome assemblies.
Aliases
assembly
Methods:
-
__call__–Execute the serotyping workflow on input genome assemblies.
-
add_output_arguments–Add standard report and FASTA file output options to argument group.
-
build–Wire command parser and subcommands into parent argparse hierarchy.
-
get_shared_parser–Return shared parent parser containing options passed to subcommands.
-
register_subcommands–Register child subcommand instances into
subcommandslist. -
setup_arguments–Configure argument parser options for the type subcommand.
Source code in src/kaptive/cli.py
__call__
¶
Execute the serotyping workflow on input genome assemblies.
Loads the requested locus database, initializes the serotyping engine, iterates through genome assemblies to call serotypes, and streams results to configured output targets.
Parameters:
Source code in src/kaptive/serotyping/cli.py
add_output_arguments
¶
add_output_arguments(opts: _ArgumentGroup, tsv_flags: tuple[str, str] = ('-o', '--out'), include_json: bool = True) -> None
Add standard report and FASTA file output options to argument group.
Parameters:
-
(opts¶_ArgumentGroup) –Target argument group to populate.
-
(tsv_flags¶tuple[str, str], default:('-o', '--out')) –Short and long flag options for TSV report output. Defaults to
("-o", "--out"). -
(include_json¶bool, default:True) –Flag indicating whether to include
--jsonargument option. Defaults toTrue.
Source code in src/kaptive/cli.py
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 | |
build
¶
build(subparsers: _SubParsersAction, parent_parsers: list[ArgumentParser] | None = None) -> None
Wire command parser and subcommands into parent argparse hierarchy.
Parameters:
-
(subparsers¶_SubParsersAction) –Target subparser action registry.
-
(parent_parsers¶list[ArgumentParser] | None, default:None) –Parent shared parsers to inherit.
Source code in src/kaptive/cli.py
get_shared_parser
¶
get_shared_parser() -> ArgumentParser | None
Return shared parent parser containing options passed to subcommands.
Returns:
-
ArgumentParser | None–argparse.ArgumentParser | None: Shared non-help argument parser or
None.
register_subcommands
¶
setup_arguments
¶
Configure argument parser options for the type subcommand.
Defines input database/genome arguments, output formatting flags via
add_output_arguments, confidence options,
and thread count parameters.