本文首發於“生信補給站”:https://mp.weixin.qq.com/s/8kz2oKvUQrCR2_HWYXQT4g
如果有maf格式的文件,可以直接oncoplot包繪制瀑布圖,有多種展示和統計maftools | 從頭開始繪制發表級oncoplot(瀑布圖)和maftools|TCGA腫瘤突變數據的匯總,分析和可視化,如果只有多個樣本的基因突變與否的excel,不用擔心,也可以用complexheatmap包繪制。
這個包功能很強大,本次只簡單的介紹如何繪制基因組景觀圖(瀑布圖)。
一 載入R包,數據
#if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install("ComplexHeatmap")
#install.packages("openxlsx")
#install.packages("circlize")
#后面直接加載即可
library(openxlsx)
library(ComplexHeatmap)
library(circlize)
#讀入數據
mut <- read.xlsx("TCGA_data.xlsx",sheet = "突變信息")
cli <- read.xlsx("TCGA_data.xlsx",sheet = "臨床信息")
查看變異數據
rownames(mut) <- mut$sample
mat <- mut[,-1]
mat[is.na(mat)]<-""
mat[1:6,1:6]
二 繪制突變景觀圖
2.0 繪制“初始”瀑布圖
oncoPrint(mat)
可以展示結果,但是為了paper,還需要一些調整!
2.1 指定變異類型的顏色和形狀大小
#指定顏色, 調整顏色代碼即可
col <- c( "mutation" = "blue" , "indel" = "green")
#指定變異的樣子,x,y,w,h代表變異的位置(x,y)和寬度(w),高度(h)
alter_fun <- list(
background = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = "#CCCCCC", col = NA))
},
mutation = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = col["mutation"], col = NA))
},
indel = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h*0.33,
gp = gpar(fill = col["indel"], col = NA))
}
)
#指定變異類型的標簽,和數據中的類型對應
heatmap_legend_param <- list(title = "Alternations",
at = c("mutation","indel"),
labels = c( "mutation","indel"))
繪制景觀圖
#設定標題
column_title <- "This is Oncoplot "
#畫圖並去除無突變的樣本和基因
oncoPrint(mat,
alter_fun = alter_fun, col = col,
column_title = column_title,
heatmap_legend_param = heatmap_legend_param)
2.2 簡單的調整
oncoPrint(mat,
alter_fun = alter_fun, col = col,
column_title = column_title,
remove_empty_columns = TRUE, #去掉空列
remove_empty_rows = TRUE, #去掉空行
row_names_side = "left", #基因在左
pct_side = "right",
heatmap_legend_param = heatmap_legend_param)
三 添加注釋信息
3.1 指定臨床注釋信息
pdata <- cli
head(pdata)
#對應患者
pdata <- subset(pdata,pdata$sampleID %in% colnames(mat))
mat <- mat[, pdata$sampleID]
#定義注釋信息
ha<-HeatmapAnnotation(Age=pdata$age,
Gender=pdata$gender,
GeneExp_Subtype = pdata$GeneExp_Subtype ,
censor = pdata$censor,
os = pdata$os,
show_annotation_name = TRUE,
annotation_name_gp = gpar(fontsize = 7))
3.2 瀑布圖 + 臨床注釋
oncoPrint(mat,
bottom_annotation = ha, #注釋信息在底部
alter_fun = alter_fun, col = col,
column_title = column_title, heatmap_legend_param = heatmap_legend_param )
此處使用默認顏色注釋,有時候會比較接近,且“變動”
#自定義樣本順序
s <- pdata[order(pdata$censor,pdata$GeneExp_Subtype),]
sample_order <- as.character(s$sampleID)
#自定義顏色
#連續性變量設置顏色(外)
col_os = colorRamp2(c(0, 4000), c("white", "red"))
ha<-HeatmapAnnotation(Age=pdata$age,
Gender=pdata$gender,
GeneExp_Subtype = pdata$GeneExp_Subtype ,
censor = pdata$censor,
os = pdata$os,
#指定顏色
col = list(censor = c("death" = "red", "alive" = "blue"),
GeneExp_Subtype = c("Classical" = "orange","Mesenchymal" = "green","Neural" = "skyblue" ),
os = col_os),
show_annotation_name = TRUE,
annotation_name_gp = gpar(fontsize = 7))
繪制瀑布圖
oncoplot_anno = oncoPrint(mat,bottom_annotation = ha,
alter_fun = alter_fun, col = col,
column_order = sample_order,
remove_empty_columns = TRUE, #去掉空列
remove_empty_rows = TRUE, #去掉空行
column_title = column_title, heatmap_legend_param = heatmap_legend_param)
oncoplot_anno
注:顏色不一定好看,只是為了當默認的顏色比較接近時,或者有要求時候,可以自定義。
3.4 調整注釋的位置
draw(oncoplot_anno ,annotation_legend_side = "bottom")
更改注釋的位置,方便后續拼圖需求。
更多參數:
https://github.com/jokergoo/ComplexHeatmap
PS:覺得內容有幫助的話,可以點點在看和轉發,新機制下容易失蹤。