R/RcppExports.R

# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Compute the transition probabilities, P, of a first-order binary Markov
#' chain given a set of marginal probabilities and log odds ratios.
#'
#' @param marginalProb the marginal probability (i.e., average methylation
#' level) for each methylation locus in the genome.
#' @param LOR the within-fragment co-methylation between each pair of
#' methylation loci in the genome. Should be log odds-ratios using base-2
#' logarithms. The LOR is 0 for the first methylation locus on each seqlevel.
#' @param seqnames_one_tuples the chromosome (seqname) of each methylation
#' locus in the genome, i.e., \code{seqnames(one_tuples)}.
#'
#' @return A $n \times 2$ matrix of the transition probabilities. Let
#' $P_{i, .}$ be the $i$-th row of P ($i = 0, \ldots, n - 1$), then
#' $P_{i, .} = [Pr(Z_{i + 1} = 1 | Z_{i} = 0), Pr(Z_{i + 1} = 1 | Z_{i} = 1)]$;
#' NB: $P_{0, } = [Pr(Z_{0} = 1), Pr(Z_{0} = 1)], i.e., sampled from the
#' marginal distribution and similarly for all other $i$ that start a new
#' chromosome.
#' More generally, we might use a scheme where the $j$-th column of P
#' ($j = 1, \ldots, 2^{m - 1}$, with $m = 2$ under the default) stores
#' $Pr(Z_{i} = 1 | Z_{i - 1}, Z_{i - 2}, ...)$.
.computeP <- function(marginalProb, LOR, mc_order = 1L) {
    .Call('methsim_computeP', PACKAGE = 'methsim', marginalProb, LOR, mc_order)
}

#' Simulate sequencing errors.
#'
#' Simulate sequencing errors by modifying \code{z} in place.
#'
#' @param z an integer vector of sampled methylation states.
#' @param u an integer vector with the same length as \code{z} of random
#' variables distributed as Uniform(0, 1).
#' @param errorRate the (combined) probability of an "error", where an error
#' may be sequencing error or error in the bisulfite-conversion process.
#'
#' @note \strong{WARNING}: \code{z} is modified \strong{in place}.
#'
#' @return \code{NULL}. \code{z} is modified \strong{in place}.
#'
#' @keywords internal
.simulateErrorInPlace <- function(z, u, errorRate) {
    invisible(.Call('methsim_simulateErrorInPlace', PACKAGE = 'methsim', z, u, errorRate))
}

#' Simulate reads (z)
#'
#' @param fh An integer vector containing the "first hit" for each read.
#' @param nh An integer vector containing the "number of hits" for each read.
#' @param N An integervector giving the number of reads with the same
#' "first hit" and "number of hits".
#' @param marginalProb A matrix of marginal probabilities that each
#' methylation locus is methylated (rows) for each componentn (columns).
#' @param component An integer vector giving the mixture component from
#' which to simulate each read.
#' @param P A list of transition matrices. Each element of P should give the
#' transition probabilities that the methylation locus is methylated given the
#' state of the previous locus. The length of P is equal to the number of
#' mixture components.
#'
#' @return A list(h, readID, z), where h is the "hit", readID is a read ID,
#' and z is the observed methylation state. Each vector has length sum(nh * N).
#'
#' @note Assumes that sum(nh * N) < .Machine$integer.max, because Rcpp cannot
#' yet work with long vectors.
.simulatez <- function(fh, nh, N, component, MarginalProb, P) {
    .Call('methsim_simulatez', PACKAGE = 'methsim', fh, nh, N, component, MarginalProb, P)
}

#' Tabulate methylation patterns.
#'
#' Tabulate methylation patterns of a given \code{size} from the elements of
#' the \code{z} slot of a \code{\link{SimulatedBS}} object.
#'
#' @param readID an integer vector of read IDs; the \code{readID} column of
#' an element of the \code{z} slot of a \code{\link{SimulatedBS}} object.
#' @param z an integer vector of methylation states; the \code{z} column of
#' an element of the \code{z} slot of a \code{\link{SimulatedBS}} object.
#' @param pos an integer vector of the positions of methylation loci sequenced
#' by each read; the \code{pos} column of an element of the \code{z} slots of
#' a \code{\link{SimulatedBS}} object.
#' @param size an integer greater than 1 specifying the size of the m-tuples
#' to be created.
#'
#' @return A list of tabulated methylation patterns. The name of each list
#' element is a comma-separated string of positions for that m-tuple and the
#' value of each element is a vector of associated counts (the order of this
#' vector is identical to that given by
#' \code{MethylationTuples:::\link[MethylationTuples]{.makeMethPatNames}}).
#'
#' @note \strong{WARNING}: Only adjacent m-tuples, with respect to the
#' sequenced methylation loci, are created. This means that (A) the list will
#' contain unobserved m-tuples (i.e., those with all counts set to zero) and
#' (B) that it will be possibly with paired-end reads to create m-tuples with
#' NIC > 0.
#' \strong{WARNING}: The special case where \code{size} = 1 is handled
#' separately by tabulating with the \code{data.table} package.
#'
#' @keywords internal
#'
.tabulatez <- function(readID, z, pos, size) {
    .Call('methsim_tabulatez', PACKAGE = 'methsim', readID, z, pos, size)
}
PeteHaitch/methsim documentation built on May 8, 2019, 1:32 a.m.