Skip to content

Commit

Permalink
Merge pull request #314 from zhewa/master
Browse files Browse the repository at this point in the history
moduleHeatmap
  • Loading branch information
zhewa authored Nov 8, 2020
2 parents cb5fb87 + 452a8a0 commit 2871163
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
45 changes: 29 additions & 16 deletions R/moduleHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@
#' @param unit Passed to \link[multipanelfigure]{multi_panel_figure}. Single
#' character object defining the unit of all dimensions defined.
#' @param ... Additional parameters passed to \link[ComplexHeatmap]{Heatmap}.
#' @return A \link[multipanelfigure]{multi_panel_figure} object.
#' @return A \link[multipanelfigure]{multi_panel_figure} object if plotting
#' more than one module heatmaps. Otherwise a
#' \link[ComplexHeatmap]{HeatmapList} object is returned.
#' @importFrom methods .hasSlot
#' @importFrom multipanelfigure multi_panel_figure
#' @export
Expand Down Expand Up @@ -155,6 +157,12 @@ setMethod("moduleHeatmap",
featureModule <- sort(unique(celdaModules(x)))
}

if (length(featureModule) == 1) {
returnHeatmap <- TRUE
} else {
returnHeatmap <- FALSE
}

if (moduleLabel == "auto") {
moduleLabel <- paste0("Module ", as.character(featureModule))
} else if (length(moduleLabel) != length(unique(celdaModules(x,
Expand Down Expand Up @@ -227,25 +235,30 @@ setMethod("moduleHeatmap",
... = ...)
}

ncol <- floor(sqrt(length(plts)))
nrow <- ceiling(length(plts) / ncol)
if (isTRUE(returnHeatmap)) {
return(plts[[1]])
} else {
ncol <- floor(sqrt(length(plts)))
nrow <- ceiling(length(plts) / ncol)

for (i in seq(length(plts))) {
plts[[i]] <- grid::grid.grabExpr(ComplexHeatmap::draw(plts[[i]]),
wrap.grobs = TRUE)
}
for (i in seq(length(plts))) {
plts[[i]] <- grid::grid.grabExpr(
ComplexHeatmap::draw(plts[[i]]),
wrap.grobs = TRUE)
}

figure <- multipanelfigure::multi_panel_figure(columns = ncol,
rows = nrow,
width = width,
height = height,
unit = unit)
figure <- multipanelfigure::multi_panel_figure(columns = ncol,
rows = nrow,
width = width,
height = height,
unit = unit)

for (i in seq(length(plts))) {
figure <- suppressMessages(multipanelfigure::fill_panel(figure,
plts[[i]], label = ""))
for (i in seq(length(plts))) {
figure <- suppressMessages(multipanelfigure::fill_panel(figure,
plts[[i]], label = ""))
}
suppressWarnings(return(figure))
}
suppressWarnings(return(figure))
}
)

Expand Down
4 changes: 3 additions & 1 deletion man/moduleHeatmap.Rd

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

0 comments on commit 2871163

Please sign in to comment.