@@ -501,6 +501,13 @@ plotAllBarPlotForCategoriesFromMyGR <- function(myGRs, nameOfColWithCate,
501501# ' @param nameOfRef the name of the reference
502502# ' @param fontsize base fontsize for the heatmaps (default is 10)
503503# ' @param display_numbers logical whether to display the numbers in the pheatmaps (default is TRUE)
504+ # ' @param whichPheatmaps a vector containing the pheatmaps to plot between 1 to 5 with:
505+ # ' 1=shared by all Set and at least one Ref or shared by all Set and Ref
506+ # ' 2=shared by all Set none of the Ref or shared by all Set no Ref
507+ # ' 3=shared by all Set: all or all shared by all Set
508+ # ' 4=shared by all Ref in not a single of the set or Ref in not a single of the set
509+ # ' 5=shared by all Ref: all or all Ref
510+ # ' (default is 1:5)
504511# ' @return Plot but do not return anything
505512# ' @importFrom pheatmap pheatmap
506513# ' @export
@@ -511,10 +518,14 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
511518 what2 ,
512519 stringSet , nameOfRef ,
513520 fontsize = 10 ,
514- display_numbers = T ){
521+ display_numbers = T ,
522+ whichPheatmaps = 1 : 5 ){
515523 if (length(myGRs ) < 2 ){
516524 stop(" Wrong myGRs\n " )
517525 }
526+ if (any(whichPheatmaps > 5 ) | any(whichPheatmaps < 1 )){
527+ stop(" Invalid whichPheatmap:" , whichPheatmaps , " should be between 1 and 5." )
528+ }
518529 if (! " inUniqueRef" %in% colnames(GenomicRanges :: mcols(myGRs [[1 ]]))){
519530 if (! " inNoneOfTheRef" %in% colnames(GenomicRanges :: mcols(myGRs [[1 ]]))){
520531 stop(" myGRs[[1]] does not contains inUniqueRef nor inNoneOfTheRef\n " )
@@ -567,7 +578,7 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
567578 inputsGR [[5 ]] <- myGRs [[2 ]]
568579 inputsGRWhat [[5 ]] <- labels [5 ]
569580
570- for (i in 1 : length( inputsGR ) ){
581+ for (i in whichPheatmaps ){
571582 # We make the table using the 2 categories
572583 t1 <- table(factor (GenomicRanges :: mcols(inputsGR [[i ]])[,
573584 nameOfColWithCate1 ],
@@ -596,6 +607,14 @@ plotAllPheatmapsFor2CategoriesFromMyGR <- function(myGRs, nameOfColWithCate1,
596607# ' @param plotBarPlots logical whether to plot the barplots (default is TRUE)
597608# ' @param only5categoriesBP logical whether to plot only the barplots with 5 categories (default is FALSE).
598609# ' @param plotPheatmaps logical whether to plot the pheatmaps (default is TRUE)
610+ # ' @param whichPheatmaps a vector containing the pheatmaps to plot between 1 to 5 with:
611+ # ' 1=shared by all Set and at least one Ref or shared by all Set and Ref
612+ # ' 2=shared by all Set none of the Ref or shared by all Set no Ref
613+ # ' 3=shared by all Set: all or all shared by all Set
614+ # ' 4=shared by all Ref in not a single of the set or Ref in not a single of the set
615+ # ' 5=shared by all Ref: all or all Ref
616+ # ' (default is 1:5)
617+ # ' @param allCates a vector of string with the categories to plot, if NULL all categories in `myGRAndAttributes` are used (default is NULL)
599618# ' @param display_numbers logical whether to display the numbers in the pheatmaps (default is TRUE)
600619# ' @return Plot barplots and pheatmaps but do not return anything
601620# ' @importFrom GenomicRanges mcols
@@ -604,8 +623,12 @@ plotCateComparisonSetAndRef <- function(myGRAndAttributes, fontsize = 10,
604623 plotBarPlots = TRUE ,
605624 only5categoriesBP = FALSE ,
606625 plotPheatmaps = TRUE ,
607- display_numbers = TRUE ){
608- allCates <- myGRAndAttributes [[" allCates" ]]
626+ display_numbers = TRUE ,
627+ whichPheatmaps = 1 : 5 ,
628+ allCates = NULL ){
629+ if (is.null(allCates )){
630+ allCates <- myGRAndAttributes [[" allCates" ]]
631+ }
609632 myGRs <- myGRAndAttributes [[" myGRs" ]]
610633 if (plotBarPlots ){
611634 for (i in 1 : length(allCates )){
@@ -624,19 +647,22 @@ plotCateComparisonSetAndRef <- function(myGRAndAttributes, fontsize = 10,
624647 }
625648 }
626649 if (plotPheatmaps ){
627- for (i in 1 : length(allCates )){
628- for (j in setdiff(1 : length(allCates ), i )){
629- plotAllPheatmapsFor2CategoriesFromMyGR(myGRs ,
630- allCates [[i ]][[" nameOfCol" ]],
631- allCates [[i ]][[" cateNames" ]],
632- allCates [[i ]][[" what" ]],
633- allCates [[j ]][[" nameOfCol" ]],
634- allCates [[j ]][[" cateNames" ]],
635- allCates [[j ]][[" what" ]],
636- myGRAndAttributes [[" stringSet" ]],
637- myGRAndAttributes [[" nameOfRef" ]],
638- fontsize = fontsize ,
639- display_numbers = display_numbers )
650+ if (length(allCates ) > 1 ){
651+ for (i in 1 : length(allCates )){
652+ for (j in setdiff(1 : length(allCates ), i )){
653+ plotAllPheatmapsFor2CategoriesFromMyGR(myGRs ,
654+ allCates [[i ]][[" nameOfCol" ]],
655+ allCates [[i ]][[" cateNames" ]],
656+ allCates [[i ]][[" what" ]],
657+ allCates [[j ]][[" nameOfCol" ]],
658+ allCates [[j ]][[" cateNames" ]],
659+ allCates [[j ]][[" what" ]],
660+ myGRAndAttributes [[" stringSet" ]],
661+ myGRAndAttributes [[" nameOfRef" ]],
662+ fontsize = fontsize ,
663+ display_numbers = display_numbers ,
664+ whichPheatmaps = whichPheatmaps )
665+ }
640666 }
641667 }
642668 }
0 commit comments