R/nbDiffSeuil.R

Defines functions nbDiffSeuil

Documented in nbDiffSeuil

#' Number of DE features according to the FDR threshold
#'
#' Number of DE features according to the FDR threshold
#'
#' @param complete a list of \code{data.frame} of the complete results of the project
#' @param out \code{TRUE} to export the figure
#' @param versionName versionName of the project
#' @return A plot of the number of DE features according to the FDR threshold
#' @author Marie-Agnes Dillies and Hugo Varet

# created dec 10th, 2013
# modified jan 10th, 2014 (fixed a bug if n==0)
# modified feb 13th, 2014 (removed type.trans which has nothing to do here)
# modified Mar 21st, 2014 (removed outputfile argument)
# modified Apr 17th, 2014 (added log2FC argument)
# modified July 31th, 2014 (removed adjMethod argument)
# modified Aug 5th, 2014 (removed graphDir and log2FC argument)
# modified August 26th, 2019 (ggplot2)

nbDiffSeuil <- function(complete, out = TRUE, versionName = "."){
  if (out) pdf(file=paste0("figures/", versionName, "-nbDiffSeuil.pdf"))
  for (name in names(complete)){
    complete.name <- complete[[name]]
    padj <- complete.name[,"padj"]
    padj <- padj[!is.na(padj)]
    padj <- sort(padj)
    seuils <- c(1e-10, 1e-5, 1e-4, 1e-3, 1e-2, 0.05)
    n <- numeric(length(seuils))
    names(n) <- as.character(seuils)
    for (s in seuils) n[as.character(s)] <- sum(padj <= s)
    d <- data.frame(seuils=factor(seuils, levels=seuils), n)
    print(ggplot(d, aes(x=.data$seuils, y=ifelse(.data$n==0, 1, .data$n+0.01))) +
            geom_bar(stat="identity", show.legend = FALSE) +
            xlab("Adjusted P-value threshold") + 
            ylab("# DE features") +
            scale_y_continuous(trans="log10", expand=expansion(mult=c(0.01, 0.1))) +
            ggtitle(paste(versionName, "Number of DE features according\nto the FDR threshold", name, sep=" - ")) +
            geom_text(aes(y=1.25*ifelse(.data$n==0, 1, .data$n+0.01), label=.data$n), color="black", size=4))
  }
  if (out) dev.off()
}
biomics-pasteur-fr/RNADiff documentation built on Aug. 27, 2020, 12:44 a.m.