Prokka gbk to json
build_bakta_sequence_entry(rec)
Convert a SeqRecord into a Bakta-style sequence entry. Missing fields are filled with None.
Source code in src/baktfold/io/prokka_gbk_to_json.py
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 | |
calc_genome_stats(records)
Compute correct genome stats (size, GC, N-ratio, N50, N90) for records from a multi-contig Prokka GenBank file.
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_assembly_gap_feature(feature, rec, id)
Convert a Prokka GenBank assembly_gap feature to a simplified Bakta-style 'gap' feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The assembly_gap feature from the Prokka GBK. |
required | |
rec |
Bio.SeqRecord The full GenBank record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Simplified Bakta-style gap feature. |
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_cds_feature(feature, seq_record, translation_table, id)
Convert a Prokka CDS Biopython SeqFeature to a Bakta CDS JSON entry.
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_misc_rna_feature(feature, rec, id)
Convert a Prokka GenBank misc_RNA (nc_rna) feature to a Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The misc_RNA feature from the Prokka GBK. |
required | |
rec |
Bio.SeqRecord The record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style misc_RNA feature. |
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_repeat_region_feature(feature, rec, id)
Convert a Prokka GenBank repeat_region (CRISPR) feature to a simplified Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The repeat_region feature (crispr) from the Prokka GBK. |
required | |
rec |
Bio.SeqRecord The full GenBank record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Simplified Bakta-style CRISPR feature. |
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_rrna_feature(feature, rec, id)
Convert a Prokka GenBank rRNA feature to Bakta-style JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The rRNA feature from the Prokka GBK. |
required | |
rec |
str The record from the GBK. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style rRNA feature |
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_tmrna_feature(feature, rec, id)
Convert a Prokka GenBank tmRNA feature to Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The tmRNA feature from the Prokka GBK. |
required | |
rec |
str The record from the GBK |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style tmRNA feature |
Source code in src/baktfold/io/prokka_gbk_to_json.py
convert_trna_feature(feature, seq_record, id)
Convert a Prokka tRNA SeqFeature to a Bakta tRNA JSON entry.
Source code in src/baktfold/io/prokka_gbk_to_json.py
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 | |
get_bakta_style_id_from_locus_tag(records)
Gets 10 char bakta-style ID tag based off the 8 char locus tag in first CDS on the first Prokka record + 2 random chars
Assumes all records will have the same locus tag prefix
Will always add 2 chars to make ID unique vs locus tag
Source code in src/baktfold/io/prokka_gbk_to_json.py
get_transl_table(records)
Gets translation table based off the first CDS on the first record
Source code in src/baktfold/io/prokka_gbk_to_json.py
parse_prokka_version(record)
Extract Prokka version from COMMENT field: Example COMMENT: 'Annotated using prokka 1.14.6 ...'
Source code in src/baktfold/io/prokka_gbk_to_json.py
prokka_gbk_to_json(records, output_json)
Convert Prokka-generated GenBank SeqRecord objects into a Bakta-style JSON annotation file.
This function takes one or more Biopython SeqRecord objects (typically parsed from a Prokka GenBank file) and reconstructs a JSON structure following the Bakta output schema. It extracts genome metadata, statistics, annotated features, nucleotide sequences, and Prokka version information. Features are converted to Bakta-compatible dictionaries and sorted in the same order Bakta expects.
The JSON file contains
• genome block – high-level organism metadata (genus, species, strain, etc.)
• stats block – genome statistics derived from all records
• features block – all features converted to Bakta-style objects, sorted
by feature type and genomic position
• sequences block – contig/sequence entries in Bakta format
• run block – timestamps and duration placeholder
• version block – Prokka version and database metadata
Parameters
list of SeqRecord
A list of Biopython SeqRecord objects already parsed from a Prokka GenBank file. Must contain at least one record. The COMMENT field is expected to contain Prokka metadata.
str
Path to the output JSON file to be written.
Returns
bool True if the JSON was successfully written.
Raises
ValueError
If records is empty.
Notes
• Features are processed in a fixed Bakta-like order:
["tRNA", "tmRNA", "rRNA", "misc_RNA", "repeat_region", "CDS", "assembly_gap"]
• Feature IDs are generated in Bakta-style using the locus tag prefix.
• Per-contig sorting is performed by genomic start coordinate.
• Runtime values in the run block are placeholders (duration = "0.00 min").
• The function does not validate that the GenBank file truly originates from
Prokka; that should be checked beforehand.
Source code in src/baktfold/io/prokka_gbk_to_json.py
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 | |
random_n_letter_id(n=4)
generates a n letter id prefix
n=2 to append to Prokka locus tag for bakta id to make it different n=10 if the locus tag is somehow missing (should never happen)