|
3 | 3 | #' Plot genome-wide snv distribution
|
4 | 4 | #' @import ggplot2
|
5 | 5 | #' @keywords distribution
|
| 6 | +#' @param snv_data A dataframe of snvs [Default: NULL] |
| 7 | +#' @param notch Filter in/out Notch region [Default: FALSE] |
| 8 | +#' @param write Write plot to file 'plots/snv_dist_genome_by.png'? [Default: FALSE] |
| 9 | +#' @param binsize Control the density adjustment if density=TRUE, or the binwidth if density=FALSE. For histograms a value of 0.1 corresponds to 1/10th of a Mb [Default:0.1] |
| 10 | +#' @param density Plot as density? [Default: TRUE] |
6 | 11 | #' @export
|
7 |
| - |
8 |
| - |
9 |
| -chromDist <- function(..., snv_data=NULL, object=NA, notch=0, write=FALSE){ |
10 |
| - if(missing(snv_data)){ |
11 |
| - snv_data<-getData(...) |
12 |
| - } |
13 |
| - ext<-'.pdf' |
14 |
| - if(is.na(object)){ |
15 |
| - object<-'grouped_trans' |
16 |
| - cols<-setCols(snv_data, "grouped_trans") |
17 |
| - } |
18 |
| - |
| 12 | +chromDist <- function(..., snv_data=NULL, notch=FALSE, write=FALSE, binsize=0.1, density=TRUE){ |
19 | 13 | if(notch){
|
20 | 14 | snv_data<-exclude_notch(...)
|
21 |
| - ext<-'_excl.N.pdf' |
| 15 | + ext<-'_excl.N.png' |
| 16 | + } else if(missing(snv_data)){ |
| 17 | + snv_data<-getData(...) |
22 | 18 | }
|
23 | 19 |
|
24 |
| - cat("Plotting snvs by", object, "\n") |
| 20 | + cols<-setCols(snv_data, "grouped_trans") |
| 21 | + blueBar <- '#3B8FC7' |
| 22 | + |
| 23 | + cat("Plotting snv distribution across genome", "\n") |
| 24 | + |
| 25 | + p <- ggplot(snv_data) |
| 26 | + if(density){ |
| 27 | + p <- p + geom_density(aes(pos/1000000, fill=chrom), alpha = 0.6, adjust=binsize) |
| 28 | + p <- p + scale_y_continuous("Density", expand = c(0.01, 0.01)) |
25 | 29 |
|
26 |
| - p<-ggplot(snv_data) |
27 |
| - p<-p + geom_histogram(aes(pos/1000000, fill = get(object)), binwidth=0.1, alpha = 0.8) |
| 30 | + } else{ |
| 31 | + p <- p + geom_histogram(aes(pos/1000000, fill=blueBar), binwidth=binsize, alpha = 0.8) |
| 32 | + p <- p + scale_y_continuous("Number of SNVs", expand = c(0.01, 0.01)) |
| 33 | + p <- p + scale_fill_identity() |
| 34 | + } |
| 35 | + # p<-p + geom_histogram(aes(pos/1000000, fill = grouped_trans), binwidth=0.1, alpha = 0.8) |
28 | 36 | p<-p + facet_wrap(~chrom, scale = "free_x", ncol = 2)
|
29 |
| - p<-p + scale_x_continuous("Mbs", breaks = seq(0,33,by=1), limits = c(0, 33),expand = c(0.01, 0.01)) |
30 |
| - p<-p + scale_y_continuous("Number of snvs", expand = c(0.01, 0.01)) |
| 37 | + p<-p + scale_x_continuous("Genomic position (Mbs)", expand = c(0.01, 0.01)) |
31 | 38 | p<-p + cleanTheme() +
|
32 | 39 | theme(axis.text.x = element_text(angle = 45, hjust=1),
|
33 | 40 | axis.text = element_text(size=12),
|
34 | 41 | axis.title = element_text(size=20),
|
35 | 42 | strip.text.x = element_text(size = 15)
|
36 | 43 | )
|
37 |
| - |
38 |
| - if (object == 'grouped_trans'){ |
39 |
| - p<-p + cols |
40 |
| - } |
| 44 | + # p <- p + cols |
41 | 45 | if(write){
|
42 |
| - chrom_outfile<-paste("snv_dist_genome_by_", object, ext, sep = "") |
43 |
| - cat("Writing file", chrom_outfile, "\n") |
44 |
| - ggsave(paste("plots/", chrom_outfile, sep=""), width = 20, height = 10) |
| 46 | + chrom_outfile<-"snv_dist_genome_by.png" |
| 47 | + cat("Writing file", paste0("plots/", chrom_outfile, "\n")) |
| 48 | + ggsave(paste0("plots/", chrom_outfile), width = 20, height = 10) |
45 | 49 | }
|
46 | 50 | p
|
47 | 51 | }
|
0 commit comments