Skip to content

Commit

Permalink
added plotProportion in pheatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
lldelisle committed Jan 14, 2020
1 parent 766f80b commit 442d538
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: analysePeaks
Title: Compare, annotate your peaks
Version: 1.0.1
Version: 1.0.2
Authors@R:
person(given = "Lucille",
family = "Lopez-Delisle",
Expand Down
41 changes: 35 additions & 6 deletions R/plottingFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ plotAllBarPlotForCategoriesFromMyGR <- function(myGRs, nameOfColWithCate,
#' 4=shared by all Ref in not a single of the set or Ref in not a single of the set
#' 5=shared by all Ref: all or all Ref
#' (default is 1:5)
#' @param plotProportion logical whether to display the pheatmap 1, 2, and 4 should be plot as proportion of pheatmap 3 and 5 (default is FALSE)
#' @return Plot but do not return anything
#' @importFrom pheatmap pheatmap
#' @export
Expand All @@ -519,7 +520,8 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
stringSet, nameOfRef,
fontsize = 10,
display_numbers = T,
whichPheatmaps = 1:5){
whichPheatmaps = 1:5,
plotProportion = F){
if (length(myGRs) < 2){
stop("Wrong myGRs\n")
}
Expand Down Expand Up @@ -586,13 +588,37 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
factor(GenomicRanges::mcols(inputsGR[[i]])[,
nameOfColWithCate2],
levels = rev(cateNames2)))
if(plotProportion && ! i %in% c(3, 5)){
if(i < 3){
t2 <- table(factor(GenomicRanges::mcols(inputsGR[[3]])[,
nameOfColWithCate1],
levels = rev(cateNames1)),
factor(GenomicRanges::mcols(inputsGR[[3]])[,
nameOfColWithCate2],
levels = rev(cateNames2)))
} else {
t2 <- table(factor(GenomicRanges::mcols(inputsGR[[5]])[,
nameOfColWithCate1],
levels = rev(cateNames1)),
factor(GenomicRanges::mcols(inputsGR[[5]])[,
nameOfColWithCate2],
levels = rev(cateNames2)))

}
line2 <- paste0(round(sum(t1) / sum(t2) * 100), "% of peaks")
t1 <- t1 / t2
t1[is.nan(t1)] <- 0
number_format <- "%.2f"
} else {
line2 <- paste0(sum(t1), " peaks")
number_format <- "%d"
}
# We plot it
pheatmap::pheatmap(t1, cluster_rows = F, cluster_cols = F,
main = paste0(inputsGRWhat[[i]], "\n", sum(t1),
" peaks\n", what1, " vs ", what2,
main = paste0(inputsGRWhat[[i]], "\n", line2, "\n", what1, " vs ", what2,
"\nset:", stringSet, "\nref:", nameOfRef),
display_numbers = T,
number_format = "%d",
number_format = number_format,
fontsize = fontsize)
}
}
Expand All @@ -614,6 +640,7 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
#' 4=shared by all Ref in not a single of the set or Ref in not a single of the set
#' 5=shared by all Ref: all or all Ref
#' (default is 1:5)
#' @param plotProportion logical whether to display the pheatmap 1, 2, and 4 should be plot as proportion of pheatmap 3 and 5 (default is FALSE)
#' @param allCates a vector of string with the categories to plot, if NULL all categories in `myGRAndAttributes` are used (default is NULL)
#' @param display_numbers logical whether to display the numbers in the pheatmaps (default is TRUE)
#' @return Plot barplots and pheatmaps but do not return anything
Expand All @@ -625,7 +652,8 @@ plotCateComparisonSetAndRef <- function(myGRAndAttributes, fontsize = 10,
plotPheatmaps = TRUE,
display_numbers = TRUE,
whichPheatmaps = 1:5,
allCates = NULL){
allCates = NULL,
plotProportion = FALSE){
if (is.null(allCates)){
allCates <- myGRAndAttributes[["allCates"]]
}
Expand Down Expand Up @@ -661,7 +689,8 @@ plotCateComparisonSetAndRef <- function(myGRAndAttributes, fontsize = 10,
myGRAndAttributes[["nameOfRef"]],
fontsize = fontsize,
display_numbers = display_numbers,
whichPheatmaps = whichPheatmaps)
whichPheatmaps = whichPheatmaps,
plotProportion = plotProportion)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion man/plotAllPheatmapsFor2CategoriesFromMyGR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/plotCateComparisonSetAndRef.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vignettes/getting-started-with-analysePeaks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ plotCateComparisonSetAndRef(myList2, fontsize = 6)
# dev.off()
```

```{r}
# You can also replot heatmaps as proportion:
plotCateComparisonSetAndRef(myList2, plotBarPlots = F, plotProportion = T, fontsize = 6)
```


The barplots confirm what was shown with histograms but help with the quantification. For example, it shows that the proportion of CUT&RUN peaks with no CTCF motif increase from 10% in the peaks shared with ChIP to 80%. The increase in the ChIP between shared with CUT&RUN and specific is only from 20 to 25%.

The heatmap are really interesting because they better qualify. Most of the peaks which are specific to CUT&RUN tend to have no CTCF binding motif and are either at TSS with high DNase score or with no DNase between 1kb and 20kb of any TSS.
Expand Down

0 comments on commit 442d538

Please sign in to comment.