Skip to content

Commit 442d538

Browse files
author
Lucille Delisle
committed
added plotProportion in pheatmap
1 parent 766f80b commit 442d538

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: analysePeaks
22
Title: Compare, annotate your peaks
3-
Version: 1.0.1
3+
Version: 1.0.2
44
Authors@R:
55
person(given = "Lucille",
66
family = "Lopez-Delisle",

R/plottingFunctions.R

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ plotAllBarPlotForCategoriesFromMyGR <- function(myGRs, nameOfColWithCate,
508508
#' 4=shared by all Ref in not a single of the set or Ref in not a single of the set
509509
#' 5=shared by all Ref: all or all Ref
510510
#' (default is 1:5)
511+
#' @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)
511512
#' @return Plot but do not return anything
512513
#' @importFrom pheatmap pheatmap
513514
#' @export
@@ -519,7 +520,8 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
519520
stringSet, nameOfRef,
520521
fontsize = 10,
521522
display_numbers = T,
522-
whichPheatmaps = 1:5){
523+
whichPheatmaps = 1:5,
524+
plotProportion = F){
523525
if (length(myGRs) < 2){
524526
stop("Wrong myGRs\n")
525527
}
@@ -586,13 +588,37 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
586588
factor(GenomicRanges::mcols(inputsGR[[i]])[,
587589
nameOfColWithCate2],
588590
levels = rev(cateNames2)))
591+
if(plotProportion && ! i %in% c(3, 5)){
592+
if(i < 3){
593+
t2 <- table(factor(GenomicRanges::mcols(inputsGR[[3]])[,
594+
nameOfColWithCate1],
595+
levels = rev(cateNames1)),
596+
factor(GenomicRanges::mcols(inputsGR[[3]])[,
597+
nameOfColWithCate2],
598+
levels = rev(cateNames2)))
599+
} else {
600+
t2 <- table(factor(GenomicRanges::mcols(inputsGR[[5]])[,
601+
nameOfColWithCate1],
602+
levels = rev(cateNames1)),
603+
factor(GenomicRanges::mcols(inputsGR[[5]])[,
604+
nameOfColWithCate2],
605+
levels = rev(cateNames2)))
606+
607+
}
608+
line2 <- paste0(round(sum(t1) / sum(t2) * 100), "% of peaks")
609+
t1 <- t1 / t2
610+
t1[is.nan(t1)] <- 0
611+
number_format <- "%.2f"
612+
} else {
613+
line2 <- paste0(sum(t1), " peaks")
614+
number_format <- "%d"
615+
}
589616
# We plot it
590617
pheatmap::pheatmap(t1, cluster_rows = F, cluster_cols = F,
591-
main = paste0(inputsGRWhat[[i]], "\n", sum(t1),
592-
" peaks\n", what1, " vs ", what2,
618+
main = paste0(inputsGRWhat[[i]], "\n", line2, "\n", what1, " vs ", what2,
593619
"\nset:", stringSet, "\nref:", nameOfRef),
594620
display_numbers = T,
595-
number_format = "%d",
621+
number_format = number_format,
596622
fontsize = fontsize)
597623
}
598624
}
@@ -614,6 +640,7 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
614640
#' 4=shared by all Ref in not a single of the set or Ref in not a single of the set
615641
#' 5=shared by all Ref: all or all Ref
616642
#' (default is 1:5)
643+
#' @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)
617644
#' @param allCates a vector of string with the categories to plot, if NULL all categories in `myGRAndAttributes` are used (default is NULL)
618645
#' @param display_numbers logical whether to display the numbers in the pheatmaps (default is TRUE)
619646
#' @return Plot barplots and pheatmaps but do not return anything
@@ -625,7 +652,8 @@ plotCateComparisonSetAndRef <- function(myGRAndAttributes, fontsize = 10,
625652
plotPheatmaps = TRUE,
626653
display_numbers = TRUE,
627654
whichPheatmaps = 1:5,
628-
allCates = NULL){
655+
allCates = NULL,
656+
plotProportion = FALSE){
629657
if (is.null(allCates)){
630658
allCates <- myGRAndAttributes[["allCates"]]
631659
}
@@ -661,7 +689,8 @@ plotCateComparisonSetAndRef <- function(myGRAndAttributes, fontsize = 10,
661689
myGRAndAttributes[["nameOfRef"]],
662690
fontsize = fontsize,
663691
display_numbers = display_numbers,
664-
whichPheatmaps = whichPheatmaps)
692+
whichPheatmaps = whichPheatmaps,
693+
plotProportion = plotProportion)
665694
}
666695
}
667696
}

man/plotAllPheatmapsFor2CategoriesFromMyGR.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotCateComparisonSetAndRef.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/getting-started-with-analysePeaks.Rmd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ plotCateComparisonSetAndRef(myList2, fontsize = 6)
687687
# dev.off()
688688
```
689689

690+
```{r}
691+
# You can also replot heatmaps as proportion:
692+
plotCateComparisonSetAndRef(myList2, plotBarPlots = F, plotProportion = T, fontsize = 6)
693+
```
694+
695+
690696
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%.
691697

692698
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.

0 commit comments

Comments
 (0)