ComplexHeatmap画基因突变热图(一)

数据格式如下:


image.png

若某个基因在某个样本中既有deletion又有mutation则以;分隔

library(ComplexHeatmap)
library(RColorBrewer)
setwd("E:/project/r")
data1<-read.csv("test_1.csv",header = T,stringsAsFactors = F,row.names = 1)            
col = c("deletion" = "#1F78B4", "insertion" = "#33A02C", "mutation" = "#E31A1C")
alter_fun = function(x, y, w, h, v) {
  n=sum(v)
  h=h*0.9
  grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"), gp = gpar(fill = "#CCCCCC", col = NA))
  if(v["mutation"])  grid.rect(x, y - h*0.5 + 0.95:n/n*h, w*1, 1/n*h,  gp = gpar(fill = col[names(which(v))], col = NA), just = "top")
  if(v["insertion"])    grid.rect(x, y - h*0.5 + 0.95:n/n*h, w*1, 1/n*h,  gp = gpar(fill = col[names(which(v))], col = NA), just = "top")
  if(v["deletion"])    grid.rect(x, y - h*0.5 + 0.95:n/n*h, w*1, 1/n*h,  gp = gpar(fill = col[names(which(v))], col = NA), just = "top")
}
oncoPrint(data1, get_type = function(x) strsplit(x, ";")[[1]],
          alter_fun = alter_fun, col = col,  row_order = NULL, column_order = NULL, show_column_names = TRUE,
          show_pct = TRUE, show_row_barplot = TRUE,         
          heatmap_legend_param = list(title = "Alternations", at = c("insertion", "mutation", "deletion"), labels = c("insertion", "mutation", "deletion")))

结果如下:


Rplot.png

其中oncoPrint()中有些参数可选,可以选择是否隐藏顶部或者左右两边的部分,例如:
如果设置这几个参数
show_pct = FALSE, show_row_barplot = FALSE, top_annotation = NULL
那么最后出来的结果就会是这样的:


Rplot01.png

你可能感兴趣的:(ComplexHeatmap画基因突变热图(一))