R/controlEM.R

Defines functions controlEM

Documented in controlEM

#' Control parameters for the EM algorithm from epigraHMM
#'
#' This function passes controlling parameters for the EM algorithm implemented in the epigraHMM package.
#'
#' @param epsilon.em Add description here
#' @param maxit.em a positive integer giving the maximum number of EM iterations. Default is 500.
#' @param minit.em a positive integer giving the minimum number of EM iterations to start evaluating the convergence. Default is 3.
#' @param maxcount.em a positive integer giving the number of consecutive EM iterations satisfying the convergence criterion in order to stop the algorithm. Default is 3.
#' @param windowSize the proportion of the genome to use as window in the sliding window initialization 
#' @param pcut a number between 0 and 1 for the cutoff of the rejection controlled EM algorithm. Default 0.05.
#' @param quiet a logical indicating whether to print messages. Default is TRUE.
#' @param cores number of cores to use
#' @param clusters number of clusters to detect
#' @param dir directory with files will be saved
#' @param fdr the FDR level to call peaks (default if 0.10)
#' @param init either 'HMM' or 'fast' (default is 'fast')
#' @param chr chromosomes for initialization
#'
#' @details
#' Add details here
#' 
#' @return A list with components equal to the arguments
#'
#' @author Pedro L. Baldoni, \email{pedrobaldoni@gmail.com}
#' @references \url{https://github.com/plbaldoni/mikado}
#'
#' @examples
#' # No more than 100 EM iterations
#' control <- controlEM(maxit.em = 100)
#'
#' @importFrom Rcpp evalCpp
#' @export
#'
controlEM = function(epsilon.em=1e-2,maxit.em=15,minit.em=1,maxcount.em=1,
                     windowSize = 100,pcut=0.05,quiet=FALSE,chr = paste0('chr',1:22),
                     cores = 1,clusters = NULL,dir = tempdir(check = TRUE),fdr = 0.10,init = 'fast'){
    if (!(length(epsilon.em)%in%c(1,4) & is.numeric(epsilon.em) & all(epsilon.em>0))){stop("epsilon.em must be a positive numerical value (or vector) of length 1 (or 4)")}
    if (!maxit.em%%1==0 || maxit.em <= 0){stop("value of 'maxit.em' must be a positive integer")}
    if (!minit.em%%1==0 || minit.em <= 0){stop("value of 'minit.em' must be a positive integer")}
    if (!maxcount.em%%1==0 || maxcount.em <= 0){stop("value of 'maxcount.em' must be a positive integer")}
    if (!(length(pcut)==1 & is.numeric(pcut) & pcut>0 & pcut<1)){stop("'pcut' must be a value between 0 and 1")}
    if (!(length(quiet)==1 & is.logical(quiet))){stop("'quiet' must be a logical value")}

    list(epsilon.em=epsilon.em,
         windowSize = windowSize,
         maxit.em=maxit.em,
         minit.em=minit.em,
         maxcount.em=maxcount.em,
         pcut=pcut,
         quiet=quiet,
         cores = cores,
         clusters = clusters,
         dir = dir,
         fdr = fdr,
         init = init,
         chr = chr)
}
plbaldoni/mikado documentation built on June 9, 2020, 3:34 p.m.