############################## #Created on Oct 07 2019 #@author: Yu-Chuan Chang ############################## ############################## # import libraries ############################## library(sqldf) library(RColorBrewer) library(gplots) library(amap) ############################## # set parameters ############################## str_inputFileName_gtex <- "~/Projects/bmcbioinformatics/GTEx/GTEx_Analysis_v6p_RNA-seq_RNA-SeQCv1.1.8_gene_median_rpkm.gct" str_outputFilePath <- "~/Projects/bmcbioinformatics/GTEx/" list_genes <- c("ADAMTS12","APOE","BACH2","CACNA1E","CLEC16A","LINC00299","MICB","PARVA","SYT6","TNKS2","TOB2","VSNL1","CLEC1A","GPR142","IFT20","MFSD6L","PRKAG2-AS1","RPL32") ############################## # define functions ############################## customizedHeatmap <- function(df_input){ matrix_input_heatmap <- data.matrix(df_input[,3:length(df_input)]) rownames(matrix_input_heatmap) <- df_input[,"Description"] #normalization matrix_input_heatmap <- (t(apply(matrix_input_heatmap, 1, function(x)scale(x))) + 1) * 50 colnames(matrix_input_heatmap) <- colnames(df_input)[3:length(df_input)] #heatmap: clustering function fun_h <- function(x) hclust(x, method = "ward.D") # ward.D complete fun_Dist <- function(x) Dist(x, method="pearson") # pearson euclidean spearman #heatmap: plot .png color_palette <- colorRampPalette(brewer.pal(9,"PuBu"))(100) png(paste0(str_outputFilePath, "./GTEx_Heatmap.png"), height=1200, width=900, pointsize=15) heatmap_result <- heatmap.2(matrix_input_heatmap, margins = c(20,7), col=color_palette, distfun=fun_Dist, hclustfun = fun_h, Rowv=T, Colv=F, dendrogram="row", key=T, keysize=1.0, srtCol=90, srtRow=45, key.xlab="Normalized RPKM", labRow=rownames(matrix_input_heatmap), cexRow=1, symkey=F, breaks=c(0:100), trace="none") dev.off() } ############################## # main function ############################## df_gtex <- read.table(str_inputFileName_gtex, skip=2, header=T, sep="\t") df_genelist <- data.frame(GeneSymbol=list_genes) df_genelist_unique <- sqldf("SELECT DISTINCT(GeneSymbol) FROM df_genelist WHERE GeneSymbol!=''") df_heatmap <- sqldf("SELECT gtex.* FROM df_genelist_unique gene LEFT JOIN df_gtex gtex ON gene.GeneSymbol==gtex.Description WHERE gtex.Name is not null") paste("Query", nrow(df_genelist_unique), "genes and", nrow(df_genelist_unique)-nrow(df_heatmap),"of them missed in GTEx Database.", sep=" ") customizedHeatmap(df_heatmap)