將多圖組合到一起;用到R包ComplexHeatmap;
此圖中包含兩種基本圖,一種是基因瀑布圖,另外一種是熱圖。
腳本如下:
setwd("F:/work/個性化/基因瀑布圖")
test<-read.delim("test.txt",?header=TRUE?,check.names?=?F)
#此處讀取的是四個文件的基因交集,只有一列基因,這樣最后呈現(xiàn)的圖的樣本和基因個數(shù)一樣。
library(ComplexHeatmap)
png("test.png",type="cairo",width=2000,height=800)
color.1?<-?colorRampPalette(rev(c("red",?"white",?"#3CB34E")))(100)
data<-?read.delim("mRNA_fpkm.list",?row.names?=?1,?header=TRUE?,check.names?=?F)
row.names(data)<-data$Symbol
data<-data[which(rownames(data)%in%test$gene_symbol),]
data=?data[,?-1]
data?<-?log10(data+0.000001)
data<-as.matrix(data)
ht1<-Heatmap(data,col=color.1,cluster_columns??=?T,cluster_rows?=?F,name="gene",column_title?=?"gene",show_row_names?=?T,show_column_names?=?T)
#此處既顯示樣品名又顯示基因名
col<-c("frameshift_mutation"="red","other"="#3CB34E","nonsynonymous_SNV"="red")
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))
??},
??frameshift_mutation=function(x,y,w,h){
????grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"),
??????????????gp=gpar(fill=col["frameshift_mutation"],col=NA))
??},
??other=function(x,y,w,h){
????grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"),
??????????????gp=gpar(fill=col["other"],col=NA))
??},
??nonsynonymous_SNV=function(x,y,w,h){
????grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"),
??????????????gp=gpar(fill=col["nonsynonymous_SNV"],col=NA))
??}
)
library(do)
mat?<-read.table("indel_keygene.xls",head=T,sep="\t",stringsAsFactors?=?FALSE)
#此處導入處理后的indel文件,格式如圖:
rownames(mat)<-mat$Gene
mat<-mat[which(rownames(mat)%in%test$gene_symbol),]
mat<-mat[,-1]
mat[is.na(mat)]<-""
mat<-Replace(mat,from?=?"^.$",to?=?"?",pattern?=?"")
#此處Replace是R包do中的函數(shù),將文件中的內(nèi)容替換成自己所需要的內(nèi)容
mat<-Replace(mat,from?=?"^,.",to?=?"?",pattern?=?"")
mat<-Replace(mat,from?=?",.$",to?=?"?",pattern?=?"")
mat<-Replace(mat,from?=?"^.,",to?=?"?",pattern?=?"")
mat<-Replace(mat,from?=?"nonframeshift?deletion,frameshift?deletion",to?=?"frameshift_mutation",pattern?=?"")
mat<-Replace(mat,from?=?"frameshift?deletion,nonframeshift?deletion",to?=?"frameshift_mutation",pattern?=?"")
mat<-Replace(mat,from?=?"nonframeshift?deletion",to?=?"other",pattern?=?"")
mat<-Replace(mat,from?=?"nonframeshift?insertion",to?=?"other",pattern?=?"")
mat<-Replace(mat,from?=?"frameshift?deletion",to?=?"frameshift_mutation",pattern?=?"")
mat<-Replace(mat,from?=?"frameshift?insertion",to?=?"frameshift_mutation",pattern?=?"")
mat<-Replace(mat,from?=?"unknown",to?=?"other",pattern?=?"")
#oncoPrint(mat)
#指定變異類型的標簽,和數(shù)據(jù)中的類型對應
heatmap_legend_param<-list(title="Indel",at=c("frameshift_mutation",?"other"),labels=c("frameshift_mutation",?"other"))
#設(shè)定標題
column_title<-"Indel?Oncoplot"
ht2<-oncoPrint(mat,alter_fun?=?alter_fun,col=col,column_title=column_title,heatmap_legend_param?=?heatmap_legend_param,remove_empty_columns?=?F,remove_empty_rows?=?F,show_column_names?=?T,show_row_names?=T)
mat?<-read.table("keygene.SNP.xls",head=T,sep="\t",stringsAsFactors?=?FALSE)
#導入SNP文件,格式如圖
rownames(mat)<-mat$Gene
mat<-mat[which(rownames(mat)%in%test$gene_symbol),]
mat<-mat[,-1]
mat[is.na(mat)]<-""
#mat<-str_replace("nonframeshift?insertion","other","")
mat<-Replace(mat,from?=?"^.$",to?=?"",pattern?=?"")
mat<-Replace(mat,from?=?"^,.",to?=?"",pattern?=?"")
mat<-Replace(mat,from?=?",.$",to?=?"",pattern?=?"")
mat<-Replace(mat,from?=?"^.,",to?=?"",pattern?=?"")
mat<-Replace(mat,from?=?"stopgain",to?=?"other",pattern?=?"")
mat<-Replace(mat,from?=?"stoploss",to?=?"other",pattern?=?"")
mat<-Replace(mat,from?=?"unknown",to?=?"other",pattern?=?"")
mat<-Replace(mat,from?=?"^synonymous?SNV$",to?=?"other",pattern?=?"")
mat<-Replace(mat,from?=?"^nonsynonymous?SNV$",to?=?"nonsynonymous_SNV",pattern?=?"")
mat<-Replace(mat,from?=?"synonymous?SNV,nonsynonymous?SNV",to?=?"nonsynonymous_SNV",pattern?=?"")
mat<-Replace(mat,from?=?"nonsynonymous?SNV,synonymous?SNV",to?=?"nonsynonymous_SNV",pattern?=?"")
#oncoPrint(mat)
mat<-as.matrix(mat)
#指定變異類型的標簽,和數(shù)據(jù)中的類型對應
heatmap_legend_param<-list(title="SNP",at=c("nonsynonymous_SNV",?"other"),labels=c("nonsynonymous_SNV",?"other"))
#設(shè)定標題
column_title<-"SNP?Oncoplot"
ht3<-oncoPrint(mat,alter_fun?=?alter_fun,col=col,column_title=column_title,heatmap_legend_param?=?heatmap_legend_param,remove_empty_columns?=?F,remove_empty_rows?=?F,show_column_names?=?T,show_row_names?=T)
data<-?read.delim("ATAC_promoter_1kb.xls",?row.names?=?1,?header=TRUE?,check.names?=?F)
row.names(data)<-data$gene_symbol
data<-data[which(rownames(data)%in%test$gene_symbol),]
data=?data[,?5:19]
data[is.na(data)]<-0
data<-data[which(rowSums(data)>0),]
data?<-?log10(data+0.000001)
data<-as.matrix(data)
library(ComplexHeatmap)
color.1?<-?colorRampPalette(rev(c("red",?"white",?"#3CB34E")))(100)
ht4<-Heatmap(data,col=color.1,cluster_columns??=?T,cluster_rows?=?F,name?=?"ATAC_promoter_1kb",column_title?=?"ATAC_promoter_1kb",show_row_names?=?T,show_column_names?=?T)
draw(ht1+ht2+ht3+ht4,gap=unit(0.8,"cm"))
dev.off()
其中需要注意的是當有多個基因瀑布圖時,alter_fun和col需在同一條命令中設(shè)置。通過以上一頓操作,快速將基因瀑布圖和熱圖組合在一起,既展示了基因的結(jié)構(gòu)變異、開放狀態(tài)、基因表達,呈現(xiàn)多組學的角度探討疾病發(fā)生發(fā)展。這不就完成了Fig1還升華了Fig1的深度。
再多的操作文檔,總是不如實際操作來得理解深刻。百邁客云平臺(BMKCloud)實現(xiàn)你零基礎(chǔ)分析的所有夢想!52款APP實現(xiàn)高度自由個性化分析,118款工具、交互的個性化分析提供無上限分析實操,云平臺課堂高效助您方案設(shè)計和信息分析(http://www.biocloud.net/),百邁客云成為您的私人信息分析平臺,讓基因分析更簡單。
所以大家快快動起手來,在實際操作中理解學習,若在學習中有不懂或疑問的地方,您可以點擊下方按鈕與我們聯(lián)系,我們可以提供相應的分析服務。