API Reference¶
BUSCOlite provides a Python API for programmatic access to BUSCO analysis functionality.
Main Modules¶
busco¶
The main module for running BUSCO analysis.
busco
¶
load_config(lineage)
¶
Load the BUSCO dataset configuration file.
Parameters¶
lineage : str Path to the BUSCO lineage directory containing the dataset.cfg file
Returns¶
dict Dictionary containing the configuration parameters from dataset.cfg
Source code in buscolite/busco.py
load_cutoffs(lineage)
¶
Load the BUSCO score and length cutoffs from the lineage directory.
Parameters¶
lineage : str Path to the BUSCO lineage directory containing the cutoff files
Returns¶
dict Dictionary containing the score and length cutoffs for each BUSCO model Format: {busco_id: {"score": float, "sigma": float, "length": int}}
Source code in buscolite/busco.py
check_lineage(lineage)
¶
Verify that the BUSCO lineage directory contains all required files and directories.
Parameters¶
lineage : str Path to the BUSCO lineage directory
Returns¶
tuple (bool, str) - Boolean indicating if the lineage is valid, and an error message if not
Source code in buscolite/busco.py
predict_and_validate(fadict, contig, prfl, cutoffs, species, start, end, strand, configpath, blast_score)
¶
Predict and validate protein coding regions using Augustus and HMMER.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fadict
|
dict
|
Dictionary containing contig sequences. |
required |
contig
|
str
|
Name of the contig. |
required |
prfl
|
str
|
Path to the protein profile file. |
required |
cutoffs
|
dict
|
Dictionary of cutoff scores for each protein. |
required |
species
|
str
|
Species name for Augustus prediction. |
required |
start
|
int
|
Start position of the region. |
required |
end
|
int
|
End position of the region. |
required |
strand
|
str
|
Strand of the region ('+' or '-') for prediction. |
required |
configpath
|
str
|
Path to the configuration file for Augustus. |
required |
blast_score
|
float
|
BLAST score threshold for validation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing the BUSCO name and the final prediction dictionary if a valid prediction is found, otherwise False. |
Source code in buscolite/busco.py
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 | |
runbusco(input, lineage, mode='genome', species='anidulans', cpus=1, offset=2000, verbosity=3, logger=False, check_augustus=True)
¶
Run BUSCO analysis on genome or protein sequences.
Parameters: - input (str): Path to the input genome or protein sequences. - lineage (str): Path to the BUSCO lineage directory. - mode (str, optional): Analysis mode, either 'genome' or 'proteins'. Defaults to 'genome'. - species (str, optional): Species name for Augustus prediction. Defaults to 'anidulans'. - cpus (int, optional): Number of CPUs to use. Defaults to 1. - offset (int, optional): Offset value for sequence extraction. Defaults to 2000. - verbosity (int, optional): Level of verbosity for logging. Defaults to 3. - logger (bool or logger object, optional): Custom logger object. Defaults to False. - check_augustus (bool, optional): Flag to check Augustus functionality. Defaults to True.
Returns: - b_final (dict): Final BUSCO results. - missing (list): List of BUSCOs not found. - stats (dict): Statistics of BUSCO analysis. - Config (dict): Parsed configuration details.
Source code in buscolite/busco.py
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 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 | |
search¶
HMM search functionality using pyhmmer.
search
¶
tblastn_version()
¶
Get the version of tblastn installed on the system.
Returns¶
str The version string of tblastn
Source code in buscolite/search.py
miniprot_version()
¶
Get the version of miniprot installed on the system.
Returns¶
str The version string of miniprot
Source code in buscolite/search.py
pyhmmer_version()
¶
miniprot_prefilter(input, query, cutoffs, tmpdir=False, cpus=1, maxhits=3, maxintron=10000, buscodb='.')
¶
Prefilter alignments using miniprot for BUSCO analysis.
Parameters¶
input : str Path to the input genome FASTA file query : str Path to the query protein FASTA file cutoffs : dict Dictionary containing score cutoffs for each BUSCO model tmpdir : str or bool, optional Path to temporary directory, or False to use system default cpus : int, optional Number of CPU threads to use (default: 1) maxhits : int, optional Maximum number of hits to return per query (default: 3) maxintron : int, optional Maximum intron size (default: 10000) buscodb : str, optional Path to the BUSCO database directory (default: ".")
Returns¶
dict Dictionary containing filtered alignment results
Source code in buscolite/search.py
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 | |
blast_prefilter(input, query, logger=None, tmpdir=False, evalue=0.001, cpus=1, maxhits=3, maxintron=10000)
¶
Prefilters alignments for augustus using tblastn.
Parameters¶
input : str Path to the input genome FASTA file query : str Path to the query protein FASTA file logger : object Logger object for logging messages tmpdir : str or bool, optional Path to temporary directory, or False to use system default evalue : float, optional E-value threshold for BLAST hits (default: 1e-3) cpus : int, optional Number of CPU threads to use (default: 1) maxhits : int, optional Maximum number of hits to return per query (default: 3) maxintron : int, optional Maximum intron size (default: 10000)
Returns¶
tuple (dict, int) - Dictionary containing filtered alignment results and number of jobs
Source code in buscolite/search.py
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 528 529 530 | |
merge_overlapping_hits(queryList, fluff=10000)
¶
Merge overlapping or nearby hits from BLAST or miniprot searches.
Parameters¶
queryList : list List of dictionaries containing hit information with 'coords' key fluff : int, optional Maximum distance between hits to consider them for merging (default: 10000)
Returns¶
list List of merged hits
Source code in buscolite/search.py
hmmer_search_single(hmmfile, seq)
¶
Search a single protein sequence against an HMM profile using pyhmmer.
Parameters¶
hmmfile : str Path to the HMM profile file seq : str Protein sequence to search
Returns¶
list List of dictionaries containing search results with the following keys: - name: Name of the HMM profile - bitscore: Bit score of the hit - evalue: E-value of the hit - domains: List of domain hits with coordinates and scores
Source code in buscolite/search.py
hmmer_search(hmmfile, sequences)
¶
Search multiple protein sequences against an HMM profile using pyhmmer.
Parameters¶
hmmfile : str Path to the HMM profile file sequences : list List of digitized protein sequences to search
Returns¶
list List of dictionaries containing search results with the following keys: - name: Name of the HMM profile - hit: Name of the sequence that matched - bitscore: Bit score of the hit - evalue: E-value of the hit - domains: List of domain hits with coordinates and scores
Source code in buscolite/search.py
gff¶
GFF3 file parsing and manipulation.
gff
¶
utilities¶
Utility functions for filtering and processing BUSCO results.
utilities
¶
overlap(start1, end1, start2, end2)
¶
how much does the range (start1, end1) overlap with (start2, end2)
filter_low_scoring_matches(busco_results, threshold=0.85)
¶
Filter out matches that score less than a threshold percentage of the top bitscore for each BUSCO. This implements the BUSCO v6 filtering logic.
Parameters¶
busco_results : dict Dictionary of BUSCO results where keys are BUSCO IDs and values are lists of match dictionaries containing 'bitscore' keys threshold : float, optional Minimum score threshold as fraction of top score (default: 0.85)
Returns¶
dict Filtered dictionary with low-scoring matches removed
Source code in buscolite/utilities.py
remove_duplicate_gene_matches(busco_results, score_key='bitscore')
¶
When the same gene/sequence matches multiple BUSCOs, keep only the highest scoring match. This prevents a single gene from being counted multiple times.
Parameters¶
busco_results : dict Dictionary of BUSCO results where keys are BUSCO IDs and values are lists of match dictionaries score_key : str, optional Key to use for scoring. Can be a simple key like 'bitscore' or a nested key like 'hmmer.bitscore' (default: 'bitscore')
Returns¶
dict Filtered dictionary with duplicate gene matches removed
Source code in buscolite/utilities.py
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 | |
zopen(filename, mode='r', buff=1024 * 1024, external=PARALLEL)
¶
Open pipe, zipped, or unzipped file automagically
external == 0: normal zip libraries¶
external == 1: (zcat, gzip) or (bzcat, bzip2)¶
external == 2: (pigz -dc, pigz) or (pbzip2 -dc, pbzip2)¶
Source code in buscolite/utilities.py
fastx¶
FASTA/FASTQ file handling.
fastx
¶
translate(dna, strand, phase, table=1)
¶
Translates DNA sequence into proteins.
Takes DNA (or rather cDNA sequence) and translates to proteins/amino acids. It requires the DNA sequence, the strand, translation phase, and translation table.
Parameters¶
dna : str DNA (cDNA) sequence as nucleotides strand : str, (+/-) strand to translate (+ or -) phase : int phase to start translation [0,1,2] table : int, default=1 translation table [1]
Returns¶
protSeq : str string of translated amino acid sequence
Source code in buscolite/fastx.py
fasta2dict(fasta, full_header=False)
¶
Read FASTA file to dictionary.
This is same as biopython SeqIO.to_dict(), return dictionary keyed by contig name and value is the sequence string.
Parameters¶
fasta : filename FASTA input file (can be gzipped) full_header : bool, default=False return full header for contig names, default is split at first space
Returns¶
seqs : dict returns OrderedDict() of header: seq
Source code in buscolite/fastx.py
fasta2headers(fasta, full_header=False)
¶
Read FASTA file set of headers.
Simple function to read FASTA file and return set of contig names
Parameters¶
fasta : filename FASTA input file (can be gzipped) full_header : bool, default=False return full header for contig names, default is split at first space
Returns¶
headers : set returns set() of header names
Source code in buscolite/fastx.py
fasta2lengths(fasta, full_header=False)
¶
Read FASTA file to dictionary of sequence lengths.
Reads FASTA file (optionally gzipped) and returns dictionary of contig header names as keys with length of sequences as values
Parameters¶
fasta : filename FASTA input file (can be gzipped) full_header : bool, default=False return full header for contig names, default is split at first space
Returns¶
seqs : dict returns dictionary of header: len(seq)
Source code in buscolite/fastx.py
explode_fasta(fasta, folder, suffix='.fa')
¶
Read FASTA file and write 1 contig per file to folder
Parameters¶
fasta : filename FASTA input file (can be gzipped) folder : directory directory to write contigs to
Returns¶
seqs : dict returns dictionary of header: len(seq)
Source code in buscolite/fastx.py
getSeqRegions(seqs, header, coordinates)
¶
From sequence dictionary return spliced coordinates.
Takes a sequence dictionary (ie from fasta2dict), the contig name (header) and the coordinates to fetch (list of tuples)
Parameters¶
seqs : dict dictionary of sequences keyed by contig name/ header header : str contig name (header) for sequence in seqs dictionary coordinates : list of tuples list of tuples of sequence coordinates to return [(1,10), (20,30)]
Returns¶
result : str returns spliced DNA sequence
Source code in buscolite/fastx.py
augustus¶
Augustus gene prediction integration.
augustus
¶
log¶
Logging utilities.
log
¶
Quick Example¶
from buscolite.busco import runbusco
# Run BUSCO analysis
results, missing, stats, config = runbusco(
input="genome.fasta",
lineage="/path/to/fungi_odb10",
mode="genome",
species="anidulans",
cpus=8,
offset=2000,
verbosity=3
)
# Print summary
print(f"Complete (single-copy): {stats['single-copy']}")
print(f"Complete (duplicated): {stats['duplicated']}")
print(f"Fragmented: {stats['fragmented']}")
print(f"Missing: {len(missing)}")
print(f"Total: {stats['total']}")
# Access individual BUSCO results
for busco_id, data in results.items():
if data.get("status") == "complete":
print(f"{busco_id}: {data['location']}")
Plotting API¶
from buscolite.plot import generate_plot, generate_multi_plot
# Generate single sample plot
datasets = [{
'name': 'My Genome',
'stats': stats,
'config': config
}]
generate_plot(datasets[0], 'output.svg')
# Generate multi-sample comparison plot
datasets = [
{'name': 'Sample 1', 'stats': stats1, 'config': config1},
{'name': 'Sample 2', 'stats': stats2, 'config': config2},
{'name': 'Sample 3', 'stats': stats3, 'config': config3},
]
generate_multi_plot(datasets, 'comparison.svg')
Detailed Module Documentation¶
For detailed documentation of each module, see the individual module pages: