Skip to content
Snippets Groups Projects
Commit 5b7e2930 authored by Hubble's avatar Hubble
Browse files

“heatmap_hhb_version_2”

parent 30ca219e
No related branches found
No related tags found
1 merge request!5Heatmap
...@@ -5,37 +5,71 @@ library("stringr") ...@@ -5,37 +5,71 @@ library("stringr")
Args <- commandArgs() Args <- commandArgs()
csv_data = fread(Args[6]) correlation_file = Args[6]
head(csv_data) p_file = Args[7]
m_data <- melt(csv_data, id.vars=c("V1")) trait_name = fread(correlation_file)
head(m_data) trait_name <- as.list(names(trait_name))
trait_name <- trait_name[-1]
pG = ggplot(m_data, aes(x = V1, y = variable, fill = value)) + geom_tile(color = "darkgrey") + scale_fill_stepsn(colors=c(low = "#075AFF", trait_name <- data.table(ID = trait_name)
trait_name$ID <- sapply(trait_name$ID, toString)
setkey(trait_name, "ID")
Rho = fread(correlation_file)
setkey(Rho, "V1")
Pval = fread(p_file)
setkey(Pval, "V1")
Rho = Rho[trait_name$ID , c("V1",trait_name$ID), with=FALSE]
Pval = Pval[trait_name$ID , c("V1",trait_name$ID), with=FALSE]
cor_long = melt(as.data.table(Rho),id.vars=c('V1'))
order_trait <- trait_name$ID
pval_long =melt(as.data.table(Pval),id.vars=c('V1'))
pval_long[,value := value*((dim(Rho)[1]-1)^2/2) ]
pval_long[,pval_annote := c("***","**","*",".","")[.bincode(pval_long$value, c(-1, 0.001, 0.01, 0.05,0.1,1))]]
pval_long[is.na(pval_long$pval_annote), pval_annote:=""]
pval_long[,cor_val:= signif(round(cor_long$value, 2), 2)]
pval_long[,full_annot := str_trim(paste0(cor_val, "\n",pval_annote))]
pval_long$full_annot[pval_long$full_annot == "1"] <- ""
cor_long[, variable:=ordered(cor_long$variable, levels=order_trait)]
cor_long[, V1:=ordered(cor_long$V1, levels=order_trait)]
pval_long[, variable:=ordered(pval_long$variable, levels=order_trait)]
pval_long[, V1:=ordered(pval_long$V1, levels=order_trait)]
pG = ggplot(cor_long, aes(x = V1, y = variable, fill = value)) + geom_tile(color = "darkgrey") + scale_fill_stepsn(colors=c(low = "#075AFF",
mid = "#FFFFCC",high = "#FF0000"), n.breaks=21, limits=c(-1,1), show.limits=T) mid = "#FFFFCC",high = "#FF0000"), n.breaks=21, limits=c(-1,1), show.limits=T)
pG = pG + coord_fixed() + xlab("") + ylab("")+ theme_minimal() + theme(axis.text = element_text(size=11), axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) pG = pG + coord_fixed() + xlab("") + ylab("")+ theme_minimal() + theme(axis.text = element_text(size=11), axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
pG = pG + theme(legend.key.size = unit(1, 'cm'), #change legend key size pG = pG + theme(legend.key.size = unit(1, 'cm'), #change legend key size
legend.key.height = unit(2, 'cm'), #change legend key height legend.key.height = unit(2, 'cm'), #change legend key height
legend.key.width = unit(1, 'cm'), #change legend key width legend.key.width = unit(1, 'cm'), #change legend key width
legend.title = element_text(size=14), #change legend title font size legend.title = element_text(size=14), #change legend title font size
legend.text = element_text(size=10)) legend.text = element_text(size=10))
pG = pG + geom_text(data=m_data, aes(x=V1,y=variable,label=value), size=3.5)
pG = pG + geom_text(data=pval_long, aes(x=V1,y=variable, label=full_annot), size=3.5)
png(paste("HeatMap_", strsplit(Args[6], split=".", fixed=T)[[1]][1],".png", sep=""),width = 20, height = 20, png(paste("HeatMap_", strsplit(Args[6], split=".", fixed=T)[[1]][1],".png", sep=""),width = 20, height = 20,
units = "in", units = "in",
res = 300, res = 300,
pointsize = 4) pointsize = 4)
print(pG) print(pG)
dev.off() dev.off()
...@@ -116,10 +116,7 @@ process Make_HeatMap { ...@@ -116,10 +116,7 @@ process Make_HeatMap {
params.compute_LDSC_matrix params.compute_LDSC_matrix
""" """
for matrix_csv in ${matrix_csv_files} Rscript ${make_heatmap_script} Correlation_matrix_genetic.csv Pval_cor_matrix_genetic.csv
do
Rscript ${make_heatmap_script} \$matrix_csv
done
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment