@@ -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 " \n set:" , stringSet , " \n ref:" , 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 }
0 commit comments