RNA¶
multimolecule.utils.rna.contact_map_to_dot_bracket
¶
contact_map_to_dot_bracket(
contact_map: Tensor | ndarray,
*,
unsafe: bool = False,
threshold: float | None = None,
matching: Matching = "greedy"
) -> 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
multimolecule.utils.rna.contact_map_to_pairs
¶
contact_map_to_pairs(
contact_map: Tensor,
*,
unsafe: bool = False,
threshold: float | None = None,
matching: Matching = "greedy"
) -> Tensor
contact_map_to_pairs(
contact_map: Tensor | ndarray | Sequence,
*,
unsafe: bool = False,
threshold: float | None = None,
matching: Matching = "greedy"
) -> 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 conflicting pairs are decoded using either greedy
NMS-style matching or exact blossom matching.
Examples:
Torch input
| Python Console Session | |
|---|---|
NumPy input
| Python Console Session | |
|---|---|
List input
Source code in multimolecule/utils/rna/secondary_structure/notations.py
| Python | |
|---|---|
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 | |
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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
multimolecule.utils.rna.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 | |
|---|---|
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 | |
multimolecule.utils.rna.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 | |
|---|---|