#' rnagsvaheat function
#'
#' Uses ComplexHeatmap to draw heatmap for GSVA analysis
#'
#' @param pat2 data frame generated by rnasubset function
#' @param rnagsva data frame of GSVA values
#' @param rnasgsvasig data frame of significant gene sets from rnagsvasig function
#' @param gene character(1) Gene symbol of gene of interest
#'
#' @import data.table
#' @import ComplexHeatmap
#' @import circlize
#' @import grid
#'
#' @return ComplexHeatmap of top 100 significant gene sets
#'
#' @examples
#' data(skcm)
#' gene <- "SOX10"
#' sox10.pat <- rnasubset(pat, rna, gene, 5)
#' sox10.gsva <- rnagsva(sox10.pat, rna)
#' sox10.gsva.sig <- rnagsvasig(sox10.pat, sox10.gsva)
#' rnagsvaheat(sox10.pat, sox10.gsva, sox10.gsva.sig, gene)
#'
#' @export
#'
rnagsvaheat <- function(pat2, rna_gsva, rna_gsvasig, gene) {
setkey(pat2, gene2)
h1 <- rna_gsva[match(rownames(rna_gsvasig)[1:100], rownames(rna_gsva)),]
h1.t <- t(apply(h1, 1, scale))
colnames(h1.t) <- colnames(h1)
df <- data.frame(as.character(pat2[!("middle"),gene2]), stringsAsFactors = FALSE)
colnames(df) <- gene
cellcol <- c("#ca0020", "#0571b0")
names(cellcol) <- c(levels(pat2$gene2)[1], levels(pat2$gene2)[2])
col1 <- list(Cell = cellcol)
names(col1) <- gene
top_ha <- HeatmapAnnotation(df = df, col = col1)
h1.heat <- Heatmap(h1.t,
top_annotation = top_ha,
col = colorRamp2(c(-max(abs(range(h1.t))), 0, max(abs(range(h1.t)))), c("blue", "black", "orange")),
name = "color scale",
show_column_names = T,
row_names_gp = gpar(fontsize=6),
column_names_gp = gpar(fontsize=6),
row_names_max_width = unit(4, "cm"),
column_dend_reorder = as.factor(df[, 1])
)
draw(h1.heat, heatmap_legend_side = "left", annotation_legend_side = "left")
for(an in colnames(df)) {
decorate_annotation(an, {
# annotation names on the right
grid.text(an, unit(1, "npc") + unit(2, "mm"), 0.5, default.units = "npc", just = "left")
# annotation names on the left
#grid.text(an, unit(0, "npc") - unit(2, "mm"), 0.5, default.units = "npc", just = "right")
})
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.