RNA Secondary Structure¶
multimolecule.utils.rna.secondary_structure
¶
RnaSecondaryStructureTopology
¶
Bases: UndirectedGraph
Source code in multimolecule/utils/rna/secondary_structure/topology.py
| Python | |
|---|---|
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 | |
loop_contexts
¶
loop_contexts() -> List[LoopContext]
Return nested-loop contexts annotated with pseudoknot pairs.
Loops are defined on nested pairs only; pseudoknot pairs are reported as inside or crossing each loop’s spans.
Source code in multimolecule/utils/rna/secondary_structure/topology.py
annotate_positions
¶
annotate_positions(
*,
view: StructureView | str | None = None,
paired: str = "stem",
mode: LoopView | str | None = None,
tier_preference: StructureView | str | None = None
) -> List[Dict[str, object]]
Return per-position annotations for paired/loop context.
Each entry includes partner, paired flag, tier, segment/loop objects, and indices where available. Negative indexing follows normal Python rules.
Source code in multimolecule/utils/rna/secondary_structure/topology.py
annotate
¶
annotate(
structure: RnaSecondaryStructureTopology,
) -> Tuple[str, str]
Return both structural and functional annotations for this structure.
Source code in multimolecule/utils/rna/secondary_structure/bprna.py
annotate_function
¶
annotate_function(
structure: RnaSecondaryStructureTopology,
) -> str
Return a bpRNA-like functional annotation string (knot/function array) for this structure.
Labels: K for bases involved in pseudoknot pairs, N otherwise.
Source code in multimolecule/utils/rna/secondary_structure/bprna.py
annotate_structure
¶
annotate_structure(
structure: RnaSecondaryStructureTopology,
) -> str
Return a bpRNA-like structural annotation string (structure array) for this structure.
Labels: S (stems), H (hairpins), B (bulges), I (internals), M (multibranch), X (external), E (end).
Source code in multimolecule/utils/rna/secondary_structure/bprna.py
noncanonical_pairs
¶
noncanonical_pairs(
pairs: Tensor | ndarray | Pairs,
sequence: str,
unsafe: bool = False,
) -> Tensor | ndarray | PairsList
Return subset of base pairs that are non-canonical (backend-aware).
Non-ACGU bases are treated as non-canonical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
Base pairs as a (n, 2) tensor or array. |
required |
|
str
|
RNA sequence string. |
required |
|
bool
|
Ignore invalid self-pairs when True; raise when False. |
False
|
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | PairsList
|
Non-canonical base pairs using the same backend as input (list inputs return list of tuples). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/noncanonical.py
noncanonical_pairs_set
¶
noncanonical_pairs_set(
pairs: Tensor | ndarray | Pairs,
sequence: str,
unsafe: bool = False,
) -> set[Pair]
Return non-canonical base pairs as a set of (i, j) tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
Base pairs as a tensor, array, or sequence of (i, j) tuples. |
required |
|
str
|
RNA sequence string. |
required |
|
bool
|
Ignore invalid self-pairs when True; raise when False. |
False
|
Returns:
| Type | Description |
|---|---|
set[Pair]
|
A set of (i, j) tuples for non-canonical pairs. |
Examples:
Source code in multimolecule/utils/rna/secondary_structure/noncanonical.py
contact_map_to_dot_bracket
¶
contact_map_to_dot_bracket(
contact_map: Tensor | ndarray,
unsafe: bool = False,
*,
threshold: float = 0.5
) -> str
Convert a contact map (NumPy or Torch) to a dot-bracket notation string.
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/notations.py
contact_map_to_pairs
¶
contact_map_to_pairs(
contact_map: Tensor,
unsafe: bool = False,
*,
threshold: float = 0.5
) -> Tensor
contact_map_to_pairs(
contact_map: Tensor | ndarray | Sequence,
unsafe: bool = False,
*,
threshold: float = 0.5
) -> Tensor | ndarray | PairsList
Convert a contact map to a list of base pairs.
If contact_map is a torch tensor, returns a (K, 2) torch.LongTensor.
Otherwise, returns a numpy (K, 2) int array (list inputs return a list of tuples).
For integer/bool contact maps, any non-zero entry is treated as a contact and the map is expected to represent a binary (symmetric) adjacency matrix.
For floating-point contact maps, values are interpreted as pairing probabilities in [0, 1]
(or logits/scores in unsafe mode), and pairs are decoded using a greedy NMS-style
one-to-one matching that prioritizes higher scores above threshold.
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/notations.py
dot_bracket_to_contact_map
¶
Convert a dot-bracket notation string to a numpy contact map.
Examples:
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/notations.py
dot_bracket_to_pairs
¶
dot_bracket_to_pairs(dot_bracket: str) -> ndarray
Convert a dot-bracket notation string to a list of base-pair indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Dot-bracket notation. Supports pseudoknots via multiple
bracket types, including (), [], {}, <>, and A-Z/a-z. Unpaired
tokens ( |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A numpy array of shape (n, 2) with pairs |
Raises:
| Type | Description |
|---|---|
ValueError
|
On unmatched or invalid symbols. |
Examples:
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/notations.py
pairs_to_contact_map
¶
pairs_to_contact_map(
pairs: Tensor,
length: int | None = None,
unsafe: bool = False,
) -> Tensor
pairs_to_contact_map(
pairs: Tensor | ndarray | Pairs,
length: int | None = None,
unsafe: bool = False,
) -> Tensor | ndarray | List[List[bool]]
Convert base pairs to a symmetric contact map.
If pairs is a torch tensor, returns a boolean torch.Tensor on the same device.
Otherwise, returns a numpy boolean array.
If length is None, it is inferred as max(pairs) + 1.
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/notations.py
pairs_to_dot_bracket
¶
pairs_to_dot_bracket(
pairs: Tensor | ndarray | Pairs,
length: int,
unsafe: bool = False,
) -> str
Convert base pairs to a dot-bracket string (backend-aware input, string output).
Torch inputs are accepted and internally converted to NumPy for string building. In safe mode, tiers are assigned using an exact minimal-tier coloring. In unsafe mode, a greedy tiering is used for speed and may use more bracket types.
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/notations.py
normalize_pairs
¶
Normalize base-pair indices to unique, sorted (i < j) pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | PairsList
|
Normalized pairs using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pairs.py
pairs_to_duplex_segment_list
¶
Convert base pairs to bulge-tolerant segments while preserving actual pairs.
Segments grow by stepping to the next paired 5’ position and the previous paired 3’ position; if those positions pair to each other, they belong to the same segment.
Source code in multimolecule/utils/rna/secondary_structure/pairs.py
pairs_to_helix_segment_arrays
¶
pairs_to_helix_segment_arrays(
pairs: Tensor | ndarray | Pairs,
) -> (
Tuple[Tensor, Tensor, Tensor]
| Tuple[ndarray, ndarray, ndarray]
| Tuple[List[int], List[int], List[int]]
)
Convert base pairs to strict stacked segments (no bulges).
Source code in multimolecule/utils/rna/secondary_structure/pairs.py
pairs_to_stem_segment_arrays
¶
pairs_to_stem_segment_arrays(
pairs: Tensor | ndarray | Pairs,
) -> (
Tuple[Tensor, Tensor, Tensor]
| Tuple[ndarray, ndarray, ndarray]
| Tuple[List[int], List[int], List[int]]
)
Convert base pairs to stem segments that allow bulges/internal loops.
Source code in multimolecule/utils/rna/secondary_structure/pairs.py
segment_arrays_to_pairs
¶
segment_arrays_to_pairs(
segments: Tuple[Tensor, Tensor, Tensor] | List[Segment],
mask: Tensor | None = None,
empty: ndarray | None = None,
) -> Tensor | ndarray
Convert segments back to base pairs.
Source code in multimolecule/utils/rna/secondary_structure/pairs.py
sort_pairs
¶
Sort base-pair indices by (i, j) without normalization or de-duplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | PairsList
|
Sorted pairs using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pairs.py
crossing_arcs
¶
crossing_arcs(
pairs: Tensor | ndarray | Pairs,
) -> Tensor | ndarray | List[Tuple[Pair, Pair]]
Return pair-level crossing arcs as ((i, j), (k, l)) where i < k < j < l.
Pair inputs are expected to be normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | List[Tuple[Pair, Pair]]
|
Crossing arcs using the same backend as input. Tensor/NumPy inputs |
Tensor | ndarray | List[Tuple[Pair, Pair]]
|
return shape (n, 2, 2). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
crossing_events
¶
crossing_events(
pairs: Tensor | ndarray | Pairs,
) -> (
Tensor
| ndarray
| List[
Tuple[
Tuple[int, int, int, int],
Tuple[int, int, int, int],
]
]
)
Return crossing events between stem segments.
Each stem is encoded as (start_5p, stop_5p, start_3p, stop_3p).
For pair-level crossing arcs, use crossing_arcs.
Pair inputs are expected to be normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | List[Tuple[Tuple[int, int, int, int], Tuple[int, int, int, int]]]
|
Crossing events using the same backend as input. Tensor/NumPy inputs |
Tensor | ndarray | List[Tuple[Tuple[int, int, int, int], Tuple[int, int, int, int]]]
|
return shape (n, 2, 4). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
crossing_mask
¶
Return a boolean mask for pairs that cross any other pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | List[bool]
|
Boolean mask for the input pairs using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
crossing_nucleotides
¶
Return nucleotide indices involved in any crossing pair.
Pair inputs are expected to be normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | List[int]
|
Unique nucleotide indices using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
crossing_pairs
¶
Return pairs from segments that cross any other segment (no-heuristic PK).
Pairs are expected to be normalized (unique, sorted with i < j).
Use normalize_pairs if you need to normalize raw inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | PairsList
|
Crossing pairs using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
has_pseudoknot
¶
Return True if any pseudoknot pairs are present under segment-MWIS split.
Pair inputs are expected to be normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if pseudoknot pairs exist, otherwise False. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
NumPy input
| Python Console Session | |
|---|---|
List input
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
nested_pairs
¶
Return primary pairs from the segment-MWIS split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | PairsList
|
Primary pairs using the same backend as input. |
This is equivalent to split_pseudoknot_pairs(pairs)[0] and expects
normalized unique pairs.
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
pseudoknot_nucleotides
¶
Return nucleotide indices involved in any pseudoknot pair.
Pair inputs are expected to be normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | List[int]
|
Unique nucleotide indices using the same backend as input (sequence inputs return Python lists). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
pseudoknot_pairs
¶
Return pseudoknot pairs from segments not selected by MWIS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | ndarray | PairsList
|
Pseudoknot pairs using the same backend as input. |
This is equivalent to split_pseudoknot_pairs(pairs)[1] and expects
normalized unique pairs.
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Tie-breaks for equal total base pairs: (1) minimize unpaired-within-span, (2) minimize total span, (3) minimize number of segments, (4) deterministic order fallback.
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
pseudoknot_tiers
¶
pseudoknot_tiers(
pairs: Tensor | ndarray | Pairs, unsafe: bool = False
) -> List[Tensor] | List[ndarray] | Tiers
Return dot-bracket tiers as non-crossing groups of pairs.
Pairs are expected to be normalized (unique, sorted with i < j).
Use normalize_pairs if you need to normalize raw inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
|
bool
|
Use greedy tiering for speed instead of minimal coloring. |
False
|
Returns:
| Type | Description |
|---|---|
List[Tensor] | List[ndarray] | Tiers
|
A list of tiers. Each tier is a list/array/tensor of pairs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
split_crossing_pairs
¶
split_crossing_pairs(
pairs: PairsList,
) -> Tuple[PairsList, PairsList]
split_crossing_pairs(
pairs: Tensor | ndarray | Pairs,
) -> Tuple[
Tensor | ndarray | PairsList,
Tensor | ndarray | PairsList,
]
Split pairs into non-crossing pairs and crossing pairs (no-heuristic).
Pairs are expected to be normalized (unique, sorted with i < j).
Use normalize_pairs if you need to normalize raw inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor | ndarray | PairsList, Tensor | ndarray | PairsList]
|
(non_crossing_pairs, crossing_pairs) using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
| Python Console Session | |
|---|---|
Source code in multimolecule/utils/rna/secondary_structure/pseudoknot.py
| Python | |
|---|---|
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 | |
split_pseudoknot_pairs
¶
split_pseudoknot_pairs(
pairs: Pairs,
) -> Tuple[PairsList, PairsList]
split_pseudoknot_pairs(
pairs: Tensor | ndarray | Pairs,
) -> Tuple[
Tensor | ndarray | PairsList,
Tensor | ndarray | PairsList,
]
Split base pairs into primary and pseudoknot pairs using segment-level MWIS.
Pairs are expected to be normalized (unique, sorted with i < j).
Use normalize_pairs if you need to normalize raw inputs.
Tie-breaks order for equal total base pairs is lexicographic on:
- minimize unpaired-within-span
- minimize total span
- minimize number of segments
- deterministic segment order (prefer 3’ segments)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor | ndarray | Pairs
|
torch.Tensor, numpy.ndarray, or array-like with shape (n, 2) and 0-based indices. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor | ndarray | PairsList, Tensor | ndarray | PairsList]
|
(nested_pairs, pseudoknot_pairs) using the same backend as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pairs has invalid shape for the selected backend. |
TypeError
|
If pairs is not a torch.Tensor, numpy.ndarray, or array-like with shape (n, 2). |
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
| Python Console Session | |
|---|---|