使用 XENA下載的TCGA-LAML.mutect2_snv.tsv文件繪製基因詞雲和突變景觀圖。
有小夥伴在https://mp.weixin.qq.com/s/DvX_pKPF9bCcNqc3u6rTuw這個帖子下面留言說使用 maftools 的 genecloud函數繪製基因雲圖時,報錯提示沒有這個函數,然後還提到 http://bioconductor.org/packages/release/bioc/vignettes/maftools/inst/doc/maftools.html 官方文檔中也沒有genecloud,,也許是我的版本比較早所以還有吧,,,
雖然genecloud無法繪製,但是可以使用wordcloud2繪製,同樣很簡單
1.1 加載R包和數據將XENA下載後的數據TCGA-LAML.mutect2_snv.tsv.gz解壓,然後直接讀入
#一鍵清空
rm(list = ls())
#載入R包
library(tidyverse)
#讀入數據
mut <- read.table("TCGA-LAML.mutect2_snv.tsv",sep = "\t" , header = T,
stringsAsFactors = FALSE ,
check.names = FALSE)
head(mut,2)1.2 計算基因頻次,繪製詞雲
#計算每個基因出現的個數
mut2 <- mut %>% filter(effect %in% c("missense_variant","inframe_insertion")) %>%
select(Sample_ID,gene) %>%
group_by(gene) %>%
summarise(Freq = n()) %>%
arrange(desc(Freq))
head(mut2)
####繪製基因詞雲#####
library(wordcloud2)
#繪製頻次大於等於5的
da <- subset(mut2,Freq >= 5) #、
wordcloud2(da)
1.3 maf文件繪製詞雲圖如果使用maftools中的maf文件繪製呢?首先根據maftools|TCGA腫瘤突變數據的匯總,分析和可視化得到了laml數據,那麼可以用以下方式獲得基因雲圖
library(wordcloud2)
data2 <- as.data.frame(table(laml@data$Hugo_Symbol))
da2 <- subset(data2,Freq >= 3) #3就是minMut參數的值
wordcloud2(da2)
2.1 提取基因提取 1.2中突變頻次較高的基因,進行繪製
mut3 <- mut %>% filter(gene %in% da$gene) %>%
select(Sample_ID,gene,effect) %>%
#只選擇"missense_variant","inframe_insertion"兩種類型
filter(effect %in% c("missense_variant","inframe_insertion")) %>%
unique()
#轉成繪製熱圖的數據形式(寬型數據)
library(reshape2)
mut3_dcast <- mut3 %>% dcast(Sample_ID ~ gene,value.var='effect') %>%
dplyr::select(Sample_ID, da$gene) %>%
column_to_rownames("Sample_ID") %>%
t()2.2 ComplexHeatmap繪製突變景觀圖library(ComplexHeatmap)
library(circlize)
mat <- mut3_dcast
mat[is.na(mat)]<-""
mat[1:6,1:6]
oncoPrint(mat)2.3 景觀圖調整#指定顏色, 調整顏色代碼即可
col <- c( "missense_variant" = "blue" , "inframe_insertion" = "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))
},
missense_variant = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = col["missense_variant"], col = NA))
},
inframe_insertion = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h*0.33,
gp = gpar(fill = col["inframe_insertion"], col = NA))
}
)
#指定變異類型的標籤,和數據中的類型對應
heatmap_legend_param <- list(title = "Alternations",
at = c("missense_variant","inframe_insertion"),
labels = c( "missense_variant","inframe_insertion"))
#設定標題
column_title <- "This is Oncoplot "
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)更多參數參考ComplexHeatmap|根據excel表繪製突變景觀圖(oncoplot)。
【覺得不錯,右下角點個「在看」,期待您的轉發,謝謝!】