rm(list = ls()) library(pheatmap) #Reference Package expFile="geneexpr.txt" #Expression Input File clusterFile="Cluster.txt" #Clustering result file cliFile="clinicaldata.txt" #Clinical data files #Reading input files exp=read.table(expFile, header=T, sep="\t", check.names=F, row.names=1) exp=t(exp) cluster=read.table(clusterFile, header=T, sep="\t", check.names=F, row.names=1) #Merging expression and typing data sameSample=intersect(row.names(exp), row.names(cluster)) exp=exp[sameSample, , drop=F] cluster=cluster[sameSample, , drop=F] expCluster=cbind(exp, cluster) Project=gsub("(.*?)\\_.*", "\\1", rownames(expCluster)) library(tidyverse) rownames(expCluster)=str_replace_all(rownames(expCluster),"TCGA_","") rownames(expCluster)=str_replace_all(rownames(expCluster),"GSE17538_","") rownames(expCluster)=str_replace_all(rownames(expCluster),"GSE39582_","") expCluster=cbind(expCluster, Project) #Merging clinical data cli=read.table(cliFile, header=T, sep="\t", check.names=F, row.names=1) sameSample=intersect(row.names(expCluster), row.names(cli)) expCluster=expCluster[sameSample,,drop=F] cli=cli[sameSample,,drop=F] data=cbind(expCluster, cli) data$fustat[data$fustat==1]="Dead" data$fustat[data$fustat==0]="Alive" #Extracting heatmap data data=data[order(data$cluster),] Type=data[,((ncol(exp)+1):ncol(data))] data=t(data[,1:ncol(exp)]) #Cluster Color bioCol=c("#0066FF","#FF9900","#FF0000","#6E568C","#7CC767","#223D6C","#D20A13","#FFD121","#088247","#11AA4D") ann_colors=list() CluCol=bioCol[1:length(levels(factor(Type$cluster)))] names(CluCol)=levels(factor(Type$cluster)) ann_colors[["cluster"]]=CluCol #Heatmap Visualization pdf("heatmap.pdf", height=6, width=9) pheatmap(data, annotation=Type, annotation_colors = ann_colors, color = colorRampPalette(c(rep("blue",5), "white", rep("red",5)))(100), cluster_cols =F, cluster_rows =F, scale="row", show_colnames=F, fontsize=6, fontsize_row=6, fontsize_col=6) dev.off()