#install.packages("pheatmap")
library(pheatmap) #引用包
expFile="uniSigGeneExp.txt" #32 表达数据文件
geneCluFile="geneCluster.txt" #32 基因分型的结果文件:样本名称 基因分型结果
prgCluFile="PRGcluster.txt" #24 细胞焦亡分型的结果文件:样本名称 细胞焦亡分型结果
cliFile="clinical.txt" #24 临床数据文件 ID AGE GENDER T N
#设置工作目录
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)
#三个文件取交集,合并数据
exp=as.data.frame(t(exp))
sameSample=intersect(row.names(exp), row.names(prgClu))
exp=exp[sameSample,,drop=F]
#三个文件cbind,列名为geneClu,PRGcluster
expData=cbind(exp, geneCluster=geneClu[sameSample,], PRGcluster=prgClu[sameSample,])
#Project为TCGA GSE
Project=gsub("(.*?)\\_.*", "\\1", rownames(expData))#TCGA GSE
rownames(expData)=gsub("(.*?)\\_(.*?)", "\\2", rownames(expData))
expData=cbind(expData, Project)
#合并临床数据
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)
#提取热图数据
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,#注释颜色
#热图颜色,低表达蓝色,高表达红色 c(rep("blue",5), "white", rep("red",5))
color = colorRampPalette(c(rep("#56B1F7",5), "white", rep("pink",5)))(50),
cluster_cols =F,#对列不聚类
cluster_rows =F,#对行不聚类
scale="row",#对行校正
show_colnames=F,#显示列名称
show_rownames=F,#显示行名称
#字体大小
fontsize=6,
fontsize_row=2,
fontsize_col=6)
dev.off()
网友评论