# Install Package: Ctrl + Shift + B
# devtools::document()
#' plot MAGeCK count summary
#'
#' Imports:
#' reshape2,
#' ggpubr,
#' ggplot2
#'
#' @param filepath character, path to file "...countsummary.txt"
#' @return list with a ggparrange, a ggplot object, and dataframes used to produce the plots
#' @details takes in the mageck count side-output "...countsummary.txt" to create plots for mapping and gini index
#' @examples
#' summ <- seekmagecksummary("myexperiment.countsummary.txt")
seekmagecksummary <- function(filepath, color1="gray30", color2="blue"){
countsummary <- read.delim(filepath, check.names=F)
countsummary$mapped=countsummary$Mapped/countsummary$Reads
countsummary$unmapped=1-countsummary$mapped
countsummary$Unmapped=countsummary$Reads-countsummary$Mapped
countsummary2 <- reshape2::melt(countsummary)
qcplot <- function(interest, title){
if(interest %in% "GiniIndex") color1="maroon"
countsummary2$variable=factor(countsummary2$variable, levels=interest)
countsummary2 <- na.omit(countsummary2)
ggplot2::ggplot(countsummary2, ggplot2::aes(x=Label, y=value, fill=variable)) +
ggplot2::geom_bar(stat="identity") +
ggplot2::scale_fill_manual(values=c(color1,color2)) +
ggplot2::scale_y_continuous(expand=c(0,0)) +
ggplot2::ggtitle(title) +
ggplot2::theme_classic() +
ggplot2::theme(axis.title=ggplot2::element_blank(),
text=ggplot2::element_text(size=10),
legend.title=ggplot2::element_blank(),
axis.text.x=ggplot2::element_text(angle=45, hjust=1))
}
gini <- qcplot("GiniIndex", "Gini index") + ggplot2::theme(legend.position="none")
mapping <- ggpubr::ggarrange(qcplot(c("Unmapped","Mapped"), "absolute reads"),
qcplot(c("unmapped","mapped"), "relative reads"),
nrow=1, common.legend=T, legend="right")
list(gini=gini, mapping=mapping, countsummary=countsummary)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.