if(!requireNamespace('BiocManager',quietly = T)) install.packages("BiocManager")
BiocManager::install("ComplexHeatmap")
library(ComplexHeatmap)
library(circlize)
mat <- read.table(system.file('extdata', package = "ComplexHeatmap", "tcga_lung_adenocarcinoma_provisional_ras_raf_mek_jnk_signalling.txt"),
                  header = T, stringsAsFactors = F, sep = '\t')
mat[is.na(mat)] <- ''
rownames(mat) <- mat[,1]
mat <- mat[,-1]
mat <- mat[, -ncol(mat)]
mat <- t(as.matrix(mat))
mat[1:4,1:4]
##      TCGA-05-4384-01 TCGA-05-4390-01 TCGA-05-4425-01 TCGA-38-4631-01
## KRAS "  "            "MUT;"          "  "            "  "           
## HRAS "  "            "  "            "  "            "  "           
## BRAF "  "            "  "            "  "            "  "           
## RAF1 "  "            "  "            "  "            "  "

mat文件中含有:HOMDEL, AMP and MUT类型突变,对突变进行颜色和突变分类定义

col <- c("HOMDEL" = "#CEC937", "AMP" = "#F41702", "MUT" = "#21306E")
alter_fun <- list(
  background = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"), h - grid::unit(0.5,"mm"),gp=grid::gpar(fill = "#CCCCCC",col=NA))
  },
  HOMDEL = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h - grid::unit(0.5, "mm"),gp=grid::gpar(fill=col["HOMDEL"],col=NA))
  },
  AMP = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h - grid::unit(0.5,"mm"),gp = grid::gpar(fill=col["AMP"],col=NA))
  },
  MUT = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h*0.33, gp = grid::gpar(fill=col["MUT"],col = NA))
  }
)

column_titleheatmap_legend_param定义

column_title <- "OncoPrint for TCGA Lung Adenocarcinoma, genes in Ras Raf MEK JNK signaling"
heatmap_legend_param <- list(title = "Alternations", at = c("HOMDEL","AMP","MUT"),
                             labels = c("Depp deletion", "Amplification", "Mutation"))
oncoPrint(mat,alter_fun = alter_fun, col = col, column_title = column_title, heatmap_legend_param = heatmap_legend_param)

删除空行和空列 remove_empty_columns = TRUEremove_empty_rows = TRUE

oncoPrint(mat, alter_fun = alter_fun, col = col,remove_empty_columns = T, remove_empty_rows = T,
          column_title = column_title, heatmap_legend_param = heatmap_legend_param)

行和列排序 row_order = 1:nrow(mat), column_order = sample_order

sample_order <- scan(paste0(system.file("extdata",package = "ComplexHeatmap"),"/sample_order.txt"),what = "character")
oncoPrint(mat, alter_fun = alter_fun, col = col, row_order = 1:nrow(mat), column_order = sample_order,
          remove_empty_columns = T, remove_empty_rows = T,
          column_title = column_title, heatmap_legend_param = heatmap_legend_param)
## All mutation types: MUT, AMP, HOMDEL

行和列注释anno_oncoprint_barplot()可以对突变类型进行筛选绘制Bar图

oncoPrint(mat,
  alter_fun = alter_fun, col = col,
  top_annotation = HeatmapAnnotation(
    column_barplot = anno_oncoprint_barplot("MUT", border = T, height = unit(4,"cm"))
  ),
  right_annotation = rowAnnotation(
    row_barplot = anno_oncoprint_barplot(c("AMP","HOMDEL"),border = T,height = unit(4,"cm"),
                                         axis_param = list(side = "bottom", labels_rot = 90))
  ),
  remove_empty_columns = T, remove_empty_rows = T,
  column_title = column_title, heatmap_legend_param = heatmap_legend_param
)
## All mutation types: MUT, AMP, HOMDEL

对显示位置进行调整pct_side = “right”, row_names_side = “left”

oncoPrint(mat,
  alter_fun = alter_fun, col = col,
  remove_empty_columns = T, remove_empty_rows = T,
  pct_side = "right", row_names_side = "left",
  column_title = column_title, heatmap_legend_param = heatmap_legend_param
)
## All mutation types: MUT, AMP, HOMDEL

增加样品分组注释

oncoPrint(mat,
  alter_fun = alter_fun, col = col,
  remove_empty_columns = T, remove_empty_rows = T,
  top_annotation = HeatmapAnnotation(cbar = anno_oncoprint_barplot(), foo1 = 1:172, bar1 = anno_points(1:172)),
  left_annotation = rowAnnotation(foo2 = 1:26),
  right_annotation = rowAnnotation(bar2 = anno_barplot(1:26)),
  column_title = column_title, heatmap_legend_param = heatmap_legend_param
)
## All mutation types: MUT, AMP, HOMDEL