#install.packages("pheatmap")
library(pheatmap)? ? ? ? #引用包
expFile="uniSigGeneExp.txt"? ? ? ? #32 表達(dá)數(shù)據(jù)文件
geneCluFile="geneCluster.txt"? ? ? #32 基因分型的結(jié)果文件:樣本名稱 基因分型結(jié)果
prgCluFile="PRGcluster.txt"? ? ? ? #24 細(xì)胞焦亡分型的結(jié)果文件:樣本名稱 細(xì)胞焦亡分型結(jié)果
cliFile="clinical.txt"? ? ? ? ? ? #24 臨床數(shù)據(jù)文件 ID AGE GENDER T N
#設(shè)置工作目錄
setwd("D:/※zixue/dead/140prgTME/34.geneHeatmap")
#讀取輸入文件
exp=read.table(expFile, header=T, sep="\t", check.names=F, row.names=1)
prgClu=read.table(prgCluFile, header=T, sep="\t", check.names=F, row.names=1)
geneClu=read.table(geneCluFile, header=T, sep="\t", check.names=F, row.names=1)
#三個(gè)文件取交集,合并數(shù)據(jù)
exp=as.data.frame(t(exp))
sameSample=intersect(row.names(exp), row.names(prgClu))
exp=exp[sameSample,,drop=F]
#三個(gè)文件cbind,列名為geneClu,PRGcluster
expData=cbind(exp, geneCluster=geneClu[sameSample,], PRGcluster=prgClu[sameSample,])
#Project為T(mén)CGA GSE
Project=gsub("(.*?)\\_.*", "\\1", rownames(expData))#TCGA GSE
rownames(expData)=gsub("(.*?)\\_(.*?)", "\\2", rownames(expData))
expData=cbind(expData, Project)
#合并臨床數(shù)據(jù)
cli=read.table(cliFile, header=T, sep="\t", check.names=F, row.names=1)
cli[,"Age"]=ifelse(cli[,"Age"]=="unknow", "unknow", ifelse(cli[,"Age"]>65,">65","<=65"))
sameSample=intersect(row.names(expData), row.names(cli))
expData=expData[sameSample,,drop=F]
cli=cli[sameSample,,drop=F]
data=cbind(expData, cli)
#提取熱圖數(shù)據(jù)
data=data[order(data$geneCluster),]
Type=data[,((ncol(data)-2-ncol(cli)):ncol(data))]
data=t(data[,1:(ncol(expData)-3)])
#聚類顏色
bioCol=c("#0066FF","#FF9900","#FF0000","#6E568C","#7CC767","#223D6C","#D20A13","#FFD121","#088247","#11AA4D")
ann_colors=list()
#PRGcol
PRGcol=bioCol[1:length(levels(factor(Type$PRGcluster)))]
names(PRGcol)=levels(factor(Type$PRGcluster))
ann_colors[["PRGcluster"]]=PRGcol
#GENEcol
GENEcol=bioCol[1:length(levels(factor(Type$geneCluster)))]
names(GENEcol)=levels(factor(Type$geneCluster))
ann_colors[["geneCluster"]]=GENEcol
#熱圖可視化
pdf("heatmap.pdf", height=6, width=8)
pheatmap(data,
? ? ? ? #注釋文件
? ? ? ? annotation=Type,
? ? ? ? annotation_colors = ann_colors,#注釋顏色
? ? ? ? #熱圖顏色,低表達(dá)藍(lán)色,高表達(dá)紅色 c(rep("blue",5), "white", rep("red",5))
? ? ? ? color = colorRampPalette(c(rep("#56B1F7",5), "white", rep("pink",5)))(50),
? ? ? ? cluster_cols =F,#對(duì)列不聚類
? ? ? ? cluster_rows =F,#對(duì)行不聚類
? ? ? ? scale="row",#對(duì)行校正
? ? ? ? show_colnames=F,#顯示列名稱
? ? ? ? show_rownames=F,#顯示行名稱
? ? ? ? #字體大小
? ? ? ? fontsize=6,
? ? ? ? fontsize_row=2,
? ? ? ? fontsize_col=6)
dev.off()
