R/falsignal.R

Defines functions falsignal

Documented in falsignal

#' @title Find false signal
#'
#' @param l A list generated by \code{\link{makefeature}}.
#' @param cutoffvar Metabolites whose variance >= cutoffvar tend to be false signal.
#' @param cutoffswt Metabolites whose number of switches >= cutoffswt tend to be false signal.
#' @param cutofflong Metabolites whose longest block < cutofflong tend to be false signal.
#' @param cutoffmr Metabolites whose mean missing rate > cutoffmr tend to be false signal
#' @return A list contains name lists of predicted false signal.
#' \itemize{
#' \item mbnames: name list of metabolites.
#' \item wsize: window size.
#' \item ssize: slide size.
#' \item defswitch: definition of switch.
#' \item mrate: missing rate matrix. Each cell of the matrix is a missing rate of a window.
#' \item variance: missing rate variance for each metabolite.
#' \item nswitches: number of switches for each metabolite.
#' \item longestblock: number of windows of the longest block for each metabolite.
#' \item boolbad1: bool vector of type 1 false signal.
#' \item boolbad2: bool vector of type 2 false signal.
#' }
#' @author Liu Cao
#' @export

falsignal <- function(l, cutoffvar=0.03, cutoffswt=1, cutofflong=NULL, cutoffmr=0.95){
  if(!is.integer(cutofflong)){
    cutofflong = dim(l$mrate)[2]
  }
  remove_var = (l$variance >= cutoffvar )
  remove_longest = (l$longestblock < cutofflong)
  remove_swt =  (l$nswitches >= cutoffswt)
  remove_mmiss = (l$meanmrate >= cutoffmr)
  remove_1 =  remove_mmiss | remove_var | remove_swt | remove_longest
  remove_2 =  remove_mmiss | remove_var | ( (!remove_var) & remove_swt & remove_longest)

  print(paste0(sum(remove_1), " type I false signal detected.") )
  print(paste0(sum(remove_2), " type II false signal detected.") )

  return(list(mbnames = l$mbnames, wsize = l$wsize, ssize = l$ssize, defswitch = l$defswitch,
              cutoffvar = cutoffvar, cutoffswt = cutoffswt, cutofflong = cutofflong, cutoffmr = cutoffmr,
              mrate = l$mrate, variance = l$variance, nswitches = l$nswitches, longestblock = l$longestblock, meanmrate = l$meanmrate,
              boolbad1 = remove_1, boolbad2 = remove_2))
}
liucaomics/genuMet documentation built on Nov. 11, 2019, 12:13 a.m.