API
ZipStrain provides a Python API for building workflows programmatically. Most users will interact with the matrix workflow through the CLI, but the underlying matrix-store helpers also live in Python.
Core Modules
Database
zipstrain.database
This module provides classes and functions to manage profile and comparison databases for efficient data handling. The ProfileDatabase class manages profiles, while the GenomeComparisonDatabase class handles comparisons between profiles. See the documentation of each class for more details.
GeneComparisonConfig
Bases: BaseModel
Configuration for gene-level comparisons between profiles.
| Attributes: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
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 | |
get_maximal_scope_config(other)
Get a new GeneComparisonConfig object with the maximal scope that is compatible with the two configurations.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
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 | |
is_compatible(other)
Check if this gene comparison configuration is compatible with another. Two configurations are compatible if they have the same parameters, except for scope. Scope can be different as long as they are not disjoint. Also, 'all' is compatible with any scope.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
validate_scope(v)
classmethod
Validate that scope follows GENOME:GENE format.
Source code in zipstrain/src/zipstrain/database.py
290 291 292 293 294 295 296 297 298 299 300 301 302 | |
GeneComparisonDatabase
GeneComparisonDatabase object holds a reference to a gene comparison parquet file. The methods in this class serve to provide functionality for working with the gene comparison data in an easy and efficient manner. The comparison parquet file is the result of running gene-level comparisons, and optionally concatenating multiple compare parquet files from single comparisons. This parquet file must contain the following columns:
- genome
- gene
- total_positions
- share_allele_pos
- ani
- sample_1
- sample_2
A GeneComparisonDatabase object needs a GeneComparisonConfig object to specify the parameters used for the comparison.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
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 | |
add_comp_database(comp_database)
Merge the provided gene comparison database into the current database.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
get_all_profile_names()
Get all profile names that are in the comparison database.
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
652 653 654 655 656 657 658 659 660 661 | |
get_remaining_pairs()
Get pairs of profiles that are in the profile database but not in the comparison database.
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
is_complete()
Check if the comparison database is complete, i.e., if all pairs of profiles in the profile database have been compared.
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
680 681 682 683 684 685 686 687 | |
save_new_compare_database(output_path)
Save the database to a parquet file.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | |
to_complete_input_table()
This method gives a table of all pairwise comparisons that is needed to make the comparison database complete. The table contains the following columns:
- sample_name_1
- sample_name_2
- profile_location_1
- profile_location_2
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
update_compare_database()
Overwrites the comparison database saved on the disk to the current comparison database object.
| Raises: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
GenomeComparisonConfig
Bases: BaseModel
In-memory options for genome comparison workflows.
| Attributes: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
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 | |
get_maximal_scope_config(other)
Get a new GenomeComparisonConfig object with the maximal scope that is compatible with the two configurations. Args: other (GenomeComparisonConfig): The other comparison configuration to get the maximal scope with. Returns: GenomeComparisonConfig: The new comparison configuration with the maximal scope.
Source code in zipstrain/src/zipstrain/database.py
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 | |
is_compatible(other)
Check if this comparison configuration is compatible with another. Two configurations are compatible if they have the same parameters, except for scope. Scope can be different as long as they are not disjoint. Also, all is compatible with any scope. Args: other (GenomeComparisonConfig): The other comparison configuration to check compatibility with. Returns: bool: True if the configurations are compatible, False otherwise.
Source code in zipstrain/src/zipstrain/database.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
GenomeComparisonDatabase
GenomeComparisonDatabase object holds a reference to a comparison parquet file. The methods in this class serve to provide functionality for working with the comparison data in an easy and efficient manner. The comparison parquet file the result of running compare, and optionally concatenating multiple compare parquet file from single comparisons. This parquet file must contain the following columns:
-
genome
-
total_positions
-
share_allele_pos
-
genome_ani
-
max_consecutive_length
-
shared_genes_count
-
identical_gene_count
-
sample_1
-
sample_2
A ComparisonDatabase object needs a ComparisonConfig object to specify the parameters used for the comparison.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
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 | |
add_comp_database(comp_database)
Merge the provided comparison database into the current database.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
get_all_profile_names()
Get all profile names that are in the comparison database.
Source code in zipstrain/src/zipstrain/database.py
480 481 482 483 484 485 486 | |
get_remaining_pairs()
Get pairs of profiles that are in the profile database but not in the comparison database.
Source code in zipstrain/src/zipstrain/database.py
487 488 489 490 491 492 493 494 495 496 | |
is_complete()
Check if the comparison database is complete, i.e., if all pairs of profiles in the profile database have been compared.
Source code in zipstrain/src/zipstrain/database.py
498 499 500 501 502 | |
save_new_compare_database(output_path)
Save the database to a parquet file.
Source code in zipstrain/src/zipstrain/database.py
523 524 525 526 527 528 529 530 531 532 | |
to_complete_input_table()
This method gives a table of all pairwise comparisons that is needed to make the comparison database complete. The table contains the following columns:
-
sample_name_1
-
sample_name_2
-
profile_location_1
-
profile_location_2
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
update_compare_database()
Overwrites the comparison database saved on the disk to the current comparison database object
Source code in zipstrain/src/zipstrain/database.py
535 536 537 538 539 540 541 542 543 544 545 546 | |
ProfileDatabase
The profile database simply holds profile information. Does not need to be specific to a comparison database. The data behind a profile is stored in a parquet file. It is basically a table with the following columns:
-
profile_name: An arbitrary name given to the profile (Usually sample name or name of the parquet file)
-
profile_location: The location of the profile
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
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 | |
add_database(profile_database)
Merge the provided profile database into the current database.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
134 135 136 137 138 139 140 141 142 143 144 145 146 | |
add_profile(data)
Add a profile to the database. The data dictionary must contain the following and only the following keys:
-
profile_name
-
profile_location
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
from_csv(csv_path, allow_mismatch=False)
classmethod
Create a ProfileDatabase instance from a CSV file with exactly same columns as the required columns for a profile database.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
save_as_new_database(output_path)
Save the database to a parquet file.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
to_csv(output_dir)
Writes the the current database object to a csv file"
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/database.py
196 197 198 199 200 201 202 203 204 205 | |
update_database()
Overwrites the database saved on the disk to the current database object
Source code in zipstrain/src/zipstrain/database.py
167 168 169 170 171 172 173 174 175 | |
ProfileItem
Bases: BaseModel
This class describes all necessary attributes of a profile and makes sure they comply with the necessary formating.
Source code in zipstrain/src/zipstrain/database.py
19 20 21 22 23 24 25 26 27 28 29 30 31 | |
Profile
zipstrain.profile
This module provides functions and utilities to profile a bamfile. By profile we mean generating gene, genome, and nucleotide counts at each position on the reference. This is a fundamental step for downstream analysis in zipstrain.
ProfilingAssets
dataclass
Concrete paths to the intermediate files needed to profile a BAM.
gene_range_table and profiling_contract_file may be None when
the caller supplied explicit assets and did not provide those optional
files; the auto-preparation path always populates every field.
Source code in zipstrain/src/zipstrain/profile.py
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 | |
adjust_for_sequence_errors(mpile_frame, null_model, min_freq=PROFILE_MIN_FREQ_DEFAULT)
Adjust the mpile frame for sequence errors based on the null model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/profile.py
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 | |
adjust_profile_parquet_for_sequence_errors(profile_parquet, null_model_parquet, output_file, min_freq=PROFILE_MIN_FREQ_DEFAULT)
Apply sequence-error adjustment to an existing profile parquet.
The output preserves the input column order/schema, except that temporary columns introduced during adjustment are not written.
Source code in zipstrain/src/zipstrain/profile.py
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 | |
build_gene_range_table(fasta_file)
Build a gene location table in the form of
Returns: pl.DataFrame: A Polars DataFrame containing gene locations.
Source code in zipstrain/src/zipstrain/profile.py
410 411 412 413 414 415 416 417 418 419 420 421 422 | |
empty_gene_range_table()
Return an empty gene-range LazyFrame with the expected schema.
Source code in zipstrain/src/zipstrain/profile.py
425 426 427 428 429 430 431 432 433 434 | |
empty_gene_stats_table(include_ref_ani=False)
Return an empty gene-stats LazyFrame with the expected schema.
Source code in zipstrain/src/zipstrain/profile.py
437 438 439 440 441 442 443 444 445 446 447 448 | |
get_reference_ani(profile, *, agg_level='genome', min_cov=5)
Calculate reference-relative ANI from a profile carrying ref_base_bitmask.
The reference base is encoded as a one-hot bitmask: - A -> 1 - C -> 2 - G -> 4 - T -> 8 - other / unknown -> 0
A covered position is treated as sharing the reference allele when the observed nucleotide counts contain the reference allele after profile sequence-error adjustment.
Source code in zipstrain/src/zipstrain/profile.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 | |
get_reference_snps(profile, *, min_cov=5)
Classify variant sites relative to the reference (inStrain-parity table).
One row per covered position that is divergent — i.e. not a monomorphic
match to the reference. Because the profile counts are already sequence-error
adjusted, a base with count > 0 is a "passing" allele. With
alleles = the passing bases, con = the consensus (most common) base
and ref = the reference base, each site is labelled:
SNS: one allele,con != ref(fixed substitution)SNV: ≥2 alleles,con == ref(reference is majority; minor variant)con_SNV: ≥2 alleles,con != ref, reference still among the allelespop_SNV: ≥2 alleles,con != ref, reference absent from the alleles
Monomorphic reference sites (one allele equal to the reference) are omitted.
Frequencies are over the (error-adjusted) position coverage. Requires a
profile carrying ref_base_bitmask (i.e. --reference-fasta).
Source code in zipstrain/src/zipstrain/profile.py
1029 1030 1031 1032 1033 1034 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 | |
normalize_gene_range_table_path(gene_range_table)
Treat missing or empty gene-range files as absent annotations.
Source code in zipstrain/src/zipstrain/profile.py
451 452 453 454 455 456 457 458 459 460 | |
parse_gene_loc_table(fasta_file)
Extract gene locations from a FASTA assuming it is from prodigal yield gene info.
Parameters: fasta_file (pathlib.Path): Path to the FASTA file.
Tuple: A tuple containing: - gene_ID - scaffold - start - end
Source code in zipstrain/src/zipstrain/profile.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
prepare_profiling_assets(*, reference_fasta, stb_file, output_dir, gene_fasta=None, error_rate=utils.NULL_MODEL_ERROR_RATE_DEFAULT, max_total_reads=utils.NULL_MODEL_MAX_COVERAGE_DEFAULT, p_threshold=utils.NULL_MODEL_P_THRESHOLD_DEFAULT, model_type='poisson')
Build every intermediate profiling asset into output_dir.
This is the shared implementation behind the prepare_profiling utility
and the auto-preparation performed by zipstrain profile. It writes the
bed file, gene range table, genome length table, null model, and profiling
contract, and returns their paths.
Source code in zipstrain/src/zipstrain/profile.py
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 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 | |
profile_bam(bed_file, bam_file, reference_fasta, gene_range_table, stb, null_model, output_dir, num_chunks=24, max_concurrency=4, profile_contract=None, min_mapq=PROFILE_MIN_MAPQ_DEFAULT, min_baseq=PROFILE_MIN_BASEQ_DEFAULT, min_read_ani=None, read_inclusion=READ_INCLUSION_ALL_MAPPED, min_freq=PROFILE_MIN_FREQ_DEFAULT)
Profile a BAM file in chunks using provided BED files.
Parameters: bed_file (list[pathlib.Path]): A bed file describing all regions to be profiled. bam_file (pathlib.Path): Path to the BAM file. gene_range_table (pathlib.Path | None): Optional path to the gene range table. stb (pl.LazyFrame): Scaffold-to-genome mapping table. null_model (pl.LazyFrame): The null model to be used for adjusting for sequence errors. output_dir (pathlib.Path): Directory to save output files. num_chunks (int): Number of BED chunks to create. max_concurrency (int): Maximum number of chunks to process concurrently. min_freq (float): Minimum fraction of the original per-position A/C/G/T coverage required to retain an allele count.
Source code in zipstrain/src/zipstrain/profile.py
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 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 | |
profile_bam_in_chunks(bed_file, bam_file, reference_fasta, gene_range_table, stb, null_model, output_dir, num_chunks=24, max_concurrency=4, profile_contract=None, min_mapq=PROFILE_MIN_MAPQ_DEFAULT, min_baseq=PROFILE_MIN_BASEQ_DEFAULT, min_read_ani=None, read_inclusion=READ_INCLUSION_ALL_MAPPED, min_freq=PROFILE_MIN_FREQ_DEFAULT)
Profile a BAM file in chunks using provided BED files.
Parameters: bed_file (list[pathlib.Path]): A bed file describing all regions to be profiled. bam_file (pathlib.Path): Path to the BAM file. gene_range_table (pathlib.Path | None): Optional path to the gene range table. stb (pl.LazyFrame): The scaffold-to-genome mapping table. null_model (pl.LazyFrame): The null model to be used for adjusting for sequence errors. output_dir (pathlib.Path): Directory to save output files. num_chunks (int): Number of BED chunks to create. max_concurrency (int): Maximum number of chunks to process concurrently. min_freq (float): Minimum fraction of the original per-position A/C/G/T coverage required to retain an allele count.
Source code in zipstrain/src/zipstrain/profile.py
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 1363 1364 1365 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 | |
read_stb(stb_file)
Scan a scaffold-to-genome (STB) TSV as scaffold, genome.
Leading/trailing whitespace around the columns is stripped so scaffold names
match the BAM/FASTA exactly. Some STB files (which inStrain tolerates) carry
stray spaces around the tab; without stripping, those scaffolds fail to join
and are silently dropped to genome NA.
Source code in zipstrain/src/zipstrain/profile.py
71 72 73 74 75 76 77 78 79 80 81 82 | |
resolve_profiling_assets(*, run_dir, reference_fasta, stb_file, gene_fasta=None, null_model_file=None, bed_file=None, genome_length_file=None, gene_range_table=None, profiling_contract_file=None, error_rate=utils.NULL_MODEL_ERROR_RATE_DEFAULT, max_total_reads=utils.NULL_MODEL_MAX_COVERAGE_DEFAULT, p_threshold=utils.NULL_MODEL_P_THRESHOLD_DEFAULT, model_type='poisson', force_prepare=False)
Resolve every profiling asset, auto-generating any that weren't supplied.
Explicitly-provided paths always win. When any of the required assets
(bed, genome length, null model) is missing, the full asset set is built
into run_dir/profiling_assets (reusing a valid cached copy when the
inputs and null-model parameters are unchanged and force_prepare is
False), and any explicitly-provided paths override the generated ones.
Source code in zipstrain/src/zipstrain/profile.py
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 1747 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 | |
sort_profile_parquet_in_place(profile_parquet, tmp_dir=None)
Sort a classic profile parquet in place and attach sortedness metadata.
Source code in zipstrain/src/zipstrain/profile.py
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 | |
Compare
zipstrain.compare
This module provides all comparison functions for zipstrain.
PolarsANIExpressions
Any kind of ANI calculation based on two profiles should be implemented as a method of this class. In defining this method, the following rules should be followed:
-
The method returns a Polars expression (pl.Expr).
-
When applied to a row, the method returns a zero if that position is a SNV. Otherwise it should return a number greater than zero.
-
A, T, C, G columns in the first profile are named "A", "T", "C", "G" and in the second profile they are named "A_2", "T_2", "C_2", "G_2".
-
popani: Population ANI based on the shared alleles between two profiles.
- conani: Consensus ANI based on the consensus alleles between two profiles.
- cosani_
: Generalized cosine similarity ANI where threshold is a float value between 0 and 1. Once the similarity is below the threshold, it is considered a SNV.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
add_contiguity_info(mpile_contig)
Adds group id information to the lazy frame. If on the same scaffold and not popANI, then they are in the same group.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/compare.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
add_genome_info(mpile_contig, scaffold_to_genome)
Adds genome information to the mpileup LazyFrame based on scaffold to genome mapping.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/compare.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
calculate_pop_ani(mpile_contig)
Calculates the population ANI (Average Nucleotide Identity) for the given mpileup LazyFrame.
NOTE: Remember that this function should be applied to the merged mpileup using _shared_loci_polars
or the equivalent shared-loci helper for the active engine.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/compare.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | |
compare_genes(mpile_contig_1, mpile_contig_2, min_cov=5, min_gene_compare_len=100, genome_scope='all', gene_scope='all', ani_method='popani', duckdb_memory_limit=None, duckdb_temp_directory=None, duckdb_threads=None, engine='polars')
Compare two profiles at gene level with selectable execution engine.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
compare_genes_polars(mpile_contig_1, mpile_contig_2, min_cov=5, min_gene_compare_len=100, genome_scope='all', gene_scope='all', ani_method='popani')
Compare two profiles fully in Polars and return gene-level ANI statistics.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
compare_genomes(mpile_contig_1, mpile_contig_2, min_cov=5, min_gene_compare_len=100, genome_scope='all', ani_method='popani', duckdb_memory_limit=None, duckdb_temp_directory=None, duckdb_threads=None, engine='polars', stb_file=None, calculate=None)
Compare two profiles with selectable execution engine.
Source code in zipstrain/src/zipstrain/compare.py
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 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
compare_genomes_polars(mpile_contig_1, mpile_contig_2, min_cov=5, min_gene_compare_len=100, genome_scope='all', ani_method='popani', stb_file=None, calculate=None)
Compare two profiles fully in Polars and return genome-level statistics.
Source code in zipstrain/src/zipstrain/compare.py
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 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
duckdb_compare_genes_to_parquet(mpile1, mpile2, output_file, sample_1_name, sample_2_name, min_cov=5, min_gene_compare_len=100, genome_scope='all', gene_scope='all', ani_method='popani', memory_limit=None, temp_directory=None, threads=None)
Run gene comparison in DuckDB and write final output directly to parquet.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
duckdb_compare_genomes(mpile1, mpile2, min_cov=5, min_gene_compare_len=100, genome_scope='all', ani_method='popani', calculate=None, stb_file=None, memory_limit=None, temp_directory=None, threads=None)
Run genome comparison in DuckDB and return selected metrics as a LazyFrame.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
duckdb_compare_genomes_to_parquet(mpile1, mpile2, output_file, stb_file, sample_1_name, sample_2_name, min_cov=5, min_gene_compare_len=100, genome_scope='all', ani_method='popani', calculate=None, memory_limit=None, temp_directory=None, threads=None)
Run genome comparison in DuckDB and write final output directly to parquet.
This path avoids materializing large intermediate tables in Python memory.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
duckdb_filter_join(mpile1, mpile2, min_cov, genome_scope='all', ani_method='popani', gene_scope='all', memory_limit=None, temp_directory=None, threads=None)
Filter two profile sources and inner-join shared loci in DuckDB.
Inputs can be parquet paths or Polars LazyFrames. Coverage, genome scope,
and optional gene scope are pushed down into DuckDB. The returned lazy frame
contains: surr, scaffold, pos, gene, and genome.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
duckdb_prefilter_by_scope(mpile1, mpile2, genome_scope='all', gene_scope='all', memory_limit=None, temp_directory=None, threads=None)
Scope-filter both profiles in DuckDB and return in-memory LazyFrames.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
genome_metric_output_columns(calculate=None)
Return ordered output columns for selected genome-level calculations.
Source code in zipstrain/src/zipstrain/compare.py
67 68 69 70 71 72 73 74 75 76 77 | |
get_gene_ani(mpile_contig, min_gene_compare_len)
Calculates gene ANI (Average Nucleotide Identity) for each gene in each genome.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/compare.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
get_longest_consecutive_blocks(mpile_contig)
Calculates the longest consecutive blocks for each genome in the mpileup LazyFrame for any genome.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in zipstrain/src/zipstrain/compare.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | |
get_unique_scaffolds(mpile_contig, batch_size=10000)
Retrieves unique scaffolds from the mpileup LazyFrame.
| Parameters: |
|
|---|
Returns: set: A set of unique scaffold names.
Source code in zipstrain/src/zipstrain/compare.py
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 | |
matrix_surr_numpy(counts_np, N, L, min_cov, ani_method, chunk_size)
CPU all-pairs match/shared counts via numpy, chunked over positions.
Parameters
counts_np:
int32 array of shape (N, L, 4) — samples × positions × bases (A,C,G,T).
N, L:
Number of samples and positions.
min_cov:
Minimum total coverage to include a position for a sample.
ani_method:
"popani", "conani", or "cosani_<threshold>".
chunk_size:
Positions processed per iteration. Peak memory is O(N²×chunk_size).
Returns
matches, shared : np.ndarray Both float64 arrays of shape (N, N).
Source code in zipstrain/src/zipstrain/compare.py
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 1231 | |
matrix_surr_torch(counts_np, N, L, min_cov, ani_method, device, chunk_size)
GPU all-pairs match/shared counts via PyTorch, chunked over positions.
Same semantics as :func:matrix_surr_numpy but runs on the given torch
device ("cuda" or "mps"). MPS uses float32 throughout since it
does not support float64/int64.
Returns
matches, shared : np.ndarray Both float64 arrays of shape (N, N), moved to CPU.
Source code in zipstrain/src/zipstrain/compare.py
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 | |
parse_genome_calculations(calculate=None)
Parse and normalize genome metric selection tokens.
Accepted input formats
- None -> default ("ani", "ibs", "identical_genes")
- "ani+ibs+identical_genes"
- "all"
- iterable of token strings
Source code in zipstrain/src/zipstrain/compare.py
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 | |
polars_prefilter_by_scope(mpile1, mpile2, genome_scope='all', gene_scope='all')
Scope-filter both profiles in Polars and return in-memory LazyFrames.
Source code in zipstrain/src/zipstrain/compare.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
Utils
zipstrain.utils
This module provides utility functions for profiling and compare operations.
CallPresence
This class provides methods to use the information
Source code in zipstrain/src/zipstrain/utils.py
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 | |
breadth_only(lf, breadth=0.5)
Call presence/absence of genomes based on breadth only. Parameters: lf (pl.LazyFrame): Input LazyFrame with genome statistics. breadth (float): Breadth threshold. Returns: pl.LazyFrame: LazyFrame with presence/absence calls.
Source code in zipstrain/src/zipstrain/utils.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
coverage_only(lf, coverage=0.1)
Call presence/absence of genomes based on coverage only. Parameters: lf (pl.LazyFrame): Input LazyFrame with genome statistics. coverage (float): Coverage threshold. Returns: pl.LazyFrame: LazyFrame
Source code in zipstrain/src/zipstrain/utils.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
metapresence(lf, ber=0.5, fug=0.5, min_cov_use_fug=0.1)
Call presence/absence of genomes based on breadth, coverage, ber, and fug. Parameters: lf (pl.LazyFrame): Input LazyFrame with genome statistics. ber (float): Breadth error rate threshold. fug (float): FUG threshold; present requires fug above this (higher fug = more uniform coverage = present). min_cov_use_fug (int): Coverage above which BER is used alone; below it FUG is also required. Returns: pl.LazyFrame: LazyFrame with presence/absence calls.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
EstimateAbundance
This class provides methods to estimate abundance of genomes based on coverage.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
coverage_ratio(lf)
Estimate abundance based on coverage ratio. Parameters: lf (pl.LazyFrame): Input LazyFrame with genome statistics. Returns: pl.LazyFrame: LazyFrame with estimated abundance.
Source code in zipstrain/src/zipstrain/utils.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
reads_ratio(lf)
Estimate abundance based on reads ratio. Parameters: lf (pl.LazyFrame): Input LazyFrame with genome statistics. Returns: pl.LazyFrame: LazyFrame with estimated abundance.
Source code in zipstrain/src/zipstrain/utils.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
build_null_poisson(error_rate=NULL_MODEL_ERROR_RATE_DEFAULT, max_total_reads=NULL_MODEL_MAX_COVERAGE_DEFAULT, p_threshold=NULL_MODEL_P_THRESHOLD_DEFAULT)
Build a null model to correct for sequencing errors based on the Poisson distribution.
Parameters: error_rate (float): Error rate for the sequencing technology. max_total_reads (int): Maximum total reads to consider. p_threshold (float): Significance threshold for the Poisson distribution.
Returns: list[tuple[int, int]]: Coverage and maximum plausible error-count pairs.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
build_single_compare_metadata(profile_1, profile_2, *, compare_kind, scope, min_cov, min_gene_compare_len, engine, uses_stb, ani_method)
Build mismatch-tolerant metadata for a single compare parquet.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
chunk_genome_compare(pair_table, output_file, stb_file, workers=None, min_cov=5, min_gene_compare_len=100, genome_scope='all', ani_method='popani', calculate='all', engine='polars', duckdb_memory_limit=None, duckdb_temp_directory=None, duckdb_threads=None, progress_callback=None)
Run classic genome compare on one pair table using in-process parallel workers.
Source code in zipstrain/src/zipstrain/utils.py
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 1231 1232 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 1363 1364 1365 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 | |
clean_bases(bases, indel_re)
Remove read start/end markers and indels from bases string using regex. Returns cleaned uppercase string of bases only. Args: bases (str): The bases string from mpileup. indel_re (re.Pattern): Compiled regex pattern to match indels and markers.
Source code in zipstrain/src/zipstrain/utils.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
count_bases(bases)
Count occurrences of A, C, G, T in the cleaned bases string. Args: bases (str): Cleaned bases string. Returns: dict: Dictionary with counts of A, C, G, T.
Source code in zipstrain/src/zipstrain/utils.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
count_mpileup_bases(bases, ref_base, indel_re)
Count A/C/G/T bases from an mpileup bases field, expanding reference matches.
In samtools mpileup, . and , indicate a read base matching the reference on
the forward and reverse strand respectively. This helper resolves those tokens
to the provided reference base before counting.
Source code in zipstrain/src/zipstrain/utils.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
decode_reference_base_bitmask(bitmask)
Decode a one-hot reference-base bitmask to the corresponding base.
Returns None when the bitmask does not represent a known single A/C/G/T
reference base.
Source code in zipstrain/src/zipstrain/utils.py
596 597 598 599 600 601 602 603 604 605 606 | |
discover_classic_profile_parquets(profile_dir)
Return classic ZipStrain profile parquets from a directory.
Source code in zipstrain/src/zipstrain/utils.py
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
encode_reference_base_bitmask(base)
Encode a reference base as a one-hot bitmask.
Mapping: - A -> 1 - C -> 2 - G -> 4 - T -> 8 - any other value -> 0
Source code in zipstrain/src/zipstrain/utils.py
583 584 585 586 587 588 589 590 591 592 593 594 | |
extract_genome_length(stb, bed_table)
Extract the genome length information from the scaffold-to-genome mapping table.
Parameters: stb (pl.LazyFrame): Scaffold-to-bin mapping table. bed_table (pl.LazyFrame): BED table containing genomic regions.
Returns: pl.LazyFrame: A LazyFrame containing the genome lengths.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
generate_sample_pairs(profile_dir, output_file, write_batch_size=100000, progress_callback=None)
Generate all non-redundant classic profile sample pairs and write them to parquet.
Source code in zipstrain/src/zipstrain/utils.py
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 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 | |
infer_sample_name_from_profile(profile_path)
Infer sample name from a classic profile parquet path.
Source code in zipstrain/src/zipstrain/utils.py
859 860 861 862 863 864 | |
infer_sample_name_from_stat_table(stat_table)
Infer sample name from a gene/genome stats parquet file name.
Source code in zipstrain/src/zipstrain/utils.py
850 851 852 853 854 855 856 | |
make_the_bed(db_fasta_dir, max_scaffold_length=500000)
Create a BED file from the database in fasta format.
Parameters: db_fasta_dir (Union[str, pathlib.Path]): Path to the fasta file. max_scaffold_length (int): Splits scaffolds longer than this into multiple entries of length <= max_scaffold_length.
Returns: pl.LazyFrame: A LazyFrame containing the BED data.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
merge_parquet_files(input_dir, output_file, batch_size=-1, allow_mismatch=False, progress_callback=None)
Merge parquet files from a directory into a single parquet file.
When batch_size is -1 the merge is performed in a single pass, which
preserves the current behavior. For positive batch_size values, inputs
are merged in staged batches to avoid building an excessively large lazy
concatenation plan at once.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
merge_stat_tables(stat_tables, output_file, progress_callback=None)
Concatenate gene/genome stat parquets and add a sample column from file names.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
normalize_profile_contract_values(contract)
Return a full profile-contract mapping with missing values set to NA.
Source code in zipstrain/src/zipstrain/utils.py
119 120 121 122 123 124 125 126 127 | |
parquet_to_csv(input_file, output_file=None, *, separator=',', include_header=True)
Stream a parquet table to CSV.
Source code in zipstrain/src/zipstrain/utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
process_mpileup_function(batch_size, output_file)
Process mpileup files and save the results in a Parquet file.
Parameters: gene_range_table_loc (str): Path to the gene range table in TSV format. batch_bed (str): Path to the batch BED file. batch_size (int): Buffer size for processing stdin from samtools. output_file (str): Path to save the output Parquet file.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
process_read_location(output_file, batch_size=10000)
This function takes the output of samtools view -F 132 and processes it to extract read locations in a parquet file.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
profile_contract_metadata_from_values(contract)
Map logical profile contract values to parquet metadata keys.
Source code in zipstrain/src/zipstrain/utils.py
130 131 132 133 134 135 136 | |
read_profile_contract_file(contract_file)
Load a profiling contract JSON file and normalize missing values to NA.
Source code in zipstrain/src/zipstrain/utils.py
148 149 150 151 152 153 154 | |
read_profile_contract_metadata(profile_parquet)
Read the ZipStrain contract metadata from a classic profile parquet.
Source code in zipstrain/src/zipstrain/utils.py
222 223 224 225 226 227 228 229 230 231 232 233 234 | |
rewrite_parquet_with_metadata(parquet_file, metadata, *, compression='zstd')
Rewrite a parquet file in-place so it carries the provided custom metadata.
Source code in zipstrain/src/zipstrain/utils.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
sha256_file(path, chunk_size=1024 * 1024)
Return the file-content SHA-256 hex digest for path.
Source code in zipstrain/src/zipstrain/utils.py
107 108 109 110 111 112 113 114 115 116 | |
split_lf_to_chunks(lf, num_chunks)
Split a Polars LazyFrame into smaller chunks.
Parameters: lf (pl.LazyFrame): The input LazyFrame to be split. num_chunks (int): The number of chunks to split the LazyFrame into.
Returns: list[pl.LazyFrame]: A list of smaller LazyFrames.
Source code in zipstrain/src/zipstrain/utils.py
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 | |
write_profile_contract_file(contract, output_file)
Persist the normalized profiling contract as JSON.
Source code in zipstrain/src/zipstrain/utils.py
139 140 141 142 143 144 145 | |
Visualize
zipstrain.visualize
This module provides statistical analysis and visualization functions for profiling and compare operations.
SilhouetteCurveResult
dataclass
Computed silhouette sweep plus peak statistics for one genome scope.
Source code in zipstrain/src/zipstrain/visualize.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
calculate_ibs(sample_to_population, comps_lf, max_perc_id_genes=15, min_total_positions=10000)
Calculate the Identity By State (IBS) between two populations for a given genome. The IBS is defined as the percentage of genes that are identical between two populations for a given genome. Args: sample_to_population (pl.LazyFrame): LazyFrame containing the sample to population mapping. comps_lf (pl.LazyFrame): LazyFrame containing the gene profiles of the samples. max_perc_id_genes (float, optional): Maximum percentage of identical genes to consider. Defaults to 0.15. Returns: pl.LazyFrame: LazyFrame containing the IBS information for the given genome and populations.
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
calculate_identical_frac_vs_popani(genome, population_1, population_2, sample_to_population, comps_lf, min_shared_genes_count=100, min_total_positions=10000)
Calculate the fraction of identical genes vs genome ANI for a given genome and two samples in any possible combination of populations. Args: genome (str): The genome to calculate the fraction of identical genes vs genome ANI for. population_1 (str): The first population to compare. population_2 (str): The second population to compare. sample_to_population (pl.LazyFrame): LazyFrame containing the sample to population mapping. comps_lf (pl.LazyFrame): LazyFrame containing the gene profiles of the samples Returns: pl.LazyFrame: LazyFrame containing the fraction of identical genes vs genome ANI information for
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
calculate_strainsharing(comps_lf, breadth_lf, sample_to_population, min_breadth=0.5, strain_similarity_threshold=99.9, min_total_positions=10000)
Calculate strain sharing between populations based on genome ANI between genomes in their profiles. Strain sharing between two samples is defined as the ratio of genomes passing a strain similarity threshold over the total number of genomes in each sample. So, for two samples A and B, the strain sharing is defined as (Note the assymetric nature of the calculation): strain_sharing(A, B) = (number of genomes in A and B passing the strain similarity threshold) / (number of genomes in A) strain_sharing(B, A) = (number of genomes in A and B passing the strain similarity threshold) / (number of genomes in B)
| Parameters: |
|
|---|
Returns: pl.LazyFrame: LazyFrame containing the strain sharing information between populations. It will be in the following form [Sample A, Sample B, Strain Sharing, Relationship]
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
compute_silhouette_curve(comps_lf, genome, min_comp_len=100000, impute_method=97.0, max_null_samples=500, linkage_method='average', min_threshold=99.8, peak_prominence=0.001, peak_distance=3)
Compute a silhouette sweep and peak summary for one genome.
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
get_cdf(data, num_bins=10000)
Calculate the cumulative distribution function (CDF) of the given data.
Source code in zipstrain/src/zipstrain/visualize.py
335 336 337 338 339 340 341 342 343 344 | |
get_cluster_assignments(comps_lf, min_comp_len=10000, impute_method=97.0, max_null_samples=500, clonal_cluster_threshold=99.93, strain_cluster_threshold=99.8, linkage_method='average')
Get clonal and strain-level cluster assignments from a genome-scoped comparison table.
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
get_clustermap(comps_lf, genome, sample_to_population, min_comp_len=10000, impute_method=97.0, max_null_samples=500, linkage_method='average', color_map=None)
Return a seaborn clustermap for one genome.
Source code in zipstrain/src/zipstrain/visualize.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 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 | |
get_silhouette_plot(comps_lf, genome, min_comp_len=100000, impute_method=97.0, max_null_samples=500, linkage_method='average', min_threshold=99.8, peak_prominence=0.001, peak_distance=3)
Plot silhouette score as a function of ANI threshold for one genome.
Source code in zipstrain/src/zipstrain/visualize.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | |
plot_dendo(comps_lf, genome, sample_to_population, min_comp_len=10000, impute_method=97.0, max_null_samples=500, linkage_method='average', color_map=None, inches_per_sample=0.15, font_size=8, color_threshold=0.03, clonal_cluster_threshold=99.93, strain_cluster_threshold=99.8, title=None, include_fraction_null=False)
Plot a left-oriented dendrogram for one genome with optional null-fraction bars.
Source code in zipstrain/src/zipstrain/visualize.py
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 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 | |
plot_ibs(df, genome, population_1, population_2, vert_thresh_hor_distance=0.001, num_bins=10000, title='IBS for <GENOME>: <POPULATION_1> vs <POPULATION_2>', xaxis_title='Max Consecutive Length', yaxis_title='CDF')
Plot the Identity By State (IBS) for a given genome and two populations.
Args:
df (pl.DataFrame): DataFrame containing the IBS information.
genome (str): The genome to plot the IBS for.
population_1 (str): The first population to plot the IBS for.
population_2 (str): The second population to plot the IBS for.
title (str, optional): Title of the plot. Defaults to "IBS for
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
plot_ibs_heatmap(df, vert_thresh=0.001, populations=None, num_bins=10000, min_member=50, title='IBS Heatmap', xaxis_title='Population Pair', yaxis_title='Genome')
Plot the Identity By State (IBS) heatmap for a given genome and two populations. Args: df (pl.DataFrame): DataFrame containing the IBS information. title (str, optional): Title of the plot. Defaults to "IBS Heatmap". xaxis_title (str, optional): Title of the x-axis. Defaults to "Population Pair". yaxis_title (str, optional): Title of the y-axis. Defaults to "Genome". Returns: go.Figure: Plotly figure containing the IBS heatmap.
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
plot_identical_frac_vs_popani(df, genome, title='Fraction of Identical Genes vs Genome ANI for <GENOME>', xaxis_title='Genome-Wide ANI', yaxis_title='Fraction of Identical Genes')
Plot the fraction of identical genes vs genome ANI for a given genome and two samples in any possible combination of populations. Args: df (pl.DataFrame): DataFrame containing the fraction of identical genes vs genome ANI information. title (str, optional): Title of the plot. Defaults to "Fraction of Identical Genes vs Genome ANI". xaxis_title (str, optional): Title of the x-axis. Defaults to "Genome ANI". yaxis_title (str, optional): Title of the y-axis. Defaults to "Fraction of Identical Genes". Returns: go.Figure: Plotly figure containing the fraction of identical genes vs genome ANI plot.
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
plot_silhouette_curve(result, *, title='Simple peak finding on silhouette curve', xaxis_title='Clustering threshold', yaxis_title='Silhouette score')
Plot a computed silhouette sweep and its peak summary.
Source code in zipstrain/src/zipstrain/visualize.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | |
plot_strainsharing(strainsharingrates, sample_frac=1, title='Strain Sharing Rates', xaxis_title='Population Pair', yaxis_title='Strain Sharing Rate')
Plot the strain sharing rates between populations. Args: strainsharingrates (dict[str, list[float]]): Dictionary containing the strain sharing rates between populations. title (str, optional): Title of the plot. Defaults to "Strain Sharing". xaxis_title (str, optional): Title of the x-axis. Defaults to "Population Pair". yaxis_title (str, optional): Title of the y-axis. Defaults to "Strain Sharing Rate". Returns: go.Figure: Plotly figure containing the strain sharing plot.
Source code in zipstrain/src/zipstrain/visualize.py
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 | |
Matrix Store Workflow
The current matrix workflow is implemented in zipstrain.matrix_pairs.
The main public entry points are:
parse_matrix_calculations(...)build_matrix_hdf5(...)append_matrix_hdf5(...)export_matrix_db_hdf5(...)matrix_compare(...)export_matrix_compare_parquet(...)
These power the CLI commands:
zipstrain utilities build-matrix-dbzipstrain utilities append-matrix-dbzipstrain utilities matrix-db-to-hdf5zipstrain utilities matrix-comparezipstrain utilities matrix-compare-export
For usage patterns and examples, see the Tutorial and the CLI reference.
Task Manager
For more advanced users, custom workflows can also be assembled through the task manager layer:
zipstrain.task_manager
Lightweight, asyncio-driven orchestration primitives for building and running scientific data-processing pipelines. This module provides a small, composable framework for defining Tasks with explicit inputs/outputs, bundling Tasks into Batches (local or Slurm), and coordinating their execution with a live terminal UI. It is designed to be easy to extend for new Task types and execution environments. For most users, this module is not directly used. However, it can be used to define new pipelines that chain together multiple steps with clear input/outputs. The unit of execution is a batch, which is a collection of tasks to be executed together. Each batch can have an optional finalization step that runs after all tasks are complete.
Key concepts
-
Inputs and Outputs: These classes encapsulate task inputs and outputs with validation logics. By default, Input and output classes for files, strings, and integers are provided. If needed, new types can be defined by subclassing Input or Output.
-
Engines: Any task object can use a container engine (Docker or Apptainer) or run natively (LocalEngine).
-
Task Each task runs a unit of bash script with defined inputs and expected outputs. If an engine is provided, the command will be wrapped accordingly to run inside the container.
-
Batches: A batch is a collection of tasks to be executed together. Batches can be run locally or submitted to Slurm. Each batch monitors the status of its tasks and updates its own status accordingly. A batch can also have expected outputs that are checked after all tasks are complete. Additionally, a batch can have a finalization step that runs after all tasks are complete.
-
Runner: The Runner class orchestrates task generation, batching, and execution. It manages concurrent batch execution, monitors progress, and provides a live terminal UI using the rich library.
Batch
Bases: ABC
Batch is a collection of tasks to be executed as a group. This is a base class and should not be instantiated directly. A batch is the unit of execution meaning that the enitre batch is either run locally or submitted to a job scheduler like Slurm.
| Parameters: |
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | |
stats
property
Returns a dictionary of task IDs and their statuses.
status
property
Returns the current status of the batch.
cancel()
abstractmethod
async
Cancels the batch. This method should be implemented by subclasses.
Source code in zipstrain/src/zipstrain/task_manager.py
838 839 840 841 | |
cleanup()
The base class defines if any cleanup is needed after batch success. By default, it does nothing.
Source code in zipstrain/src/zipstrain/task_manager.py
833 834 835 836 | |
log_progress(message='', force=False)
async
Log progress if the batch snapshot changed, unless forced.
Source code in zipstrain/src/zipstrain/task_manager.py
801 802 803 804 805 806 807 808 | |
outputs_ready()
Check if all BATCH-LEVEL expected outputs are ready.
Source code in zipstrain/src/zipstrain/task_manager.py
843 844 845 846 | |
run()
abstractmethod
async
Runs the batch. This method should be implemented by subclasses.
Source code in zipstrain/src/zipstrain/task_manager.py
852 853 854 855 | |
update_status()
async
Updates the status of the batch by collecting the status of all tasks.
Source code in zipstrain/src/zipstrain/task_manager.py
872 873 874 875 | |
BatchFileOutput
Bases: Output
This is used when the output is a file path relative to the batch directory. Also it will be registered to the batch instead of the task.
Source code in zipstrain/src/zipstrain/task_manager.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
ready()
Check if the expected output file exists.
Source code in zipstrain/src/zipstrain/task_manager.py
265 266 267 | |
register_batch(batch)
Registers the batch that produces this output and sets the expected file path.
Args: batch (Batch): The batch that produces this output and sets the expected file path.
Source code in zipstrain/src/zipstrain/task_manager.py
269 270 271 272 273 274 275 | |
CollectComps
Bases: Task
A Task that collects and merges comparison parquet files from multiple FastCompareTask tasks into a single parquet file.
| Parameters: |
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 | |
CollectGeneComps
Bases: Task
A Task that collects and merges gene comparison parquet files from multiple FastGeneCompareTask tasks into a single parquet file.
| Parameters: |
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 | |
CompareRunner
Bases: Runner
Creates and schedules batches of FastCompareTask tasks using either local or Slurm batches.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 1587 1588 1589 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 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 | |
CompareTaskGenerator
Bases: TaskGenerator
This TaskGenerator generates FastCompareTask objects from a polars DataFrame. Each task compares two profiles using compare_genomes functionality in zipstrain.compare module.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
generate_tasks()
async
Yeilds lists of FastCompareTask objects based on the data in batches of yield_size. This method yields the control back to the event loop while polars is collecting data to avoid blocking.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
get_total_tasks()
Returns total number of pairwise comparisons to be made.
Source code in zipstrain/src/zipstrain/task_manager.py
652 653 654 | |
FastCompareLocalBatch
Bases: LocalBatch
A LocalBatch that runs FastCompareTask tasks locally.
Source code in zipstrain/src/zipstrain/task_manager.py
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 | |
FastCompareSlurmBatch
Bases: SlurmBatch
A SlurmBatch that runs FastCompareTask tasks on a Slurm cluster. Maybe removed in future
Source code in zipstrain/src/zipstrain/task_manager.py
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 | |
FastCompareTask
Bases: Task
A Task that performs a genome comparison using zipstrain utilities single_compare_genome.
| Parameters: |
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 | |
FastGeneCompareLocalBatch
Bases: LocalBatch
A LocalBatch that runs FastGeneCompareTask tasks locally.
Source code in zipstrain/src/zipstrain/task_manager.py
2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 | |
FastGeneCompareSlurmBatch
Bases: SlurmBatch
A SlurmBatch that runs FastGeneCompareTask tasks on a Slurm cluster.
Source code in zipstrain/src/zipstrain/task_manager.py
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 | |
FastGeneCompareTask
Bases: Task
A Task that performs a gene comparison using zipstrain utilities single_compare_gene.
| Parameters: |
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 | |
FileInput
Bases: Input
This is used when the input is a file path. By default, the validate method checks for file existence.
Source code in zipstrain/src/zipstrain/task_manager.py
171 172 173 174 175 176 177 178 179 | |
get_value()
Returns the absolute path of the input file as a string.
Source code in zipstrain/src/zipstrain/task_manager.py
177 178 179 | |
FileOutput
Bases: Output
This is used when the output is a file path.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
ready()
Check if the expected output file exists.
Source code in zipstrain/src/zipstrain/task_manager.py
244 245 246 | |
register_task(task)
Registers the task that produces this output and sets the expected file path.
Args: task (Task): The task that produces this output.
Source code in zipstrain/src/zipstrain/task_manager.py
248 249 250 251 252 253 254 255 | |
GeneCompareRunner
Bases: Runner
Creates and schedules batches of FastGeneCompareTask tasks using either local or Slurm batches.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 | |
GeneCompareTaskGenerator
Bases: TaskGenerator
This TaskGenerator generates FastGeneCompareTask objects from a polars DataFrame. Each task compares two profiles using compare_genes functionality in zipstrain.compare module.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 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 | |
generate_tasks()
async
Yields lists of FastGeneCompareTask objects based on the data in batches of yield_size. This method yields the control back to the event loop while polars is collecting data to avoid blocking.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
get_total_tasks()
Returns total number of pairwise comparisons to be made.
Source code in zipstrain/src/zipstrain/task_manager.py
2167 2168 2169 | |
Input
Bases: ABC
Abstract base class for task inputs. DO NOT INSTANTIATE DIRECTLY. Most commonly used Input types are provided but if you want to define a new one, subclass this and implement validate() and get_value().
Source code in zipstrain/src/zipstrain/task_manager.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
IntInput
Bases: Input
This is used when the input is an integer.
Source code in zipstrain/src/zipstrain/task_manager.py
195 196 197 198 199 200 201 202 203 204 205 206 | |
get_value()
Returns the integer value as a string.
Source code in zipstrain/src/zipstrain/task_manager.py
202 203 204 205 206 | |
validate()
Validate that the input value is an integer.
Source code in zipstrain/src/zipstrain/task_manager.py
197 198 199 200 | |
IntOutput
Bases: Output
This is used when the output is an integer.
Source code in zipstrain/src/zipstrain/task_manager.py
290 291 292 293 294 295 296 297 298 299 | |
ready()
Check if the output value is an integer.
Source code in zipstrain/src/zipstrain/task_manager.py
292 293 294 295 296 297 298 299 | |
LocalBatch
Bases: Batch
Batch that runs tasks locally in a single shell script.
Source code in zipstrain/src/zipstrain/task_manager.py
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 962 963 964 965 966 967 968 969 | |
cancel()
async
Cancels the local batch by terminating the subprocess if it's running.
Source code in zipstrain/src/zipstrain/task_manager.py
960 961 962 963 964 965 966 967 968 969 | |
run()
async
This method runs all tasks in the batch locally by creating a shell script and executing it.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
Messages
Bases: StrEnum
Enumeration of common messages used in task and batch management.
Source code in zipstrain/src/zipstrain/task_manager.py
149 150 151 | |
Output
Bases: ABC
Abstract base class for task outputs. DO NOT INSTANTIATE DIRECTLY. Most commonly used Output types are provided but if you want to define a new one, subclass this and implement ready(). This method is used to check if the output is ready/valid after task completion.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
register_task(task)
Registers the task that produces this output. In most cases, you won't need to override this.
Args: task (Task): The task that produces this output.
Source code in zipstrain/src/zipstrain/task_manager.py
227 228 229 230 231 232 233 | |
PrepareCompareGenomeRunOutputs
Bases: Task
A Task that prepares the final output by merging all parquet files after all genome comparisons are done.
Source code in zipstrain/src/zipstrain/task_manager.py
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 | |
pre_run
property
Sets the task status to RUNNING and changes directory to the runner's run directory since this task may need to access multiple batch outputs.
PrepareGeneCompareRunOutputs
Bases: Task
A Task that prepares the final output by merging all gene comparison parquet files after all gene comparisons are done.
Source code in zipstrain/src/zipstrain/task_manager.py
2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 | |
pre_run
property
Sets the task status to RUNNING and changes directory to the runner's run directory since this task may need to access multiple batch outputs.
ProfileBamTask
Bases: Task
A Task that profiles a BAM file into the standard ZipStrain parquet outputs. The inputs to this task includes:
- bam-file: The input BAM file to be profiled.
- bed-file: The BED file specifying the regions to profile.
- sample-name: The name of the sample being processed.
- null-model: The null-model parquet file used for sequencing-error adjustment.
- gene-range-table: A BED file specifying the gene ranges for the sample.
- num-chunks: The number of BED chunks to create for processing.
- max-concurrency: The number of chunks that may run concurrently.
- genome-length-file: A file containing the lengths of the genomes in the reference fasta.
- stb-file: The STB file used for profiling.
| Parameters: |
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
ProfileRunner
Bases: Runner
Creates and schedules batches of ProfileBamTask tasks using either local or Slurm batches.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 1482 1483 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 | |
ProfileTaskGenerator
Bases: TaskGenerator
This TaskGenerator generates FastProfileTask objects from a polars DataFrame. Each task profiles a BAM file.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
generate_tasks()
async
Yeilds lists of FastProfileTask objects based on the data in batches of yield_size. This method yields the control back to the event loop while polars is collecting data to avoid blocking.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
get_total_tasks()
Returns total number of profiles to be generated.
Source code in zipstrain/src/zipstrain/task_manager.py
546 547 548 | |
Runner
Bases: ABC
Base Runner class to manage task generation, batching, and execution.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 1145 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 1231 1232 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 1363 1364 1365 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 | |
run()
async
Run the producer, batcher and worker coroutines and present a live UI while working. Runs the task generator to produce tasks, batches them using the batcher, and executes batches with up to [max_concurrent_batches] parallel workers. UI: displays an overall panel (produced/finished counts), active batch Progress bars, and system stats (CPU/RAM) using Rich Live to mirror the Runner presentation.
Source code in zipstrain/src/zipstrain/task_manager.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 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 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 | |
SlurmBatch
Bases: Batch
Batch that submits tasks to a Slurm job scheduler.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 1033 1034 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 | |
cancel()
async
Cancel a running or submitted Slurm job.
Source code in zipstrain/src/zipstrain/task_manager.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
run()
async
This method submits the batch to Slurm by creating a batch script and using sbatch command. It also monitors the job status until completion. This method is unavoidably different from LocalBatch.run() because of the nature of Slurm job submission.
Source code in zipstrain/src/zipstrain/task_manager.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 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 | |
SlurmConfig
Bases: BaseModel
Configuration model for Slurm batch jobs.
| Attributes: |
|
|---|
NOTE: Additional paramters for slurm should be provided in the additional_params dict in the form of {"param-name": "param-value"}, e.g., {"cpus-per-task": "4"} will result in the addition of "#SBATCH --cpus-per-task=4" to the sbatch script.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
from_json(json_path)
classmethod
Load SlurmConfig from a JSON file.
Source code in zipstrain/src/zipstrain/task_manager.py
101 102 103 104 105 106 107 | |
to_slurm_args()
Generates the slurm batch file header form the configuration object
Source code in zipstrain/src/zipstrain/task_manager.py
90 91 92 93 94 95 96 97 98 99 | |
validate_time(v)
Validate time format HH:MM:SS (H..HHH allowed).
Source code in zipstrain/src/zipstrain/task_manager.py
83 84 85 86 87 88 | |
Status
Bases: StrEnum
Enumeration of possible task and batch statuses.
Source code in zipstrain/src/zipstrain/task_manager.py
138 139 140 141 142 143 144 145 146 147 | |
StringInput
Bases: Input
This is used when the input is a string.
Source code in zipstrain/src/zipstrain/task_manager.py
182 183 184 185 186 187 188 189 190 191 192 | |
get_value()
Returns the string value.
Source code in zipstrain/src/zipstrain/task_manager.py
190 191 192 | |
validate()
Validate that the input value is a string.
Source code in zipstrain/src/zipstrain/task_manager.py
185 186 187 188 | |
StringOutput
Bases: Output
This is used when the output is a string.
Source code in zipstrain/src/zipstrain/task_manager.py
278 279 280 281 282 283 284 285 286 287 | |
ready()
Check if the output value is a string.
Source code in zipstrain/src/zipstrain/task_manager.py
280 281 282 283 284 285 286 287 | |
Task
Bases: ABC
Abstract base class for tasks. DO NOT INSTANTIATE DIRECTLY. Any new task type should subclass this
and implement the TEMPLATE_CMD class attribute. Inputs and expected outputs are specified using <>.
As an example, if a task has an input file called "input-file" and an expected output file called "output-file",
the TEMPLATE_CMD could be something like:
TEMPLATE_CMD = "some_command --input
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
batch_dir
property
Returns the batch directory path. Raises an error if the task is not associated with any batch yet.
command
property
Returns the command to be executed, wrapped with the engine if applicable.
post_run
property
Does the necessary steps after running the task command. This should not be overridden by subclasses unless a task needs special teardown like batch aggregation.
pre_run
property
Does the necessary setup before running the task command. This should not be overridden by subclasses unless a task needs special setup like batch aggregation.
status
property
Returns the current status of the task.
task_dir
property
Returns the task directory path.
get_status()
async
Asynchronously reads the task status from the .status file in the task directory.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
map_io()
Maps inputs and expected outputs to the command template. Note that when this method is called, all of the inputs and outputs in the TEMPLATE_CMD must be defined in the inputs and expected_outputs dictionaries. However, this method is not called by the user directly. It is called by the Batch when the task is added to a batch.
Source code in zipstrain/src/zipstrain/task_manager.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
TaskGenerator
Bases: ABC
Abstract base class for task generators. DO NOT INSTANTIATE DIRECTLY. A subclass of this class should provide an async generator method called generate_tasks() that yields lists of Task objects in an async manner. Some important concepts:
-
generate_tasks() is an async generator that yields lists of Task objects.
-
yield_size determines how many tasks are generated and yielded at a time.
-
get_total_tasks() returns the total number of tasks that can be generated.
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
get_cpu_usage()
Returns the current CPU usage percentage.
Source code in zipstrain/src/zipstrain/task_manager.py
1109 1110 1111 | |
get_memory_usage()
Returns the current memory usage percentage.
Source code in zipstrain/src/zipstrain/task_manager.py
1113 1114 1115 | |
lazy_run_compares(run_dir, container_engine, comps_db=None, tasks_per_batch=10, max_concurrent_batches=1, poll_interval=5.0, execution_mode='local', slurm_config=None, ani_method='popani', calculate='all', duckdb_memory_limit=None, duckdb_threads=None, compare_engine='polars')
A helper function to quickly set up and run a CompareRunner with given parameters.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
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 | |
lazy_run_gene_compares(run_dir, container_engine, comps_db=None, tasks_per_batch=10, max_concurrent_batches=1, poll_interval=5.0, execution_mode='local', slurm_config=None, ani_method='popani', duckdb_memory_limit=None, duckdb_threads=None, compare_engine='polars')
A helper function to quickly set up and run a GeneCompareRunner with given parameters.
| Parameters: |
|
|---|
Source code in zipstrain/src/zipstrain/task_manager.py
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 | |