R/transprob.R

#' transprob
#'
#' \code{transprob} creats the transition matrix for the hidden markov chain.
#'
#' @export
#' @param trans c(rho_u, rho, delta)
#' @param stp   1 if next codon is stop codon
#' @param stp2  In \code{generate_uORF}, stp = theta_u, stp2 = theta
#' @return      The transition matrix \code{A}
#'
#' @examples
#' trans <- c(0.1, 0.2, 0.3)
#' stp <- 0.4; stp2 <- 0.45
#' A <- transprob(trans, stp, stp2)
#' colnames(A) <- seq(1,21)
#' View(A)

transprob <- function(trans, stp, stp2){
  A <- diag(21)
  A <- cbind(0, A[,-21])

  A[1,1] <- 1 - trans[1] - trans[2]
  A[1,2] <- trans[1]
  A[1,12] <- trans[2]

  A[11, 12] <- trans[3]
  A[11, 11] <- 1-trans[3]

  A[4,8] <- A[7,8] <-  stp
  A[4,5] <- A[7,5] <-  1-stp
  A[14,18] <- A[17,18] <- stp2
  A[14,15] <- A[17,15] <- 1-stp2

  A[21,21] <- 1

  return(A)
}
shimlab/riboHMM2 documentation built on May 19, 2019, 6:23 p.m.