serogen.loci¶
Biosynthetic locus archetypes, exact All-Contiguous-Partitions Dynamic Programming (ACP-DP) locus segmentation, cross-contig boundary stitching, and bipartite reference serotype matching.
High-Level Locus Prediction (serogen.loci.predictor)¶
predictor
¶
End-to-end biosynthetic locus prediction pipeline (LocusPredictor / LocusFinder).
Classes:
| Name | Description |
|---|---|
LocusPredictor |
High-level biosynthetic gene cluster (BGC) discovery and segmentation pipeline. |
LocusPredictor
¶
High-level biosynthetic gene cluster (BGC) discovery and segmentation pipeline.
Orchestrates:
1. Open Reading Frame (ORF) prediction via OrfPredictor,
2. Protein sequence functional role classification via GeneRoleClassifier, and
3. Archetype-constrained chromosomal segmentation via LocusSegmenter.
Methods:
| Name | Description |
|---|---|
predict_role_probabilities |
Predict full |
predict |
Discover, classify, and segment biosynthetic |
Attributes:
| Name | Type | Description |
|---|---|---|
archetype_classifier |
ArchetypeClassifier
|
Return the underlying |
Source code in src/serogen/loci/predictor.py
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 | |
archetype_classifier
property
¶
archetype_classifier: ArchetypeClassifier
Return the underlying ArchetypeClassifier used by self.segmenter.
predict_role_probabilities
¶
predict_role_probabilities(genes: Genes) -> ndarray[tuple[int, int], dtype[float64]]
Predict full (N, 30) GeneRole probability distributions (including UNKNOWN) for genes.
Source code in src/serogen/loci/predictor.py
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 | |
predict
¶
predict(target: bytes | str | Sequence | Sequences | GenomeAssembly | Genes, *, categories: ArchetypeCategory | str | Iterable[ArchetypeCategory | str] | None = None, archetypes: LocusArchetype | str | int | Iterable[LocusArchetype | str | int] | None = None, min_completeness: float = 0.0, min_score: float = 0.0, max_frameshift_fraction: float = 1.0, only_intact: bool = False, heal_mobile_elements: bool = False) -> Loci
Discover, classify, and segment biosynthetic Loci from genomic sequences or Genes.
Source code in src/serogen/loci/predictor.py
ACP-DP Locus Segmentation (serogen.loci.segmenter)¶
segmenter
¶
Archetype-Constrained Exact Partitioning Dynamic Programming (ACP-DP) locus segmenter.
Classes:
| Name | Description |
|---|---|
LocusSegmenter |
Archetype-Constrained Exact Partitioning Dynamic Programming (ACP-DP) locus segmenter. |
LocusSegmenter
¶
Archetype-Constrained Exact Partitioning Dynamic Programming (ACP-DP) locus segmenter.
Segments chromosomal Genes and their GeneRole probability
distributions (or discrete role labels) into non-overlapping Loci,
disambiguating tandem loci (e.g., adjacent K-locus and O-locus in Klebsiella / E. coli),
bridging internal unannotated (UNKNOWN) and mobile element (TRANSPOSASE/INTEGRASE) gaps,
and stitching loci split across contig boundaries in fragmented assemblies.
Methods:
| Name | Description |
|---|---|
segment |
Source code in src/serogen/loci/segmenter.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 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 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 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 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 | |
segment
¶
segment(genes: Genes, role_probs: ndarray | Sequence[int | GeneRole], *, clusters: Sequence[int] | ndarray | None = None) -> Loci
Segment a Genes container and role predictions into Loci.
Source code in src/serogen/loci/segmenter.py
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 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 | |
Locus & Graph Models (serogen.loci.models)¶
models
¶
Data models for biosynthetic gene clusters (Locus, Loci) and syntenic graph primitives.
Classes:
| Name | Description |
|---|---|
IntergenicOrientation |
Relative transcriptional orientation between two adjacent genes in a locus. |
IntergenicType |
32-bit integer encoding for an intergenic synteny transition between adjacent genes. |
IntergenicEdge |
Directed synteny edge connecting adjacent gene nodes |
GeneNode |
32-bit integer encoding for a gene node inside a biosynthetic locus graph. |
Locus |
Scalar view and directed syntenic graph of a single biosynthetic gene cluster. |
Loci |
Structure-of-Arrays (SoA) batch container for biosynthetic gene clusters ( |
IntergenicOrientation
¶
Bases: IntEnum
Relative transcriptional orientation between two adjacent genes in a locus.
Source code in src/serogen/loci/models.py
IntergenicType
¶
Bases: IntNode
32-bit integer encoding for an intergenic synteny transition between adjacent genes.
Bit 0..1 (2 bits): Relative transcriptional orientation (IntergenicOrientation, 0..2).
Bit 2..5 (4 bits): Discretized intergenic distance bin (0 = overlap, 1 = <50bp, 2 = 50..200bp,
3 = >200bp, 15 = healed MGE scar).
Bit 31 (1 bit): TAG_EDGE (1 = intermediate edge node in bipartite graphs).
Methods:
| Name | Description |
|---|---|
from_adjacent |
Construct an |
Attributes:
| Name | Type | Description |
|---|---|---|
orientation |
IntergenicOrientation
|
Relative transcriptional orientation between source and target genes. |
gap_bin |
int
|
Discretized intergenic distance bin ( |
is_contig_break |
bool
|
True if this edge bridges a contig boundary in a fragmented assembly. |
is_healed_scar |
bool
|
True if this edge bridges a healed mobile genetic element (MGE) insertion. |
Source code in src/serogen/loci/models.py
orientation
property
¶
orientation: IntergenicOrientation
Relative transcriptional orientation between source and target genes.
is_contig_break
property
¶
True if this edge bridges a contig boundary in a fragmented assembly.
is_healed_scar
property
¶
True if this edge bridges a healed mobile genetic element (MGE) insertion.
from_adjacent
classmethod
¶
Construct an IntergenicType from adjacent gene strands and base-pair distance.
Source code in src/serogen/loci/models.py
IntergenicEdge
dataclass
¶
Bases: DirectedEdge
Directed synteny edge connecting adjacent gene nodes (source -> target) in a Locus.
Source code in src/serogen/loci/models.py
GeneNode
¶
Bases: IntNode
32-bit integer encoding for a gene node inside a biosynthetic locus graph.
Bit 0..4 (5 bits): Canonical GeneRole index (0..29).
Bit 5 (1 bit): Frameshift / pseudogene indicator (0 = intact, 1 = frameshifted).
Bit 6..30 (25 bits): Sequence homology cluster ID (0 = unclustered, 1..33,554,431 = cluster ID).
Bit 31 (1 bit): TAG_EDGE (0 = primary gene node).
Methods:
| Name | Description |
|---|---|
with_cluster |
Return a copy of this |
Attributes:
| Name | Type | Description |
|---|---|---|
role_idx |
int
|
Integer |
role |
GeneRole
|
Canonical |
is_frameshift |
bool
|
True if this gene contains a frameshift indel or premature stop. |
cluster_id |
int
|
Sequence homology cluster ID ( |
is_clustered |
bool
|
True if assigned to a homology cluster ( |
is_mobile_element |
bool
|
True if this node is a mobile genetic element ( |
is_biosynthetic |
bool
|
True if this node is an active biosynthetic, modifier, or transport gene. |
Source code in src/serogen/loci/models.py
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 | |
is_frameshift
property
¶
True if this gene contains a frameshift indel or premature stop.
is_mobile_element
property
¶
True if this node is a mobile genetic element (TRANSPOSASE or INTEGRASE).
is_biosynthetic
property
¶
True if this node is an active biosynthetic, modifier, or transport gene.
Locus
dataclass
¶
Bases: GraphModel
Scalar view and directed syntenic graph of a single biosynthetic gene cluster.
Embeds its constituent Genes container (self.genes),
deriving per-gene intervals, strands, lengths, coding sequences, and frameshifts directly
without duplicating metadata across parallel tuples.
Methods:
| Name | Description |
|---|---|
with_name |
Return a copy of this |
canonicalize_strand |
Orient the locus into canonical 5' -> 3' operon order ( |
heal_mobile_elements |
Excise mobile genetic element ( |
from_genes |
Construct a |
match |
Compare this |
Attributes:
| Name | Type | Description |
|---|---|---|
num_genes |
int
|
Number of genes in this locus. |
start |
int
|
0-based inclusive start coordinate on the parent contig. |
end |
int
|
0-based exclusive end coordinate on the parent contig. |
strand |
int
|
Dominant transcriptional strand ( |
strands |
ndarray[tuple[int], dtype[int8]]
|
1D |
lengths |
ndarray[tuple[int], dtype[int32]]
|
1D |
roles |
ndarray[tuple[int], dtype[int32]]
|
1D array of integer |
cluster_ids |
ndarray[tuple[int], dtype[int32]]
|
1D array of homology |
frameshifts |
ndarray[tuple[int], dtype[bool_]]
|
1D boolean array indicating which genes carry frameshift mutations. |
role_mask |
int
|
32-bit integer presence bitmask of all |
has_mobile_elements |
bool
|
True if this locus contains any |
has_mge |
bool
|
Alias for |
is_fragmented |
bool
|
True if this locus spans multiple contigs across an assembly break. |
num_frameshifts |
int
|
Number of genes in this locus carrying frameshift mutations or premature stops. |
frameshift_fraction |
float
|
Fraction of genes in this locus ( |
is_intact |
bool
|
True if this locus is on a single contig, has no mobile elements, and has no frameshifted genes. |
category |
ArchetypeCategory
|
High-level |
num_contigs |
int
|
Number of distinct contigs spanned by this locus. |
Source code in src/serogen/loci/models.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
strands
property
¶
1D int8 array of per-gene transcriptional strands from self.genes.
lengths
property
¶
1D int32 array of per-gene base-pair lengths from self.genes.
roles
property
¶
1D array of integer GeneRole indices (0..29) for each gene in the locus.
cluster_ids
property
¶
1D array of homology cluster_id values for each gene in the locus.
frameshifts
property
¶
1D boolean array indicating which genes carry frameshift mutations.
role_mask
property
¶
32-bit integer presence bitmask of all GeneRoles present in this locus.
has_mobile_elements
property
¶
True if this locus contains any TRANSPOSASE or INTEGRASE insertions.
is_fragmented
property
¶
True if this locus spans multiple contigs across an assembly break.
num_frameshifts
property
¶
Number of genes in this locus carrying frameshift mutations or premature stops.
frameshift_fraction
property
¶
Fraction of genes in this locus ([0.0, 1.0]) carrying frameshift mutations.
is_intact
property
¶
True if this locus is on a single contig, has no mobile elements, and has no frameshifted genes.
category
property
¶
category: ArchetypeCategory
High-level ArchetypeCategory (Capsule, O-Antigen, Exopolysaccharide, Other) of this locus.
with_name
¶
with_name(name: str | bytes) -> Locus
Return a copy of this Locus with an updated identifier name.
Source code in src/serogen/loci/models.py
canonicalize_strand
¶
canonicalize_strand() -> Locus
Orient the locus into canonical 5' -> 3' operon order (strand = +1).
If self.strand >= 0, returns self unchanged. If self.strand < 0, reverses
nodes and genes and re-indexes edges so that directed synteny transitions
run 5' -> 3' along the dominant transcriptional strand.
Source code in src/serogen/loci/models.py
heal_mobile_elements
¶
heal_mobile_elements(remove_nodes: bool = True) -> Locus
Excise mobile genetic element (TRANSPOSASE, INTEGRASE) insertions and heal synteny edges.
Source code in src/serogen/loci/models.py
from_genes
classmethod
¶
from_genes(genes: Genes | Sequence[str | bytes | int | GeneRole] | ndarray, roles: Sequence[str | bytes | int | GeneRole] | ndarray | None = None, *, strands: Sequence[int] | ndarray | None = None, lengths: Sequence[int] | ndarray | None = None, clusters: Sequence[int] | ndarray | None = None, frameshifts: Sequence[bool] | ndarray | None = None, archetype: LocusArchetype = UNKNOWN, completeness: float = 0.0, score: float = 0.0, is_tandem_split: bool = False, contig_index: int = 0, name: str = '') -> Self
Construct a Locus from either a Genes container or a sequence of gene symbols/roles.
Source code in src/serogen/loci/models.py
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 | |
match
¶
Compare this Locus against a target Locus (returns Match) or target Loci database (returns Matches).
Source code in src/serogen/loci/models.py
Loci
dataclass
¶
Bases: GraphBatch[Locus, 'Loci']
Structure-of-Arrays (SoA) batch container for biosynthetic gene clusters (Locus).
Combines GraphBatch sparse topology arrays (node_types, node_offsets, edge_sources,
edge_targets, edge_types, edge_offsets) with a flat Genes
container (self.genes, indexed per locus by node_offsets) and per-locus archetype metadata.
Methods:
| Name | Description |
|---|---|
with_names |
Return a new |
best |
Return the highest-scoring |
filter |
Filter loci by |
empty |
Create an empty 0-length |
concat |
Concatenate multiple |
from_list |
Compile a sequence of scalar |
canonicalize_strands |
Orient all loci in the batch into canonical 5' -> 3' operon order ( |
heal_mobile_elements |
Excise mobile genetic element ( |
with_clusters |
Return a new |
cluster_genes |
Cluster translated locus proteins and return a new |
as_pan_graph |
Compress the |
match |
Compare one or more |
Attributes:
| Name | Type | Description |
|---|---|---|
roles |
ndarray[tuple[int], dtype[int32]]
|
Flat 1D array of |
cluster_ids |
ndarray[tuple[int], dtype[int32]]
|
Flat 1D array of homology |
is_fragmented |
ndarray[tuple[int], dtype[bool_]]
|
1D boolean array ( |
num_frameshifts |
ndarray[tuple[int], dtype[int32]]
|
1D |
frameshift_fractions |
ndarray[tuple[int], dtype[float32]]
|
1D |
has_mge |
ndarray[tuple[int], dtype[bool_]]
|
1D boolean array ( |
is_intact |
ndarray[tuple[int], dtype[bool_]]
|
1D boolean array ( |
categories |
ndarray[tuple[int], dtype[str_]]
|
1D string array ( |
Source code in src/serogen/loci/models.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 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 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 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 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 | |
roles
property
¶
Flat 1D array of GeneRole indices (0..29) across all gene nodes in the batch.
cluster_ids
property
¶
Flat 1D array of homology cluster_id values across all gene nodes in the batch.
is_fragmented
property
¶
1D boolean array ((N,)) indicating whether each locus spans a contig break (gap_bin == 14).
num_frameshifts
property
¶
1D int32 array ((N,)) of frameshifted gene counts per locus.
frameshift_fractions
property
¶
1D float32 array ((N,)) of frameshifted gene fractions ([0.0, 1.0]) per locus.
has_mge
property
¶
1D boolean array ((N,)) indicating whether each locus contains TRANSPOSASE or INTEGRASE insertions.
is_intact
property
¶
1D boolean array ((N,)) indicating whether each locus is single-contig, MGE-free, and frameshift-free.
categories
property
¶
1D string array ((N,)) of ArchetypeCategory values ('Capsule', 'O-Antigen', etc.) per locus.
with_names
¶
Return a new Loci batch with updated per-locus identifier names.
Source code in src/serogen/loci/models.py
best
¶
best(*, prefer_intact: bool = False) -> Locus | None
Return the highest-scoring Locus in the batch (or None if empty).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefer_intact
|
bool
|
If True, prioritize intact loci without frameshifts or assembly breaks
(e.g., an intact ectopic |
False
|
Source code in src/serogen/loci/models.py
filter
¶
filter(*, names: str | Iterable[str] | None = None, categories: ArchetypeCategory | str | Iterable[ArchetypeCategory | str] | None = None, archetypes: LocusArchetype | str | int | Iterable[LocusArchetype | str | int] | None = None, min_completeness: float = 0.0, min_score: float = 0.0, max_frameshift_fraction: float = 1.0, only_intact: bool = False) -> Self
Filter loci by names, ontology categories, specific archetypes, min_completeness, min_score, max_frameshift_fraction, and/or only_intact.
Source code in src/serogen/loci/models.py
empty
classmethod
¶
Create an empty 0-length Loci container.
Source code in src/serogen/loci/models.py
concat
classmethod
¶
Concatenate multiple Loci batches into a single contiguous Loci container.
Source code in src/serogen/loci/models.py
from_list
classmethod
¶
from_list(loci: Sequence[Locus]) -> Self
Compile a sequence of scalar Locus objects into a contiguous Loci batch.
Source code in src/serogen/loci/models.py
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 970 971 972 973 974 975 976 977 | |
canonicalize_strands
¶
Orient all loci in the batch into canonical 5' -> 3' operon order (strand = +1).
Source code in src/serogen/loci/models.py
heal_mobile_elements
¶
Excise mobile genetic element (TRANSPOSASE, INTEGRASE) insertions across all loci in the batch.
Source code in src/serogen/loci/models.py
with_clusters
¶
with_clusters(clusters: Clusters | ndarray) -> Self
Return a new Loci batch with homology cluster_id bitfields updated from Clusters or an ID array.
Source code in src/serogen/loci/models.py
cluster_genes
¶
cluster_genes(clusterer: Clusterer | None = None, *, by_role: bool = True, classifier: Any | None = None, embedding_layer: str = 'task_weighted_conv_max', **kwargs: Any) -> Self
Cluster translated locus proteins and return a new Loci batch with packed homology CLUSTER_IDs.
Source code in src/serogen/loci/models.py
as_pan_graph
¶
as_pan_graph(node_mask: int | None = None, *, canonicalize_strands: bool = True, heal_mges: bool = False, cluster_genes: bool = False, clusterer: Clusterer | None = None) -> tuple[csr_array, ndarray[tuple[int], dtype[uint32]], ndarray[tuple[int], dtype[uint32]]]
Compress the Loci batch into a directed consensus pan-locus graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_mask
|
int | None
|
Optional bitmask to apply to |
None
|
canonicalize_strands
|
bool
|
If True (default), orient |
True
|
heal_mges
|
bool
|
If True, excise |
False
|
cluster_genes
|
bool
|
If True (or if |
False
|
clusterer
|
Clusterer | None
|
Optional pre-configured |
None
|
Returns:
| Type | Description |
|---|---|
tuple[csr_array, ndarray[tuple[int], dtype[uint32]], ndarray[tuple[int], dtype[uint32]]]
|
A tuple of |
Source code in src/serogen/loci/models.py
match
¶
match(query: Locus | Loci, *, top_k: int | None = None, min_score: float = 0.0, sort: bool = True, **matcher_kwargs: Any) -> Any
Compare one or more query loci against this Loci batch acting as a reference database.
Source code in src/serogen/loci/models.py
Biosynthetic Archetypes (serogen.loci.archetypes)¶
archetypes
¶
Biosynthetic locus archetypes, ontology categories, and structural specifications.
Classes:
| Name | Description |
|---|---|
ArchetypeCategory |
High-level structural category of a polysaccharide biosynthetic locus archetype. |
ArchetypeSpec |
Immutable biological specification for a canonical |
LocusArchetype |
Canonical biosynthetic locus archetypes (0..10). |
ArchetypeTensors |
Immutable container holding precomputed bitmask and role-indicator tensors for all |
Functions:
| Name | Description |
|---|---|
roles_to_mask |
Pack a collection of |
mask_to_roles |
Unpack a 32-bit integer presence bitmask into a sorted tuple of |
get_archetype_tensors |
Return the cached singleton |
ArchetypeCategory
¶
Bases: StrEnum
High-level structural category of a polysaccharide biosynthetic locus archetype.
Source code in src/serogen/loci/archetypes.py
ArchetypeSpec
dataclass
¶
Immutable biological specification for a canonical LocusArchetype.
Attributes:
| Name | Type | Description |
|---|---|---|
required_mask |
int
|
Combined 32-bit union mask of all roles participating in any required module. |
all_relevant_mask |
int
|
Combined 32-bit bitmask of all required and optional cargo roles. |
num_modules |
int
|
Number of required functional modules ( |
Source code in src/serogen/loci/archetypes.py
LocusArchetype
¶
Bases: IntEnum
Canonical biosynthetic locus archetypes (0..10).
Defines the ontological classification and structural requirements of bacterial
surface polysaccharide biosynthetic gene clusters. Scoring, completeness evaluation,
and segment classification are encapsulated in ArchetypeClassifier.
Methods:
| Name | Description |
|---|---|
from_name |
Resolve an archetype by integer ID, enum name, or biological alias. |
resolve |
Resolve an archetype identifier, falling back to |
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
ArchetypeSpec
|
Return the |
category |
ArchetypeCategory
|
High-level |
forbidden_mask |
int
|
32-bit bitmask of |
cargo_mask |
int
|
32-bit bitmask of optional cargo/modifier/precursor |
required_mask |
int
|
Combined 32-bit union mask of all roles participating in any required module. |
all_relevant_mask |
int
|
Combined 32-bit bitmask of all required and optional cargo roles. |
description |
str
|
Human-readable biological description of the pathway. |
module_masks |
tuple[int, ...]
|
Tuple of 32-bit disjunctive module bitmasks ( |
num_modules |
int
|
Number of required functional modules ( |
Source code in src/serogen/loci/archetypes.py
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 | |
category
property
¶
category: ArchetypeCategory
High-level ArchetypeCategory (Capsule, O-Antigen, Exopolysaccharide, Other).
forbidden_mask
property
¶
32-bit bitmask of GeneRole bits that are incompatible with this archetype.
cargo_mask
property
¶
32-bit bitmask of optional cargo/modifier/precursor GeneRole bits.
required_mask
property
¶
Combined 32-bit union mask of all roles participating in any required module.
all_relevant_mask
property
¶
Combined 32-bit bitmask of all required and optional cargo roles.
module_masks
property
¶
Tuple of 32-bit disjunctive module bitmasks (M_1, ..., M_k) required for completeness.
num_modules
property
¶
Number of required functional modules (M_A) for this archetype.
from_name
classmethod
¶
from_name(key: str | bytes | int | LocusArchetype) -> LocusArchetype
Resolve an archetype by integer ID, enum name, or biological alias.
Source code in src/serogen/loci/archetypes.py
resolve
classmethod
¶
resolve(key: str | bytes | int | LocusArchetype, default: LocusArchetype | None = None) -> LocusArchetype
Resolve an archetype identifier, falling back to default (or UNKNOWN).
Source code in src/serogen/loci/archetypes.py
ArchetypeTensors
dataclass
¶
Immutable container holding precomputed bitmask and role-indicator tensors for all LocusArchetypes.
Encapsulates the vectorized lookup tables required by ArchetypeClassifier
and LocusSegmenter.
Methods:
| Name | Description |
|---|---|
build |
Construct and freeze all archetype bitmask and indicator tensors from |
Source code in src/serogen/loci/archetypes.py
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 | |
build
classmethod
¶
Construct and freeze all archetype bitmask and indicator tensors from LocusArchetype specs.
Source code in src/serogen/loci/archetypes.py
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 | |
roles_to_mask
¶
roles_to_mask(roles: Iterable[int | GeneRole] | ndarray) -> int
Pack a collection of GeneRole values into a 32-bit integer presence bitmask.
Source code in src/serogen/loci/archetypes.py
mask_to_roles
¶
mask_to_roles(mask: int) -> tuple[GeneRole, ...]
Unpack a 32-bit integer presence bitmask into a sorted tuple of GeneRole enums.
get_archetype_tensors
cached
¶
get_archetype_tensors() -> ArchetypeTensors
Archetype Classification (serogen.loci.classifier)¶
classifier
¶
Probabilistic and bitmask-based classifier for biosynthetic locus archetypes.
Classes:
| Name | Description |
|---|---|
ArchetypeClassifier |
Scikit-learn compatible classifier and segment scorer for |
ArchetypeClassifier
¶
Scikit-learn compatible classifier and segment scorer for LocusArchetypes.
Encapsulates all discrete bitmask evaluations and continuous noisy-OR log-likelihood-ratio
(LLR) scoring over ArchetypeTensors. Works out-of-the-box
with domain-calibrated weights (w_comp, w_incomp, w_llr, unknown_logit), and optionally
supports empirical weight calibration via .fit(X, y) on labeled loci.
Methods:
| Name | Description |
|---|---|
check_modules |
Count how many required functional modules are satisfied for each archetype ( |
check_forbidden |
Return a boolean array |
is_complete |
Evaluate whether a 32-bit role presence mask satisfies each archetype. |
classify_mask |
Classify a single 32-bit role presence mask into its best-matching |
is_boundary_relevant |
Return True if |
to_probability_matrix |
Convert 1D discrete role indices or a 2D probability matrix into a clean |
precompute_prefixes |
Precompute \(O(L)\) prefix sums of log-complement and log-odds probabilities across a contig. |
score_segments |
Evaluate completeness, incompatibility, and LLR scores for \(K\) candidate segments in \(O(K \cdot |\mathcal{A}|)\). |
score_components |
Compute |
decision_function |
Compute unnormalized archetype logits of shape |
predict_proba |
Compute calibrated softmax posterior probabilities |
predict |
Predict the integer |
classify |
Classify a single |
fit |
Calibrate |
score |
Compute classification accuracy on labeled segments |
Attributes:
| Name | Type | Description |
|---|---|---|
classes_ |
ndarray[tuple[int], dtype[int32]]
|
1D array of archetype class labels ( |
active_weights |
tuple[float, float, float, float]
|
Return |
Source code in src/serogen/loci/classifier.py
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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
classes_
property
¶
1D array of archetype class labels (0..10).
active_weights
property
¶
Return (w_comp, w_incomp, w_llr, unknown_logit), preferring fitted parameters if present.
check_modules
¶
Count how many required functional modules are satisfied for each archetype ((11,)).
Source code in src/serogen/loci/classifier.py
check_forbidden
¶
Return a boolean array (11,) indicating whether any forbidden role is present.
is_complete
¶
Evaluate whether a 32-bit role presence mask satisfies each archetype.
Source code in src/serogen/loci/classifier.py
classify_mask
¶
classify_mask(mask: int, min_completeness: float | None = None) -> tuple[LocusArchetype, float]
Classify a single 32-bit role presence mask into its best-matching LocusArchetype.
Source code in src/serogen/loci/classifier.py
is_boundary_relevant
¶
is_boundary_relevant(archetype: LocusArchetype | int, role: GeneRole | int) -> bool
Return True if role is a valid boundary/anchor/cargo gene for archetype (excluding MGEs/UNKNOWN).
Source code in src/serogen/loci/classifier.py
to_probability_matrix
staticmethod
¶
to_probability_matrix(roles_or_probs: ndarray | Sequence[int | GeneRole], confidence: float = 0.98) -> ndarray[tuple[int, int], dtype[float64]]
Convert 1D discrete role indices or a 2D probability matrix into a clean (L, 30) float64 matrix.
Source code in src/serogen/loci/classifier.py
precompute_prefixes
¶
precompute_prefixes(probs: ndarray[tuple[int, int], dtype[float64]]) -> tuple[ndarray[tuple[int, int, int], dtype[float64]], ndarray[tuple[int, int], dtype[float64]], ndarray[tuple[int, int], dtype[float64]]]
Precompute \(O(L)\) prefix sums of log-complement and log-odds probabilities across a contig.
Source code in src/serogen/loci/classifier.py
score_segments
¶
score_segments(starts: ndarray[tuple[int], dtype[intp]], ends: ndarray[tuple[int], dtype[intp]], *, probs: ndarray[tuple[int, int], dtype[float64]] | None = None, prefixes: tuple[ndarray, ndarray, ndarray] | None = None) -> tuple[ndarray[tuple[int, int], dtype[float64]], ndarray[tuple[int, int], dtype[float64]], ndarray[tuple[int, int], dtype[float64]]]
Evaluate completeness, incompatibility, and LLR scores for \(K\) candidate segments in \(O(K \cdot |\mathcal{A}|)\).
Source code in src/serogen/loci/classifier.py
score_components
¶
score_components(X: ArchetypeInput) -> tuple[ndarray[tuple[int, int], dtype[float64]], ndarray[tuple[int, int], dtype[float64]], ndarray[tuple[int, int], dtype[float64]]]
Compute (llr_scores, completeness, incompatibility) matrices of shape (N, 11) across a batch.
Source code in src/serogen/loci/classifier.py
decision_function
¶
Compute unnormalized archetype logits of shape (N, 11) for input segments.
Source code in src/serogen/loci/classifier.py
predict_proba
¶
Compute calibrated softmax posterior probabilities (N, 11) across archetypes.
Source code in src/serogen/loci/classifier.py
predict
¶
Predict the integer LocusArchetype index (0..10) for each input locus or segment.
Source code in src/serogen/loci/classifier.py
classify
¶
classify(X: Locus | ndarray | Sequence[int | GeneRole]) -> tuple[LocusArchetype, float, float]
Classify a single Locus, role sequence, or (L, 30) probability matrix into (archetype, completeness, score).
Source code in src/serogen/loci/classifier.py
fit
¶
fit(X: ArchetypeInput, y: Sequence[int | LocusArchetype] | ndarray) -> Self
Calibrate w_comp_, w_incomp_, w_llr_, and unknown_logit_ via L-BFGS-B cross-entropy minimization.
Source code in src/serogen/loci/classifier.py
score
¶
score(X: ArchetypeInput, y: Sequence[int | LocusArchetype] | ndarray) -> float
Compute classification accuracy on labeled segments (X, y).
Source code in src/serogen/loci/classifier.py
Reference Serotype Matching (serogen.loci.matcher)¶
matcher
¶
Vectorized locus comparison, structural difference bitflags, and database matching.
Classes:
| Name | Description |
|---|---|
MatchType |
Composable bitflag enumeration describing how two biosynthetic loci differ. |
Match |
Scalar view of a pairwise comparison between a query locus and a target locus. |
Matches |
Vectorized Structure-of-Arrays (SoA) batch container of locus comparison results. |
LocusNodeCostStrategy |
Semantic node compatibility cost model for aligning two |
LocusMatcher |
Vectorized 1-to-many and batch-to-many biosynthetic locus matcher. |
MatchType
¶
Bases: IntFlag
Composable bitflag enumeration describing how two biosynthetic loci differ.
MatchType.EXACT (0) indicates that two loci share identical non-MGE gene content,
gene order, relative transcriptional orientations, dominant strand, frameshift state,
and mobile genetic element (MGE) state. Any combination of structural or allelic
differences is represented as the bitwise OR of the corresponding variant flags.
Attributes:
| Name | Type | Description |
|---|---|---|
is_exact |
bool
|
True if no variant flags are set ( |
is_novel |
bool
|
True if the comparison involves gene gain/loss, synteny rearrangement, or archetype mismatch. |
flag_count |
int
|
Number of active difference bitflags set in this |
Source code in src/serogen/loci/matcher.py
is_novel
property
¶
True if the comparison involves gene gain/loss, synteny rearrangement, or archetype mismatch.
Match
dataclass
¶
Bases: ScalarView
Scalar view of a pairwise comparison between a query locus and a target locus.
Attributes:
| Name | Type | Description |
|---|---|---|
is_exact |
bool
|
True if the query and target loci are an exact match ( |
is_novel |
bool
|
True if the query differs from this target by gene content, synteny, or archetype. |
Source code in src/serogen/loci/matcher.py
Matches
dataclass
¶
Bases: BatchedContainer[Match, 'Matches']
Vectorized Structure-of-Arrays (SoA) batch container of locus comparison results.
Methods:
| Name | Description |
|---|---|
empty |
Create an empty 0-length |
concat |
Concatenate multiple |
sort |
Sort matches by score, breaking ties by fewer |
best |
Return the highest-scoring |
best_per_query |
Return a |
filter |
Filter matches by minimum similarity metrics and/or permitted |
Attributes:
| Name | Type | Description |
|---|---|---|
is_novel |
ndarray[tuple[int], dtype[bool_]]
|
1D boolean array ( |
Source code in src/serogen/loci/matcher.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
is_novel
property
¶
1D boolean array ((N,)) indicating whether each match involves gene, synteny, or archetype divergence.
empty
classmethod
¶
Create an empty 0-length Matches container.
Source code in src/serogen/loci/matcher.py
concat
classmethod
¶
Concatenate multiple Matches containers into a single batch.
Source code in src/serogen/loci/matcher.py
sort
¶
Sort matches by score, breaking ties by fewer MatchType bitflags, higher AA identity, and lower target_index.
Source code in src/serogen/loci/matcher.py
best
¶
best() -> Match | None
Return the highest-scoring Match across the container (or None if empty).
Source code in src/serogen/loci/matcher.py
best_per_query
¶
Return a Matches container holding the single best target match for each unique query_index.
Source code in src/serogen/loci/matcher.py
filter
¶
filter(*, min_score: float = 0.0, min_jaccard: float = 0.0, min_coverage: float = 0.0, allowed_flags: MatchType | None = None) -> Self
Filter matches by minimum similarity metrics and/or permitted MatchType flags.
Source code in src/serogen/loci/matcher.py
LocusNodeCostStrategy
dataclass
¶
Bases: CostStrategy
Semantic node compatibility cost model for aligning two Locus graphs via GraphAligner.
Source code in src/serogen/loci/matcher.py
LocusMatcher
¶
Vectorized 1-to-many and batch-to-many biosynthetic locus matcher.
Indexes a reference database of target Loci (automatically clustering
target proteins and building a single RandstrobeIndex over
target proteins when translations are present) and compares query Locus
or Loci instances in parallel via _match_loci_kernel.
Methods:
| Name | Description |
|---|---|
assign_query_clusters |
Assign target homology |
match |
Compare one or more query loci against all indexed target loci. |
align |
Perform detailed node-by-node bipartite |
Source code in src/serogen/loci/matcher.py
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 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 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 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 | |
assign_query_clusters
¶
assign_query_clusters(queries: Loci) -> tuple[Loci, ndarray[tuple[int], dtype[float32]], ndarray[tuple[int, int], dtype[float32]]]
Assign target homology CLUSTER_IDs and compute per-gene AA identity in a single RandstrobeIndex pass.
Source code in src/serogen/loci/matcher.py
match
¶
match(query: Locus | Loci | Iterable[Locus], *, top_k: int | None = None, min_score: float = 0.0, sort: bool = True) -> Matches
Compare one or more query loci against all indexed target loci.
Source code in src/serogen/loci/matcher.py
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 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 | |
align
¶
align(query: Locus, target_index: int | str, *, canonicalize_strand: bool = True, heal_mges: bool = False) -> Alignment
Perform detailed node-by-node bipartite GraphAligner alignment between query and targets[target_index].