R/Entropy_methods.R

#' Calculate entropy values.
#'
#' @param x vector of frequency values
#' @param logbase given base of the logarithm function
#' @param method chosen entropy calculation method
#' @return Calculated gene-level entropy values in a vector.
#' @import entropy
#' @export
calculateDefaultEntropy <- function(x, logbase=exp(1)) {

  x_log = ifelse(is.finite(log(x, base = logbase)), log(x, base=logbase), 0)
  entropy = -sum(x * x_log)

  return(entropy)
}

valid_logs <- c("log", "log2", "log10")
valid_methods <-c("ML", "MM", "Jeffreys", "Laplace", "SG", "minimax", "CS", "NSB", "shrink")

calculateMLEntropy <- function(x, method, logbase) {

  try(
    if(!(logbase %in% valid_logs)) {
      stop("This log type is not valid in the given method!", call. = FALSE)
    }
    if(!(method %in% valid_methods)) {
      stop("Invalid method.", call. = FALSE)
    }
    if(!is.numeric(logbase)) {
      stop("The given logbase is not a numerical value.", call. = FALSE)
    }
  )
  result = entropy(x, method = method, unit = logbase)
  return(result)
}

calculateMMEntropy <- function(x, method, logbase) {
  try(
    if(!(logbase %in% valid_logs)) {
      stop("This log type is not valid in the given method!", call. = FALSE)
    }
    if(!(method %in% valid_methods)) {
      stop("Invalid method.", call. = FALSE)
    }
    if(is.numeric(logbase)) {
      stop("The given logbase is not a numerical value.", call. = FALSE)
    }
  )
  result = entropy(x, method = method, unit = logbase)
  return(result)
}

calculateJeffreysEntropy <- function(x, method) {
}

calculateLaplaceEntropy <- function(x, method) {
}

calculateSGEntropy <- function(x, method) {
}

calculateMinimaxEntropy <- function(x, method) {
}

calculateCSEntropy <- function(x, method) {
}

calculateNSBEntropy <- function(x, method) {
}

calculateShrinkEntropy <- function(x, method) {
}
peterszikora/SplicingEntropy documentation built on June 28, 2019, 7:06 p.m.