## ----, echo = FALSE, message = FALSE------------------------------------- library(markdown) options(markdown.HTML.options = c(options('markdown.HTML.options')[[1]], "toc")) library(knitr) knitr::opts_chunk$set( error = FALSE, tidy = FALSE, message = FALSE, fig.align = "center") options(markdown.HTML.stylesheet = "custom.css") options(width = 100) ## ----, echo = FALSE, message = FALSE------------------------------------- suppressPackageStartupMessages(library(EnrichedHeatmap)) ## ----, eval = FALSE------------------------------------------------------ ## library(EnrichedHeatmap) ## ------------------------------------------------------------------------ set.seed(123) load(paste0(system.file("extdata", "chr21_test_data.RData", package = "EnrichedHeatmap"))) ls() ## ----h3k4me3, fig.width = 3---------------------------------------------- tss = promoters(genes, upstream = 0, downstream = 1) tss[1:5] H3K4me3[1:5] mat1 = normalizeToMatrix(H3K4me3, tss, value_column = "coverage", extend = 5000, mean_mode = "w0", w = 50) mat1 EnrichedHeatmap(mat1, name = "H3K4me3") ## ----anno, fig.width = 3------------------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", top_annotation = HeatmapAnnotation(lines = anno_enriched()), top_annotation_height = unit(2, "cm")) ## ----smooth, fig.width = 3----------------------------------------------- library(circlize) mat1_smoothed = normalizeToMatrix(H3K4me3, tss, value_column = "coverage", extend = 5000, mean_mode = "w0", w = 50, smooth = TRUE) # note we set the color range same as the unsmoothed matrix EnrichedHeatmap(mat1_smoothed, col = colorRamp2(range(mat1), c("white", "red")), name = "H3K4me3") ## ----split, fig.width = 3------------------------------------------------ EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", split = sample(c("A", "B"), length(genes), replace = TRUE), column_title = "Enrichment of H3K4me3") ## ----kmeans, fig.width = 4----------------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", km = 3, column_title = "Enrichment of H3K4me3", row_title_rot = 0) ## ----, kmeans_anno, fig.width = 4---------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", # note we have three row-clusters, so we assign three colors for the annotation lines top_annotation = HeatmapAnnotation(lines = anno_enriched(gp = gpar(col = 2:4))), top_annotation_height = unit(2, "cm"), km = 3, row_title_rot = 0) ## ----, cluster, fig.width = 3-------------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", cluster_rows = TRUE, show_row_dend = FALSE, column_title = "Enrichment of H3K4me3") ## ----aixs, fig.width = 3------------------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", pos_line_gp = gpar(col = "blue", lwd = 2), axis_name = c("-5kb", "TSS", "5kb"), axis_name_rot = -45, border = FALSE) ## ----extend, fig.width = 3----------------------------------------------- # upstream 1kb, downstream 2kb mat12 = normalizeToMatrix(H3K4me3, tss, value_column = "coverage", extend = c(1000, 2000), mean_mode = "w0", w = 50) EnrichedHeatmap(mat12, name = "H3K4me3", col = c("white", "red")) ## ----meth, fig.width = 3------------------------------------------------- meth[1:5] mat2 = normalizeToMatrix(meth, tss, value_column = "meth", mean_mode = "absolute", extend = 5000, w = 50, empty_value = 0.5) EnrichedHeatmap(mat2, name = "methylation", column_title = "methylation near TSS") ## ----meth2, fig.width = 3------------------------------------------------ mat2 = normalizeToMatrix(meth, tss, value_column = "meth", mean_mode = "absolute", extend = 5000, w = 50, empty_value = NA, smooth = TRUE) EnrichedHeatmap(mat2, name = "methylation", column_title = "methylation near TSS") ## ----cgi, fig.width = 3-------------------------------------------------- mat3 = normalizeToMatrix(meth, cgi, value_column = "meth", mean_mode = "absolute", extend = 5000, w = 50, empty_value = NA, smooth = TRUE) EnrichedHeatmap(mat3, name = "methylation", column_title = "methylation near CGI") ## ----fat_cgi, fig.width = 3---------------------------------------------- mat3 = normalizeToMatrix(meth, cgi, value_column = "meth", mean_mode = "absolute", extend = 5000, w = 50, empty_value = NA, smooth = TRUE, target_ratio = 0.3) EnrichedHeatmap(mat3, name = "methylation", axis_name_rot = 90, column_title = "methylation near CGI") ## ----list, fig.width = 6------------------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", width = 1) + EnrichedHeatmap(mat2, name = "methylation", width = 1) + Heatmap(log2(rpkm+1), col = c("white", "orange"), name = "log2(rpkm+1)", show_row_names = FALSE, width = unit(5, "mm")) ## ----list_split, fig.width = 7------------------------------------------- EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", km = 3, width = 1, top_annotation = HeatmapAnnotation(lines = anno_enriched()), top_annotation_height = unit(2, "cm"), row_title_rot = 0, column_title = "H3K4me3") + EnrichedHeatmap(mat2, name = "methylation", width = 1, column_title = "Methylation") + Heatmap(log2(rpkm+1), col = c("white", "orange"), name = "log2(rpkm+1)", show_row_names = FALSE, width = unit(5, "mm")) ## ------------------------------------------------------------------------ load(paste0(system.file("/extdata/neg_cr.RData", package = "EnrichedHeatmap"))) all_tss = promoters(all_genes, upstream = 0, downstream = 1) all_tss = all_tss[unique(neg_cr$gene)] neg_cr all_tss ## ----neg_cr, fig.width = 3----------------------------------------------- mat4 = normalizeToMatrix(neg_cr, all_tss, mapping_column = "gene", w = 50, mean_mode = "w0") EnrichedHeatmap(mat4, col = c("white", "green"), name = "neg_cr", cluster_rows = TRUE, top_annotation = HeatmapAnnotation(lines = anno_enriched(gp = gpar(col = "green"))), top_annotation_height = unit(2, "cm")) ## ----neg_cr_with_tx, fig.width = 6--------------------------------------- mat5 = normalizeToMatrix(tx, all_tss, mapping_column="gene", w = 50, mean_mode = "w0") ht_list = EnrichedHeatmap(mat4, col = c("white", "green"), name = "neg_cr", cluster_rows = TRUE, top_annotation = HeatmapAnnotation(lines1 = anno_enriched(gp = gpar(col = "green"))), top_annotation_height = unit(2, "cm")) + EnrichedHeatmap(mat5, col = c("white", "black"), name = "tx", top_annotation = HeatmapAnnotation(lines2 = anno_enriched(gp = gpar(col = "black"))), top_annotation_height = unit(2, "cm")) draw(ht_list, gap = unit(1, "cm")) ## ----, eval = FALSE------------------------------------------------------ ## ht_list = draw(ht_list) ## row_order(ht_list) ## ----, eval = FALSE------------------------------------------------------ ## draw(ht_list) ## pos = select() ## ----, eval = FALSE------------------------------------------------------ ## EnrichedHeatmap(..., column_title_gp = ...) ## ----, eval = FALSE------------------------------------------------------ ## EnrichedHeatmap(..., heatmap_legend_param = ...) ## # or set is globally ## ht_global_opt(...) ## EnrichedHeatmap(...) ## ht_global_opt(RESET = TRUE) ## ----, eval = FALSE------------------------------------------------------ ## EnrichedHeatmap(..., width = unit(...)) + EnrichedHeatmap(...) ## ------------------------------------------------------------------------ sessionInfo()