Probabilities
This module implements Probabilities, an immutable view into a Compound's probability matrix. It holds a reference to its parent Compound to make sure it does not outlive it. The module provides accessors and iterators, so the Probability object handles just as an array would.
Example usage
We have an RNA sequence and want to know the probabilities of base pairing for some base pairs.
import strformat import nimna var c: Compound = ... # The RNA sequence in question. prob = c.probabilities for idx in 0 ..< c.len div 2: let onStemProbability = prob[idx, c.len - idx] echo fmt"Probability for base pair on diagonal: {onStemProbability}"
Procs
proc `[]`(p: Probabilities; i, j: int): float {.
raises: [IndexError], tags: [].}- Bracket accessor for a set of Probabilities.
proc probabilities(c: Compound): Probabilities {.
raises: [Exception, FieldError], tags: [].}- Returns a Probabilities object for monitoring the base pair probabilities inside the Compound. If no probabilities exist, they will be computed.
proc prob(c: Compound; i, j: int): float {.
raises: [IndexError, Exception, FieldError], tags: [].}- Returns the probability of base-pairing at positions i and j in a Compound.
Iterators
iterator items(p: Probabilities): float {.
raises: [IndexError], tags: [].}- Iterates over all entries in the probability matrix.
iterator pairs(p: Probabilities): tuple[pos: tuple[i, j: int], val: float] {.
raises: [IndexError], tags: [].}- Iterates over all pairs of indices (i, j) and their corresponding base pairing probabilities val.
iterator triples(p: Probabilities): tuple[i, j: int, val: float] {.
raises: [IndexError], tags: [].}- Iterates over all triples of indices i, j and their corresponding base pairing probabilities val.
iterator positions(p: Probabilities): seq[float] {.
raises: [IndexError], tags: [].}- Iterates over all positions in the sequence corresponding to the Probabilities, returning a seq of their base pairing probabilities.