Bakta
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
assign_annotation_confidence(entry, prostt5_confidence, structures)
Classify a Foldseek hit into a confidence tier: 'high', 'medium' or 'low'.
Mirrors phold's heuristic (phold.subcommands.compare.assign_annotation_confidence).
entry is the hierarchy-selected pstc hit carrying query_cov (qCov),
subject_cov (tCov), identity (fident) and evalue.
prostt5_confidence is the protein's mean ProstT5 confidence (0-100), or
None for structure input. With structures (or no ProstT5 confidence
available) the ProstT5 criteria are dropped.
Source code in src/baktfold/bakta/annotation.py
attach_prostt5_confidence(features, mean_probs_csv, has_duplicate_locus=False)
Attach each CDS's mean ProstT5 confidence (0-100) from the
{prefix}_prostT5_3di_mean_probabilities.csv file (cds_id,mean_prob,
no header) as feature['prostt5_confidence']. No-op if the file is absent
(e.g. structure input).
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
cath_domain_label(name)
Turn a CATH superfamily name into a domain-level product name.
A CATH hit is evidence that the protein contains a domain of that superfamily, not that the whole protein has the named function, so the label says so explicitly (the NCBI/Bakta convention for domain-only evidence): "SH2 domain" -> "SH2 domain-containing protein", "Enoyl acyl carrier protein reductase" -> "Enoyl acyl carrier protein reductase domain-containing protein". Representative-specific suffixes ("; Chain A", ", domain 2", "from Thermus thermophilus HB27") are removed.
Source code in src/baktfold/bakta/annotation.py
combine_annotation(feature, fast, structures=False)
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 |
structures
|
bool
|
True for structure input (no ProstT5 confidence available) |
False
|
Returns: None
Examples:
Source code in src/baktfold/bakta/annotation.py
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 | |
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
is_informative_product(product)
True if product names a function, i.e. is not empty and not a
hypothetical/uncharacterised placeholder (before or after Bakta's product
revision).
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
pstc_db_xrefs(entry, fast, selected_entry=None)
The db_xrefs that combine_annotation adds for one PSTC hit.
Kept in one place so reset_baktfold_annotation can remove exactly what combine_annotation added.
Source code in src/baktfold/bakta/annotation.py
reset_baktfold_annotation(feature, keep_product=False)
Undo combine_annotation on a CDS so that label selection can be rerun
on its stored hits (baktfold json --relabel).
Only features Baktfold labelled (baktfold key, set whenever a CDS had
hits) are reset: the product goes back to "hypothetical protein", the
db_xrefs that came from its hits are removed, and the confidence tier and
structure scores are dropped. The hits themselves (pstc) are kept.
Must run before the hits are changed (chains or descriptions refreshed),
because the xrefs to remove are rebuilt from them.
A product the input tool had assigned before Baktfold overwrote it (only
possible with --all-proteins) cannot be recovered. With
keep_product (a curated input label that label selection kept: hits,
but no confidence tier), the product is kept as the starting state, as
run starts from it.
Returns True if the feature was reset.
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
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 | |
select_informative_entry(entries)
Return the first entry, in hierarchy order, whose description names a function. Uninformative hits ("hypothetical protein", "Uncharacterized protein ...") are skipped so they cannot mask a functional hit from a lower-precedence database. Returns None if no entry is informative.
Source code in src/baktfold/bakta/annotation.py
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 Args: output (string): The output directory destination path force_override (Bool): Whether to override existing output directories
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
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 | |
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
|
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_pdb_chain_description(conn, entry, chain, with_uniprot=False)
Chain-level PDB name from the pdb_chain table (UniProt name of the
chain via SIFTS, else the PDB entity name), or None if the chain is not
listed. Never falls back to the entry title: an unlisted chain is left
for the next database in the hierarchy.
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
|
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
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)
Resolve PSTC accessions to product descriptions from the SQLite DB.
One read-only connection is opened for the whole feature set and reused
for every accession. SQLite point lookups on the indexed id column
are microsecond-scale, so a single serial pass is dramatically faster
than the previous design, which opened (and tore down) a brand-new
connection per accession inside a ThreadPoolExecutor — thousands of
connection opens for a bacterial genome, with no real parallelism since
each feature's futures were collected before the next feature was
submitted and most features carry a single PSTC entry. Benchmarked at
~16x faster for a 5k-CDS genome (810 ms -> 51 ms).
Each conn.execute returns its own short-lived cursor consumed
immediately, so sequential CATH multi-domain lookups can't collide.
threads is accepted for signature compatibility but unused: the
bottleneck was connection setup, not query execution.
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
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 | |
pdb_chain_from_target(target_id)
Chain ID of a Foldseek PDB target, e.g. '6xgw-assembly1.cif.gz_A' -> 'A'.
Symmetry copies in biological assemblies carry a copy suffix ('..._A-2'); they are the same molecule as the base chain, so the suffix is dropped. Returns None if the target has no chain part.
Source code in src/baktfold/bakta/pstc.py
read_pdb_tophit_chains(tophit_tsv)
Query -> PDB chain from a <prefix>_pdb_tophit.tsv.
JSONs written before chain-level PDB labels don't record which chain was
hit, but the tophit TSV does (target '
Source code in src/baktfold/bakta/pstc.py
refresh_descriptions(features, baktfold_db, pdb_chains=None, has_duplicate_locus=False)
Re-resolve the stored hits' descriptions from baktfold_db, as
baktfold json --relabel -d does before label selection is rerun.
PDB hits without a chain take one from pdb_chains (query -> chain,
see read_pdb_tophit_chains), which is also written back to the hit.
Two kinds of description are kept as stored rather than looked up
- custom_db hits: their descriptions came from the user's annotations file, not from baktfold.db;
- PDB hits with no recoverable chain, when the database has chain-level names: these keep the entry title they were labelled with. A lookup would find no chain and drop the hit, which is right for an unlisted chain but not for a chain that simply wasn't recorded.
Returns counts: pdb_chains_added, pdb_no_chain_kept.