Skip to contents

Calculates base substitution ratio (e.g.: editing frequency) for ref and base counts stored in nx4 matrix bases. ref must have only one reference base. A->G is okay, but AG->G is NOT allowed! If bc is not provided, count the substitution ratio of the largest non-reference base (@seealso max_observed_bc). Make sure that number of alleles in ref(erence) and bases is 2 at maximum.

Usage

sub_ratio(ref, bases, bc = NULL)

Arguments

ref

vector of reference bases.

bases

matrix of observed base call counts.

bc

vector strings that represent observed base calls. Default: NULL.

Value

vector of base call substitution ratios.

Examples

ref <- c("A", "A", "T")
# Only one non-ref. base
bases <- matrix(c( 1,  0, 9, 0,
                   5,  0, 5, 0,
                   0, 10, 0, 0),
                ncol = 4, byrow = TRUE)
# show base substitution ratios for observed base calls
sub_ratio(ref, bases)
#> [1] 0.9 0.5 1.0

# > one non-ref. base
bases <- matrix(c( 1,  2, 9, 1,
                   5,  3, 5, 1,
                   2, 10, 2, 1),
               ncol = 4, byrow = TRUE)
# we are only interested in A->G, T->C
bc <- c("G", "G", "C")
# show base substitution ratios for A->G, T->C
sub_ratio(ref, bases, bc)
#> [1] 0.6923077 0.3571429 0.6666667