R/density_plot.R

Defines functions plot_density

Documented in plot_density

#' A density plot of reads over chromosomes generetor
#' A function that allows you to plot the read density over chromosomes
#' @param samples a list of data frames of bed converted alignment file
#' @param plot_dir the directory in which you want the plots, default = "plots"
#' @keywords density
#' @import tidyverse gridExtra
#' @export
#' @examples
#' plot_density(samples, plot_dir)
plot_density <- function(samples, plot_dir = "plots"){
  dir.create(file.path(plot_dir), showWarnings = FALSE)
  ###subfunction for plotting chromosome density(in a very unelegnt way)
  density_over_chrom <- function(first_sample, ...){
    data("hg_gap")
    chromPlot(gaps=hg_gap, bands=hg_cytoBandIdeo, annot1=first_sample, colAnnot1="#E64B35B2", ..., figCols=(length(chromosomes)+1)/2, chrSide=c(-1, 1, -1, 1, 1, 1, 1, 1), colAnnot2="#4DBBD5B2", colAnnot3="#00A087B2", colAnnot4="#3C5488B2")
  }
  arguments <- list(samples[[1]])
  count <- 2
  for (n in 2:length(samples)) {
    arguments[[paste("annot", n, sep = "")]] <- samples[[n]]
  }
  pdf(file.path(plot_dir, "density_plot.pdf"))
  do.call(density_over_chrom, arguments)
  legend("bottom",
         legend = names(samples),
         col = pal_npg("nrc", alpha = 0.7)(length(samples)),
         pch = 15,
         bty = "n",
         pt.cex = 1.8,
         cex = 1,
         text.col = "black",
         horiz = F)
  dev.off()
}
riccardo-trozzo/BlissR documentation built on Aug. 1, 2020, 12:23 a.m.