API
Scheme
A class representing a primer scheme with headers and primer bed lines.
A Scheme contains both the header lines (comments) and the primer bed lines that define a complete primer scheme for amplicon sequencing or qPCR.
Please use Scheme.from_str() or Scheme.from_file() for creation.
Attributes:
| Name | Type | Description |
|---|---|---|
headers |
list[str]
|
List of header/comment lines from the bed file |
bedlines |
list[BedLine]
|
List of BedLine objects representing primers |
Source code in primalbedtools/scheme.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 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 | |
contains_probes
property
Check if the scheme contains any probe primers.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any bedlines are PROBE type primers, False otherwise. |
header_dict
property
Parse headers into a dictionary format.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary representation of the header lines, parsed according to common header formats used in bed files. |
__init__(headers, bedlines)
Initialize a Scheme with headers and bedlines.
Please use Scheme.from_str() or Scheme.from_file() for creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Optional[list[str]]
|
Optional list of header strings. If None, defaults to empty list. |
required |
bedlines
|
list[BedLine]
|
List of BedLine objects representing the primers in the scheme. |
required |
Source code in primalbedtools/scheme.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
from_file(file)
classmethod
Create a Scheme from a bed file on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the bed file to read. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scheme |
A new Scheme object loaded from the file. |
Source code in primalbedtools/scheme.py
77 78 79 80 81 82 83 84 85 86 87 88 | |
from_str(str)
classmethod
Create a Scheme from a bed file string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String containing bed file content with headers and primer lines. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scheme |
A new Scheme object parsed from the string. |
Source code in primalbedtools/scheme.py
64 65 66 67 68 69 70 71 72 73 74 75 | |
merge_primers()
merges bedlines with the same chrom, amplicon number and class in place
Source code in primalbedtools/scheme.py
116 117 118 | |
sort_bedlines()
Sort the bedlines in canonical order in place.
Sorts bedlines by chromosome, amplicon number, direction, and primer suffix to ensure consistent ordering across the scheme.
Source code in primalbedtools/scheme.py
108 109 110 111 112 113 114 | |
to_file(path)
Write the scheme to a bed file on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path where the bed file should be written. |
required |
Source code in primalbedtools/scheme.py
99 100 101 102 103 104 105 | |
to_str()
Convert the scheme to a bed file format string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String representation of the scheme in bed file format, including headers and all primer lines. |
Source code in primalbedtools/scheme.py
90 91 92 93 94 95 96 97 | |
update_primernames()
Updates PrimerNames into V2 format in place
Source code in primalbedtools/scheme.py
120 121 122 | |
to_delim_str(scheme, include_headers=True, use_header_aliases=False)
Turns a bedfile into a full expanded delim separated file
Source code in primalbedtools/scheme.py
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 | |
BedFileModifier
Collection of methods for modifying BED files.
This class provides static methods for common BED file operations such as updating primer names, sorting BED lines, and merging BED lines with the same characteristics.
Source code in primalbedtools/bedfiles.py
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 | |
downgrade_primernames(bedlines, merge_alts=False)
staticmethod
Downgrades primer names to v1 format in place.
Converts all primer names in the provided BedLine objects to the v1 format (prefix_number_class_ALT). Groups primers by chromosome and amplicon number, then updates each group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
A list of BedLine objects to downgrade. |
required |
Returns:
| Type | Description |
|---|---|
list[BedLine]
|
list[BedLine]: The updated list of BedLine objects with v1 format names. |
Source code in primalbedtools/bedfiles.py
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 | |
merge_primers(bedlines)
staticmethod
Merges bedlines with the same chrom, amplicon number and class.
Groups BedLine objects into primer pairs, then for each forward and reverse group, creates a merged BedLine with: - The earliest start position - The latest end position - The longest sequence - The amplicon prefix, number, and pool from the first BedLine
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
A list of BedLine objects to merge. |
required |
Returns:
| Type | Description |
|---|---|
list[BedLine]
|
list[BedLine]: A new list containing new merged BedLine objects. |
Examples:
>>> from primalbedtools.bedfiles import BedLine, BedFileModifier
>>> bedlines = [BedLine(...)] # List of BedLine objects
>>> merged_lines = BedFileModifier.merge_primers(bedlines)
Source code in primalbedtools/bedfiles.py
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 | |
sort_bedlines(bedlines)
staticmethod
Sorts the bedlines by chrom, amplicon number, class, and sequence.
Groups BedLine objects into primer pairs, sorts those pairs by chromosome and amplicon number, then returns a flattened list of the sorted BedLine objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
A list of BedLine objects to sort. |
required |
Returns:
| Type | Description |
|---|---|
list[BedLine]
|
list[BedLine]: A new list containing the sorted original BedLine objects. |
Examples:
>>> from primalbedtools.bedfiles import BedLine, BedFileModifier
>>> bedlines = [BedLine(...)] # List of BedLine objects
>>> sorted_lines = BedFileModifier.sort_bedlines(bedlines)
Source code in primalbedtools/bedfiles.py
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 | |
update_primernames(bedlines)
staticmethod
Updates primer names to v2 format in place.
Converts all primer names in the provided BedLine objects to the v2 format (prefix_number_class_index). Groups primers by chromosome and amplicon number, then updates each group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
A list of BedLine objects to update. |
required |
Returns:
| Type | Description |
|---|---|
list[BedLine]
|
list[BedLine]: The updated list of BedLine objects with v2 format names. |
Examples:
>>> from primalbedtools.bedfiles import BedLine, BedFileModifier
>>> bedlines = [BedLine(...)] # List of BedLine objects
>>> updated = BedFileModifier.update_primernames(bedlines)
Source code in primalbedtools/bedfiles.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 | |
BedLine
A class representing a single line in a primer.bed file.
BedLine stores and validates all attributes of a primer entry in a BED file, with support for primername version handling, position validation, and output formatting. It maintains internal consistency between related fields like strand and primer direction, and automatically parses complex primername formats.
Attributes:
| Name | Type | Description |
|---|---|---|
chrom |
str
|
Chromosome name, must match pattern [a-zA-Z0-9_.]+ |
start |
int
|
0-based start position of the primer |
end |
int
|
End position of the primer |
primername |
str
|
Name of the primer in either format v1 or v2 |
pool |
int
|
1-based pool number (use ipool for 0-based pool number) |
strand |
str
|
Strand of the primer ("+" for forward, "-" for reverse) |
sequence |
str
|
Sequence of the primer |
attributes |
(dict[str, str | float], None)
|
Dict of primer attributes (e.g., primerWeights (pw) for rebalancing). |
Properties
length (int): Length of the primer (end - start) amplicon_number (int): Amplicon number extracted from primername amplicon_prefix (str): Amplicon prefix extracted from primername primer_suffix (int, str, None): Suffix of the primer (integer index or alt string) primername_version (PrimerNameVersion): Version of the primername format ipool (int): 0-based pool number (pool - 1) direction_str (str): Direction as string ("LEFT" or "RIGHT")
Examples:
>>> from primalbedtools.bedfiles import BedLine
>>> bedline = BedLine(
... chrom="chr1",
... start=100,
... end=120,
... primername="scheme_1_LEFT_alt1",
... pool=1,
... strand="+",
... sequence="ACGTACGTACGTACGTACGT",
... )
>>> print(bedline.length)
20
>>> print(bedline.primername_version)
PrimerNameVersion.V1
>>> print(bedline.to_bed())
chr1 100 120 scheme_1_LEFT_alt1 1 + ACGTACGTACGTACGTACGT
>>> bedline.amplicon_prefix = "new-scheme"
>>> print(bedline.to_bed())
chr1 100 120 new-scheme_1_LEFT_alt1 1 + ACGTACGTACGTACGTACGT
Source code in primalbedtools/bedfiles.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
amplicon_name
property
Return the amplicon name of the primer
amplicon_number
property
writable
Return the amplicon number of the primer
amplicon_prefix
property
writable
Return the amplicon_prefix of the primer
attributes
property
writable
Returns the primer attributes
chrom
property
writable
Return the chromosome of the primer
direction_str
property
Return 'LEFT' or 'RIGHT' based on strand
ipool
property
Return the 0-based pool number
length
property
Return the length of the primer
pool
property
writable
Return the 1-based pool number of the primer
primer_class
property
writable
Return the PrimerDirection enum
primer_class_str
property
Return the string representation of PrimerDirection
primer_suffix
property
writable
Return the primer_suffix of the primer
primername
property
writable
Return the primername of the primer
sequence
property
writable
Return the sequence of the primer
start
property
writable
Return the start position of the primer
strand
property
writable
Return the strand of the primer
strand_class
property
Return the strand class of the primer
weight
property
writable
Return the weight of the primer from the attributes dict
force_change(primer_class, strand)
Updates compatible primerclass and strand simultaneously.
Source code in primalbedtools/bedfiles.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
to_bed()
Convert the BedLine object to a BED formatted string.
Source code in primalbedtools/bedfiles.py
726 727 728 729 730 731 732 733 734 735 | |
to_fasta(rc=False)
Convert the BedLine object to a FASTA formatted string.
Source code in primalbedtools/bedfiles.py
737 738 739 740 741 | |
BedLineParser
Collection of methods for BED file input/output operations.
This class provides static methods for parsing and writing BED files in various formats, handling both file system operations and string conversions.
Source code in primalbedtools/bedfiles.py
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 | |
from_file(bedfile)
staticmethod
Reads and parses a BED file from disk.
Reads a BED file from the specified path and returns the header lines and parsed BedLine objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedfile
|
Union[str, Path]
|
Path to the BED file. Can be a string or Path object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[list[str], list[BedLine]]
|
A tuple containing: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file doesn't exist |
ValueError
|
If the file contains invalid BED entries |
Examples:
>>> from primalbedtools.bedfiles import BedLineParser
>>> headers, bedlines = BedLineParser.from_file("primers.bed")
>>> print(f"Found {len(bedlines)} primer entries")
Source code in primalbedtools/bedfiles.py
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 | |
from_str(bedfile_str)
staticmethod
Parses a BED file from a string.
Parses a string containing BED file content and returns the header lines and parsed BedLine objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedfile_str
|
str
|
String containing BED file content. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[list[str], list[BedLine]]
|
A tuple containing: - list[str]: Header lines from the BED string (lines starting with '#') - list[BedLine]: Parsed BedLine objects from the string |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string contains invalid BED entries |
Source code in primalbedtools/bedfiles.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | |
to_file(bedfile, headers, bedlines)
staticmethod
Writes headers and BedLine objects to a BED file.
Creates or overwrites a BED file at the specified path with the provided headers and BedLine objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedfile
|
Union[str, Path]
|
Path where the BED file will be written. Can be a string or Path object. |
required |
headers
|
Optional[list[str]]
|
List of header strings (with or without leading '#') or None for no headers. |
required |
bedlines
|
list[BedLine]
|
List of BedLine objects to write to the file. |
required |
Raises:
| Type | Description |
|---|---|
IOError
|
If the file cannot be written |
Source code in primalbedtools/bedfiles.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | |
to_str(headers, bedlines)
staticmethod
Creates a BED file string from headers and BedLine objects.
Combines header lines and BedLine objects into a properly formatted BED file string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Optional[list[str]]
|
List of header strings (with or without leading '#') or None for no headers. |
required |
bedlines
|
list[BedLine]
|
List of BedLine objects to format as strings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A formatted BED file string with headers and entries. |
Examples:
>>> from primalbedtools.bedfiles import BedLine, BedLineParser
>>> bedlines = [BedLine(...)] # List of BedLine objects
>>> headers = ["Track name=primers"]
>>> bed_string = BedLineParser.to_str(headers, bedlines)
Source code in primalbedtools/bedfiles.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | |
bedline_from_str(bedline_str)
Create a list of BedLine objects from a BED string.
Source code in primalbedtools/bedfiles.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | |
check_amplicon_prefix(amplicon_prefix)
Check if an amplicon prefix is valid.
Source code in primalbedtools/bedfiles.py
65 66 67 68 69 | |
check_valid_class_and_strand(cls, strand)
This takes the PrimerClass str (LEFT|RIGHT|PROBE) and the strand str (+|-) and returns True is compatible.
Source code in primalbedtools/bedfiles.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
create_bedline(bedline)
Creates a BedLine object from a list of string values.
:param bedline: list[str] A list of string values representing a BED line. The list should contain the following elements: - chrom: str, the chromosome name - start: str, the start position (will be converted to int) - end: str, the end position (will be converted to int) - primername: str, the name of the primer - pool: str, the pool number (will be converted to int) - strand: str, the strand ('+' or '-') - sequence: str, the sequence of the primer
:return: BedLine A BedLine object created from the provided values.
:raises ValueError: If any of the values cannot be converted to the appropriate type. :raises IndexError: If the provided list does not contain the correct number of elements.
Source code in primalbedtools/bedfiles.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
create_primer_attributes_str(primer_attributes)
Parses the dict into the ';' separated str. Strips all whitespace
Returns None on empty dict or None
Source code in primalbedtools/bedfiles.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
create_primername(amplicon_prefix, amplicon_number, primer_class, primer_suffix)
Creates an unvalidated primername string.
Source code in primalbedtools/bedfiles.py
114 115 116 117 118 119 120 121 122 123 124 | |
downgrade_primernames(bedlines)
Downgrades primer names to v1 format in place.
Source code in primalbedtools/bedfiles.py
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 | |
expand_bedlines(bedlines)
Expands ambiguous bases in the primer sequences to all possible combinations.
Source code in primalbedtools/bedfiles.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 | |
group_amplicons(bedlines)
Groups all (including PROBES) BedLine objects into amplicons by chromosome and amplicon number.
This function takes a list of BedLine objects and groups them based on chromosome and amplicon number. For each amplicon number, it creates a dict containing the LEFT, PROBE, and RIGHT as the keys pointing to a list of corresponding Bedlines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
A list of BedLine objects to group into primer pairs. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, list[BedLine]]]
|
A list of dicts, with the key being the primer class string, and value a list of BedLines. |
Source code in primalbedtools/bedfiles.py
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | |
group_by_amplicon_number(list_bedlines)
Groups a list of BedLine objects by amplicon number.
Takes a list of BedLine objects and organizes them into a dictionary where keys are amplicon numbers and values are lists of BedLine objects with that amplicon number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_bedlines
|
list[BedLine]
|
A list of BedLine objects to group. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, list[BedLine]]
|
dict[int, list[BedLine]]: A dictionary mapping amplicon numbers (int) to lists of BedLine objects. |
Source code in primalbedtools/bedfiles.py
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |
group_by_chrom(list_bedlines)
Groups a list of BedLine objects by chromosome.
Takes a list of BedLine objects and organizes them into a dictionary where keys are chromosome names and values are lists of BedLine objects that belong to that chromosome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_bedlines
|
list[BedLine]
|
A list of BedLine objects to group. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[BedLine]]
|
dict[str, list[BedLine]]: A dictionary mapping chromosome names (str) to lists of BedLine objects. |
Source code in primalbedtools/bedfiles.py
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |
group_by_class(list_bedlines)
Groups a list of BedLine objects by primer class.
Takes a list of BedLine objects and organizes them into a dictionary where keys are class values and values are lists of BedLine objects in that class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_bedlines
|
list[BedLine]
|
A list of BedLine objects to group. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[BedLine]]
|
dict[str, list[BedLine]]: A dictionary mapping class values (str) to lists of BedLine objects. |
Source code in primalbedtools/bedfiles.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 | |
group_by_pool(list_bedlines)
Groups a list of BedLine objects by pool number.
Takes a list of BedLine objects and organizes them into a dictionary where keys are pool numbers and values are lists of BedLine objects with that pool number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_bedlines
|
list[BedLine]
|
A list of BedLine objects to group. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, list[BedLine]]
|
dict[int, list[BedLine]]: A dictionary mapping pool numbers (int) to lists of BedLine objects. |
Source code in primalbedtools/bedfiles.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
group_by_strand(list_bedlines)
Groups a list of BedLine objects by strand.
Takes a list of BedLine objects and organizes them into a dictionary where keys are strand values ("+" or "-") and values are lists of BedLine objects on that strand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_bedlines
|
list[BedLine]
|
A list of BedLine objects to group. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[BedLine]]
|
dict[str, list[BedLine]]: A dictionary mapping strand values (str) to lists of BedLine objects. |
Source code in primalbedtools/bedfiles.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 | |
group_primer_pairs(bedlines)
Groups Primer BedLine objects into primer pairs by chromosome and amplicon number.
This function takes a list of BedLine objects and groups them based on chromosome and amplicon number. For each group, it creates a tuple containing the forward (LEFT) primers as the first element and the reverse (RIGHT) primers as the second element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
A list of BedLine objects to group into primer pairs. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[list[BedLine], list[BedLine]]]
|
A list of tuples, where each tuple contains: (First element: List of forward (LEFT) primers, Second element: List of reverse (RIGHT) primers) |
Source code in primalbedtools/bedfiles.py
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 | |
lr_string_to_strand_char(s)
Convert a LEFT/RIGHT string to a Strand.
Source code in primalbedtools/bedfiles.py
186 187 188 189 190 191 192 193 194 195 196 197 | |
merge_primers(bedlines)
merges bedlines with the same chrom, amplicon number and class.
Source code in primalbedtools/bedfiles.py
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 | |
parse_headers_to_dict(headers)
parses the header strings into a dict. - Removes the leading # and any padding white space. - splits the header line on the first '=', with the key, value being the left, or right|None
Source code in primalbedtools/bedfiles.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
sort_bedlines(bedlines)
Sorts bedlines by chrom, start, end, primername.
Source code in primalbedtools/bedfiles.py
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 | |
update_primernames(bedlines)
Update primer names to v2 format in place.
Source code in primalbedtools/bedfiles.py
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 | |
validate_amplicon_prefix(amplicon_prefix)
Validates and returns the amplicon_prefix. Raises ValueError
Source code in primalbedtools/bedfiles.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
validate_primer_name(primername)
Validates the structure of the primer Name, and returns the unvalidated components. (Amplicon_prefix, Amplicon_number, Primer_class, Primer_suffix)
Source code in primalbedtools/bedfiles.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
validate_strand(strand)
Validates and returns the strand. Raises ValueError
Source code in primalbedtools/bedfiles.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
version_primername(primername)
Check the version of a primername.
Source code in primalbedtools/bedfiles.py
53 54 55 56 57 58 59 60 61 62 | |
Amplicon
A class representing a PCR amplicon with forward and reverse primers, and optional probes.
An Amplicon object encapsulates all primers (LEFT, RIGHT, and optional PROBE) that belong to the same amplicon number and pool. It provides methods to calculate amplicon boundaries, coverage regions, and validate that all primers are consistent.
Attributes:
| Name | Type | Description |
|---|---|---|
left |
list[BedLine]
|
List of LEFT primer BedLine objects |
right |
list[BedLine]
|
List of RIGHT primer BedLine objects |
probes |
list[BedLine]
|
List of PROBE primer BedLine objects |
chrom |
str
|
Chromosome name where the amplicon is located |
pool |
int
|
1-based pool number |
amplicon_number |
int
|
Amplicon number from primer names |
prefix |
str
|
Amplicon prefix from primer names |
Raises:
| Type | Description |
|---|---|
ValueError
|
If primers have inconsistent chromosome, pool, or amplicon numbers |
ValueError
|
If LEFT or RIGHT primers are missing |
Examples:
>>> from primalbedtools.bedfiles import BedLine
>>> left_primer = BedLine(chrom="chr1", start=100, end=120,
... primername="scheme_1_LEFT_1", pool=1,
... strand="+", sequence="ACGT")
>>> right_primer = BedLine(chrom="chr1", start=200, end=220,
... primername="scheme_1_RIGHT_1", pool=1,
... strand="-", sequence="ACGT")
>>> amplicon = Amplicon(left=[left_primer], right=[right_primer])
>>> print(amplicon.amplicon_name)
scheme_1
>>> print(amplicon.amplicon_start, amplicon.amplicon_end)
100 220
Source code in primalbedtools/amplicons.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 | |
amplicon_end
property
Get the end position of the amplicon (latest RIGHT primer end).
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The largest end position among all RIGHT primers |
amplicon_name
property
Get the name of the amplicon.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Amplicon name in format "prefix_number" |
amplicon_start
property
Get the start position of the amplicon (earliest LEFT primer start).
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The smallest start position among all LEFT primers |
coverage_end
property
Get the end of the coverage region (earliest RIGHT primer start).
This represents the last base that would be covered after primer trimming.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The smallest start position among all RIGHT primers |
coverage_start
property
Get the start of the coverage region (latest LEFT primer end).
This represents the first base that would be covered after primer trimming.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The largest end position among all LEFT primers |
ipool
property
Get the 0-based pool number.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Pool number converted from 1-based to 0-based indexing |
is_circular
property
Check if the amplicon appears to be circular (LEFT primer end > RIGHT primer start).
This can indicate a circular genome where the amplicon spans the origin.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any LEFT primer end is greater than any RIGHT primer start |
left_region
property
Get the genomic region covered by LEFT primers.
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
tuple[int, int]: Half-open interval (start, end) of LEFT primer region |
probe_region
property
Get the genomic region covered by PROBE primers.
Returns:
| Type | Description |
|---|---|
Optional[tuple[int, int]]
|
Optional[tuple[int, int]]: Half-open interval (start, end) of PROBE region, or None if no probes are present |
right_region
property
Get the genomic region covered by RIGHT primers.
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
tuple[int, int]: Half-open interval (start, end) of RIGHT primer region |
__hash__()
Hash is based off the self.to_amplicon_str()
Source code in primalbedtools/amplicons.py
168 169 170 | |
__init__(left, right, probes=None)
Initialize an Amplicon with LEFT and RIGHT primers, and optional PROBE primers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
list[BedLine]
|
List of BedLine objects representing LEFT primers |
required |
right
|
list[BedLine]
|
List of BedLine objects representing RIGHT primers |
required |
probes
|
Optional[list[BedLine]]
|
Optional list of BedLine objects representing PROBE primers |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If primers have inconsistent chromosome, pool, or amplicon numbers |
ValueError
|
If LEFT or RIGHT primers are missing |
Source code in primalbedtools/amplicons.py
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 | |
to_amplicon_str()
Convert the amplicon to a BED format string representing the full amplicon.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Tab-delimited string with chrom, amplicon_start, amplicon_end, amplicon_name, and pool |
Source code in primalbedtools/amplicons.py
271 272 273 274 275 276 277 278 | |
to_primertrim_str()
Convert the amplicon to a BED format string representing the coverage region.
This represents the region that would remain after primer trimming.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Tab-delimited string with chrom, coverage_start, coverage_end, amplicon_name, and pool |
Source code in primalbedtools/amplicons.py
280 281 282 283 284 285 286 287 288 289 | |
create_amplicons(bedlines)
Group BedLine objects into Amplicon objects by chromosome, amplicon number, and pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bedlines
|
list[BedLine]
|
List of BedLine objects to group into amplicons |
required |
Returns:
| Type | Description |
|---|---|
list[Amplicon]
|
list[Amplicon]: List of Amplicon objects created from the input bedlines |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any amplicon is missing LEFT or RIGHT primers |
ValueError
|
If primers within an amplicon have inconsistent attributes |
Examples:
>>> from primalbedtools.bedfiles import BedLineParser
>>> headers, bedlines = BedLineParser.from_file("primers.bed")
>>> amplicons = create_amplicons(bedlines)
>>> print(f"Created {len(amplicons)} amplicons")
Source code in primalbedtools/amplicons.py
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 | |
do_pp_ol(pp1, pp2)
Check if two amplicons have overlapping genomic regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pp1
|
Amplicon
|
First amplicon to compare |
required |
pp2
|
Amplicon
|
Second amplicon to compare |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the amplicons have any overlapping genomic coordinates |
Examples:
>>> amplicon1 = Amplicon(left=[...], right=[...]) # Covers 100-200
>>> amplicon2 = Amplicon(left=[...], right=[...]) # Covers 150-250
>>> do_pp_ol(amplicon1, amplicon2)
True
Source code in primalbedtools/amplicons.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |