Index
calc_md5_sum(tarball_path, buffer_size=1024 * 1024)
Calculate the MD5 checksum of the given file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tarball_path |
Path
|
The path to the file for which the MD5 checksum needs to be calculated. |
required |
buffer_size |
int
|
The buffer size for reading the file. |
1024 * 1024
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The MD5 checksum of the file. |
Source code in src/baktfold/databases/db.py
check_db_installation(db_dir, foldseek_gpu)
Check if the baktfold database is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_dir |
Path
|
The directory where the database is installed. |
required |
foldseek_gpu |
bool
|
Whether to install foldseek-gpu compatible baktfold db |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all required files are present, False otherwise. |
Source code in src/baktfold/databases/db.py
check_prostT5_download(model_dir, model_name)
Args: model_dir (Path): Directory where the model and tokenizer is be stored. model_name (str): Name of the pre-trained T5 model.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
bool to tell baktfold whether to download ProstT5 |
Source code in src/baktfold/databases/db.py
download(tarball_path, cache_dir)
Download the database from the given URL using HF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tarball_path |
Path
|
The path where the downloaded tarball should be saved. |
required |
Source code in src/baktfold/databases/db.py
download_requests(db_url, tarball_path)
Downloads a file from a given URL using the requests library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_url |
str
|
The URL of the file to download. |
required |
tarball_path |
Path
|
The path to save the downloaded file. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
>>> download_requests("https://zenodo.org/records/17347516/files/baktfold_db.tar.gz", Path("baktfold_db.tar.gz"))
Source code in src/baktfold/databases/db.py
download_zenodo_prostT5(model_dir, logdir, threads)
Download the ProstT5 model from Zenodo
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_url |
str
|
The URL of the database. |
required |
tarball_path |
Path
|
The path where the downloaded tarball should be saved. |
required |
Source code in src/baktfold/databases/db.py
foldseek_makepaddedseqdb(db_dir)
Runs the Foldseek makepaddedseqdb command on a given database directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_dir |
Path
|
The path to the database directory. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Source code in src/baktfold/databases/db.py
install_database(db_dir, foldseek_gpu, threads)
Install the baktfold database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_dir |
Path
|
The directory where the database should be installed. |
required |
foldseek_gpu |
bool
|
Whether to install foldseek-gpu compatible baktfold db |
required |
threads |
int
|
Number of threads available (makes downloading faster) |
required |
Source code in src/baktfold/databases/db.py
untar(tarball_path, output_path, DICT)
Extract the tarball to the output path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tarball_path |
Path
|
The path to the tarball file. |
required |
output_path |
Path
|
The path where the contents of the tarball should be extracted. |
required |
DICT |
dict
|
version dictionary |
required |
Source code in src/baktfold/databases/db.py
validate_db(database, default_dir, foldseek_gpu)
Validates the baktfold database is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database |
str
|
The directory where the database is installed. |
required |
default_dir |
str
|
Default DB location |
required |
foldseek_gpu |
bool
|
Whether to install foldseek-gpu compatible baktfold db |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
Path
|
True if all required files are present, False otherwise. |
Source code in src/baktfold/databases/db.py
subcommand_predict(hypotheticals, cds_dict, output, prefix, cpu, omit_probs, model_dir, model_name, checkpoint_path, batch_size, save_per_residue_embeddings, save_per_protein_embeddings, threads, mask_threshold, has_duplicate_locus, gpus=None)
Wrapper command for baktfold predict. Predicts embeddings using ProstT5 encoder + CNN prediction head.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hypotheticals |
Dict[str, any]
|
feature dict for all Bakta hypothetical proteins |
required |
cds_dict |
Dict[str, any]
|
id:aa dictionary |
required |
output |
str
|
Output directory path. |
required |
prefix |
str
|
Prefix for output file names. |
required |
cpu |
bool
|
Flag indicating whether to use CPU for prediction. |
required |
omit_probs |
bool
|
Flag indicating whether to omit prediction probabilities from ProstT5. |
required |
model_dir |
str
|
Directory containing the ProstT5 model. |
required |
model_name |
str
|
Name of the ProstT5 model. |
required |
checkpoint_path |
Path
|
Path to ProstT5 CNN checkpoint. |
required |
batch_size |
int
|
Batch size for prediction. |
required |
proteins_flag |
bool
|
True if baktfold proteins-predict, false otherwise |
required |
save_per_residue_embeddings |
bool
|
Whether to save per residue embeddings to h5 file. Defaults to False. |
required |
save_per_protein_embeddings |
bool
|
Whether to save mean per protein embeddings to h5 file. Defaults to False. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
hypotheticals |
Dict[str, any]
|
feature dict for all Bakta hypothetical proteins. Updated with ProstT5 3Di strings (unmasked) |
Source code in src/baktfold/subcommands/predict.py
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 | |
subcommand_compare(hypotheticals, output, threads, evalue, sensitivity, database, prefix, predictions_dir, structures, structure_dir, logdir, proteins_flag, max_seqs, ultra_sensitive, extra_foldseek_params, custom_db, foldseek_gpu, custom_annotations, has_duplicate_locus, fast, gpus=None)
Compare 3Di or PDB structures to the baktfold DB
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hypotheticals |
Dict
|
hypothetical features dictionary |
required |
output |
Path
|
Path to the output directory. |
required |
threads |
int
|
Number of threads to use. |
required |
evalue |
float
|
E-value threshold. |
required |
card_vfdb_evalue |
float
|
E-value threshold for CARD and VFDB databases. |
required |
sensitivity |
float
|
Sensitivity threshold. |
required |
database |
Path
|
Path to the reference database. |
required |
prefix |
str
|
Prefix for output files. |
required |
predictions_dir |
Optional[Path]
|
Path to the directory containing predictions. |
required |
structures |
bool
|
Flag indicating whether structures files are used. |
required |
structure_dir |
Optional[Path]
|
Path to the directory containing structures (.pdb or .cif) files. |
required |
logdir |
Path
|
Path to the directory for log files. |
required |
proteins_flag |
bool
|
Flag indicating whether proteins are used. |
required |
max_seqs |
int
|
Maximum results per query sequence allowed to pass the prefilter for foldseek. |
required |
ultra_sensitive |
bool
|
Whether to skip foldseek prefilter for maximum sensitivity |
required |
extra_foldseek_params |
str
|
Extra foldseek search parameters |
required |
custom_db |
str
|
Custom foldseek database |
required |
foldseek_gpu |
bool
|
Use Foldseek-GPU acceleration and ungappedprefilter |
required |
custom_annotations |
Optional[Path]
|
Path to the tsv containing the custom_db annotations, 2 columns |
required |
has_duplicate_locus |
bool
|
If same locus tag has multiple annots (can happen in some euks) |
required |
fast |
bool
|
If true, skips AFDB search |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if sub-databases are created successfully, False otherwise. |
Source code in src/baktfold/subcommands/compare.py
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 | |
move_product_to_note_if_exists(qualifiers)
If a 'product' qualifier exists, append it to 'note' and remove 'product'.
Designed for the eukaryotic entries
Parameters
dict
Feature qualifiers dictionary (values are usually lists).
Returns
None Modifies qualifiers in place.
Source code in src/baktfold/io/insdc.py
revise_dbxref_insdc(dbxrefs)
Remove INSDC non-compliant DbXrefs.
Source code in src/baktfold/io/insdc.py
revise_product_insdc(product)
Revise product name for INSDC compliant submissions
Source code in src/baktfold/io/insdc.py
parse_json_input(input_path, faa_path, all_proteins, protein_json_flag)
Parses genome annotations from input JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path |
str
|
Path to input JSON file. |
required |
faa_path |
str
|
Path to output file for hypothetical proteins. |
required |
all_proteins |
bool
|
Whether to keep all proteins or only hypothetical ones. |
required |
protein_json_flag |
bool
|
Whether input is protein JSON |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing the data, features, and whether there are duplicate locus tags. |
Examples:
>>> parse_json_input('input.json', 'hypotheticals.faa', False, False)
(data, features, False, False)
Source code in src/baktfold/io/json_in.py
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 | |
Module for manipulating genbank files some taken from phynteny https://github.com/susiegriggo/Phynteny
get_genbank(genbank)
Convert a GenBank file to a dictionary.
This function reads a GenBank file and converts it into a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genbank |
Path
|
Path to the GenBank file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary representation of the GenBank file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided file is not a GenBank file. |
Source code in src/baktfold/io/handle_genbank.py
get_proteins(fasta)
Convert an Amino Acid FASTA file to a dictionary.
This function reads a AA FASTA file and converts it into a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta |
Path
|
Path to the FASTA file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary representation of the FASTA file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided file is not a FASTA file. |
Source code in src/baktfold/io/handle_genbank.py
identify_long_ids(gb_dict)
Checks all feature IDs in gb_dict. If longer than 54 chars (line break from Pharokka/biopython reading GBK files), removes the space
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dict |
A dictionary representation of the GenBank file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary representation of the GenBank file. |
Source code in src/baktfold/io/handle_genbank.py
is_gzip_file(f)
Method copied from Phispy see https://github.com/linsalrob/PhiSpy/blob/master/PhiSpyModules/helper_functions.py
This is an elegant solution to test whether a file is gzipped by reading the first two characters. I also use a version of this in fastq_pair if you want a C version :) See https://stackoverflow.com/questions/3703276/how-to-tell-if-a-file-is-gzip-compressed for inspiration
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f |
Path
|
The file to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the file is gzip compressed, otherwise False. |
Source code in src/baktfold/io/handle_genbank.py
open_protein_fasta_file(input_file)
Open a fasta file, whether it is gzipped or plain text.
input_file (str): The path to the fasta file, either gzipped or plain.
Union[IO[str], gzip.GzipFile]: A file handle to the opened fasta file.
Source code in src/baktfold/io/handle_genbank.py
add_optional_qualifiers(entry, qualifiers, single_valued=None, multi_valued=None)
Add optional INSDC qualifiers to a feature entry dict in Bakta style.
Parameters
dict
The feature dictionary being built.
dict
The qualifiers dictionary from Bio.SeqFeature.
set or list
Qualifiers expected to be single-valued (take the first if multiple).
set or list
Qualifiers that can have multiple values (keep as list if >1, else single value).
Source code in src/baktfold/io/eukaryotic_to_json.py
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/eukaryotic_to_json.py
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 | |
calc_genome_stats(records)
Compute correct genome stats (size, GC, N-ratio, N50, N90) for records from a multi-contig GenBank file.
Source code in src/baktfold/io/eukaryotic_to_json.py
convert_assembly_gap_feature(feature, rec, id)
Convert a 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 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/eukaryotic_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/eukaryotic_to_json.py
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 | |
convert_exon_feature(feature, rec, id)
Convert a GenBank exon feature to a simplified Bakta-style 'exon' feature.
Parameters
Bio.SeqFeature
The exon feature from the GenBank record.
Bio.SeqRecord
The full GenBank record.
str
Unique feature ID.
Returns
dict Bakta-style exon feature.
Source code in src/baktfold/io/eukaryotic_to_json.py
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | |
convert_gene_feature(feature, rec, id)
Convert a Funannotate GenBank gene feature to Bakta-style JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The rRNA feature from the 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/eukaryotic_to_json.py
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 | |
convert_mat_peptide_feature(feature, rec, id)
Convert a mat_peptide feature to a Bakta-style feature.
mus musculus chrom 1 NC_000067
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the 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/eukaryotic_to_json.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 | |
convert_misc_feature(feature, rec, id)
Convert a misc feature to a Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the GBK. |
required | |
rec |
Bio.SeqRecord The record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style misc_feature feature. |
Source code in src/baktfold/io/eukaryotic_to_json.py
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 | |
convert_misc_rna_feature(feature, rec, id)
Convert a GenBank misc_rna feature to a simplified Bakta-style 'misc_rna' feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The assembly_gap feature from the 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/eukaryotic_to_json.py
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 | |
convert_mobile_element_feature(feature, rec, id)
Convert a GenBank mobile_element feature to a Bakta-style feature.
Source code in src/baktfold/io/eukaryotic_to_json.py
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 | |
convert_mrna_feature(feature, rec, id)
Convert a funannotate mrna feature to a Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the GBK. |
required | |
rec |
Bio.SeqRecord The record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style mRNA feature. |
Source code in src/baktfold/io/eukaryotic_to_json.py
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 | |
convert_ncrna_feature(feature, rec, id)
Convert a ncrna feature to a Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the 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/eukaryotic_to_json.py
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 | |
convert_precursor_rna_feature(feature, rec, id)
Convert a GenBank precursor_RNA feature to a Bakta-style feature.
Source code in src/baktfold/io/eukaryotic_to_json.py
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 | |
convert_proprotein_propeptide_feature(feature, rec, id)
Convert a proprotein or propeptide feature to a Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the GBK. |
required | |
rec |
Bio.SeqRecord The record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style proprotein feature. |
Source code in src/baktfold/io/eukaryotic_to_json.py
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 | |
convert_protein_bind_feature(feature, rec, id)
Convert a GenBank protein_bind feature to a Bakta-style feature.
Source code in src/baktfold/io/eukaryotic_to_json.py
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 | |
convert_regulatory_feature(feature, rec, id)
Convert a GenBank regulatory feature to a Bakta-style feature.
Source code in src/baktfold/io/eukaryotic_to_json.py
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 | |
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/eukaryotic_to_json.py
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 | |
convert_rrna_feature(feature, rec, id)
Convert a GenBank rRNA feature to a Bakta-style feature.
Source code in src/baktfold/io/eukaryotic_to_json.py
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 | |
convert_sig_peptide_feature(feature, rec, id)
Convert a sig_peptide feature to a Bakta-style feature.
mus musculus chrom 1 NC_000067
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the GBK. |
required | |
rec |
Bio.SeqRecord The record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style sig_peptide feature. |
Source code in src/baktfold/io/eukaryotic_to_json.py
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 | |
convert_transit_peptide_feature(feature, rec, id)
Convert a transit_peptide feature to a Bakta-style feature.
mus musculus chrom 1 NC_000067
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The mRNA feature from the GBK. |
required | |
rec |
Bio.SeqRecord The record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Bakta-style transit_peptide feature. |
Source code in src/baktfold/io/eukaryotic_to_json.py
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 | |
convert_trna_feature(feature, seq_record, id)
Convert a funannotate tRNA SeqFeature to a Bakta tRNA JSON entry.
Source code in src/baktfold/io/eukaryotic_to_json.py
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 | |
convert_utr_region_feature(feature, rec, id, three)
Convert a UTR GenBank feature to a simplified Bakta-style feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
Bio.SeqFeature The UTR feature from the GBK. |
required | |
rec |
Bio.SeqRecord The full GenBank record containing the sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Simplified Bakta-style feature. |
Source code in src/baktfold/io/eukaryotic_to_json.py
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 | |
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 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/eukaryotic_to_json.py
random_n_letter_id(n=4)
generates a n letter id prefix
n=2 to append to locus tag for bakta id to make it different n=10 if the locus tag is somehow missing (should never happen)
Source code in src/baktfold/io/eukaryotic_to_json.py
write_bakta_outputs(data, features, features_by_sequence, output, prefix, custom_db, euk, has_duplicate_locus, fast, translation_table, prokka, other_genbank, cds_program, trna_program, rrna_program, tmrna_program, ncrna_program, bakta_version)
Writes the bakta outputs to a given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
dict
|
The dictionary containing the bakta outputs. |
required |
features |
Sequence[dict]
|
The sequence of dictionaries containing the features. |
required |
features_by_sequence |
Sequence[dict]
|
The sequence of dictionaries containing the features by sequence. |
required |
output |
Path
|
The path to save the bakta outputs to. |
required |
prefix |
str
|
The prefix to use for the bakta outputs. |
required |
custom_db |
bool
|
A boolean indicating whether a custom database is used. |
required |
euk |
bool
|
A boolean indicating whether the sequences are eukaryotic. |
required |
has_duplicate_locus |
bool
|
A boolean indicating whether there are duplicate loci. |
required |
fast |
bool
|
If True, skips AFDB step |
required |
translation_table |
str
|
Translation table inferred from input JSON |
required |
prokka |
bool
|
boolean indicating if prokka was used to do initial annotation |
required |
other_genbank |
bool
|
boolean indicating if other genbank (prokaryotic, genbank_to) was used to do initial annotation |
required |
bakta_version |
dict
|
Dictionary of Bakta (or whatever other program) was used for the initial annotation |
required |
Returns:
| Type | Description |
|---|---|
|
None. |
Examples:
>>> write_bakta_outputs(data, features, features_by_sequence, output, prefix, custom_db, euk, has_duplicate_locus, fast, translation_table, prokka, other_genbank, bakta_version)
Source code in src/baktfold/io/io.py
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 | |
write_bakta_proteins_outputs(aas, output, prefix, custom_db, fast, bakta_version)
Writes the bakta protein outputs to a given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aas |
Sequence[dict]
|
The sequence of dictionaries containing the amino acids. |
required |
output |
Path
|
The path to save the bakta protein outputs to. |
required |
prefix |
str
|
The prefix to use for the bakta protein outputs. |
required |
custom_db |
bool
|
A boolean indicating whether a custom database is used. |
required |
fast |
bool
|
If True, skips AFDB step |
required |
bakta_version |
dict
|
Original Bakta version |
required |
Returns:
| Type | Description |
|---|---|
|
None. |
Examples:
Source code in src/baktfold/io/io.py
write_foldseek_tophit(tophit_df, pdb_tophit_path)
Writes the foldseek tophits to a given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tophit_df |
pd.DataFrame
|
The dataframe containing the foldseek tophits. |
required |
pdb_tophit_path |
Path
|
The path to save the foldseek tophits to. |
required |
Returns:
| Type | Description |
|---|---|
|
None. |
Examples:
Source code in src/baktfold/io/io.py
map_aa_columns(feat, custom_db, has_duplicate_locus, fast)
Maps amino acid columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feat |
dict
|
The dictionary containing the features. |
required |
custom_db |
bool
|
A boolean indicating whether a custom database is used. |
required |
has_duplicate_locus |
bool
|
A boolean indicating whether there are duplicate loci. |
required |
fast |
bool
|
A boolean indicating whether AFDBclusters Foldseek search should be skipped |
required |
Returns:
| Type | Description |
|---|---|
Sequence[str]
|
Sequence[str]: A sequence of strings containing the mapped amino acid columns. |
Examples:
>>> map_aa_columns({'locus': 'ABC', 'length': 100, 'product': 'protein'}, False, False)
['ABC', '100', 'protein', '', '', '', '']
Source code in src/baktfold/io/tsv.py
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 | |
write_feature_inferences(sequences, features_by_sequence, tsv_path)
Export feature inference statistics in TSV format.
Source code in src/baktfold/io/tsv.py
write_features(sequences, features_by_sequence, tsv_path)
Export features in TSV format.
Source code in src/baktfold/io/tsv.py
write_hypotheticals(hypotheticals, tsv_path)
Export hypothetical information in TSV format.
Source code in src/baktfold/io/tsv.py
write_protein_features(features, header_columns, tsv_path, custom_db, has_duplicate_locus, fast)
Export protein features in TSV format.
Source code in src/baktfold/io/tsv.py
parse_protein_input(input_path, faa_path)
handles regular FASTA and gzipped returns cds_dict
Source code in src/baktfold/io/fasta_in.py
encode_annotations(annotations)
Encodes annotations into a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotations |
dict
|
A dictionary containing the annotations. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The encoded annotations. |
Examples:
>>> encode_annotations({
'ID': 'EHICP_3230_sigpep',
'Name': 'signal peptide',
'product': 'signal peptide',
'score': 0.5,
'Parent': 'EHICP_3230'
})
'ID=EHICP_3230_sigpep;Name=signal peptide;product=signal peptide;score=0.5;Parent=EHICP_3230'
Source code in src/baktfold/io/gff.py
encode_attribute(product)
Replace special characters forbidden in column 9 of the GFF3 format: https://github.com/The-Sequence-Ontology/Specifications/blob/master/gff3.md
Source code in src/baktfold/io/gff.py
write_euk_cds_feature(fh, seq_id, feat)
Write a eukaryotic CDS feature to GFF3 with multiple CDS parts.
Parameters
fh : file-handle seq_id : str
dict-like feature with keys:
"start", "stop", "strand", "locus", "starts", "stops"
Source code in src/baktfold/io/gff.py
write_euk_repeat_region_feature(fh, seq_id, feat)
Writes a repeat region feature to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fh |
file
|
The file handle to write to. |
required |
seq_id |
str
|
The sequence ID. |
required |
feat |
dict
|
A dictionary containing the feature information. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
>>> write_euk_repeat_region_feature(fh, 'DS572673.1', {
"type": "repeat_region",
"sequence": "DS571531.1",
"start": 1470,
"stop": 1716,
"strand": "?",
"family": "LINE2",
"rpt_type": null,
"repeat_unit": null,
"product": null,
"nt": "AATAAAATCATATCAGAAATAAAAAGAATGAAAATAAACAAATTAAAGAAAATAATTATAAAATTAATAAACGATATTTAAATGAAAGAAAATAGAGAATATGTAATAAGTACAAATGGTTCATTCATTAATAAGAAATTAACAATAATAAAATAGAGAATATTGATTATAAAAAGAAATATATTTCTCAAAACAGTAGAGATACAAAAAGAATAGATATGAAATAAATATTAATTCTAAAATACTC",
"id": "EHICP_3230",
"db_xrefs": [
"SO:0000657"
]
})
Source code in src/baktfold/io/gff.py
write_euk_trna_feature(fh, seq_id, feat)
Write a tRNA feature to GFF3 with a top-level line and single exon.
Parameters
file-like
Open file handle to write GFF lines.
str
Sequence/contig ID.
SeqFeature
Biopython SeqFeature object of type 'tRNA'.
Notes
- Generates one tRNA line and one exon line.
- Includes optional 'product' qualifier.
Source code in src/baktfold/io/gff.py
write_euk_utr_feature(fh, seq_id, feat, locus_counter, three=False)
Write a 'utr' feature.
Source code in src/baktfold/io/gff.py
write_features(data, features_by_sequence, gff3_path, prokka=False, euk=False, other_genbank=False, cds_tool='Prodigal:2.6', trna_program='tRNAscan-SE:2.0.12', tmrna_program='Aragorn', rrna_program='Infernal', ncrna_program='Infernal')
Export features in GFF3 format.
Source code in src/baktfold/io/gff.py
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 | |
write_gene_feature(fh, seq_id, feat)
Write a 'gene' feature including fuzzy boundaries.
Source code in src/baktfold/io/gff.py
write_mrna_feature(fh, seq_id, feat)
Write mRNA + implied exons based on join() structure.
Source code in src/baktfold/io/gff.py
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 | |
write_signal_peptide(fh, feat)
Writes a signal peptide feature to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fh |
file
|
The file handle to write to. |
required |
feat |
dict
|
A dictionary containing the feature information. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
>>> write_signal_peptide(fh, {
'locus': 'EHICP_3230',
'sequence': 'DS571531.1',
'strand': '+',
'signal_peptide': {
'start': 1,
'stop': 20,
'score': 0.5
}
})
Source code in src/baktfold/io/gff.py
export_sequences(sequences, fasta_path, description=False, wrap=False)
Write sequences to Fasta file.
Source code in src/baktfold/io/fasta.py
import_sequences(sequences_path, is_genomic=True, is_dna=True)
Import raw sequences from Fasta file.
Source code in src/baktfold/io/fasta.py
wrap_sequence(sequence)
Wraps a sequence into lines of 60 characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence |
str
|
The sequence to wrap. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The wrapped sequence. |
Examples:
Notes
This function is used to format sequences in FASTA files.
Source code in src/baktfold/io/fasta.py
write_faa(features, faa_path)
Write translated CDS sequences to Fasta file.
Source code in src/baktfold/io/fasta.py
write_ffn(features, ffn_path)
Write annotated nucleotide sequences to Fasta file.
Source code in src/baktfold/io/fasta.py
Some code adapted from @mheinzinger
https://github.com/mheinzinger/ProstT5/blob/main/scripts/generate_foldseek_db.py
create_foldseek_prostt5_gpu_db(fasta_aa, foldseek_db_path, db_dir, logdir)
Convert a Foldseek DB with ProstT5 3Di predictions using Foldseek-GPU
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_aa |
Path
|
Path to the amino-acid FASTA file. |
required |
foldseek_db_path |
Path
|
Path to the directory where Foldseek database will be stored. |
required |
db_dir |
Path
|
Path to the baktfold DB |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/create_foldseek_db.py
foldseek_tsv2db(in_tsv, out_db_name, db_type, logdir)
Convert a Foldseek TSV file to a Foldseek database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_tsv |
Path
|
Path to the input TSV file. |
required |
out_db_name |
Path
|
Path for the output Foldseek database. |
required |
db_type |
int
|
Type of the output database. |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/create_foldseek_db.py
generate_foldseek_db_from_aa_3di(fasta_aa, fasta_3di, foldseek_db_path, logdir, prefix)
Generate Foldseek database from amino-acid and 3Di sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_aa |
Path
|
Path to the amino-acid FASTA file. |
required |
fasta_3di |
Path
|
Path to the 3Di FASTA file. |
required |
foldseek_db_path |
Path
|
Path to the directory where Foldseek database will be stored. |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
prefix |
str
|
Prefix for the Foldseek database. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/create_foldseek_db.py
generate_foldseek_db_from_structures(fasta_aa, foldseek_db_path, structure_dir, logdir, prefix, proteins_flag)
Generate Foldseek database from PDB files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_aa |
Path
|
Path to the amino-acid FASTA file. |
required |
foldseek_db_path |
Path
|
Path to the directory where Foldseek database will be stored. |
required |
structure_dir |
Path
|
Path to the directory containing .pdb or .cif structure files. |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
prefix |
str
|
Prefix for the Foldseek database. |
required |
proteins_flag |
bool
|
Flag - True if proteins-compare is run |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/create_foldseek_db.py
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 | |
create_result_tsv(query_db, target_db, result_db, result_tsv, logdir, foldseek_gpu, structures, threads)
Create a TSV file containing the results of a Foldseek search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_db |
Path
|
Path to the query database. |
required |
target_db |
Path
|
Path to the target database. |
required |
result_db |
Path
|
Path to the result database generated by the search. |
required |
result_tsv |
Path
|
Path to save the resulting TSV file. |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
foldseek_gpu |
bool
|
Run Foldseek-GPU with accelerate ungapped prefilter |
required |
structures |
bool
|
Whether structures were input (not ProstT5) |
required |
threads |
int
|
Number of threads to use. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/run_foldseek.py
run_foldseek_search(query_db, target_db, result_db, temp_db, threads, logdir, evalue, sensitivity, max_seqs, ultra_sensitive, extra_foldseek_params, foldseek_gpu, structures, gpus=None)
Run a Foldseek search using given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_db |
Path
|
Path to the query database. |
required |
target_db |
Path
|
Path to the target database. |
required |
result_db |
Path
|
Path to store the result database. |
required |
temp_db |
Path
|
Path to store temporary files. |
required |
threads |
int
|
Number of threads to use for the search. |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
evalue |
float
|
E-value threshold for the search. |
required |
sensitivity |
float
|
Sensitivity threshold for the search. |
required |
max_seqs |
int
|
Maximum results per query sequence allowed to pass the prefilter for foldseek. |
required |
ultra_sensitive |
bool
|
Whether to skip foldseek prefilter for maximum sensitivity |
required |
extra_foldseek_params |
str
|
Extra foldseek search params |
required |
foldseek_gpu |
bool
|
Run Foldseek-GPU with accelerate ungapped prefilter |
required |
structures |
bool
|
Run Foldseek with structures, not ProstT5 3Dis |
required |
gpus |
Optional[str]
|
Comma-separated CUDA indices (e.g. "0,2") to
restrict foldseek's GPU prefilter to a subset of devices. When
|
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/run_foldseek.py
summarise_hits(result_db, result_db_greedy_best_hits, logdir, threads)
Get all non-overlapping tophits covering a query (designed for CATH)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_db |
Path
|
Path to the result database generated by the search. |
required |
result_db_greedy_best_hits |
Path
|
Path to save the greedy best hits results db. |
required |
logdir |
Path
|
Path to the directory where logs will be stored. |
required |
threads |
int
|
Number of threads to use. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/features/run_foldseek.py
3Di prediction for baktfold — wraps pholdlib's shared inference engine.
Baktfold-specific: flat cds_dict (no contig nesting), Bakta hypotheticals format with in-place annotation updates, has_duplicate_locus support.
Code adapted from @mheinzinger https://github.com/mheinzinger/ProstT5/blob/main/scripts/predict_3Di_encoderOnly.py
get_embeddings(hypotheticals, cds_dict, out_path, prefix, model_dir, model_name, checkpoint_path, output_3di, output_h5_per_residue, output_h5_per_protein, half_precision, max_residues=100000, max_seq_len=30000, max_batch=10000, cpu=False, output_probs=True, save_per_residue_embeddings=False, save_per_protein_embeddings=False, threads=1, mask_threshold=0, has_duplicate_locus=False, gpus=None)
Run ProstT5 + CNN 3Di prediction for all sequences in cds_dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hypotheticals |
List[Dict]
|
List of Bakta feature dicts (mutated in-place with "3di"). |
required |
cds_dict |
Dict[str, str]
|
Flat |
required |
out_path |
Path
|
Directory for output files. |
required |
prefix |
str
|
Filename prefix for CSV / JSONL outputs. |
required |
model_dir |
Path
|
Directory where ProstT5 is cached. |
required |
model_name |
str
|
HuggingFace model identifier. |
required |
checkpoint_path |
Path
|
Path to the CNN |
required |
output_3di |
Path
|
Output FASTA path for 3Di sequences. |
required |
output_h5_per_residue |
Path
|
HDF5 path for per-residue embeddings. |
required |
output_h5_per_protein |
Path
|
HDF5 path for per-protein embeddings. |
required |
half_precision |
bool
|
If True, cast model + predictor to fp16 after loading. |
required |
max_residues |
int
|
Max total residues per inference batch. |
100000
|
max_seq_len |
int
|
Sequences longer than this flush a batch immediately. |
30000
|
max_batch |
int
|
Max sequences per batch. |
10000
|
cpu |
bool
|
Force CPU inference. |
False
|
output_probs |
bool
|
Whether to write per-residue probability JSONL. |
True
|
save_per_residue_embeddings |
bool
|
Save per-residue HDF5. |
False
|
save_per_protein_embeddings |
bool
|
Save per-protein HDF5. |
False
|
threads |
int
|
Number of CPU threads for torch. |
1
|
mask_threshold |
float
|
Residues with max softmax prob < threshold/100 → 'X'. |
0
|
has_duplicate_locus |
bool
|
If True use feat["id"] rather than feat["locus"]. |
False
|
gpus |
Optional[str]
|
Comma-separated CUDA indices (e.g. "0,2"). None = auto-detect
all visible CUDA GPUs. Overridden by |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
predictions |
Dict
|
Flat |
Source code in src/baktfold/features/predict_3Di.py
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 | |
write_embeddings(embeddings, out_path)
Write per-residue or per-protein embeddings to HDF5 (flat key structure).
Source code in src/baktfold/features/predict_3Di.py
write_predictions(hypotheticals, predictions, out_path, mask_threshold, has_duplicate_locus=False)
Write 3Di predictions to FASTA and update Bakta hypotheticals in-place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hypotheticals |
List[Dict]
|
List of Bakta feature dicts. Each is mutated in-place
with a |
required |
predictions |
Dict[str, Tuple]
|
Flat |
required |
out_path |
Path
|
Output FASTA path. |
required |
mask_threshold |
float
|
Residues with max softmax prob (0–100) below this threshold are replaced with 'X'. |
required |
has_duplicate_locus |
bool
|
If True, use |
False
|
Source code in src/baktfold/features/predict_3Di.py
autotune_batching_real_data(model_dir, model_name, cpu, threads, probe_seqs, start_bs=1, max_bs=100, step=5, device=None)
Autotunes the batch size for a given model and set of sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir |
str
|
The directory where the model is stored. |
required |
model_name |
str
|
The name of the model. |
required |
cpu |
bool
|
Whether to use the CPU or not. |
required |
threads |
int
|
The number of threads to use. |
required |
probe_seqs |
list
|
A list of sequences to use for probing. |
required |
start_bs |
int
|
The starting batch size to use. |
1
|
max_bs |
int
|
The maximum batch size to use. |
100
|
step |
int
|
The step size to use when increasing the batch size. |
5
|
device |
Optional[str]
|
Torch device string (e.g. "cuda:1") to pin autotune to a specific GPU. None preserves the original auto-detection behaviour. Used by the multi-GPU caller. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
The optimal batch size. |
|
int |
The maximum number of residues per batch. |
Examples:
>>> autotune_batching_real_data("model_dir", "model_name", True, 4, ["ATCG", "GCTA"], 1, 100, 5)
(10, 100)
Source code in src/baktfold/features/autotune.py
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 | |
run_autotune(input_path, model_dir, model_name, cpu, threads, step, min_batch, max_batch, sample_seqs, gpus=None)
Runs the batch size autotuning process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path |
str
|
The path to the input file. |
required |
model_dir |
str
|
The directory where the model is stored. |
required |
model_name |
str
|
The name of the model. |
required |
cpu |
bool
|
Whether to use the CPU or not. |
required |
threads |
int
|
The number of threads to use. |
required |
step |
int
|
The step size to use when increasing the batch size. |
required |
min_batch |
int
|
The minimum batch size to use. |
required |
max_batch |
int
|
The maximum batch size to use. |
required |
sample_seqs |
int
|
The number of sequences to sample for probing. |
required |
gpus |
Optional[str]
|
Comma-separated CUDA indices (e.g. "0,2"). When set, autotune runs on the lowest selected index. Default None = existing behaviour (cuda:0 / mps / xpu / cpu auto-detect). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
The optimal batch size. |
Examples:
Source code in src/baktfold/features/autotune.py
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 | |
sample_probe_sequences(seqs, n=5000, seed=0)
samples sequences
Source code in src/baktfold/features/autotune.py
annotate_aa(aas)
Combines IPS and PSC annotations and marks hypotheticals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aas |
Sequence[dict]
|
A sequence of amino acid dictionaries to annotate. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
>>> aas = [{'sequence': 'ATG', 'start': 1, 'stop': 3, 'strand': '+'}]
>>> annotate_aa(aas)
>>> aas
[{'sequence': 'ATG', 'start': 1, 'stop': 3, 'strand': '+'}]
Source code in src/baktfold/bakta/annotation.py
calc_annotation_score(orf)
Calculates the annotation score for a given ORF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orf |
dict
|
The ORF to calculate the annotation score for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The annotation score for the given ORF. |
Examples:
Source code in src/baktfold/bakta/annotation.py
combine_annotation(feature, fast)
Combines annotation information from different sources into a single feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
dict
|
The feature to combine annotation for. |
required |
fast |
bool
|
If True, skips AFDB |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
Source code in src/baktfold/bakta/annotation.py
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 | |
extract_protein_gene_symbol(product)
Extracts a valid gene symbol from a protein name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product |
str
|
The protein name to extract a gene symbol from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The extracted gene symbol. |
Examples:
Source code in src/baktfold/bakta/annotation.py
mark_as_baktfold(feature)
Adds the baktfold key to the given feature dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
dict
|
The feature dictionary to add the baktfold key to. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
>>> feature = {'sequence': 'ATG', 'start': 1, 'stop': 3, 'strand': '+'}
>>> mark_as_baktfold(feature)
>>> feature
{'sequence': 'ATG', 'start': 1, 'stop': 3, 'strand': '+', 'baktfold': True}
Source code in src/baktfold/bakta/annotation.py
mark_as_hypothetical(feature)
Marks a feature as hypothetical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
dict
|
The feature to mark as hypothetical. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
Source code in src/baktfold/bakta/annotation.py
revise_cds_gene_symbols(raw_genes)
Revises a list of gene symbols to ensure they are valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_genes |
Sequence[str]
|
The list of gene symbols to revise. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
The revised list of gene symbols. |
Examples:
Source code in src/baktfold/bakta/annotation.py
revise_cds_product(product)
Revise product name for INSDC compliant submissions
Source code in src/baktfold/bakta/annotation.py
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 | |
unmark_as_hypothetical(feature)
Removes the hypothetical key from the given feature dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature |
dict
|
The feature dictionary to remove the hypothetical key from. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
>>> feature = {'sequence': 'ATG', 'start': 1, 'stop': 3, 'strand': '+'}
>>> unmark_as_hypothetical(feature)
>>> feature
{'sequence': 'ATG', 'start': 1, 'stop': 3, 'strand': '+'}
Source code in src/baktfold/bakta/annotation.py
check_content_size(file_name, file_path)
Checks if a file is empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name |
str
|
The name of the file to check. |
required |
file_path |
Path
|
The path to the file to check. |
required |
Returns:
| Type | Description |
|---|---|
|
None. |
Examples:
Source code in src/baktfold/bakta/config.py
check_db_path(args)
Checks the path to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args |
Namespace
|
The arguments passed to the program. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The path to the database. |
Examples:
Source code in src/baktfold/bakta/config.py
check_output_path(output, force_override)
Check provided output path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output |
string
|
The output directory destination path |
required |
force_override |
Bool
|
Whether to override existing output directories |
required |
Source code in src/baktfold/bakta/config.py
check_readability(file_name, file_Path)
Checks if a file is readable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name |
str
|
The name of the file to check. |
required |
file_Path |
Path
|
The path to the file to check. |
required |
Returns:
| Type | Description |
|---|---|
|
None. |
Examples:
Source code in src/baktfold/bakta/config.py
check_threads(args)
Checks the number of threads to use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args |
Namespace
|
The arguments passed to the program. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of threads to use. |
Examples:
Source code in src/baktfold/bakta/config.py
check_tmp_path(args)
Checks the path to the temporary directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args |
Namespace
|
The arguments passed to the program. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The path to the temporary directory. |
Examples:
Source code in src/baktfold/bakta/config.py
check_user_proteins(args)
Checks the path to the user proteins file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args |
Namespace
|
The arguments passed to the program. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
The path to the user proteins file. |
Examples:
Source code in src/baktfold/bakta/config.py
setup(args)
Test environment and build a runtime configuration.
Source code in src/baktfold/bakta/config.py
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 | |
fetch_db_pscc_result(conn, uniref50_id)
Fetches the PSCC result for a given uniref50_id from a sqlite3 database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
sqlite3.Connection
|
The connection to the sqlite3 database. |
required |
uniref50_id |
str
|
The uniref50_id to fetch the PSCC result for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
The PSCC result for the given uniref50_id. |
Source code in src/baktfold/bakta/pstc.py
fetch_sql_description(conn, source, accession)
Fetches the product description for a given source and accession from a sqlite3 database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
sqlite3.Connection
|
The connection to the sqlite3 database. |
required |
source |
str
|
The source of the accession. |
required |
accession |
str
|
The accession to fetch the description for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The product description for the given source and accession. |
Source code in src/baktfold/bakta/pstc.py
fetch_sql_description_threadsafe(db_path, source, accession)
makes new connection every time so don't have 2 CATH accessions colliding (for multi domain proteins)
Source code in src/baktfold/bakta/pstc.py
lookup_custom(features, baktfold_db, custom_annotations)
Lookup PSTC information from custom db
Source code in src/baktfold/bakta/pstc.py
lookup_sql(features, baktfold_db, threads)
Lookup PSTC information
Source code in src/baktfold/bakta/pstc.py
parse(features, foldseek_df, db_name='swissprot', has_duplicate_locus=False)
Update CDS in place with PSTC hits from foldseek_df if they pass filters.
has_duplicate_locus - some euks have multiple CDS per locus tag
Source code in src/baktfold/bakta/pstc.py
Originally taken from Michael Hall's tbpore https://github.com/mbhall88/tbpore/blob/main/tbpore/external_tools.py
Also used by a variety of other tools (Dnaapler, Plassembler, Pharokka)
ExternalTool
Class for running external tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
str
|
The path to the tool to run. |
required |
input |
str
|
The input file. |
required |
output |
str
|
The output file. |
required |
params |
str
|
The parameters to pass to the tool. |
required |
logdir |
Path
|
The directory to store log files. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
command |
List[str]
|
The command to run. |
out_log |
str
|
The path to the stdout log file. |
err_log |
str
|
The path to the stderr log file. |
Examples:
>>> tool = ExternalTool("tool", "input", "output", "params", "logdir")
>>> tool.command
["tool", "params", "output", "input"]
>>> tool.out_log
"logdir/tool_1234567890abcdef1234567890abcdef.out"
>>> tool.err_log
"logdir/tool_1234567890abcdef1234567890abcdef.err"
Source code in src/baktfold/utils/external_tools.py
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 | |
command_as_str: str
property
__init__(tool, input, output, params, logdir, env=None)
Initializes an ExternalTool object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
str
|
The path to the tool to run. |
required |
input |
str
|
The input file. |
required |
output |
str
|
The output file. |
required |
params |
str
|
The parameters to pass to the tool. |
required |
logdir |
Path
|
The directory to store log files. |
required |
env |
Optional[Dict[str, str]]
|
Extra env vars merged with os.environ for the subprocess (e.g. CUDA_VISIBLE_DEVICES for multi-GPU foldseek). None == inherit unchanged. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
command |
List[str]
|
The command to run. |
out_log |
str
|
The path to the stdout log file. |
err_log |
str
|
The path to the stderr log file. |
env |
Optional[Dict[str, str]]
|
Extra subprocess env vars. |
Examples:
>>> tool = ExternalTool("tool", "input", "output", "params", "logdir")
>>> tool.command
["tool", "params", "output", "input"]
>>> tool.out_log
"logdir/tool_1234567890abcdef1234567890abcdef.out"
>>> tool.err_log
"logdir/tool_1234567890abcdef1234567890abcdef.err"
Source code in src/baktfold/utils/external_tools.py
run()
Runs the tool.
Examples:
Source code in src/baktfold/utils/external_tools.py
run_download(tool, ctx=None)
staticmethod
Runs the given external tool and prints the aria2c output to the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
ExternalTool
|
The external tool to run. |
required |
ctx |
Optional[click.Context]
|
The click context to use. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
subprocess.CalledProcessError
|
If there is an error calling the external tool. |
Examples:
Source code in src/baktfold/utils/external_tools.py
run_stream()
Runs the tool and streams the output to the terminal.
Examples:
Source code in src/baktfold/utils/external_tools.py
run_tool(tool, ctx=None)
staticmethod
Runs the given external tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
ExternalTool
|
The external tool to run. |
required |
ctx |
Optional[click.Context]
|
The click context to use. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
subprocess.CalledProcessError
|
If there is an error calling the external tool. |
Examples:
Source code in src/baktfold/utils/external_tools.py
run_tools(tools_to_run, ctx=None)
staticmethod
Runs a list of tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools_to_run |
Tuple[ExternalTool]
|
The list of tools to run. |
required |
ctx |
Optional[click.Context]
|
The click context. |
None
|
Examples:
>>> tool1 = ExternalTool("tool1", "input1", "output1", "params1", "logdir")
>>> tool2 = ExternalTool("tool2", "input2", "output2", "params2", "logdir")
>>> ExternalTool.run_tools((tool1, tool2))
>>> ExternalTool.run_tools((tool1, tool2), ctx)
Source code in src/baktfold/utils/external_tools.py
log_fmt = '[<green>{time:YYYY-MM-DD HH:mm:ss}</green>] <level>{level: <8}</level> | <level>{message}</level>'
module-attribute
begin and end functions
OrderedCommands
Bases: click.Group
This class will preserve the order of subcommands, which is useful when printing --help
Source code in src/baktfold/utils/util.py
list_commands(ctx)
Returns a list of subcommands in the order they were added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx |
click.Context
|
The click context. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of subcommands in the order they were added. |
Source code in src/baktfold/utils/util.py
baktfold_base(rel_path)
Returns the absolute path to the given relative path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rel_path |
str
|
The relative path to the file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The absolute path to the file. |
Source code in src/baktfold/utils/util.py
begin_baktfold(params, subcommand, no_log=False)
Begin baktfold process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params |
Dict[str, Any]
|
A dictionary of parameters for baktfold. |
required |
subcommand |
str
|
Subcommand indicating the baktfold operation. |
required |
no_log |
bool
|
No log file |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Start time of the baktfold process. |
Source code in src/baktfold/utils/util.py
clean_up_temporary_files(output, prefix)
Clean up temporary files generated during the baktfold process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output |
Path
|
Path to the output directory. |
required |
prefix |
str
|
prefix str |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/utils/util.py
echo_click(msg, log=None)
Prints a message to stdout and optionally to a log file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg |
str
|
The message to print. |
required |
log |
str
|
The path to the log file. |
None
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in src/baktfold/utils/util.py
end_baktfold(start_time, subcommand)
Finish baktfold process and log elapsed time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time |
float
|
Start time of the process. |
required |
subcommand |
str
|
Subcommand name indicating the baktfold operation. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/utils/util.py
get_type_rank(f)
ranks eukaryotic features 1) in order of gene -> mRNA -> CDS and gene -> tRNA dynamically adjusts if 5'UTR and 3'UTR is present
Source code in src/baktfold/utils/util.py
get_version()
Returns the version number from the VERSION file.
Returns:
| Name | Type | Description |
|---|---|---|
str |
The version number. |
print_citation()
Prints the contents of the CITATION file to stdout.
Returns:
| Type | Description |
|---|---|
|
None |
print_splash()
Prints the splash screen to stdout.
Returns:
| Type | Description |
|---|---|
|
None |
Source code in src/baktfold/utils/util.py
remove_directory(dir_path)
Remove a directory and all its contents if it exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path |
Path
|
Path to the directory to remove. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/utils/util.py
remove_file(file_path)
Remove a file if it exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
Path
|
Path to the file to remove. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/utils/util.py
replace_pipe_in_fasta(input_path)
Reads a FASTA with Biopython, replace '~PIPE~' with '|' in headers, and write the result.
Source code in src/baktfold/utils/util.py
sort_euk_feature_key(f)
Sorts a feature dictionary by start, locus, type rank, and stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f |
dict
|
The feature dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple of the sorted values. |
Source code in src/baktfold/utils/util.py
touch_file(path)
Update the access and modification times of a file to the current time, creating the file if it does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path
|
Path to the file. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/utils/util.py
check_dependencies()
Checks the dependencies and versions of non Python programs (i.e. Foldseek)
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in src/baktfold/utils/validation.py
check_genbank_and_prokka(filepath, euk)
Validate that an input file is a readable GenBank file and check whether it was
annotated using Prokka. The function transparently supports compressed files
(e.g., .gz, .bz2, .xz, .zst) via xopen.
Validation steps
• Attempts to parse the file as GenBank using Biopython. • Logs an error and returns None if no GenBank records are found. • Checks the COMMENT field of each record for a Prokka signature ("Annotated using prokka", case-insensitive). • If no Prokka annotation is detected, a warning is logged but parsing continues as it is a valid genbank.
Parameters
str
Path to the GenBank or compressed GenBank file.
flag
whether or not the input is eukaryotic (skips prokka)
Returns
list[SeqRecord] or None A list of Biopython SeqRecord objects if parsing succeeds. Returns None if the file is not valid GenBank or cannot be parsed.
Source code in src/baktfold/utils/validation.py
instantiate_dirs(output_dir, force)
Checks and instantiates the output directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir |
Union[str, Path]
|
Path to the output directory. |
required |
force |
bool
|
Force flag indicating whether to overwrite existing directory. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Final output directory path. |
Source code in src/baktfold/utils/validation.py
validate_outfile(outfile, force)
Checks and instantiates the output file for baktfold convert-prokka
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outfile |
Union[str, Path]
|
Path to the output file. |
required |
force |
bool
|
Force flag indicating whether to overwrite existing outfile. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Final output file path. |
Source code in src/baktfold/utils/validation.py
get_tophit(result_tsv, structures, cath=False)
Process Foldseek output to extract top hit and weighted bitscores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_tsv |
Path
|
Path to the Foldseek result TSV file. |
required |
structures |
bool
|
Flag indicating whether structures have been added. |
required |
cath |
bool
|
Flag indicating whether this is for CATH database (all greedy besthits kept not just top) |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[pd.DataFrame, pd.DataFrame]
|
Tuple[pd.DataFrame, pd.DataFrame]: A tuple containing two DataFrames: 1. DataFrame containing the top functions extracted from the Foldseek output. 2. DataFrame containing weighted bitscores for different functions. |
Source code in src/baktfold/results/tophit.py
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 | |