Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moduleHeatmap #314

Merged
merged 2 commits into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.